Monday, 3 December 2018

THREE JS draw line as a child of object pointing to Vector non related with object or parents

I have scene with objects as a parent /child.

I need to define a Vector3 relative to (deepest) child object which pointing on vector in scene (look_point).

var grandParent = new THREE.Object3D();
var parent = new THREE.Object3D();
var child= new THREE.Object3D();

var look_point = new THREE.Vector3();

grandParent.position.set(9,5,3);
grandParent.rotation.set(1,2,3);

parent.position.set(5,8,3);
parent.rotation.set(2,1,3);

child.position.set(2,5,3);
child.rotation.set(3,2,1);

scene.add(grandParent);
grandParent.add(parent);
parent.add(child);



var m = new THREE.LineBasicMaterial({ color: 0xFF00FF, blending: THREE.AdditiveBlending,  transparent: true, opacity: 1, depthTest: false })

/// draw line in scene
var v = new THREE.Vector3().copy(child.position);
    v = parent.localToWorld(v);
    v = grandParent.localToWorld(v);

var g = new THREE.Geometry();

    g.vertices.push(new THREE.Vector3().copy(v)); 
    g.vertices.push(new THREE.Vector3().copy(look_point));   


scene.add(new THREE.Line(g,m));    

// how to get relative points to draw line with child object as a parent

var g2 = new THREE.Geometry();

    g2.vertices.push(???); //// how to get Vector3 relative to child pos and rot?
    g2.vertices.push(new THREE.Vector3());   

child.add(new THREE.Line(g2,m));  



from THREE JS draw line as a child of object pointing to Vector non related with object or parents

No comments:

Post a Comment