SceneUtils.js 1.3 KB

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