SceneUtils

A class containing useful utility functions for scene manipulation.

Import

SceneUtils is an add-on, and must be imported explicitly. See Installation / Addons.

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

Methods

.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 : BufferGeometry, 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.

.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 ) : undefined

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, three.js 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).

.traverseGenerator ( object : Object3D ) : Generator

object — The 3D object to traverse.

A generator based version of Object3D.traverse().

.traverseVisibleGenerator ( object : Object3D ) : Generator

object — The 3D object to traverse.

A generator based version of Object3D.traverseVisible().

.traverseAncestorsGenerator ( object : Object3D ) : Generator

object — The 3D object to traverse.

A generator based version of Object3D.traverseAncestors().

Leave a comment

Your email address will not be published. Required fields are marked *