View3D: project/unproject

Software: Away3D 4.x

D.M., Newbie
Posted: 23 April 2012 09:04 PM   Total Posts: 5

I need transform mouse coordinates to 3d-coords. I find some methods in view3d: project and unproject.
But i don’t understand why i got different results when i make for example:

var sceneVector:Vector3D = new Vector3D(event.sceneX, event.sceneY, event.sceneZ)
var p:Point = view3D.project(sceneVector);
//p.x == view3D.mouseX and p.y == view3D.mouseY
var v:Vector3D = view3D.unproject(p.x, p.y);
// in this case sceneVector != v

Why it happens? How i can method unproject() to get same result as in sceneVector?
I just want to construct 3d coordinates when i click on free space on scene (not on object), when 3d events not firing. Maybe you can advise better solutions?

Thanks!

   

bradbury, Newbie
Posted: 11 September 2012 11:47 AM   Total Posts: 4   [ # 1 ]

BUMP!

Any help on this?

   

bradbury, Newbie
Posted: 11 September 2012 12:35 PM   Total Posts: 4   [ # 2 ]

Solved it myself: Borrowed some code from Drag3d, simplified it for our purpose - targetZ is the z position of the layer you want to project your stage cords to.

public static function get2dTo3dPosition(view:View3Dposition2d:Vector3DtargetZ:Number):Vector3D
{
 
var targetPosAtCameraNull:Vector3D view.unproject(position2d.xposition2d.y);
 var 
targetDifferenceZ:Number = -view.camera.position.targetZ;

 var 
originDifference:Number targetDifferenceZ view.camera.position.z;
 var 
unprojectDifference:Number targetDifferenceZ targetPosAtCameraNull.z;
 var 
factor:Number unprojectDifference / (unprojectDifference originDifference);

 var 
result:Vector3D view.camera.position.subtract(targetPosAtCameraNull);
 
result.scaleBy(factor);
 
result result.add(targetPosAtCameraNull);
 return 
result;
   

bradbury, Newbie
Posted: 15 November 2012 06:12 PM   Total Posts: 4   [ # 3 ]

Bump again

Above method is just a workaround, doesn’t work on rotated layers (since it just takes target z into consideration).

So. Is there a reverse method (or combination) for .project()?

Anyone? Is this thing on?

   

Avatar
Rob Bateman, Administrator
Posted: 17 November 2012 10:13 PM   Total Posts: 120   [ # 4 ]

This error has been noted and patched in hotfix: https://github.com/away3d/away3d-core-fp11/commit/21a6cea0f

After review early next week, the fix should be merged with master and dev branches. If there are any aspects of the patch that don’t work as expected, please let us know in this thread

   

Avatar
Rob Bateman, Administrator
Posted: 22 November 2012 02:51 PM   Total Posts: 120   [ # 5 ]

patch is now live in master branch. Link to specific commit:

https://github.com/away3d/away3d-core-fp11/commit/21a6cea0fa

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X