[name]

A class containing useful utility functions for scene manipulation.

Import

[name] is an add-on, and must be imported explicitly. See [link:#manual/introduction/Installation Installation / Addons].

import * as SceneUtils from 'three/addons/utils/SceneUtils.js';

Methods

[method:Group createMeshesFromInstancedMesh]( [param:InstancedMesh instancedMesh] )

instancedMesh -- The instanced mesh.

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

[method:Group createMeshesFromMultiMaterialMesh]( [param:Mesh mesh] )

mesh -- A mesh with multiple materials.

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

[method:Group createMultiMaterialObject]( [param:BufferGeometry geometry], [param:Array materials] )

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.

[method:T reduceVertices]( [param:Object3D object], [param:function func], [param:T initialValue] )

object -- The object to traverse (uses [page:Object3D.traverseVisible 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.

[method:undefined sortInstancedMesh]( [param:InstancedMesh mesh], [param:Function compareFn] )

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

Sorts the instances within an [page: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 [link:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#description Array.prototype.sort] for more information on sorting callbacks and their return values.

Because of the high performance cost, three.js does not sort [page: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).

[method:Generator traverseGenerator]( [param:Object3D object] )

object -- The 3D object to traverse.

A generator based version of [page:Object3D.traverse]().

[method:Generator traverseVisibleGenerator]( [param:Object3D object] )

object -- The 3D object to traverse.

A generator based version of [page:Object3D.traverseVisible]().

[method:Generator traverseAncestorsGenerator]( [param:Object3D object] )

object -- The 3D object to traverse.

A generator based version of [page:Object3D.traverseAncestors]().

Source

[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/utils/SceneUtils.js examples/jsm/utils/SceneUtils.js]