|
drbii, Member
Posted: 17 July 2014 02:51 PM Total Posts: 72
Hello all,
I have objects with two or more vertex animations states in them. I would like to be able to display a mix of two or more states… a blended state if you will. I see that the morpher class has been ported to away3d 4 gold by johnnyMichigan. Here is the thread: http://away3d.com/forum/viewthread/4223/
Does anyone have insight or examples of how to use/implement it. I have been banging my head on this for a few days with no progress.
Thanks in advance for any and all help!
|
dottob, Jr. Member
Posted: 18 July 2014 02:57 AM Total Posts: 49
[ # 1 ]
|
|
drbii, Member
Posted: 18 July 2014 01:02 PM Total Posts: 72
[ # 3 ]
Thanks dottob! I’ll try this. Two questions can I use my existing vertex animation state or do I need to make each state into an object? Second, does this work with my existing models or do I need to re-export from sea3d? Thanks again for the info!
|
|
drbii, Member
Posted: 18 July 2014 02:14 PM Total Posts: 72
[ # 5 ]
Looks like what I need but really would like to keep all my models from prefab.
|
drbii, Member
Posted: 18 July 2014 03:43 PM Total Posts: 72
[ # 6 ]
any idea why i would be getting a “Cannot access a property or method of a null object reference.” error?
The line it is referring to is in the Morpher.as class (marked bold):
...
public function mix(comp:Mesh, k:Number):void{
this.weight += k;
...
var sub:CompactSubGeometry=(this.baseMesh.geometry.subGeometries[0] as CompactSubGeometry);
sub.updateData(newVertexData);
}
“sub” in the “mix” function is null?
Here is how I am passing my objects:
var m:Morpher=new Morpher(mapper._Disc1restMesh);
m.mix(mapper._Disc1Q1bulgeMesh,0.5);
I did add them to the scene to make sure they were there.
|
dottob, Jr. Member
Posted: 18 July 2014 03:55 PM Total Posts: 49
[ # 7 ]
Here is my way to do(no need Morpher.as):
Function from Morpher.as and this link:
http://away3d.com/forum/viewthread/5412/#16009
Thanks!
Model from:
http://samplerinfo.com/demo/neuronet/facetest.swf
Thanks!
public function mix(comp:Mesh,k:Number,baseMesh:Mesh,target:Mesh):void{ var tar:CompactSubGeometry=(target.geometry.subGeometries[0] as CompactSubGeometry); var sub:CompactSubGeometry=(baseMesh.geometry.subGeometries[0] as CompactSubGeometry); var originalVertexData:Vector.<Number> = baseMesh.geometry.subGeometries[0].vertexData; var compVertexData:Vector.<Number> = comp.geometry.subGeometries[0].vertexData; var length:Number=baseMesh.geometry.subGeometries[0].vertexData.length; var i:Number; for(i=0; i<length; i+=13){ var startPoint:Vector3D = new Vector3D(originalVertexData[i], originalVertexData[i+1], originalVertexData[i+2]); var endPoint:Vector3D = new Vector3D(compVertexData[i], compVertexData[i+1], compVertexData[i+2]); var pos:Vector3D=new Vector3D(originalVertexData[i], originalVertexData[i+1], originalVertexData[i+2]); var ln:Vector3D = endPoint.subtract(startPoint); ln.scaleBy(k); pos = pos.add(ln); originalVertexData[i]=pos.x; originalVertexData[i+1]=pos.y; originalVertexData[i+2]=pos.z; } tar.updateData(originalVertexData); }
see post pic red is morpher,blue is base,yellow is changeto.
Wish this will be ok *^_^*.
|
drbii, Member
Posted: 18 July 2014 05:19 PM Total Posts: 72
[ # 8 ]
I’m confused now.
So I don’t need to import the morpher.as class???
Do I pass three meshes to the mix function? a base mesh, a target and a comp?
Can you explain the variables a little.
Sorry! I think I am just looking at this wrong. I may need a break!
Thanks again!
|
dottob, Jr. Member
Posted: 19 July 2014 01:34 AM Total Posts: 49
[ # 9 ]
It is a demo,just show how it works,so,there be 3 models.
But the way is working.
You only need two models,the base,the target,you mush rewrite the function
main function update:
public function mix(comp:Mesh, k:Number,baseMesh:Mesh,target:Mesh):void{ var tar:CompactSubGeometry=(target.geometry.subGeometries[0] as CompactSubGeometry); var sub:CompactSubGeometry=(baseMesh.geometry.subGeometries[0] as CompactSubGeometry); var newVertexData:Vector.<Number>=new Vector.<Number>; var originalVertexData:Vector.<Number> = baseMesh.geometry.subGeometries[0].vertexData; var compVertexData:Vector.<Number> = comp.geometry.subGeometries[0].vertexData; var length:Number=baseMesh.geometry.subGeometries[0].vertexData.length; var i:Number; for(i=0; i<length; i+=13){ var startPoint:Vector3D = new Vector3D(originalVertexData[i], originalVertexData[i+1], originalVertexData[i+2]); var endPoint:Vector3D = new Vector3D(compVertexData[i], compVertexData[i+1], compVertexData[i+2]); var pos:Vector3D=new Vector3D(originalVertexData[i], originalVertexData[i+1], originalVertexData[i+2]); var ln:Vector3D = endPoint.subtract(startPoint); ln.scaleBy(k); pos = pos.add(ln); newVertexData[i]=pos.x; newVertexData[i+1]=pos.y; newVertexData[i+2]=pos.z; newVertexData[i+3]=originalVertexData[i+3]; newVertexData[i+4]=originalVertexData[i+4]; newVertexData[i+5]=originalVertexData[i+5]; newVertexData[i+6]=originalVertexData[i+6]; newVertexData[i+7]=originalVertexData[i+7]; newVertexData[i+8]=originalVertexData[i+8]; newVertexData[i+9]=originalVertexData[i+9]; newVertexData[i+10]=originalVertexData[i+10]; newVertexData[i+11]=originalVertexData[i+11]; newVertexData[i+12]=originalVertexData[i+12]; } tar.updateData(newVertexData); }
Please see the swf sample attached
File Attachments
|
dottob, Jr. Member
Posted: 19 July 2014 02:32 AM Total Posts: 49
[ # 10 ]
This solution maybe not so correct,it just move the morph model’s vertexs from the base model’s vertexs’s postion to the target model’s vertexs’s postion by a straight line between two point(see the title http://away3d.com/forum/viewthread/5412/#16009)
So maybe there is an other better way *^_^*
|