Author Topic: Custom Vertex Animation by code  (Read 231 times)

Jason Huang   «   on: April 16, 2012, 03:35:03 AM »
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

Jason Huang   «   Reply #1 on: April 16, 2012, 03:42:31 AM »

For my understanding, Ariel is INVINCIBLE :P
You never let us down,NEVER!
I doubt myself may become one of your FANS:)

Jason Huang   «   Reply #2 on: April 17, 2012, 09:45:25 AM »

Any ideas from Ariel?:)

Jason Huang   «   Reply #3 on: April 17, 2012, 04:04:59 PM »
 Well, I tried to use Icomponent to manually render the fake vertices. But still, it crashes...I will give it another try then....

Jason Huang   «   Reply #4 on: April 24, 2012, 07:20:10 AM »

Hey, Ariel. Could you plz have look at this plz?:)

Ivan Vodopiviz   «   Reply #5 on: April 24, 2012, 11:26:58 AM »
Hi Jason,

The problem was that getChildByName is very, very slow, so putting it in an update event was a little too much. To solve that, Ariel suggested to store the cubes into a vector for faster access.

Here's the resulting code. It's a very cool effect :)

Jason Huang   «   Reply #6 on: April 24, 2012, 11:49:44 AM »
Cheers, Ivan. You are almost invincible too:)

Jason Huang   «   Reply #7 on: April 27, 2012, 02:12:55 PM »
Hi, Ivan,
Thanks for your paitience.
Now I understand the Idrawable class is  identical with scene.render event, am I right?

For the bulging of a mesh, this effect is what I exactly looking for. I am inspired by what you said. And I came up an two ideas:
(1) Directly update position of those spheres, and simulate meshes bulging. But this may require source code of premitives to help arranging positions. it limits a lot so that the advanced bugling shape can not be easily done:(  
(2) Modify the vertexBuffer of mesh by add new vertex data to it. Therefore, when mouse click on that mesh just add a new vertex data to that mesh, and update vertexBuffer when the mouse moving on it. For adding vertex data to the disire positions, should we have a try to implement the utility "merge" of Flare studio to flare engine?  or may be we can try to add collitions for vertex?

Those are just for basic ideas.
Cheers

Ivan Vodopiviz   «   Reply #8 on: April 27, 2012, 05:25:58 PM »
Hi Jason,

That's a very cool effect so I wrote a quick demo you can find here. No as cool as mesh bulging though :P

Jason Huang   «   Reply #9 on: April 28, 2012, 02:53:48 AM »

Hi Ivan,
Thank you very much, you are brilliant:)
However, this is what I have done already, and sorry for I did not explain it very well. The point of the site I showed to you, is customizing vertex part( the first one in the left menu). So I came up with the ideas above. Hope you could help me with that, because you are awesome:)

For the example you showed me there is couple of issues.
(1) The most important for you guys, should you do not post commercial swc to the source code?
I assume that you accidently did:)
(2)  In the part of "create spheres if we don't have enough ", I think to check the length of _spheres should use this:if (_spheres.length < _length/_sizePerVertex).

Cheers