Hi!
I am trying to make an Earth sphere mesh to rotate towards a a clicked point in itself (change rotation but no position). I already have the clicked mesh point coords in this code:
var pickerPoint = new THREE.Vector3()
THREE.Mesh.prototype.raycast = (function () {
var originalRaycast = THREE.Mesh.prototype.raycast;
var localPoint = new THREE.Vector3 ()
return function (raycaster, intersects) {
originalRaycast.call (this, raycaster, intersects);
for (var i = 0, n = intersects.length; i < n; i++) {
if (this === intersects[i].object) {
this.worldToLocal (localPoint.copy (intersects[i].point));
var face = intersects[i].face
// Get the vertices intersected
let a = this.geometry.vertices[face.a];
let b = this.geometry.vertices[face.b];
let c = this.geometry.vertices[face.c];
// Averge them together
let vector = new THREE.Vector3( (a.x + b.x + c.x) / 3,
(a.y + b.y + c.y) / 3,
(a.z + b.z + c.z) / 3 )
pickerPoint = vector
}}}
})();
With this point I made a temporal mesh, set it with pickerPoint position and and looking towards to the World mesh position to copy its quaternion to the World mesh quaternion and make the rotation:
var world = new THREE.Mesh(new THREE.SphereGeometry(sphereRadius + 5 , sphereSegments,
sphereSegments), worldMeshMaterial)
lookAtPoint = (e) => { //called on dblclick event listener
let vector = new THREE.Vector3();
vector.set( ((e.clientX - 1) / window.innerWidth) * 2 - 1,
-((e.clientY - 1) / window.innerHeight) * 2 + 1,
0.5 )
raycaster.setFromCamera(vector, camera)
let target = raycaster.intersectObject(wireframedMesh, false)
if(target.length > 0){
var tempMaterial = new THREE.MeshPhongMaterial({color: '#ffea05', transparent: false, wireframe: true });
var worldPosition = new THREE.Vector3()
var temp = new THREE.Mesh(new THREE.SphereGeometry(0.5, 40 ,40), tempMaterial);
var qEnd = new THREE.Quaternion();
temp.position.copy(pickerPoint);
temp.lookAt(world.position);
temp.getWorldQuaternion(qEnd)
temp.quaternion.copy(qEnd)
temp.updateMatrix()
world.add(temp) //just to watch the reference point
this.makeTweenVector(world.rotation, { x: temp.rotation.x , y: temp.rotation.y, z: temp.rotation.z }, {
duration: 2000,
easing: TWEEN.Easing.Sinusoidal.InOut,
update: function(vector){
world.updateMatrixWorld(true)
},
})}}
The thing isā¦ the rotation is going to the exact opposed pickerPoint,I mean, itās rotating 180 degrees of the picked point, kinda inversed! I dont know why is it happening. Is it required to make pickerPoint.localToWorld maybe? A flip? Anyone overthere to help please? thanks!