ThreeJS scenegraph issues

370 views Asked by At

I have spent the last few days working on a rubik's cube in Three JS. I am almost done with it, but am having a problem with proper nesting of groups. Basically I have all the cubies made up and when one of the center cubies on a face is clicked, all cubies on that face are added to a group and the group is rotated. The problem is when I try to readd the cubie to the scene they go back to their original location, not the new rotated one. Here is an example if the top face is clicked

else if(cubie.position.x == 0 && cubie.position.y == 12.5 && cubie.position.z == 0){
    for(var i = scene.children.length - 1; i >=0; i--){
        var cubie = scene.children[i];
        if(cubie.position.y == 12.5){
            group.add(cubie);
        }
    }
    group.rotateOnAxis(new THREE.Vector3(0,-1,0), Math.PI/2);
}

and here is where I try to readd the cubie back to the scene

for(var i = group.children.length - 1; i >= 0; i--){
    scene.add(group.children[i]);
}
scene.remove(group);

if I comment out both lines, then one complete rotation appears, but since the cubies are now apart of group I cant rotate them again. If I remove the first line, and leave remove(group) then obviously the row disappears, but if I leave both lines in, then the cube doesn't change at all as if when I readd the cubie to the scene it takes its original place back...I have tried everything I can think of. Any help would be greatly appreciated

I will post the entire code to pastebin if anyone needs it. http://pastebin.com/vj6LgR0r

0

There are 0 answers