Darbas su scenų grafika
Darbas su scenų grafika
Kiekviena 3D scena Aspose.3D Java organizuojama kaip mediena. Node ir objektų. Scene Tai yra viena šaknis - getRootNode() - ir kiekvienas geometrijos, medžiagos ir gyvybės transformacijos gabalas po to šaknis kaip vaikas ar palikuonis.
Sukurkite sceną ir prieigą prie šaknų mazgo
Scene pradeda automatizuoti su šaknų mazgais, pavadinta "RootNode":
import com.aspose.threed.Scene;
import com.aspose.threed.Node;
Scene scene = new Scene();
Node root = scene.getRootNode(); // always "RootNode"Vaikų nodo pridėjimas
Kvietimas createChildNode() bet kokio mazgo pridėti vaiką. metodas turi tris paprastai naudojamas perpildymus:
import com.aspose.threed.*;
Scene scene = new Scene();
Node root = scene.getRootNode();
// 1. Named node with no entity — useful as a pivot or group container
Node pivot = root.createChildNode("pivot");
// 2. Named node with an entity
Mesh mesh = new Mesh("box");
mesh.getControlPoints().add(new Vector4(0, 0, 0));
mesh.getControlPoints().add(new Vector4(1, 0, 0));
mesh.getControlPoints().add(new Vector4(1, 1, 0));
mesh.getControlPoints().add(new Vector4(0, 1, 0));
mesh.createPolygon(0, 1, 2, 3);
Node meshNode = root.createChildNode("box", mesh);
// 3. Named node with entity and material
PbrMaterial mat = new PbrMaterial("red");
mat.setAlbedo(new Vector4(0.8f, 0.2f, 0.2f, 1.0f));
Node decorated = pivot.createChildNode("red_box", mesh, mat);Norėdami pridėti mazgą, kuris buvo pastatytas atskirai, naudokite addChildNode():
Node detached = new Node("standalone");
root.addChildNode(detached);Vaikų noras NODS
Ieškoti tiesioginio vaiko pagal vardą arba indeksą, arba iterate visus tiesioginius vaikus:
// By name — returns null if no direct child has that name
Node found = root.getChild("box");
if (found != null) {
System.out.println("Found: " + found.getName());
}
// By index
Node first = root.getChild(0);
// Iterate all direct children
for (Node child : root.getChildNodes()) {
System.out.println(child.getName());
}
getChild(String name)Ieškoti tik Tiesioginiai vaikai,Ne visą žemę, bet tai yra.accept()apsilankys tik vadinamasis mazgas; iterategetChildNodes()Iš karto ieškoti viso medžio.
Per visą medį
node.accept(NodeVisitor) aplanko tik vadinamąjį mazgą – jis neatsiranda į vaikus. Per visą medį, iterate getChildNodes() Atgal – lankytojas grįžta true tęsti arba false Netrukus sustoti:
import com.aspose.threed.NodeVisitor;
// Print every node name in the scene
scene.getRootNode().accept(n -> {
System.out.println(n.getName());
return true; // false would stop traversal
});
// Stop after finding the first node that has an entity
final Node[] found = {null};
scene.getRootNode().accept(n -> {
if (n.getEntity() != null) {
found[0] = n;
return false; // stop walking
}
return true;
});NodeVisitor Tai vienkartinis sąsaja, todėl ji priima lambda Java 8+.
Matomumo ir eksporto išimties kontrolė
Nodos gali būti paslėptos arba pašalinamos iš eksporto, nepašalinant jų iš hierarchijos:
Node ground = root.createChildNode("ground_plane", mesh);
ground.setVisible(false); // hidden in viewport / renderer
Node helperNode = root.createChildNode("debug_arrow", mesh);
helperNode.setExcluded(true); // omitted from all export operationssetVisible(false) Tai yra parodų indikacija. setExcluded(true) nuda neatsiranda eksportuojamų failų, nepriklausomai nuo formato.
Įtraukti kelias vienetas į vieną mazgą
Nuda turi vieną pirminė Įmonė (getEntity() / setEntity()• Galima naudoti papildomas įstaigas, kuriose addEntity().Tai naudinga, kai skirtingi kaukolės gabalai dalijasi vienu transformacija:
Mesh body = new Mesh("body");
Mesh wheel = new Mesh("wheel");
Node carNode = root.createChildNode("car");
carNode.addEntity(body);
carNode.addEntity(wheel);
// Retrieve all entities on this node
for (Entity ent : carNode.getEntities()) {
System.out.println(ent.getName());
}Įtempti NODS
merge() perkelia visus vaikus, subjektus ir medžiagas iš šaltinio mazgo į tikslinį mazgą. šaltinis mazgas paliekamas tuščias:
Node lod0 = root.createChildNode("lod0");
lod0.createChildNode("mesh_high", mesh);
Node lod1 = root.createChildNode("lod1");
lod1.createChildNode("mesh_low", mesh);
// Consolidate lod0 children into lod1
lod1.merge(lod0);
// lod1 now has both mesh_high and mesh_low; lod0 is emptyGreitas API atsiliepimas
| narys | Aprašymas |
|---|---|
scene.getRootNode() | Šaknis scenoje medžio; visada esantis po new Scene() |
node.createChildNode(name) | Sukurkite vardą vaiko mazgas be subjekto |
node.createChildNode(name, entity) | Sukurkite vadinamą vaiko mazgą su subjektu |
node.createChildNode(name, entity, material) | Sukurkite vadinamą vaiko mazgą su subjektu ir medžiaga |
node.addChildNode(node) | Atskirai pastatytas Node |
node.getChild(name) | Ieškoti tiesioginio vaiko pagal vardą; grįžta null Jei nerasite |
node.getChild(index) | Įsitikinkite, kad vaikas yra ant tam tikro indekso. |
node.getChildNodes() | List<Node> Visiems tiesioginiams vaikams |
node.accept(visitor) | Apsilankykite tik šiame mazgoje (neatsiranda į vaikus) |
node.addEntity(entity) | Pridėkite papildomą subjektą prie mazgo |
node.getEntities() | List<Entity> Visi šios grupės subjektai |
node.setVisible(bool) | Parodyti arba paslėpti mazgą |
node.setExcluded(bool) | Įtraukti arba pašalinti mazgą iš eksporto |
node.merge(other) | Iš visų vaikų ir subjektų išsiunčiama other Į šį mazgą |