import old three.js element into react three fiber? #2187
nikolaigeorgie
started this conversation in
General
Replies: 1 comment
-
You could put existing scene objects into primitives, often done with things created outside of fiber from loaders: <primitive object={myThreeObject} /> But a better way would be to wrap your objects into classes and extend them, that way you get to take advantage of the whole react lifecycle. import { extend } from '@react-three/fiber'
class MyObject extends THREE.Mesh {
constructor() {
const geometry = new THREE.BoxGeometry(1, 1, 1)
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 })
super(geometry, material)
}
}
// register object as a native jsx element
extend({ MyObject })
<myObject /> |
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
Uh oh!
There was an error while loading. Please reload this page.
-
I'm migrating an old project to react-three-fiber...
Is it possible to create a jsx component out of THREE.js and declare it in react-three/fiber?
Beta Was this translation helpful? Give feedback.
All reactions