# 场景工具（[name]）

一个用于操控场景的实用类。

## 进口

[name] 是一个附加组件，必须显式导入。 See [link:#manual/introduction/Installation Installation / Addons].

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

## 方法

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

instancedMesh -- 实例化网格。

为给定的实例化网格的每个实例，创建一个包含新网格的新物体组（Object Group）。

### [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 -- 材料集的几何形状。
materials -- 为物体准备的材料。

创建一个新组，囊括了在材质中定义的每种材质的新网格。请注意，这和为一个网格定义多种材质的材质数组不同。
该方法对于同时需要材质和线框绘制的物体非常有用。

### [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]().

## 源代码

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