(An improved version of my earlier answer).
This jsfiddle illustrates 3 ways of aligning child cones.
Red cone has fixed orientation relative to its parent box.
Green cone is aligned so that its' z-axis is aligned to the white world cone.
Blue cone has its' XYZ axes co-aligned with the XYZ axes of the white world cone.
CODE (from the init function):-
cone_geometry = new THREE.CylinderGeometry(3, 40, 120, 40, 10, false);
//... The following mod is as recommended by WestLangley's answer at:-
//... http://stackoverflow.com/questions/13757483/three-js-lookat-seems-to-be-flipped
//... cone.LookAt(PosX) will then point the cone Z-axis towards PosX
//... (assuming cone.position and PosX are relative to the same coordinate system).
cone_geometry.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI / 2 ) );
CORE CODE (from the update/animate function):-
worldCone.lookAt(target.position);
var worldVec = new THREE.Vector3();
worldVec.copy(target.position).sub(worldCone.position);
worldBox.rotation.x += 0.01;
worldBox.rotation.y += 0.03;
worldBox.rotation.z += 0.02;
var localVec = new THREE.Vector3();
localVec = F_get_LocalDirectionVector_relativeTo_Object3D_of_WorldDirectionVector
( worldBox, worldVec, localVec) ;
//=================================================================
function F_get_LocalDirectionVector_relativeTo_Object3D_of_WorldDirectionVector
( givenObject, WDV, LDV)
{
givenObject.updateMatrixWorld();
//FLABBY method: - works but verbose and excessive object creation
/*
var ob_InvWorldQuaternion = new THREE.Quaternion();
ob_InvWorldQuaternion = ob_WorldQuaternion.inverse();
LDV.copy( WDV ).applyQuaternion( ob_InvWorldQuaternion );
*/
//LEAN method: copies WDV value into LDV
//then applies inverse world quaternion of givenObject.
LDV.copy( WDV )
.applyQuaternion(
givenObject.getWorldQuaternion().inverse()
);
return LDV;
}
//=================================================================
//... Apply localVec
//... Get the localCone_G to point in the direction of the LocalVec
var localCone_G_target_pos = new THREE.Vector3();
//... LHS becomes sum of two RHS vectors
localCone_G_target_pos.addVectors( localCone_G.position, localVec );
//... ORIENT THE CHILD CONES
//...Cone_R has fixed orientation relative to parent cube
localCone_R.lookAt(1,0,0);
//... Cone_G has z-vector pointing in the same direction as world cone
localCone_G.lookAt(localCone_G_target_pos);
//... Cone_B has its' xyz axes aligned with the world cone
localCone_B.lookAt(1,0,0);
localCone_B.quaternion.multiply( worldBox.getWorldQuaternion().inverse() );
localCone_B.quaternion.multiply( worldCone.quaternion );