Show HN: Three and React = react-three-fiber, a new renderer based on Fiber
github.com
github.com
I think the performance increase for a large project with a complex scene graph could be drastic compared to handling it manually - just like vanilla js would not easily get even with react unless you implement change detection, read/write queues, etc. With react-fibers scheduling the difference will only get larger since now it can bail out of or defer actions that would blow the 60fps frame budget.
As for memory and immutability, the actual v-dom tree is next to nothing, a node is a couple of bytes. This is the same as for a huge dom UI app with millions of divs and spans and table fields. The logical tree never hurts. One big problem with THREE has always been garbage and the object overhead - it's super easy to create leaks or create objects needlessly
mesh.position.copy(xyz.clone())
I've been doing three for a couple of years now and to not be wasteful takes a lot of discipline as basically everything nudges you into re-creating objects since re-use can have unexpected side-effects. With the reconciler you can stow away objects into the graph, which means they're managed. Probably will reduce the memory footprint in the end, even with a v-dom on top. function Text({ children, ...props }) {
const { camera, size, viewport } = useThree()
const { width } = viewport()
const canvas = useMemo(() => {
const canvas = document.createElement('canvas')
canvas.width = canvas.height = size.width * 2
const context = canvas.getContext('2d')
context.font = `bold ${size.width *
0.45}px -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, ubuntu, roboto, noto, segoe ui, arial, sans-serif`
context.textAlign = 'center'
context.fillStyle = 'black'
context.fillText(children, size.width, size.height + size.width * 0.4)
return canvas
}, [children, size.width])
return (
<sprite scale={[width, width]} {...props}>
<spriteMaterial name="material">
<canvasTexture name="map" image={canvas} premultiplyAlpha onUpdate={s => (s.needsUpdate = true)} />
</spriteMaterial>
</sprite>
)
}