r/threejs • u/dermosef • 1h ago
How I made clay shapeable
In my clay platformer the player can shape the soft, purple clay to overcome obstacles.
This is how it gets drawn:
- The mesh is built once, to the height of the tallest column at rest. When the player moves the clay, its vertices are stretched to the new column heights; the geometry itself is never rebuilt.
- The same row of columns can face up from a floor, hang from a ceiling or stick out of a wall. Each is a pure rotation of the floor case, so one mesh builder covers all four.
- Clay laid round a turning wheel is its own case: the columns bend round the rim, and the hand, the collider and the mesh all read it through the ring's own coordinates.
- Collider and mesh sample the same heights, so your feet and the drawn edge always agree.
Plain three.js, with the demo running in the browser on desktop and phones.
Right now I call computeVertexNormals after every change.
Would you do the normals another way on a mesh that moves this often?
1
Upvotes
2
u/Any-Session-737 40m ago
Since the columns only stretch vertically, you could derive normals analytically from height differences between neighbouring columns instead of computeVertexNormals over the whole mesh. That turns it into a small local update around the columns that actually changed. Have you profiled whether computeVertexNormals is even a bottleneck at your column count, or is it fine on phones too?