Class Node
Pakotne: @aspose/3d (v24.12.0)
Mezgls pārstāv nosauktu elementu ainas grafika hierarhijā. Katram mezglam ir lokāla transformācija, tas var saturēt bērna mezglus un nes nulles vai vairākas Entity objektus, piemēram, režģus, kameras vai gaismas.
export class Node extends SceneObjectImageRenderOptions
A3DObject ← SceneObject ← Node
ImageRenderOptions
Izveidojiet vecāku mezglu, pievienojiet tam divus bērna mezglus un pārlūkojiet visu hierarhiju pēc nosaukuma.
import { Scene, Node } from '@aspose/3d';
const scene = new Scene();
const root = scene.rootNode;
const vehicle = root.createChildNode('vehicle');
const body = vehicle.createChildNode('body');
const wheel = vehicle.createChildNode('wheel_front_left');
function traverse(node: Node, depth = 0): void {
console.log(' '.repeat(depth * 2) + node.name);
for (const child of node.childNodes) {
traverse(child, depth + 1);
}
}
traverse(root);
// Output:
// vehicle
// body
// wheel_front_left
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | string | Šī mezgla nosaukums. Lietots, lai identificētu mezglu ainas grafika ietvaros. |
parentNode | `Node | null` |
childNodes | Node[] | Masīvs ar tiešajiem bērna mezgliem, kas pievienoti šim mezglam. |
entities | Entity[] | Saraksts ar vienībām (režģi, kameras, gaismas utt.), kas pievienotas šim mezglam. |
materials | Material[] | Materiālu saraksts, kas saistīts ar šo mezglu. |
transform | Transform | Šī mezgla lokālais transformējums, ar translation: Vector3, rotation: Quaternion, un scaling: Vector3 komponentes. |
globalTransform | GlobalTransform | Tikai lasāms. Pasaules telpas transformējums, aprēķināts, reizinot visus priekšgājējus transformējumus līdz saknei. |
visible | boolean | Vai šis mezgls un tā apakškoks tiek renderēti. Noklusējuma vērtība ir true. |
excluded | boolean | ImageRenderOptions true, mezgls un tā apakškoks tiek izslēgti no eksporta. Noklusējuma vērtība ir false. |
entity | `Entity | undefined` |
ImageRenderOptions
addChildNode(node)
Pievieno esošu Node instanci kā tiešu bērnu šim mezglam.
addChildNode(node: Node): voidImageRenderOptions
node Node
Mezgls, ko pievienot. Mezgls tiek pārcelts no savas pašreizējās vecāka uz šo mezglu.
ImageRenderOptions
void
ImageRenderOptions
import { Scene, Node } from '@aspose/3d';
const scene = new Scene();
const parent = scene.rootNode.createChildNode('parent');
const child = new Node('child');
parent.addChildNode(child);
console.log(`Children of parent: ${parent.childNodes.length}`); // 1
createChildNode(name?, entity?, material?)
Izveido jaunu Node, pēc izvēles ar nosaukumu, entītiju un materiālu, un pievieno to kā bērnu šim mezglam.
createChildNode(name?: string, entity?: Entity, material?: Material): NodeImageRenderOptions
name string (pēc izvēles)
Nosaukums jaunajam bērna mezglam.
entity Entity (pēc izvēles)
Entītija, ko pievienot jaunajam mezglam, piemēram, Mesh instanci.
material Material (pēc izvēles)
Materiāls, ko saistīt ar jauno mezglu.
ImageRenderOptions
Node
Jaunizveidotais bērna mezgls.
ImageRenderOptions
import { Scene } from '@aspose/3d';
import { Mesh } from '@aspose/3d/entities';
const scene = new Scene();
const mesh = new Mesh();
// ... populate mesh ...
const meshNode = scene.rootNode.createChildNode('geometry', mesh);
console.log(`Node name: ${meshNode.name}`);
console.log(`Entities attached: ${meshNode.entities.length}`);evaluateGlobalTransform(withGeometricTransform)
Aprēķina un atgriež pasaules telpas transformācijas matricu šim mezglam. Padod true lai iekļautu mezglā saglabāto ģeometriskā transformācijas nobīdi (izmanto dažas FBX eksportētājas).
evaluateGlobalTransform(withGeometricTransform: boolean): Matrix4ImageRenderOptions
withGeometricTransform boolean
ImageRenderOptions true, iekļauj ģeometrisko transformāciju rezultātā.
ImageRenderOptions
Matrix4
4×4 pasaules telpas transformācijas matrica.
ImageRenderOptions
import { Scene } from '@aspose/3d';
const scene = new Scene();
scene.open('model.fbx');
const node = scene.rootNode.childNodes[0];
const matrix = node.evaluateGlobalTransform(false);
console.log('World transform matrix computed.');getBoundingBox()
Aprēķina šī mezgla un visus tā pēcnācējus pasaules telpā esošo as‑izlīdzināto robežkasti.
getBoundingBox(): BoundingBoxImageRenderOptions
BoundingBox
As‑izlīdzinātā robežkaste, kas aptver visu ģeometriju zem šī mezgla.
ImageRenderOptions
import { Scene } from '@aspose/3d';
const scene = new Scene();
scene.open('model.obj');
const bbox = scene.rootNode.getBoundingBox();
console.log(`Min: ${JSON.stringify(bbox.minimum)}`);
console.log(`Max: ${JSON.stringify(bbox.maximum)}`);merge(node)
Apvieno cita mezgla saturu (tā elementus, materiālus un bērnus) ar šo mezglu un noņem avota mezglu no ainas.
merge(node: Node): voidImageRenderOptions
node Node
Avota mezgls, kura saturs tiek apvienots šajā mezglā.
ImageRenderOptions
void
ImageRenderOptions
import { Scene } from '@aspose/3d';
const scene = new Scene();
scene.open('multi_part.fbx');
const root = scene.rootNode;
if (root.childNodes.length >= 2) {
root.childNodes[0].merge(root.childNodes[1]);
console.log(`Children after merge: ${root.childNodes.length}`);
}