mrdoob/three.js — Issue #1473: strange problem with __dirtyVertices = true!
Author: VelvetValve
Created: 2012-03-08 18:32:01+00:00
State: open

hey guys, i got a really strange problem with procedurally changing vertices positions when the mouse button is pressed.

i got 2 jquery handlers for mouse down and mouse up recognition that set a global mouseDownPos variable to the mouse coordinates and to undefined respectively. here they are:

// MOUSE DOWN HANDLER
$(renderer.domElement).mousedown(function(event) {
mouseDownPos = new THREE.Vector2(event.pageX, event.pageY);
});

// MOUSE UP HANDLER
$(renderer.domElement).mouseup(function(event) {
mouseDownPos = undefined;
});

now in my render loop, if I put the following piece of code, the respective object won't move a micron, not when the mouse is pressed nor when it is released.

if (shapes.length > 0 && mouseDownPos != undefined) {
console.log(mouseDownPos);

var object = shapes[0];

console.log(object.geometry.vertices[0].position.x );

for (var i = 0; i < object.geometry.vertices.length; i++) {
object.geometry.vertices[i].position.x += 5;
}

object.geometry.dynamic = true;
object.geometry.__dirtyVertices = true;
}

strangely, however, when I leave out the mouseDownPos != undefined part, it will move constantly as expected, regardless of whether mouse is pressed or not. and even more strangeley, when I turn it into mouseDownPos == undefined it will only move if the mouse button is released - as expected again! And even one step more strangely :D in the above version when I console.log the respecitve positions of the vertices they will increase, but they are not updated for presentation.

could someone tell me what I am overseeing here, please?? :D I would be really grateful! :)

mike