javascript - Three.js and collision detection -


i'm quite new in 3d , threejs.

i set scene ground, on top of ground lots of cubes.

http://jsfiddle.net/whurp02s/1/

i'm trying select cubes cross yellow rectangle.

so looked @ exemple on internet , found raycaster object , it's intersectobject function

//**************** colision detection     var caster = new three.raycaster();     var collisions = [];      var rays = [       new three.vector3(0, 0, 1),       new three.vector3(1, 0, 1),       new three.vector3(1, 0, 0),       new three.vector3(1, 0, -1),       new three.vector3(0, 0, -1),       new three.vector3(-1, 0, -1),       new three.vector3(-1, 0, 0),       new three.vector3(-1, 0, 1)     ];      ( var = 0; < rays.length; += 1 ) {         caster.set( squaretl.position, rays[i] );          for( var boxid in boxgroup ) {             var boxobj = boxgroup[boxid];              collisions = caster.intersectobject( boxobj );              if ( collisions.length ) {                 console.log(collisions);             } else console.log("no colision");         }      } 

but 0 collision found.

there obvious i'm missing...

i've looked @ jsfiddle code , i've seen few things should help:

-your "boxgroup" array needs populated array containing object , not object itself

-the statement: if ( collisions.length) should changed (collisions.length >0) . in case length > 1

-optional actions: add collision logic animation/run loop

-i create new jsfeedle code specific collition work less objects. should easier debug , understand.

good luck, j3zusla


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -