I’m building a web app that involves integrating LEGO-style models along with canvas-based interactions and editing capabilities. I’m currently a bit confused about which frameworks would work best for this setup, so I’m looking for guidance on selecting the right tools especially for handling interactions and modifying the appearance of the models dynamically.
Following are features needed.
Features:
Lego models (.dat, .ldr)
Canvas
Drag n Drop
Collision detection
Physics (Weight, Smoothness)
Blocks connection feedback (Correctly connected or not)
After research, I have found following frameworks - need guidance if it’s good to go:
Frameworks:
Drag & Drop:
React Three Fiber + @react-three/drei
Uses useDragControls or built-in mesh event handlers
Handles 3D dragging in space
Canvas:
React Three Fiber ( component)
Creates the 3D viewport where blocks live
Wraps Three.js WebGL renderer
Collision Detection: @react-three/cannon (React wrapper)
Cannon.js (the actual physics engine)
Detects when blocks touch each other
Physics:
Cannon.js (same library as collision)
Handles gravity, weight, bouncing
Makes blocks feel realistic
Toolbar: Not sure what to use for changing appearance, colours etc..
Any guidance on toolchain recommendations, or best practices would be really appreciated!
That all looks like a decent starting point especially if you’re comfortable with react/r3f.
The only caution I would have is that applying physics to a lego simulation will be pretty tricky, and probably a lot more complicated than simply making a rigidbody for each brick. You’ll likely have to group them in their assembled blocks and create simplified collision representations for those functional units. (spheres/boxes/convex hulls)
webgpu may enable future optimizations/enhancements, but for the basic sim, it’s probably easier to start with webgl2 and only switch when you need to… or just use the defaults for r3f and follow their latest patterns.
I think the initial version of your system, it won’t matter which you choose. It will only start to matter when you start getting into advanced rendering/simulation techniques.
By itself, cannon doesn’t know about the kind of renderer… and for the kinds of rendering you’re gonna do initially (instancedMeshes most likely, or merged geometries).. the webgpu and webgl code will look almost identical.
webgpu is a new layer of the rendering stack that gives you more fine grained control over the rendering process itself, at the expense of some complexity, and learning curve.
Try searching here on the discourse “webGPU” and look at the types of questions and dates that they are from to get an idea of some of the kinds of issues you may confront while trying to get webgpu rolling, as it is still in very active development, as opposed to the main webgl renderer which has been in development/being debugged, for over a decade.
Thanks for the great suggestion And for the toolbars and controls Instead leva.js what options we have for full fledged controls like here Mecabricks.com | Workshop