topical media & game development

talk show tell print

mobile-query-three-plugins-ogsworkshop-examples-physicsr45-CollisionUtils.js / js



  

author: bartek drozdz / everyday3d.com/

  
  
  THREE.CollisionUtils = {};
  
  // @params m THREE.Mesh
  //
returns: CBox dynamic Object Bounding Box
THREE.CollisionUtils.MeshOBB = function( m ) { m.geometry.computeBoundingBox(); var b = m.geometry.boundingBox; var min = new THREE.Vector3( b.x[0], b.y[0], b.z[0] ); var max = new THREE.Vector3( b.x[1], b.y[1], b.z[1] ); var box = new THREE.BoxCollider( min, max ); box.mesh = m; return box; } // @params m THREE.Mesh //
returns: CBox static Axis-Aligned Bounding Box
// // The AABB is calculated based on current // position of the object (assumes it won't move) THREE.CollisionUtils.MeshAABB = function( m ) { var box = THREE.CollisionUtils.MeshOBB( m ); box.min.addSelf( m.position ); box.max.addSelf( m.position ); box.dynamic = false; return box; }; // @params m THREE.Mesh //
returns: CMesh with aOOB attached (that speeds up intersection tests)
THREE.CollisionUtils.MeshColliderWBox = function( m ) { var mc = new THREE.MeshCollider( m, THREE.CollisionUtils.MeshOBB( m ) ); return mc; };


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.