Skip to content Skip to sidebar Skip to footer

Controlling The Scaling Of Custom Geometries In Three.js

I have a custom object which is a subtraction of two meshes. This subtraction creates a frame-like object. createFrame (x, y, z) { const frameMesh = new THREE.Mesh(new THREE.Bo

Solution 1:

The scale() method transforms every vertex equally by multiplying their positions. So if you have the inner edge of the frame at x=6, and the outer edge at x=10, scaling it by 2 would give you inner: x=12, outer: x=20, making the frame 8 units wide.

To alleviate this, you could separate your frame into 4 different boxes: top, bottom, left and right. When you want to scale it in the x-axis, you can stretch top & bottom, and simply move the left and right edges. That way you maintain the thickness of 4:

The inverse can be done when you want to scale on the y-axis. You stretch the left & right boxes, then move the top & bottom so they line up.

Post a Comment for "Controlling The Scaling Of Custom Geometries In Three.js"