【发布时间】:2020-06-23 04:13:43
【问题描述】:
尝试在 Threejs 背景上对齐 HTML 内容,我需要将 div 与 3d 平面匹配。
按照this post,我能够让 div 跟随平面位置,但即使遵循 this post 的建议,我仍然无法确定方向
到目前为止,这是我的代码:
screenPlane.updateWorldMatrix()
screenPlane.getWorldPosition(tempV)
screenPlane.getWorldQuaternion(tempQuat)
tempRotationV3.copy(screenPlane.up ).applyQuaternion(tempQuat)
tempV.project(camera)
const x = (tempV.x * .5 + .5) * container.clientWidth
const y = (tempV.y * -.5 + .5) * container.clientHeight
div.style.transform = `translate(-50%, -50%) translate(${x}px,${y}px) `
div.style.transform += ` rotateX(${tempRotationV3.x}rad) rotateY(-${tempRotationV3.y}rad) rotateZ(${tempRotationV3.z}rad)`
位置不错,但方向明显坏了:
任何帮助将不胜感激。
【问题讨论】:
-
你考虑过使用 CSS3DRenderer 吗? threejs.org/docs/index.html#examples/en/renderers/CSS3DRenderer 该页面中有一些演示。
-
出于某种原因,我确信它已从 3 中弃用,我会调查一下,这绝对是个好主意。
标签: matrix three.js quaternions