July 7, 2009


Posted in Uncategorized tagged , , , , , , , , , , , , at 12:06 am by sagito

After a long, long day of work, I’m proud to announce that the Conspiracy Engine now feature textures (finally)! Well, textures do not use to be such a pain, why did it took so long this time? The answer is quite simple… When exporting the object data, 3D Studio Max exports the (X,Y,Z) vertex data and the (U, V, W) texture coordinate data. However, I was surprised to see that I had 8 vertices in my object and 12 sets of texture coordinates… Well, this made sense, because a vertex shared between edges may hava different texture coordinates along each face!

The problem is that 3DS does not keep any kind of relation between one vertex and its texture coordinates. So, we must first ask the face which vertices and which texture coordinates it uses and only then attempt to relate both these kinds of vertices. I could have done this the easy way by just ignoring repetitions of vertices and letting DirectX handle the optimizations. Of course that I chose not to…

So, I had to create two auxiliar data structures to aid me: An Hash Table (with customizable rehashing) and a Pair. With the Hash Table I was now able to set keys for each vertex individually, thereby removing repeated indices and vertices with ease! The Pair was just a helper utility that I used to handle some data more easily. However, I think that these structures will prove worthy in the future, as they did now! 😀

Well, here is the actual result from all this work:


Tomorrow I will be working with collisions, although that should be a pretty simple matter to handle… 😉 As promised, I will be keeping you posted!


July 5, 2009

Conspiracy Engine First Render!

Posted in Computer Graphics tagged , , , , , , , , , , , , , , at 12:23 am by sagito

And finally, here it is! The Conspiracy Engine first rendered screenshot! Well, it consists of a single teapot lit by diffuse and ambient lighting using Gouraud shading, some text on the screen, one camera (so far), and two lights (one ambient and a point light). It is not something amazing, but this is only the first nice render screen of this engine! And what is most impressive is that this is not a standard DirectX teapot, but a 3DS Max exported teapot, which was loaded using my 3DS Exporter and Importer, presented below. I changed the code a bit to support materials and textures and also to optimize it a bit… Please note that the normals are still not being saved directly, so the lighting can look a bit awkward…

Here is the screenshot of my new engine:

Conspiracy First ShotConspiracy First Shot

Feel free to comment! 😀

June 30, 2009

Basic 3DS exporter

Posted in Computer Graphics tagged , , , , , , at 11:51 pm by sagito

Yesterday I began my learning journey in the realm of MaxScript. Today, I have finished my basic exporter! Although this scripting language is vastly documented, this documentation is quite confusing at first. But with some patience and thanks to this post (http://forum.hardware.fr/hfr/Graphisme/Divers-5/maxscript-getfacematid-sujet_17077_1.htm) from Nico5779 I have managed to get my exporter working.

So, if anyone needs to look at this script for reference or use it, be my guest… If you want some explanation about what is being done in the code below, I will be most happy to help you. Please note that texture coordinates are still not being considered. I will do that in a later version of this exporter and I shall post it here again afterwards. 😉

Here is the code:

–Start by selecting every thing
select $*

out_name = ((GetDir #export) + “/test.cmf”)
out_file = createfile out_name

–For every one of them
for obj in $ do
actualMesh = snapshotAsMesh obj as TriMesh

–Get the number of faces
format “Name: %\n” obj.name to:out_file

numFaces = actualMesh.numfaces
numVerts = actualMesh.numverts

format “Faces: %\n” numFaces to:out_file

format “<vertices %>\n” numVerts to:out_file
for v = 1 to numVerts do
vert = getVert actualMesh v
normal = getNormal actualMesh v
format “% % % % % %\n” vert.x vert.y vert.z normal.x normal.y normal.z to:out_file
format “</vertices>\n” to:out_file

print “>>> Obtaining face information!\n”

midold = -1
objMaterials = #()

for f = 1 to numFaces do
face = getFace actualMesh f
materialClass = classof obj.material

if(materialClass == Standardmaterial) then
matname = obj.material
objMaterial = obj.material

if (findItem(objMaterials objMaterial) == 0) then
append objMaterials objMaterial
else if (materialClass != UndefinedClass) then
matid = getFaceMatId actualMesh f
matname = obj.material[matid]
objMaterial = obj.material[matid]

if (findItem(objMaterials objMaterial) == 0) then
append objMaterials objMaterial

if(midold != matname) then
format “<material %>\n” matname to:out_file
format “% % % % % % % % %\n” objMaterial.ambient.r objMaterial.ambient.g objMaterial.ambient.b objMaterial.diffuse.r objMaterial.diffuse.g objMaterial.diffuse.b objMaterial.specular.r objMaterial.specular.g objMaterial.specular.b to:out_file

format “<ambientmap> % </ambientmap>\n” objMaterial.ambientMap
format “<diffusemap> % </diffusemap>\n” objMaterial.diffuseMap
format “<specularmap> % </specularmap>\n” objMaterial.specularMap

format “</material>\n” to:out_file
midold = matname

face3 = getFaceNormal actualMesh f

x = face.x as integer
y = face.y as integer
z = face.z as integer

x2 = face3.x as integer
y2 = face3.y as integer
z2 = face3.z as integer

format “<face>% % % % % %</face>\n” x y z x2 y2 z2 to:out_file

for om = 1 to objMaterials.count do
for m = 1 to objMaterials[om].maps.count do
if (objMaterials[om].maps[m] != undefined) then
format “<map %>\n” objMaterials[om].maps[m] to:out_file
format “Filename: %\n” objMaterials[om].maps[m].filename to:out_file
format “</map>\n” to:out_file
close out_file

X File Format Dying?

Posted in Computer Graphics tagged , , , , , , , , , , , , , , at 12:13 am by sagito

As some of you should know, .X files were the Microsoft “standard” format for three-dimensional model and animation within DirectX. These consisted of binary or ASCII files with some a kind of scene graph describing a specific scene. Although they were not very complete, this format along with the helper functions such as D3DXLoadMeshFromX were always a major help while developing simple games or applications using DirectX.

Of course that almost every major company developed their own formats, and in that perspective, the .X file format was quite useless… But what about the small developers? Or the people who are learning DirectX? Will they have to start learning parsing techniques in order to read some other file format? Or will they have to learn some scripting language like MaxScript to export their own models?

As a matter of fact, as far as I know, Microsoft never said anything official about this matter. However, everyone who uses the DirectX SDK may have noticed that since November 2007, support for writing files in the .x file format has just disappeared. Also, what happened to the DirectX Mesh Tool? It was replaced by the DirectX Viewer which is buggy, slow and to be honest, quite useless…

Without .X file format, what can small developers use? Well, for one side we have the .FBX file format. As the .X file format it has a binary and an ASCII mode, so that could be an option… But there is so many useless code inside that I doubt I couldn’t get a working parser for this format in less than one week… Also, the binary mode is a proprietary (undocumented) format from Autodesk…

If this is really Microsoft’s decision, then I’m terribly sorry… Really… If this is just a matter of giving less importance to the small developers… I’m even more sorry… As I mentioned before, I will try to develop an exporter for 3D Studio Max on my own… If it gets anywhere near good, I will post it here… At least, I hope that can help someone!