Wednesday, June 30, 2010

Tracking Vertices In Away3D Animated 3D Models

Tracking Vertex Positions In Away3D MovieMesh Class For Animated Models In Away3dLite (Jan. 28th 2010 )

**Useful for interchangeable handheld weapons for models to find attachment points**

Add MovieMesh Variable Declaration:
public var leftHandx:Number;

public var leftHandy:Number;

public var leftHandz:Number;


MovieMesh.onEnterFrame:

Place after "while(i--)" update of all vertices:

var tempOffset:int = 100;

leftHandx = _vertices[(tempOffset*3)];

leftHandy = _vertices[(tempOffset*3) + 1];

leftHandz = _vertices[(tempOffset*3) + 2];


Added to MyProject code:

mySphere = new Sphere();
mySphere.radius = 10;
mySphere.x = mySphere.y = mySphere.z = 0;
scene.addChild(mySphere);


MyProject.onEnterFrame:

//trace(mesh.leftHandx);
mySphere.x = mesh.leftHandx;
mySphere.y = mesh.leftHandy;
mySphere.z = mesh.leftHandz;

2 comments:

  1. I just tried this and it seemed like it wouldn't work correctly at first so I figured out I should have kept the rotation and xyz of the model as zeroes.

    To keep the correct position of the marker sphere when rotating or moving the mesh you need to add both to an ObjectContainer and perform the rotations and xyz changes on the new ObjectContainer containing the mesh and the sphere together.


    Best regards,

    CG

    ReplyDelete
  2. Ummm, actually... I remember in the code I had the rotation first... before the change in position so maybe that's why the problem appeared.

    Not sure but this works anyway. :)

    ReplyDelete

Give me your best comment. *_*