Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js Updating mesh of TubeGeometry object

Tags:

three.js

I'm trying to create an tube and ability to interact with that tube like dragging mouse to change the start point/end point of the tube .For that I modify directly vertices position values and I would like update object in the scene

However, I've struck a problem with the tube object I'm using: when I update the path points the mesh object doesn't update on the screen, so it seems like I can't modify it after it's been created.

My 3d object creation is roughly like this:

var curve = new THREE.SplineCurve3([new THREE.Vector3(x, y, z), new THREE.Vector3(x2, y2, z2)]);
var geometry = new THREE.TubeGeometry(curve, segments, 2, radiusSegments, closed);
geometry.dynamic = true;
var tubeMesh = THREE.SceneUtils.createMultiMaterialObject(geometry, [new THREE.MeshBasicMaterial({color: 0xffffff, opacity: 1, transparent: true})]);
scene.add(tubeMesh);    

And when I want to update the points. I'm doing it like this:

tubeMesh.children[0].geometry.path.points[0] = new THREE.Vector3(x4, y4, z4));
tubeMesh.children[0].geometry.path.points[1] = new THREE.Vector3(x3, y3, z3));
tubeMesh.children[0].geometry.verticesNeedUpdate = true;

However, when I make changes the object doesn't seem to update on screen. Is it possible to do this with a Tube?

like image 943
user1533481 Avatar asked Sep 10 '12 12:09

user1533481


1 Answers

You have only provided code fragments, but you probably need

geometry.verticesNeedUpdate = true;

and

geometry.dynamic = true;

You can find more detail and examples in the Three.js wiki about how to update things with WebGLRenderer.

https://github.com/mrdoob/three.js/wiki/Updates

like image 62
WestLangley Avatar answered Oct 01 '22 08:10

WestLangley