Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var map;
- var maparray = [];
- var meshwithphysicsarray = [];
- var physicsobjects = [];
- var loader = new THREE.ObjectLoader();
- function loadmap( url ) {
- loader.load( url, function( obj ) {
- console.log( url + ' LOADED' );
- map = obj;
- maparray = map.children;
- world.scene.add( map );
- } );
- }
- var applyphysicsloop = setInterval( function() {
- if ( map ) {
- maparray.forEach( applyphysics );
- }
- }, 1 );
- function applyphysics( mesh ) {
- ///////////////////////////////////CUBE////////////////////////////////////////////////
- if ( mesh.name.indexOf( '[PhyBox]' ) != - 1 ) {
- if ( meshwithphysicsarray.indexOf( mesh ) != - 1 ) {
- physicsobjects.forEach( function( physicsobject ) {
- if ( physicsobject.native.name == mesh.name ) {
- mesh.position.x = physicsobject.native.position.x;
- mesh.position.y = physicsobject.native.position.y;
- mesh.position.z = physicsobject.native.position.z;
- mesh.quaternion._w = physicsobject.native.quaternion._w;
- mesh.quaternion._x = physicsobject.native.quaternion._x;
- mesh.quaternion._y = physicsobject.native.quaternion._y;
- mesh.quaternion._z = physicsobject.native.quaternion._z;
- }
- } );
- } else {
- var box = new WHS.Box( {
- geometry: {
- width: mesh.geometry.parameters.width,
- height: mesh.geometry.parameters.height,
- depth: mesh.geometry.parameters.depth
- },
- mass: Number( mesh.name.replace( /\D/g, '' ) ),
- material: {
- kind: 'basic',
- color: 0xffffff
- },
- position: {
- x: mesh.position.x,
- y: mesh.position.y,
- z: mesh.position.z
- }
- } );
- box.native.name = mesh.name;
- box.native.visible = false;
- box.addTo( world );
- physicsobjects.push( box );
- meshwithphysicsarray.push( mesh );
- }
- }
- /////////////////////////////////////////SPHERE////////////////////////////////////////////
- if ( mesh.name.indexOf( '[PhyBall]' ) != - 1 ) {
- if ( meshwithphysicsarray.indexOf( mesh ) != - 1 ) {
- physicsobjects.forEach( function( physicsobject ) {
- if ( physicsobject.native.name == mesh.name ) {
- mesh.position.x = physicsobject.native.position.x;
- mesh.position.y = physicsobject.native.position.y;
- mesh.position.z = physicsobject.native.position.z;
- mesh.quaternion._w = physicsobject.native.quaternion._w;
- mesh.quaternion._x = physicsobject.native.quaternion._x;
- mesh.quaternion._y = physicsobject.native.quaternion._y;
- mesh.quaternion._z = physicsobject.native.quaternion._z;
- }
- } );
- } else {
- var sphere = new WHS.Sphere( {
- geometry: {
- radius: mesh.geometry.parameters.radius
- },
- mass: Number( mesh.name.replace( /\D/g, '' ) ),
- material: {
- color: 0xffffff,
- kind: 'lambert'
- },
- position: {
- x: mesh.position.x,
- y: mesh.position.y,
- z: mesh.position.z
- }
- } );
- sphere.native.name = mesh.name;
- sphere.native.visible = false;
- sphere.addTo( world );
- physicsobjects.push( sphere );
- meshwithphysicsarray.push( mesh );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement