Scene
| Type | Name | Interface Description |
|---|---|---|
| Functions | createSceneObject(name: string) : SceneObject | • Function: Creates a new SceneObject object and assigns it a specified name. • Return Value: Returns the created SceneObject object. • Default Behavior: By default, newly created objects are mounted in the 3D scene if no parent object is set. |
Example
let newObject = scene.createSceneObject("MyObject");
newObject.parent = this.getSceneObject();
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
const scene = this.getSceneObject().scene;
const newObj = scene.createSceneObject("test");
newObj.parent = this.getSceneObject();
const obj = scene.findSceneObject("test");
console.log('test name:', obj?.name);
}
onUpdate(deltaTime: number) {
}
}
| Type | Name | Interface Description |
|---|---|---|
| Functions | removeSceneObject(obj: SceneObject): boolean | • Function: Remove the specified SceneObject object from the scene. • Return value: If the removal is successful, returns true; otherwise, returns false. |
| Functions | getRootSceneObjects(): SceneObject[] | • Function: Get all root-level SceneObject objects in the scene. • Return Value: Returns an array containing all root-level SceneObject objects. |
| Functions | findSceneObject(objName: string, root?: SceneObject):SceneObject | undefined | • Function: Find a SceneObject with the specified name in the scene. • Parameter: ◦ objName: The name of the object to be searched for. ◦ root: The starting node for the search. If it is null, the search starts from the root node of the scene. • Return Value: Returns the found SceneObject object; if not found, returns undefined. |
| Functions | getAllSceneObjects(): SceneObject[] | • Function: Get all SceneObject objects in the scene. • Return Value: Returns an array containing all SceneObject objects. |
Examples
removeSceneObject(obj: SceneObject): boolean
let result = scene.removeSceneObject(myObject);
getRootSceneObjects(): SceneObject[]
let rootObjects = scene.getRootSceneObjects();
findSceneObject(objName: string, root?: SceneObject):SceneObject | undefined
let foundObject = scene.findSceneObject("MyObject", null);
getAllSceneObjects(): SceneObject[]
let allObjects = scene.getAllSceneObjects();
Use Case
@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {
onStart() {
const scene = this.getSceneObject().scene;
let toBeRemovedSO = scene.findSceneObject("ToBeRemoved");
console.log("ToBeRemoved SceneObject Existed: ", toBeRemovedSO !== null);
toBeRemovedSO && scene.removeSceneObject(toBeRemovedSO);
console.log("Remove SceneObject");
toBeRemovedSO = scene.findSceneObject("ToBeRemoved");
console.log("ToBeRemoved SceneObject Existed: ", toBeRemovedSO !== null);
const rootObjects = scene.getRootSceneObjects();
for (const obj of rootObjects) {
console.log("Root SceneObject Name:", obj.name);
}
const allObjects = scene.getAllSceneObjects();
for (const obj of allObjects) {
console.log("All SceneObject Name:", obj.name);
}
}
onUpdate(deltaTime: number) {
}
}