Replies: 1 comment
-
Imperative code should live in effects or a import { createRoot } from 'react-dom/client'
import { OrbitControls, useGLTF } from '@react-three/drei'
import { extend, useFrame, Canvas } from '@react-three/fiber'
import { useMemo, Suspense } from 'react'
import * as THREE from 'three'
import { uniform, skinning, PointsNodeMaterial } from 'three/nodes'
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js'
class PointsNode extends THREE.Points {
constructor(node) {
const material = new PointsNodeMaterial()
material.colorNode = uniform(new THREE.Color())
material.positionNode = skinning(node)
super(node.geometry, material)
}
}
extend({ PointsNode })
function Model() {
const gltf = useGLTF('models/gltf/Michelle.glb')
const mixer = useMemo(() => new THREE.AnimationMixer(gltf.scene), [gltf])
useFrame((_, delta) => mixer.update(delta))
const points = useMemo(() => {
const _points = []
gltf.scene.traverse((node) => node.isMesh && _points.push(node))
return _points
}, [gltf])
return (
<>
<primitive visible={false} object={gltf.scene} />
{points.map((point) => (
<pointsNode key={point.uuid} args={[point]} />
))}
</>
)
}
createRoot(root).render(
<Canvas
frameloop="never"
gl={(canvas) => new WebGPURenderer({ canvas })}
camera={{ fov: 50, position: [0, 300, -85] }}
onCreated={(state) => {
state.gl.init().then(() => state.set({ frameloop: 'always' }))
}}
>
<Suspense>
<Model />
</Suspense>
<OrbitControls target={[0, 0, -85]} />
</Canvas>,
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I've come across some source code that implements a GLTF model animated with ThreeJS as a PointCloud.
When I tried to change it to react format with this code and use it, I got this error.
and this is the code that i used
How do I fix it?
I'll also share the code implemented in threejs.
https://threejs.org/examples/?q=point#webgpu_skinning_points
Beta Was this translation helpful? Give feedback.
All reactions