舞台グラフと共に働く
舞台グラフと共に働く
ジャワのためのAspose.3D のすべての 3D シーンは、木として組織されています。 Node 物体です。. Scene ひとつの根を提供する――。 getRootNode() 地質、物質のあらゆる部分とその根底にある生命を子どものか子孫として変える。.
シーンを作成し、ルートノードにアクセスする
Scene 自動的に起動する、名付けのルートノードで。 "RootNode":
import com.aspose.threed.Scene;
import com.aspose.threed.Node;
Scene scene = new Scene();
Node root = scene.getRootNode(); // always "RootNode"子どものノードを追加する
電話 createChildNode() 子供を追加するためのノードのいずれかで、この方法には3つの一般的に使用される過剰充電があります:
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);別々に構築されたノードを付けるには、使用する。 addChildNode():
Node detached = new Node("standalone");
root.addChildNode(detached);子供のノードを求める
名前の由来または指数による直接子を見つけるか、すべての直接の子をイタラートする:
// 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)検索のみ 直接児童,全土の木ではない!そのことを覚えておいてください。accept()ノードと呼ばれる単なる訪問; iterategetChildNodes()再び、木全体を探す。.
満樹を渡る。
node.accept(NodeVisitor) ノードと呼ばれるだけを訪問する――それは子供たちに戻らない。 getChildNodes() 返信:訪問者回復 true 続けるか、または false 早めに止まる:
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 単一の方法インターフェイスなので、Java 8+でLambdaを受け入れる。.
見通しの制御と輸出排除
ノードは、階級から除去されずに輸出から隠されるか排除することができる。:
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) 展示ヒントです。. setExcluded(true) ノードがフォーマットに関係なく、輸出されたファイルに表示されるのを防ぐ。.
複数のエンティティを一つのノードに結びつけること
ノードはA 初心者 団体(getEntity() / setEntity()さらに、追加の団体を介して addEntity().これは、異なるメッシュパーツが単一の変換を共有する場合に有用です:
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());
}ノードの流れ
merge() すべての子ども、団体、材料をソースノードからターゲットノートに移動します。:
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 emptyAPI リファレンス
| メンバー | 説明 |
|---|---|
scene.getRootNode() | 舞台の木の根;常に現れる後 new Scene() |
node.createChildNode(name) | 名付け子ノードを作成する、エンティティなしで |
node.createChildNode(name, entity) | 子どものノードをエンティティと名付けます。 |
node.createChildNode(name, entity, material) | エンティティと材料を含む名称子ノードを作成する |
node.addChildNode(node) | 別々に建てられたもの。 Node |
node.getChild(name) | 名前の由来で直接子を見つける;返信 null 見つからなかったら |
node.getChild(index) | 直接子供を指数に付ける。 |
node.getChildNodes() | List<Node> すべての直接児童 |
node.accept(visitor) | このノードだけを訪問する(子供に戻らない) |
node.addEntity(entity) | ノードに追加のエンティティを加える |
node.getEntities() | List<Entity> このノードのすべてのエンティティから |
node.setVisible(bool) | ノードを表示または隠す |
node.setExcluded(bool) | ノードを輸出から含むか排除する。 |
node.merge(other) | すべての子どもや団体を動かすこと。 other このノードに |