1

How to dynamically change the radius of a mesh based on the TubeGeometry at runtime.

Here is how I create the mesh:

var points = new THREE.SplineCurve3([
  new THREE.Vector3(source.x, source.y, source.z),
  new THREE.Vector3(target.x, target.y, target.z)
]);
var geometry = new THREE.TubeGeometry(points, 10, 1, 10, false, false);
geometry.dynamic = true;
var material =  new THREE.MeshLambertMaterial({color:0x0000cc});
var mesh = new THREE.Mesh(geometry, material);

And here how I try to update the radius of the tube:

var geometry = mesh.geometry;
geometry.radius = 200;
geometry.verticesNeedUpdate = true;
mesh.updateMatrix();

Unfortunately it does not update the tube radius. How is it done correctly? Is it possible at all?

medihack
  • 16,045
  • 21
  • 90
  • 134

1 Answers1

3

The radius parameter is only used during construction of the geometry. Changing it will have no effect.

You could change mesh.scale, but that will likely not work as you would like in your case due to the spline curve. ( It would work for a CyllinderGeometry. )

three.js r.58

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • Indeed, the radius of a tube can't be easily changed by scaling it. I am using a cylinder now (as I only connect two points) using [this solution](http://stackoverflow.com/questions/15316127/three-js-line-vector-to-cylinder) (reference if someone else got stuck here). – medihack May 02 '13 at 22:20