Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing a THREE.CubeGeometry at runtime

Tags:

three.js

I am using Three.JS r58 and I would like to resize a CubeGeometry object on the screen.

One approach I tried is, when resizing required, to remove the effected cubes and add a new one with updated dimentions. This process works but it slows down the visualisation dramatically. I would like to know if there is a way to resize a CubeGeometry dynamically using Three.js rather than removing/adding a new one. A sample in jsfiddle is appreciated.

like image 505
Ali Salehi Avatar asked May 30 '13 12:05

Ali Salehi


1 Answers

Call .scale.set(x, y, z) on the mesh (see this ticket).

Initially the scale is set to (1, 1, 1) (see the constructor of Object3D, the parent class of Mesh). You will want to increase those values by the percentage scale you require, in the dimensions you require.

In this fiddle I increase the cube in all directions by 50 percent using .scale.set(1.5, 1.5, 1.5).

like image 133
theblang Avatar answered Oct 20 '22 00:10

theblang