Create custom skinned meshes with bones programmatically

Software: Away3D 4.x

Avatar
Huck, Jr. Member
Posted: 14 January 2012 06:11 PM   Total Posts: 45

Hi guys,

i would like to create entirely programmatically meshes with vertex, normal index bone weights and bone index data.

i managed to create a simple static mesh by adding subGeometry to a mesh class and it works. the thing is, if i want to add bone weights and indices, the class SkinnedSubGeometry has the methods updateJointIndexData and updateJointWeightsData noted as “arcane” which prevents them from being visible to the outside.

is it that im not using the proper method to create custom meshes or is it a “bug” that these methods not be exposed to the outside?

and a last question, is it possible to animate the bones of a custom made mesh manually? (not using any animations, just moving transforming the bones with programmatic transformations).

thanks!

   

Avatar
Huck, Jr. Member
Posted: 14 January 2012 11:02 PM   Total Posts: 45   [ # 1 ]

hi guys, please ignore this quesiton, got it fixed and added a useranimator code in the following thread. lets hope the devs add it (or a derivate) to the final away3d 4.

i hope you dont mind the repost, but i think this can be useful in the support group.

regards

————————————-repost—————————-

oh well, turns out it was really easy to do, once we know how. Im really starting to like away3d. the skeleton animation system is really powerful indeed smile

so, for the sake of new users, here is how to perform custom animations.

first, in your class that will create the mesh data, add the following lines to allow for the “hidden” functions to work:

import away3d.arcane;
use namespace 
arcane

now, create your vertex, normals, uv and index data as usual, and then add the bone weights and index data. here is a small abstract example using my 23 classes i add as attachments:

mesh = new Mesh();
 
   
mesh.name "mymesh";
   
   var 
vercount:Number 32;
   var 
boneCount:Number =3;
   
   var 
subGeom SkinnedSubGeometry = new SkinnedSubGeometry(boneCount);
   

   
   var 
vertices Vector.<Number> = new Vector.<Number>(vercount 3true);
   var 
normals Vector.<Number> = new Vector.<Number>(vercount 3true);
   
   
   var 
ix:Number 0;
   
   var 
dataVector.<Vector3f> = new Vector.<Vector3f>(vercount);
   
data[ix++= new Vector3f(1.000000, -1.000000, -1.000000);
   
data[ix++= new Vector3f(1.000000, -1.0000001.000000);
   
data[ix++= new Vector3f(-1.000000, -1.0000001.000000);
   
data[ix++= new Vector3f(-1.000000, -1.000000, -1.000000);

   
   var 
index:Number 0;
   var 
vert:Vector3f;
   for (var 
i:int 0<vercounti++ )
   
{
    vert 
data[i];
    var 
v1:Number index 3;

    
vertices[v1] vert.x;
    
vertices[v1+1] vert.y;
    
vertices[v1+2] vert.z;
    
    
index++;
   
}
   
   data
.splice(0data.length);
   
data = new Vector.<Vector3f>(vercount);
   
ix 0;
   
data[ix++= new Vector3f(0.000000, -1.0000000.000000);
   
data[ix++= new Vector3f(0.000000, -1.0000000.000000);
   
data[ix++= new Vector3f(0.000000, -1.0000000.000000);
   
data[ix++= new Vector3f(0.000000, -1.0000000.000000);


   
index 0;
   for (
0<vercounti++ )
   
{
    vert 
data[i];
    
v1 index 3;

    
normals[v1] vert.x;
    
normals[v1+1] vert.y;
    
normals[v1+2] vert.z;
    
    
index++;
   
}
   
   
var indexes:Vector.<uint> = new Vector.<uint>();
   
   var 
indexesA:Array = [ 01202 ];
   
    for 
each (var elem:uint in indexesA
    
indexes.push(elem);

    
   
// bone weights
   
var jointIndices Vector.<Number> = new Vector.<Number>(vercount boneCounttrue);
   var 
jointWeights Vector.<Number> = new Vector.<Number>(vercount boneCounttrue);

   
// set bone strength
   
jointWeights[boneCount*0] 1.0;
   
jointWeights[boneCount*1] 1.0;
   
jointWeights[boneCount*2] 1.0;
   
jointWeights[boneCount*3] 1.0;
   
   
// and which vertex connects to which bone (note, away3d seems to require that the indices be multipled by 3, dont know why)
   
jointIndices[boneCount*0] 1*3;
   
jointIndices[boneCount*1] 1*3;
   
jointIndices[boneCount*2] 1*3;
   
jointIndices[boneCount*3] 1*3;
   
   
subGeom.updateVertexData(vertices);
   
subGeom.updateVertexNormalData(normals);
   
//subGeom.updateUVData(uvs);
   
subGeom.updateIndexData(indexes);
   
   
// and now the arcane bone data
   
subGeom.updateJointIndexData(jointIndices);
   
subGeom.updateJointWeightsData(jointWeights);
   
   
// add our submesh
   
mesh.geometry.addSubGeometry(subGeom);

   
// create our 3 bone skeleton
   
var skeleton:Skeleton = new Skeleton();
   
   
//1
   
var joint:SkeletonJoint = new SkeletonJoint();
   
   
joint.name "root";
   
//joint.parentIndex = -1; // root is always -1, set by default
   
var pos:Matrix3D = new Matrix3D();
   
pos.position = new Vector3D(0,00);
   
pos.invert();
   
joint.inverseBindPose pos.rawData;
   
skeleton.joints[0] joint;
   
   
//2
   
joint = new SkeletonJoint();
   
   
joint.name "child";
   
joint.parentIndex 0;
   
pos = new Matrix3D();
   
pos.position = new Vector3D(020);
   
pos.invert();
   
joint.inverseBindPose pos.rawData;
   
skeleton.joints[1] joint;
   
   
//3
   
joint = new SkeletonJoint();
   
   
joint.name "child2";
   
joint.parentIndex 1;
   
pos = new Matrix3D();
   
pos.position = new Vector3D(040);
   
pos.invert();
   
joint.inverseBindPose pos.rawData;
   
skeleton.joints[2] joint;
   
   
// attach our animation to our mesh
   
mesh.geometry.animation = new SkeletonAnimation(skeletonboneCount);
   
   
// important note!!  due to some bug in away3D, the materials MUST be atatched to the mesh AFTER all the vertex data and animations
   
var ctr:ObjectContainer3D = new ObjectContainer3D();
   var 
green ColorMaterial = new ColorMaterial(0x00FF00);
   
green.lights [light];
   
   
mesh.material green;
   
   
ctr.addChild(mesh);
   
   
ctr.scale(80);
   
this.scene.addChild(ctr);
   
   
// good, now we attach our user animator that i provded as a zip file (hopefully the devs will incorporate them or some derivative of in the final away3d code)
   
controller = new UserAnimator(SkeletonAnimationState(mesh.animationState));
   
   
// adn when you are ready to start the animation, play :)   (note: here you need to add methods to hook in and add your transformations to each bone)
   
controller.play(); 

there you go, i hope this helps.


admins and devs, please add some form of user admin in away3d 4. will really help smile

 

File Attachments
UserAnimator.zip  (File Size: 2KB - Downloads: 316)
   

Skyser, Newbie
Posted: 09 January 2013 11:05 AM   Total Posts: 7   [ # 2 ]

Thanks for the post! Is there a version of this that has been updated for Away 3D 4.1. There are a number of inconsistencies that keep it from compiling and I can’t seem to fix it because I don’t understand enough about the framework.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X