July 7, 2009

Textures!

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:

textured

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!

Advertisements

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!

June 29, 2009

It lives!

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

The Conspiracy engine is already rendering stuff! πŸ˜€ Yesterday I managed to get a teapot (the CG Hello World thing) on the screen! Also, I have implemented input with DirectInput. To be quite honest, I was quite afraid of doing so because the DirectInput’s usual approach requires polling. Although I could wire it up to the WndProc and receive events through there, this is quite painful and not documented… However, the performance of DirectInput is nevertheless stunning at the moment!

Also, the Memory Management Layer (MML) has proved itself very useful as everything is being released as it should, obtaining a great memory performance too. Now I’m developing an importer of 3D files, exported directly from 3D Studio Max. However, I did not want to rely on Microsoft’s .X file because this format is now marked as deprecated and as far as I know, there is no substitute so far… So, I’m trying to build my very own MaxScript exporter for 3DS Max! So far it only exports geometry data, but I will try to make it export materials, textures and so on very soon! Also, I would like to make it export skeletal animations, but that does not seem easy at this moment…

For those of you who are interested or cannot find any example of how to do this, here is my (rather naive yet) Β approach (the code is poorly structured, I didn’t had the time to organize it yet, I’m sorry):

–Start by selecting every darn thing
select $*

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

–For every one of them
for obj in $ where superclassof obj == geometryclass do
(
–Convert every single one of them to poly
p = convertToPoly(obj)

–Get the number of faces
format “Name: %\n” p.name to:out_file
polyop.setFaceSelection p #all
faces = polyop.getFaceSelection p

format “Faces: %\n” faces.count to:out_file

–For every face
for i = 1 to faces.count do
(
–Why is this boolean?
if (faces[i]) then
(
faceVerts = polyop.getFaceVerts p i

if (faceVerts.count == 4) then
(
v1 = polyop.getVert p faceVerts[1]
v2 = polyop.getVert p faceVerts[2]
v3 = polyop.getVert p faceVerts[3]
v4 = polyop.getVert p faceVerts[4]

format “% % % %\n” v1 v2 v3 v4 to:out_file
outstr = (v1 as string) + ” ” + (v2 as string) + ” ” + (v3 as string) + ” ” + (v4 as string)
print outstr
)
)
)
)

More news will be coming very soon πŸ˜‰