Doc > API > PolyScene

Doc > API > PolyScene

PolyScene contains all nodes within a scene.

Methods

.threejsScene(): Scene

Returns the THREE.Scene.

Read more about how to use a THREE.Scene on THREE's documentation

.mainCamera()

Returns the camera object that has been set as main

.waitForCooksCompleted(): Promise

Returns a promise to wait for all nodes to have cooked when loading a scene.

.setRaycaster(raycaster: Raycaster)

When using Polygonjs viewers, a raycaster is created to use mouse events

and detect if there are any object under the cursor.

But if no viewer is created, such as when importing a scene in react three fiber,

It is then useful to give a raycaster.

.createNode( nodeClass: S, paramsInitValueOverrides?: ParamsInitData ): ObjNodeChildrenMap[S];

Creates a new node.

nodeClass can be either a string or a node class. Both examples below work:

  • polyScene.createNode('box'): returns a BoxSopNode

  • polyScene.createNode(boxSopNode): returns a BoxSopNode

.nodesByType(type: string): BaseNodeType[]

returns all nodes with a given type

  • polyScene.nodesByType('box'): returns all BoxSopNodes
.findObjectByMask(mask: string): Object3D | undefined

returns a THREE.Object3D whose name matches the mask

.objectsByMask(mask: string): Object3D[]

returns a list THREE.Object3Ds whose names matche the mask

.setFrame(frame: number)

sets the current frame

.frame(): number

returns the current frame

.time(): number

returns the current time

.play()

starts playing the scene

.pause()

pauses the scene

.incrementTime(options?: TimeControllerUpdateTimeOptions)

increments the time

.incrementTimeIfPlaying(options?: TimeControllerUpdateTimeOptions)

increments the time if the scene is playing()

.registerRenderer(renderer: WebGLRenderer, options?: RegisterRendererOptions)

registers a renderer

.batchUpdates(callback: SceneBatchUpdateCallback)

batchUpdates can be useful to set multiple parameter values without triggering a recook for each update.

.node(path: string)

returns a node based on its path

  • polyScene.node('/geo1')
.root()

returns the root node

.traverseNodes(callback: (node: BaseNodeType) => void)

traverse all nodes and runs a callback for each

.registerOnBeforeTick(callbackName: string, callback: onTimeTickHook): void

registers a BeforeTick callback. BeforeTick callbacks are run before updating the frame (and therefore before any time dependent node has changed)

.unRegisterOnBeforeTick(callbackName: string): void

unregisters BeforeTick callback

.registeredBeforeTickCallbacks(): Map

Returns the list registered BeforeTick callback names

.registerOnAfterTick(callbackName: string, callback: onTimeTickHook): void

registers AfterTick callback. AfterTick callbacks are run after updating the frame (and therefore after any time dependent node has changed)

.unRegisterOnAfterTick(callbackName: string): void

unregisters AfterTick callback

.registeredAfterTickCallbacks(): Map

Returns the list registered AfterTick callback names

source