Scene Graph와 함께 작업하는 방법

Scene Graph와 함께 작업하는 방법

Scene Graph와 함께 작업하는 방법

Java를 위한 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() 단지 소위 노드만 방문; iterate getChildNodes() 다시 나무 전체를 찾는 방법.


완전한 나무를 건너다

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 operations

setVisible(false) 그것은 표시 힌트입니다. setExcluded(true) 노드가 형식에 관계없이 수출 된 파일에 나타나지 않도록합니다.


여러 개의 단체를 하나의 노드에 연결하는 방법

노드가 하나를 가지고 있다. 원시적 멤버(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 empty


API 빠른 참조

회원설명
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 이 노드에 들어가서
 한국어