
In short to build loader you need to extend ModelLoader class with already binary and text loader helper and event handling mechanism ....
When item is loaded you use loader.model.addTo(sceneNode) function from ModelData and returns ModelManifest.
ModelManifest is document containing info of loaded bones,meshes,animations,materials...
Magnificent addTo function do everything so find out this approach less customizable for example if you want to init SceneMesh.userData during creation of the mesh not after adding on scene.
It create materials,meshes,bones,nodes??? from MaterialData,MeshElementData,BonesData,SceneNodeData create model manifest and add all nodes and subnodes to scene.
After parsing of data this strucutre should be created
ModelData
->SceneNodeData
->MeshData
First we define types of vertex inputs or properties. Position,Texcoord,Normal
meshData.addVertexInput(new Input(Input.SEMANTIC_POSITION, "positions", 0));
meshData.addVertexInput(new Input(Input.SEMANTIC_TEXCOORD, "texcoords", 1));
meshData.addVertexInput(new Input(Input.SEMANTIC_NORMAL, "normals", 2));
//indices 0,1,2 specify
how array of primitives would be filled with vertex values( x1,y1,z1,u1,v1,w1, nx1,ny1,nz1
how array of primitives would be filled with vertex values( x1,y1,z1,u1,v1,w1, nx1,ny1,nz1
add sources to of the Inputs
meshData.addSource(new Source("texcoords", new ArrayElementFloat(texcoords), 2));
// index 2 mean that data in texcoords would be read by pairs texcoords=[u1,v1,u2,v2,u3,v3....num_texcoords pairs
meshData.addSource(new Source("positions", new ArrayElementFloat(positions), 3));
// index 3 mean that data in position would be read by tripples texcoords=[x1,y1,z1, next tripple x2,y2,z2...num_vertices
meshData.addSource(new Source("normals", new ArrayElementFloat(normals), 3));
Create MeshElementData
var polylist:MeshElementDataPolylist = new MeshElementDataPolylist(meshData, meshData.vertexInputs,num_primitives, primitives, null, vcount, "MeshElementDataPolylistDoll", "materialName");
//primitives array containing vertex position, texcoord, normal, index triples
//ex primitives=[0,1,2, 0,2,3...
//ex. 0,1,2 => 0 is index inside vertex position array, 1=> is index inside texture cords array, 2=> index inside vertex normals postion
//vcount is array showing how many vertices in primitives array make primitive(face/polygon).(index>3)
//ex. vcount=[3,4,3,4,3,5...] so first primitive is formed of 3 groups of ( x1,y1,z1,u1,v1,w1, nx1,ny1,nz1)
And workhorse is MeshElementDataSource that extends MeshElement process and puck all data and source of vertices, normals and texcoords to structures and buffers ready for AGAL Compiler.
How we can access vertices(and structures containing data) so we can apply some transformation???
To expose them we need to extend MeshElementDataSource or MeshElementDataPolylist so I can access vertexSources and vertexIndices??? Ofcourse vetex positions and normals should be calculated before putting inside this structures.
override protected function initModels():void
{
//super.initModels();
var md2Model:String =
//"../res/models/"+
//"doll.md2";
//"box.md2";
//"spos_body.md2";
//"spos_weapon.md2";
//"spos_body.md2";
"tris.md2";
_md2Loader = new MD2Loader(md2Model );
_md2Loader.addEventListener( Event.COMPLETE, completeEventHandler, false, 0, true );
}
protected function completeEventHandler(event:Event):void
{
var loader:MD2Loader = event.target as MD2Loader;
var manifest:ModelManifest = loader.model.addTo(scene);
_mesh = manifest.meshes[0];
...
...
As half of Proscenium lean towards handling Collada files it is important to check Collada specification.
Many thanks to my friend Tim Knip for quick 3D tips and creator of extraordinary Collada library .
You will also need Proscenium framework from Adobe site.
Source
please update the links
ReplyDelete