Hi,Ariel.
I stucked again:( Right now, I am trying to create my own custom vertex animation by code, the result is trying to simulate the process of forming an object by vetices. Everything was fine until I tried to add an animation to this object and update those "vertices" in each frame. My app crashes everytime I use these codes:
var surface:Surface3D = mesh.surfaces[0];
position = surface.offset[Surface3D.POSITION];
vector = surface.vertexVector;
length = surface.vertexVector.length;
sizePerVertex = surface.sizePerVertex;
for (var i:int = 0; i < length; i += sizePerVertex)
{
var cubeClone:Pivot3D = cube.clone();
cubeClone.name="cube"+i
TweenMax.to(cubeClone, 2, { delay:i / getTimer() / 5, x:Math.random() * 100 - 50, y:Math.random() * 100 - 50, z:Math.random() * 100 - 50, ease:Expo.easeOut } );
scene.addChild(cubeClone);
}
stage.addEventListener(MouseEvent.CLICK, click);
private function click(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.CLICK, click);
scene.addEventListener(Scene3D.UPDATE_EVENT, updateEvent);
model.play();
}
private function updateEvent(e:Event):void
{
for (var i:int = 0; i < length; i += sizePerVertex)
{
var x:Number = vector[i + position];
var y:Number = vector[i + position + 1];
var z:Number = vector[i + position + 2];
scene.getChildByName("cube" + i).x = x;
scene.getChildByName("cube" + i).y = y;
scene.getChildByName("cube" + i).z = z;
}
}
it was running just fine without put the codes to an updateEvent, which means it runs perfectly when it is just forming the object, However, when I want those vertices to follow those vertexbuffer in each frame, it just dies:( Is this related to the number of my vertices(430)? or should I not using update them directly? Or should I try to extends Idrawable class to create my own component?
Or should I directly ask you to give me a basic example:) Cuz you are the best:P