3d to 2d screen coordinates

Software: Away3D 4.x

macgor, Newbie
Posted: 25 November 2011 12:51 AM   Total Posts: 3

Hi,

I am trying to cycle trough vertexData of loaded 3ds model, and translate those 3d points to 2 x,y.
Loaded 3d object contains few separate meshes that after load I make clickable.
Exaclty what I’m trying do do is to mark clicked triangle verticies thae same way like in http://www.vatrobot.de/molehill_broomstick/HelloCube_VertexPoint2D.html

I am using hover controller and need to mark those verticies whenever I click on this.
I am looking for HelloCube_VertexPoint2D piece of code that do the trick, or anybody that can help me.
I tryed many ways but im getting every time distorted view or bad scale and not rotated (like should be because of camera hovering)

I have found pos on https://groups.google.com/group/away3d-dev/browse_thread/thread/142410f7be8f570c/03743242b435a2da?lnk=gst&q=screen+coordinates#03743242b435a2da

But probably I’m missing something..

Please help!

   

John Brookes, Moderator
Posted: 25 November 2011 02:22 AM   Total Posts: 732   [ # 1 ]

You dont need all that II wrote back then

view.project(worldVerticePosition)

would give you the 2d point


so

private function getVerticeWorldPosition(mesh:MeshvtxIndex:uintsubgIndex:uint 0): Vector3D
{
 
var iData:Vector.<uint> = mesh.geometry.subGeometries[subgIndex].indexData;
 var 
vData:Vector.<Number> = mesh.geometry.subGeometries[subgIndex].vertexData;
 var 
vtx:Vector3D = new Vector3D(vData[iData[vtxIndex]*3]vData[iData[vtxIndex]*1]vData[iData[vtxIndex]*2]);
 
vtx =  mesh.sceneTransform.transformVector(vtx)
 return 
vtx;

then something like

var stage2dPos:Point = view.project(getVerticeWorldPosition(plane, 0, 0));
sprite.x = stage2dPos.x
sprite.y = stage2dPos.y

   

macgor, Newbie
Posted: 25 November 2011 07:45 PM   Total Posts: 3   [ # 2 ]

Hi,

Thank You very much!! That works great:)

   

John Brookes, Moderator
Posted: 26 November 2011 01:39 PM   Total Posts: 732   [ # 3 ]

Just realised that getVerticeWorldPosition above was wrong.

Edited the post to correct it
Sorry

   

macgor, Newbie
Posted: 26 November 2011 04:16 PM   Total Posts: 3   [ # 4 ]

I have fixed it alredy during tests but this was not hard to find:)
Any way Your post saved me lot of time:)

Thanks again

   

kr15h, Newbie
Posted: 15 January 2012 04:53 PM   Total Posts: 1   [ # 5 ]

Works great! Thanks!

   

mwoodman, Newbie
Posted: 01 October 2012 05:36 AM   Total Posts: 4   [ # 6 ]

Using Away3d 4.0.9 gold, I tried the above.  It works, but this works fine for getting the 2D position in a scene for a Mesh or Sprite3D:

var stage2dPos:Vector3D view.project(mesh.scenePosition); 

 

   

valck, Newbie
Posted: 26 October 2012 02:51 PM   Total Posts: 4   [ # 7 ]

Look this post. =)
http://away3d.com/forum/viewthread/3425/

   
   
‹‹ is vector3D in cube

X

Away3D Forum

Member Login

Username

Password

Remember_me



X