OVERALL DESCRIPTION OF CLASSES
Moussa Dembélé – www.mousman.com- firstname.lastname@example.org
I – FIRST OF ALL
To fully understand how all this work a basic knowledge of AGAL and Stage3D at least is required…
The classes have been made with the purpose of beeing integrated in a project as easily as possible.
That is to say with a low dependency level (at least I try).
The core of these toolset classes are located in the package\com\mousman\as3\agal\parser\ directory.
Most of the other classes are here more to illustrate a way of using them rather than beeing a part of the core (except for the IMesh interface).
So let’s talk about the core.
there are four subpackages
- dto : contains only one class (MBuffersWriterDTO) wich is used to pass some parameters to the vertices writers.
- objs : has in charge the construction of the 3D model object.
- shaders : provides a link between the 3D model object and the shaders.
- verticeswriter : has in charge the construction of vertices byteArrays for VertexBuffer3Ds and a vector of indices for IndexBuffer3Ds.
II – OBJS SUBPACKAGE
Classes here have in charge the construction and the description of the 3D model object.
So… what is the 3D model object ?
I’ve made a class called MObjMesh which is a representation of a 3D model in a wavefront way.
I won’t really explain here what is the Wavefront format but if you want to know more you can go there and there.
But in a nutshell a 3D model in wavefront is described with two files :
- a .obj file,
- a .mtl file.
The mtl file contains data about materials of the model (colors, textures…).
The obj file contains data about vertices, normales and uv mapping (position, size…).
In this obj file the model is made of several objects, with names,
and these objects are made of one or more polygon groups, each one having also his name.
These polygon groups are linked to data contained in the mtl file via an id.
I have kept this structure and adapted it to Agal :
MObjMesh can contain several objects (MObject3D instances)
a MObject3D is made of several polygon groups (MPolygoneGroup3D)
a MPolygoneGroup3D is made of
- a MMtlSet wich contains the mtl datas used by the poygon group
- several MPolygonGroupBuffers
- an Id
- the number of vertices in this group
a MPolygonGroupBuffers is made of
- a vertexBuffer (VertexBuffer3D)
- an indexBuffer (IndexBuffer3D)
- an Id
In the mtl files, for each polygon group textures can be defined by their file name.
Rather than automatically load them, I used these names as id and use two classes :
- MTexture, which contains this id and a Texture (flash.display3D.textures.Texture),
- MTextureManager which has in charge to create and store MTexture instances.
And to create all this there is MObjParser.
MObjparser is at the center of this package.
It is the one which will do the job based on the wavefront files.
Of course it won’t do it all by itself and require some workers :
As I mentioned earlier MPolygonGroupBuffers are made of VertexBuffer3D and IndexBuffer3D.
These VertexBuffer3D can be made with differents formats (number of data per vertex, how they are formated…), here for more info.
And so, depending on the structure of each polygon group and/or the way we want to use them we will have to create the vertex buffers differently.
In order to that MObjParser requires writer objects.
Theses objects must implement IMBytesArrayWriter.
As the way we build VertexBuffer3D is deeply linked to the shaders wich will be used for restitution,
writers and shaders are associated and stored in a ShaderSet object which contains also an ID that can be linked to a polygon group.
All shaderSet objects are then stored in a ShaderStore object.
This is the ShaderStore object which is given to the MObjParser.
It may seem a lot, but to do that allows us to use different kinds of shaders for each specific polygon group if we want to.
(it will get clearer in the exemples.)
two writers are already in the package : MVerticesBytesArrayWriter and MVerticesBytesArrayWriterWT,
one for textured groups and another for groups without textures.
Now let’s see that in practice !
Just learning Stage3D.
This article helps a lot.
3Q very much.
And do you have any idea of parsing a picture as .png to 3D model?
As we are doing this:
User can upload a 2d pictures.
And he can easily use the flash we offered to change to a 3d model
He can see the model in the flash, and can change the colors for the model by the offerd color.
by ChrisYu on juin 17, 2014 at 10 h 36 min