是否可以在threeJS中选择线对象?
我尝试过raycaster
http://jsfiddle.net/nelsonlbtn/z43hjqm9/43/
运行测试时出现此错误
three.min.js:598 Uncaught TypeError: d.distanceTo is not a function
at pb.distanceSqToSegment (three.min.js:598)
at pa.raycast (three.min.js:650)
at xe (three.min.js:295)
at uf.intersectObjects (three.min.js:863)
at HTMLDocument.moveMouse ((index):107)
有什么解决方案?
答案 0 :(得分:1)
问题是您为线创建了自己的几何点。 (https://threejs.org/docs/#api/en/objects/Line)
您应该使用THREE.Vector3构造函数,而不是创建自己的对象。原因是THREE.Vector3在其原型上有一个称为distanceTo的方法。手动创建坐标时,缺少该方法。
... inside the your init function ...
// instead of
/* p1 = {
x: 0,
y: 0,
z: -100
}
p2 = {
x: 100,
y: 0,
z: 0
} */
// do this
p1 = new THREE.Vector3(0,0,-100)
p2 = new THREE.Vector3(100,0,0)
... more init function ...
上线有点困难,但有可能。
答案 1 :(得分:1)
Three.js中的点的定义如下:
p1 = new THREE.Vector3( 0, 0, - 100 );
p2 = new THREE.Vector3( 100, 0, 0 );
使用未缩小的版本three.js
进行调试;使用three.min.js
进行生产。
更新的小提琴:http://jsfiddle.net/z43hjqm9/45/
three.js r.97