javascript - Three.js:使用鼠标选择线条对象
问题描述
有没有办法在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)
有什么解决办法?
解决方案
问题是您为线创建了自己的几何点。(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 ...
打线有点困难,但有可能。
推荐阅读
- android - 滚动recyclerview时,滚动视图内的视图不滚动
- android - 如何使用Retrofit忽略JSON中根元素中的所有字段,但其中一个?
- angular - 在孩子中使用结构的指令模板
- firebase - Firebase 部署错误:y 中的编译错误:[E] 1:1 - 输入不匹配 '{' 期望 {'function'、'service'、'rules_version'}
- typescript - 解构数组正在从类型中删除可能的未定义值
- android - 在单元测试中覆盖类
- python - 带有通用 ELSE 子句的 IF 语句
- javascript - 如何在重复的某个字符后删除获取子字符串
- reporting-services - SSRS 从另一个数据集填充一个数据集的列
- css - 当我将页脚放在页面底部时,它位于页面中间