Need help with adapting my model parser to Away3D 4

Software: Away3D 4.x

GVG-Vit, Newbie
Posted: 23 October 2011 06:50 PM   Total Posts: 5

Hello! I’ve made DFF (Grand Theft Auto 3/VC/SA) model parser and I’ve managed to make it read all data from file and build wireframe(WireframePrimitiveBase) model but I can’t figure out how to make Away3D parser out of it :(

Help me, please.

PS I’m going to commit it when it’s done.

   

Richard Olsson, Administrator
Posted: 24 October 2011 04:41 PM   Total Posts: 1192   [ # 1 ]

Extend AbstractParser, override the proceedParsing() method, do your parsing in there (preferably in a while (hasTime() loop for green threading) and return PARSING_DONE when you’re done, or MORE_TO_PARSE if you want to continue parsing on next frame (green threading.)

Once you’ve completed assembling a mesh or any other asset, invoke finalizeAsset(myMesh) to dispatch the proper events.

Have a look at for example the AWD2Parser or the new Max3DSParsers which are both pretty clean implementations of the Away3D 4.0 parsing architecture.

   

GVG-Vit, Newbie
Posted: 24 October 2011 06:55 PM   Total Posts: 5   [ # 2 ]

Thanks. But in general I have problem with building mesh. Where to start building it? As far as I understand I need Geometry with SubGeometries in it and Mesh as container for this Geometry, right?
SubGeometry has methods like updateVertexData(vector), updateVertexTangentData(vector) and few more to build the mesh, but I have no idea how their data should look like.

I’ve got arrays(vectors) with vertex, triangle, UV, normal data and more.
Here are their structures:

Vertex array (size = vertex count * 3)
It looks like this: [x, y, z, x, y, z, x, y, z ...] (3 vertices)
Each vertex occupies 3 elements in array (XYZ Numbers for each).

Face(triangle) array (size = face count * 4)
Look: [vertex1, vertex2, flags, vertex3, vertex1, vertex2, flags, vertex3 ...] (2 faces)
vertex1, vertex2 and vertex3 are vertices’ numbers in their array

UV array (size = UV coordinates count * 2)
Look: [U, V, U, V, U, V ...] (3 coordinates)

So, how can I convert all this data to SubGeometry-compatible format?

   

Avatar
80prozent, Sr. Member
Posted: 24 October 2011 07:52 PM   Total Posts: 430   [ # 3 ]

hi

the Subgeometry object expects your data to be like this:

indexdata is a vector.<uint> that descripes all triangles of the mesh by storing
3 uints for each triangle. each of this 3 stored values are indicies into the vertexData, UVData, vertexNormalData and VertexTangentdata.
the length of the indexData should allways be 3*trianglecount.


indexData=(t1,t2,t3,t1,t2,t3,t1,t2,t3,......)

the vertexData is a vector.<Number> storing x,y,z for each verticle.
the length of the vertexData should allways be 3*verticleCount.
vertexData=(x,y,z,x,y,z,x,y,z,......)

the UVData is a vector.<Number> storing u,v for each verticle.
the length of the UVData should allways be 2*verticleCount.
UVData=(x,y,z,x,y,z,x,y,z,......)

the vertexNormalData is a vector.<Number> storing normalX,normalY,normalZ for each verticle.
the length of the vertexNormalData should allways be 3*verticleCount.
vertexNormalData=(normalX,normalY,normalZ,normalX,normalY,normalZ,......)


the vertexTangentData is a vector.<Number> storing tangentX,tangentY,tangentZ for each verticle.
the length of the vertexTangentData should allways be 3*verticleCount.
vertexTangentData=(tangentX,tangentY,tangentZ,tangentX,tangentY,tangentZ,......)


vertexdata.length = vertexNormalData.length = vertexTangentData.length

vertexdata.length/3 = UVData.length/2

the indicies you store for each triangle must be multiplied by 3 to get the corresponding verticle / normal / or tangent, while ii must be multiplied by 2 to get the corresponding uv.


Note that the verticlecount is not allways trianglecount*3 because a verticle could be used by more then one triangle. triangles that share points between each other will be rendered with smooth edges, while not sharing points preserves hard edges.


80

 Signature 

sorry…i hope my actionscript is better than my english…

   

GVG-Vit, Newbie
Posted: 24 October 2011 09:00 PM   Total Posts: 5   [ # 4 ]

Thank you, this is very useful! And which Vectors are minimum requirements for SubGeometry to build the model? Obviously indices and vertices are required by definition, but what about UV, Tangent and Normal Vectors?

   

Richard Olsson, Administrator
Posted: 24 October 2011 09:02 PM   Total Posts: 1192   [ # 5 ]

Vertices and indices are required to be able to render anything. A UV stream is required if you want to use texture (not just color) materials. Normal and tangent vectors are far from always stored in files, so there are means to auto-generate them. If you don’t have them in your files, check out the autoDeriveVertexNormals and autoDeriveVertexTangents properties.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X