씬 그래프 작업

씬 그래프 작업

모든 3D 씬은 Aspose.3D for Java에서 트리 형태로 구성됩니다 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"

자식 노드 추가

Call createChildNode() 어떤 노드든 자식을 추가하려면 Call을 사용합니다. 이 메서드에는 일반적으로 사용되는 세 가지 오버로드가 있습니다:

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() 전체 트리를 검색합니다.


전체 트리 순회

node.accept(NodeVisitor) 노드와 그 모든 하위 노드를 깊이 우선 순서로 순회합니다. 방문자는 반환합니다 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+에서 람다를 허용합니다.


가시성 제어 및 내보내기 제외

Nodes can be hidden or excluded from export without being removed from the hierarchy:

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) 형식에 관계없이 노드가 내보낸 파일에 나타나는 것을 방지합니다.


Attaching Multiple Entities to One Node

노드에는 기본 entity (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());
}

Merging Nodes

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

Next Steps


API Quick Reference

멤버설명
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 이 노드로
 한국어