【发布时间】:2022-10-18 21:45:45
【问题描述】:
我正在处理这个反应项目,它使用threeJs对象,我升级了threeJs的版本,并且这部分代码说明了这个错误。
Text.js:16 Uncaught TypeError: self.geometry.computeBoundingBox is not a function
导致此问题的代码部分如下
const data = useLoader(FontLoader, font)
const geom = useAsset(() => new Promise((res) => res(new TextBufferGeometry(children, { font: data, size: 1, height, curveSegments: 32 }))), [children])
const onUpdate = useCallback(
(self) => {
const box = new Vector3()
self.geometry.computeBoundingBox(box)
self.geometry.boundingBox.getSize(box)
self.position.x = left ? 0 : right ? -box.x : -box.x / 2
self.position.y = top ? 0 : bottom ? -box.y : -box.y / 2
},
[left, right, top, bottom]
)
const ref = useRef()
let last = state.top.current
useFrame(() => {
ref.current.shift = lerp(ref.current.shift, (state.top.current - last) / 100, 0.1)
last = state.top.current
})
return (
<group {...props} scale={[size, size, 0.1]}>
<mesh geometry={geom} onUpdate={onUpdate} frustumCulled={false}>
<customMaterial ref={ref} color={color} transparent opacity={opacity} />
</mesh>
</group>
)
}
我正在寻找我应该调整此代码以在新版本中工作的方式
【问题讨论】:
-
你怎么称呼
onUpdate? -
@KonradLinkowski 我在问题本身中添加了它,谢谢
标签: javascript reactjs three.js react-three-fiber react-three-drei