SceneUtils.js 846 B

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