reactjs - Print rotation angles when rotating with TransformControls in R3F - Stack Overflow

I’m trying out R3F in React and rotating a capsule model using TransformControls (only on the Z-axis).

I’m trying out R3F in React and rotating a capsule model using TransformControls (only on the Z-axis). I want to print the current rotation angle whenever it changes, but only the initial angle gets logged, and the updated angles don’t appear. What’s the issue?

function SidePageModel2_1() {

  const capsuleRef = useRef()

  useEffect(() => {
    if (capsuleRef.current) {
      const geometry = capsuleRef.current.geometry
      geometry.translate(0, -1, 0)

      const euler = new THREE.Euler(0, 0, Math.PI / 4, 'XYZ')
      capsuleRef.current.rotation.copy(euler)

      console.log(capsuleRef.current.rotation)
    }
  }, [])

  return (
    <>
      <mesh position={[0, 0, 0]}>
        <boxGeometry args={[6, 0.5, 1]} />
        <meshStandardMaterial color="white" />
      </mesh>

      <TransformControls
        mode="rotate"
        position={[0, -1.2, 0]}
        onMouseDown={() => (orbitRef.current.enabled = false)}
        onMouseUp={() => (orbitRef.current.enabled = true)}
        showX={false}
        showY={false}
      >
        <mesh ref={capsuleRef} position={[0, 0, 0]}>
          <capsuleGeometry args={[0.5, 2, 32, 100]} /> 
          <meshStandardMaterial color="blue" />
        </mesh>
      </TransformControls>
    </>
  )
}

enter image description here

I want to output the changing angles, like the one in the image.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744308041a4567814.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信