SceneUtils.js 1.3 KB

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