SceneUtils.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ( function () {
  2. function createMeshesFromInstancedMesh( instancedMesh ) {
  3. const group = new THREE.Group();
  4. const count = instancedMesh.count;
  5. const geometry = instancedMesh.geometry;
  6. const material = instancedMesh.material;
  7. for ( let i = 0; i < count; i ++ ) {
  8. const mesh = new THREE.Mesh( geometry, material );
  9. instancedMesh.getMatrixAt( i, mesh.matrix );
  10. mesh.matrix.decompose( mesh.position, mesh.quaternion, mesh.scale );
  11. group.add( mesh );
  12. }
  13. group.copy( instancedMesh );
  14. group.updateMatrixWorld(); // ensure correct world matrices of meshes
  15. return group;
  16. }
  17. function createMultiMaterialObject( geometry, materials ) {
  18. const group = new THREE.Group();
  19. for ( let i = 0, l = materials.length; i < l; i ++ ) {
  20. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  21. }
  22. return group;
  23. }
  24. function detach( child, parent, scene ) {
  25. console.warn( 'THREE.SceneUtils: detach() has been deprecated. Use scene.attach( child ) instead.' );
  26. scene.attach( child );
  27. }
  28. function attach( child, scene, parent ) {
  29. console.warn( 'THREE.SceneUtils: attach() has been deprecated. Use parent.attach( child ) instead.' );
  30. parent.attach( child );
  31. }
  32. THREE.SceneUtils = {};
  33. THREE.SceneUtils.attach = attach;
  34. THREE.SceneUtils.createMeshesFromInstancedMesh = createMeshesFromInstancedMesh;
  35. THREE.SceneUtils.createMultiMaterialObject = createMultiMaterialObject;
  36. THREE.SceneUtils.detach = detach;
  37. } )();