three.js - Stretching towards a vector
问题描述
I am stumped.
I've created a line geometry in the shape of a spring, and I'd like to be able to transform this spring such that one end remains fixed in place while the other follows a vector3 position. The object3D.lookAt() method gets it pointing the right way, but I can't figure out a way to stretch it to that point.
I figure it'd be a matrix4.makeTransform() but I don't know how to calculate the amounts to scale in each direction. I thought it'd be simply dividing the x, y, and z coordinates of the endpoint of my spring and the target point, but that hasn't worked at all.
Is there a method to do this that I've somehow missed?
解决方案
您的 .lookAt 调用,使弹簧点成为自己的 z 轴(希望轴沿着弹簧的长度运行!如果您的网格设置正确!)
一旦你把它指向目标,你需要弄清楚目标有多远......
使用类似的东西
distance = new THREE.Vector3().copy(targetPoint).sub( springObject.position).length()
一旦您知道该距离,并假设您知道弹簧模型的默认长度,那么只需将弹簧的 z 轴比例设置为距离/defaultLength .. 类似于:
springObject.scale.z = defaultLength/distance
如果您已经将弹簧模型缩放了一定数量,这可能会有点复杂,您也必须考虑到这一点。
推荐阅读
- ruby-on-rails - 尝试使用活动存储上传文件时,无法允许:rails 控制器中的文件参数
- swiftui - 如何使分段选取器的最初选择的第一个分段响应?
- amazon-web-services - 如何将命令的输出设置为 AWS Codebuild 中的导出变量
- aws-lambda - 无服务器 - ApiGatewayResourcePostsUseridVar - 此资源的同级 ({postId}) 已经有一个可变路径部分 - 只允许一个
- javascript - 单击按钮时继续执行。DOM
- appimage - 除了将要执行的二进制文件之外,如何包含二进制文件?
- kubernetes - Kubernetes,Fluentd:匹配“stdout”日志
- three.js - three.js - 如何围绕lookAt(object)和相机位置之间的线旋转相机
- antlr4 - 在词法分析器中定义时,解析器警告中标记的隐式定义
- r - 在 R 中的值向量后添加百分比,并用单引号将每个值括起来