未验证 提交 8a896954 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #18603 from Mugen87/dev41

SceneUtils: Introduce createMeshesFromInstancedMesh().
......@@ -15,6 +15,13 @@
<h2>Methods</h2>
<h3>[method:Group createMultiMaterialObject]( [param:InstancedMesh instancedMesh] )</h3>
<p>
instancedMesh -- The instanced mesh.
</p>
<p>
Creates a new group object that contains a new mesh for each instance of the given instanced mesh.
</p>
<h3>[method:Group createMultiMaterialObject]( [param:Geometry geometry], [param:Array materials] )</h3>
<p>
......
......@@ -4,6 +4,32 @@
THREE.SceneUtils = {
createMeshesFromInstancedMesh: function ( instancedMesh ) {
var group = new THREE.Group();
var count = instancedMesh.count;
var geometry = instancedMesh.geometry;
var material = instancedMesh.material;
for ( var i = 0; i < count; i ++ ) {
var mesh = new THREE.Mesh( geometry, material );
instancedMesh.getMatrixAt( i, mesh.matrix );
mesh.matrix.decompose( mesh.position, mesh.quaternion, mesh.scale );
group.add( mesh );
}
group.copy( instancedMesh );
group.updateMatrixWorld(); // ensure correct world matrices of meshes
return group;
},
createMultiMaterialObject: function ( geometry, materials ) {
var group = new THREE.Group();
......
import { Geometry, Material, Object3D, Scene } from '../../../src/Three';
import { Geometry, Group, InstancedMesh, Material, Object3D, Scene } from '../../../src/Three';
export namespace SceneUtils {
export function createMultiMaterialObject( geometry: Geometry, materials: Material[] ): Object3D;
export function createMeshesFromInstancedMesh( instancedMesh: InstancedMesh ): Group;
export function createMultiMaterialObject( geometry: Geometry, materials: Material[] ): Group;
/**
* @deprecated Use scene.attach( child ) instead.
*/
export function detach( child: Object3D, parent: Object3D, scene: Scene ): void;
/**
* @deprecated Use parent.attach( child ) instead.
*/
export function attach( child: Object3D, scene: Scene, parent: Object3D ): void;
}
......@@ -9,6 +9,32 @@ import {
var SceneUtils = {
createMeshesFromInstancedMesh: function ( instancedMesh ) {
var group = new Group();
var count = instancedMesh.count;
var geometry = instancedMesh.geometry;
var material = instancedMesh.material;
for ( var i = 0; i < count; i ++ ) {
var mesh = new Mesh( geometry, material );
instancedMesh.getMatrixAt( i, mesh.matrix );
mesh.matrix.decompose( mesh.position, mesh.quaternion, mesh.scale );
group.add( mesh );
}
group.copy( instancedMesh );
group.updateMatrixWorld(); // ensure correct world matrices of meshes
return group;
},
createMultiMaterialObject: function ( geometry, materials ) {
var group = new Group();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册