, Jr. Member
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
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 * 3, true);
var normals : Vector.<Number> = new Vector.<Number>(vercount * 3, true);
var ix:Number = 0;
var data: Vector.<Vector3f> = new Vector.<Vector3f>(vercount);
data[ix++] = new Vector3f(1.000000, -1.000000, -1.000000);
data[ix++] = new Vector3f(1.000000, -1.000000, 1.000000);
data[ix++] = new Vector3f(-1.000000, -1.000000, 1.000000);
data[ix++] = new Vector3f(-1.000000, -1.000000, -1.000000);
var index:Number = 0;
var vert:Vector3f;
for (var i:int = 0; i <vercount; i++ )
{
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(0, data.length);
data = new Vector.<Vector3f>(vercount);
ix = 0;
data[ix++] = new Vector3f(0.000000, -1.000000, 0.000000);
data[ix++] = new Vector3f(0.000000, -1.000000, 0.000000);
data[ix++] = new Vector3f(0.000000, -1.000000, 0.000000);
data[ix++] = new Vector3f(0.000000, -1.000000, 0.000000);
index = 0;
for (i = 0; i <vercount; i++ )
{
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 = [ 0, 1, 2, 0, 2 ];
for each (var elem:uint in indexesA)
indexes.push(elem);
// bone weights
var jointIndices : Vector.<Number> = new Vector.<Number>(vercount * boneCount, true);
var jointWeights : Vector.<Number> = new Vector.<Number>(vercount * boneCount, true);
// 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,0, 0);
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(0, 2, 0);
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(0, 4, 0);
pos.invert();
joint.inverseBindPose = pos.rawData;
skeleton.joints[2] = joint;
// attach our animation to our mesh
mesh.geometry.animation = new SkeletonAnimation(skeleton, boneCount);
// 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