SceneUtils.js 858 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Matrix4 } from '../math/Matrix4';
  2. import { Mesh } from '../objects/Mesh';
  3. import { Group } from '../objects/Group';
  4. var SceneUtils;
  5. /**
  6. * @author alteredq / http://alteredqualia.com/
  7. */
  8. SceneUtils = {
  9. createMultiMaterialObject: function ( geometry, materials ) {
  10. var group = new Group();
  11. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12. group.add( new Mesh( geometry, materials[ i ] ) );
  13. }
  14. return group;
  15. },
  16. detach: function ( child, parent, scene ) {
  17. child.applyMatrix( parent.matrixWorld );
  18. parent.remove( child );
  19. scene.add( child );
  20. },
  21. attach: function ( child, scene, parent ) {
  22. var matrixWorldInverse = new Matrix4();
  23. matrixWorldInverse.getInverse( parent.matrixWorld );
  24. child.applyMatrix( matrixWorldInverse );
  25. scene.remove( child );
  26. parent.add( child );
  27. }
  28. };
  29. export { SceneUtils };
粤ICP备19079148号