manipulate vertices of an as3 object

Software: Away3D 4.x

drbii, Member
Posted: 23 July 2014 12:43 AM   Total Posts: 72

Anyone know if it is possible to manipulate programmatically the vertices of an as3 mesh?  I can’t seem to get it to work.

I know the premiss is to get the current vertex data, move the vertices and then update the vertices to the object.  I haven’t seen it done on an AS3 model though.

Thanks for your help.

 

   

Avatar
Fabrice Closier, Administrator
Posted: 23 July 2014 10:37 AM   Total Posts: 1265   [ # 1 ]

Not sure what you mean by as3 mesh… But if you mean some mesh data in class form exported from Prefab or one some geometry generated via code, it doesn’t matter. That you load an obj, md2, 3ds or generate geometry via code, once a mesh exists in away3D, there is no difference. They are all the same.
You can then access the mesh.geometry.subGeometries[indexofyourchoice].vertexData and alter/change update at will.

Note that if you run on 4.1 and higher, there is a difference between CompactSubGeometry and SubGeometry. Where the subgeometries of the geometry is either SubGeometry for <4.1 or SubgeometryBase for >4.1.
The “classic” subGeometry holds multiple buffers, so accessing vertexData getter returns ONLY the vertices, while the same method with a CompactGeometry case will return a single buffer with the entire mesh data (uvs, vertices, normals etc). This is done this way to reduce uploads for better performance. You can if you want to access only the vertices use the stripBuffer method.

  * - stripBuffer(0, 3), return only the vertices
  * - stripBuffer(3, 3): return only the normals
  * - stripBuffer(6, 3): return only the tangents
  * - stripBuffer(9, 2): return only the uv’s
  * - stripBuffer(11, 2): return only the secondary uv’s

To update, you will have to either use fromVectors method, or better, if the updates are frequent, loop over the entire data buffer using offsets and strides.
In SubGeometry case, you simply alter the vertices and call the updateVertexData method with the updated buffer.

 

   

Whypay, Newbie
Posted: 23 July 2014 01:33 PM   Total Posts: 12   [ # 2 ]

If you are creating looping animations, i would recommend the vertex animator.
You can export animated meshes from prefab3D as as3 class to see how it works.

 

   

drbii, Member
Posted: 23 July 2014 01:41 PM   Total Posts: 72   [ # 3 ]

Thanks guys, 
I’m sure it is way out of my coding skill set but I’m going to try to figure out a way to do a “morph” so that I can display two or more animation states at once.  My thought is to read the base mesh’s vertices positions, the vertices positions of a target(s) mesh(es) and add them with a blend factor(%), then update the mesh.  That’s the thought.  I just can’t believe as advanced some of the features in Away3d and that we have vertex animation states that two cannot be turned on at once…like morph tracks/banks in 3d apps.  If you guys have any thoughts on this, why it should/shouldn’t work or general warnings please feel free to let me know.

 

   

Avatar
Fabrice Closier, Administrator
Posted: 23 July 2014 04:28 PM   Total Posts: 1265   [ # 4 ]

@whypay, the way prefab handles the animation is not suitable for multiple blendings. It indeed interpolates a value to another.

‘add them with a blend factor(%), then update the mesh…’

Blending multiple states isn’t as simple as one may think.
Take the eyes blinking on a turning head for instance.
If the animation state blinking eyes is to go back and forth on the y axis using the coordinates relative to a given state at start. when the head has turned say 30 degrees, blending using percentage as described above will likely place the blinking eyes vertices pretty much out of the eye sockets.
In order to do it this way, you must animate each and every state using the same transforms. This means also a bunch of preparation and a small mistake can ruin the whole thing. Lots of data will probably involved too, as you need keep the same information as the “master”. Say a modern 3d version of what used to be the way to animate vectors in flash 4 on the timeline smile

Blending this way will be ok If you have a model, say a box that stays still, and you want to animate the opening of the sides. Then each side animation could be blended the way you want without big problems. You will only have to keep track of the indices that requires to be updated per animation.

Another approach (if you do more than the box case) which looks to me a better idea, is to define regions on the master mesh geometry, and isolate the vertices involved. Then runtime transform these from the current transform of the master state. This would perform better, would use less data, and last but not least, a code like this could be added to the existing animator with not much pain, which would let all this be done on the gpu.

Updating the buffers every frames as you plan to do will probably lead to noticeable slowdown if the scene is more than just a few cubes. As every program will need to be invalidated, reconstructed and uploaded over and over…

 

   

drbii, Member
Posted: 23 July 2014 09:21 PM   Total Posts: 72   [ # 5 ]

Great insight, but I’m still having trouble seeing why this wouldn’t work.  Perhaps it is my experience using other 3d packages that has lead me to a jaded view.  Morphs are almost always linear movement of vertices from point a to point b.  I don’t think I have ever created a morph in another package that wasn’t linear wink

I do see your point though, and perhaps Away3D is working differently.  For instance in LightWave if I create a morph for a muscle bulge and move the arm with another method, i.e. via skeleton or just by translating or rotating the model, the morph still works in respect to the translation or skeletal animation. 

The problem with animations states is that only one state can be used at a time.  This really limits what they could be used for.  For instance I have a disc shaped object (see the attached image).  The object needs to be deformed in any of the pie shaped divisions and any number of them can be deformed at once.  The bulges need to blend from pie shape to pie shape, so I can’t literally divide into pie shapes.  The bulges can happen at any degree of bulge as well.  So If I need pie shape 1 to bulge out to 100% and pie shape 5 to bulge out to 20%, etc.  I know how I would do it in Lightwave.  Each pie shape bulge would be morph in morphmixer and then I could at anytime dial up or down each pie division to bulge.  In the attached image the grey areas represent two bulges that would be two separate morphs.

How would one do that in Away3d?  I am stumped…which I admit is easy to do wink

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X