Vector3 unproject issue


I am havin a problem in order to convert screen coordinates into 3d world coordinates.

The goal is to project 3d screen coord into the near plane of my camera.
In my code I am using this function:

function screenPositionToWorldPosition(pos) {
		var screenNormalizedPosition = new THREE.Vector3(pos.x / canvas_w * 2 - 1, -pos.y / canvas_h * 2 + 1, 0);
		var vector = new THREE.Vector3( screenNormalizedPosition.x, screenNormalizedPosition.y, -1 ).unproject( aCamera );
		console.log("world near plane coords: ", vector);
		return vector;

In the version v113 this is not working, it doesn’t matter which 2d scrren coordinates I pass to the function the 3d coords are always the same.

In the previous version I used this function it was working v101.

Best regards

Starting with R103, Vector3.unproject() does not recompute the inverse projection matrix anymore. This already happened automatically when calling updateProjectionMatrix(). Try to call this method (and updateMatrixWorld() in order to ensure all relevant matrices are up-to-date before using Vector3.unproject().

Hi Mikel.

It doesn’t work, here you can see:

console.log(new THREE.Vector3(0, 0, 0.5).unproject(aCamera));
    Vector3 {x: 26749.836375147395, y: 50204.284069682326, z: 4162.34619140625}

console.log(new THREE.Vector3(0, 0.5, 0.5).unproject(aCamera));
         Vector3 {x: 26749.836375147395, y: 50204.284069682326, z: 4162.351550390079}

Best regards

Hi Mikel.

I have done a small trace and it seems that the argument camera on unproject function on three.js is not properly taken.

Best regards

Not sure what you mean by that. The implementation of Vector3.unproject() looks correct.

Can you please demonstrate with a small editable live example the wrong behavior?