Categories
3d

Preview 2: of 3D file parsing tool

Well sort of! Here is an example I made that makes use of the files exported from the tool.

First up the demo:

Left/Right arrows to change the model, and mouse wheel to zoom
(sorry it is super lame but in my defence it was put together in under an hour)

Here is an external link: click me

The swf itself is under 5k, so the library is small!
In a nutshell the swf loads binary assets that were exported from the air app I discussed in a previous post.
Once loaded it simply traverses the scene of the file and renders any meshes it finds using the native flash drawing api (i.e. crap and slow but good enough for demo purposes).

I will attach the project zip later so you can have a look at it and also provide links to the library swc and the test files featured above so you can have a play if you want to.

I just wanted to show you how easy it was to use the lib and the files it parses, the whole demo above including all the imports, listeners and other boilerplate stuff is still only just over 200 lines… not bad!

It should be very easy to integrate with away3d, flare3d or anything else really. I will probably also make a JSON export so you can use it with javascript projects too (if you should choose too).

So a little more about the library, it is just a collection of classes that describe a 3d scene. I will outline the main classes here but these are subject to change so it is just so you can get a feel for how it might work.

Assimp.as – Use this to convert the loaded binary into a AssimpScene with a static method.

AssimpScene.as – This is the main file you will be working with, it contains information about the scene such as the number of meshes, materials etc, it also contains a reference to the rootNode.

AssimpNode.as – This is a node that represents an object in the scene graph. It may or may not have a mesh, and may or may not contain child nodes. It will contain a transform that describes it position in 3d space relative to its parent. If it has a parent, you will get a pointer to it and if it contains a mesh (or multiple meshes) you will get a vector of indices that point to the mesh in the AssimpScene.meshes vector via index.

AssimpTransform3D.as – a property of a node, it contains a matrix and a getter to obtain the local to world matrix based on its parents.

AssimpMesh.as – the class that contains the information about the mesn; its vertices, ids, uvs and optionally normals, tangents etc..

So in its most basic form you could load in the binary file or embed it. Then convert that ByteArray into an AssimpScene using the Assimp class static method loadFromCompressedBinary:

var scene:AssimpScene = Assimp.loadFromCompressedBinary(data);

Once you have the scene you could loop through all the meshes:

for (var i:int = 0; i < scene.numMeshes; i++)
{
	var mesh:AssimpMesh = scene.meshes[i];
	renderMesh(mesh.ids, mesh.vertices);
}

Or to render things more true to the scene graph you could do something like I did in the demo above, so please feel free to download the project file and copy code from in there.

Downloads:
assimp.swc <-- you need this to handle the binaries assimp project <-- a simple sample flash develop project A few 3d binaries (these are already in the project): present scene
heart scene
candle scene
cctv scene

Do note that this is a very early beta version (probably an alpha) so there will be some things missing, but they are coming do not worry!

Next time round expect more (any/some) documentation, more demos and more features – hope to have animations and bones in there too!

Sorry I had to rush through that all so fast – crazy busy at the moment! Getting there though!
Let me know if you run into any problems (hopefully not too many).

Keep on flashing!

credits:
heart, candle and present models from videocopilot.net, and the cctv model was from a random forum somewhere (cheers mystery person)