SceneUtils

A class containing useful utility functions for scene manipulation.

Methods

.assignDefaultControls(camera : Camera, sceneBox : Box3)

camera — default scene camera.
sceneBox — bounding box which includes all objects located on the scene.

Assigns default control settings on the camera based on the given sceneBox param.

.calcSceneBox(scene : Scene) → Box3

scene — current scene.

Calculates scene bounding box.

.checkActionIsUsed(scene : Object3D, action : AnimationAction) → Boolean

scene — The scene to check if the action is used with one of the scene objects.
action — The action to check.

Checks if the given action is used with one of the scene objects, i.e. the action's target node exists on the scene.

.createDefaultCamera(sceneBox : Box3, aspect : Float) → Camera

sceneBox — scene box.
aspect — camera aspect ratio.

Creates default PerspectiveCamera which looks to the center of the scene bounding box.

.createEnvironmentMaterial(name : String, envTex : Texture, bkgTexOrColor : Texture | Color) → MeshNodeMaterial

name — material name.
envTex — environment texture.
bkgTexOrColor — background texture or color.

Create node-based material which can be used for environment lighting and scene background.

.createMeshesFromInstancedMesh(instancedMesh : InstancedMesh) → Group

instancedMesh — The instanced mesh.

Creates a new group object that contains a new mesh for each instance of the given instanced mesh.

.createMeshesFromMultiMaterialMesh(mesh : Mesh) → Group

mesh — A mesh with multiple materials.

Converts the given multi-material mesh into an instance of Group holding for each material a separate mesh.

.createMultiMaterialObject(geometry : Geometry, materials : Array) → Group

geometry — The geometry for the set of materials.
materials — The materials for the object.

Creates a new Group that contains a new mesh for each material defined in materials. Beware that this is not the same as an array of materials which defines multiple materials for 1 mesh.
This is mostly useful for objects that need both a material and a wireframe implementation.

.getAnimationActionByName(scope : App, animClipName : String) → AnimationAction

scope — The instance of application class.
animClipName — The name of the animation clip.

Search for animation action by its clip name.

.getMaterialByName(appInstance : App, matName : String) → Material

appInstance — application to search for the material.
matName — material name.

Find material by the given name. If not found, returns null.

.getMaterialsByName(appInstance : App, matName : String) → Material

appInstance — application to search for the materials.
matName — material name.

Find materials by the given name. If not found, returns [].

.reduceVertices(object : Object3D, func : Function, initialValue : T) → T

object — The object to traverse (uses traverseVisible internally).
func — The binary function applied for the reduction. Must have the signature: (value: T, vertex: Vector3) → T.
initialValue — The value to initialize the reduction with. This is required as it also sets the reduction type, which is not required to be Vector3.

Akin to Array.prototype.reduce(), but operating on the vertices of all the visible descendant objects, in world space. Additionally, it can operate as a transform-reduce, returning a different type T than the Vector3 input. This can be useful for e.g. fitting a viewing frustum to the scene.

.sortInstancedMesh(mesh : InstancedMesh, compareFn : Function)

mesh — InstancedMesh in which instances will be sorted.
compareFn — Comparator function defining the sort order.

Sorts the instances within an InstancedMesh, according to a user-defined callback. The callback will be provided with two arguments, indexA and indexB, and must return a numerical value. See Array.prototype.sort for more information on sorting callbacks and their return values.

Because of the high performance cost, Verge3D does not sort InstancedMesh instances automatically. Manually sorting may be helpful to improve display of alpha blended materials (back to front), and to reduce overdraw in opaque materials (front to back).

Source

For more info on how to obtain the source code of this module see this page.