0

我正在尝试在特定点将一个立方体附加到另一个立方体。我能够发生碰撞并且 .add() 工作正常。但是,我想在父多维数据集发生碰撞的点处添加子多维数据集。

for (var vertexIndex = 0; vertexIndex < MovingCube.geometry.vertices.length; vertexIndex++) {       
  var localVertex = MovingCube.geometry.vertices[vertexIndex].clone();
  var globalVertex = localVertex.applyMatrix4( MovingCube.matrix );
  var directionVector = globalVertex.sub( MovingCube.position );
  var ray = new THREE.Raycaster( originPoint, directionVector.clone().normalize() );
  var collisionResults = ray.intersectObjects( collidableMeshList );

  if ( collisionResults.length > 0 && collisionResults[0].distance < directionVector.length() )             
console.log(" Hit and collision detected " + SELECTED);
MovingCubeBig.add(SELECTED);

      // Is there way to get collision point and attach object at that point?


  } 
4

1 回答 1

0

交叉点结果应包含一个point属性。 https://github.com/mrdoob/three.js/blob/master/src/core/Raycaster.js#L255

也许你可以用它把孩子固定在正确的位置?

此外,这个例子可能有助于http://threejs.org/examples/#webgl_geometry_terrain_raycast

于 2013-10-10T13:07:55.600 回答