Hello,
I’m trying to access to geometry.vertices.length of my collada object in animate() to detect collisions.
I load my collada in init() :
loader.load('dae/myKart/myKart.dae', function ( collada ) {
myKart = collada.scene;
setObject(myKart,1,15,15,15,300,-28,-500,-Math.PI/2,0,0);
scene.add( myKart );
arrayObject.push(myKart);
myKart.userData.name = "kartControled";
myKart.userData.gameDone = false;
} );
And then I try to detect collisions but I have the error, can not read vertices of undefined :
if(myKart){
var originPoint = myKart.position.clone();
for (var vertexIndex = 0; vertexIndex < myKart.geometry.vertices.length; vertexIndex++)
{
var localVertex = myKart.geometry.vertices[vertexIndex].clone();
var globalVertex = localVertex.applyMatrix4( myKart.matrix );
var directionVector = globalVertex.sub( myKart.position );
var ray = new THREE.Raycaster( originPoint, directionVector.clone().normalize() );
var collisionResults = ray.intersectObject( collidableMeshList );
if ( collisionResults.length > 0 && collisionResults.distance < directionVector.length() )
appendText(" Hit ");
}
}
I don’t know if I can use myKart.userData.geometry ?
Thank you.