Getting model from 3DS Max to my game engine

Started by
13 comments, last by BornToCode 11 years, 3 months ago

For a 3D game engine I wrote,

I currently get models loaded into the engine by parsing files exported from 3DS Max using the ASCII export function. However, I cannot get this to work usefully for anything other than the geometry.

Specifically, animations and particle systems.

I have tried to export from 3DS Max in most of the formats in the list of export options, but I can't see any useful information in the resulting exported files about the animations and particle systems.

For my engine, I need the actual key frame information for animations. The engine is designed to just take the keyframe information and then do the interpolation and calculations in real-time. But I can't seem to figure out how to get 3DS Max to export the animations like that. Instead, they appear to be exported by just listing the transform at each various sampled frames, instead of listing the keyframes.

This is what I see when I try to export a model in the ASCII format with an animation that just translates a cube.


*TM_ANIMATION {
*NODE_NAME "Box001"
*CONTROL_POS_TRACK {
*CONTROL_POS_SAMPLE 0 48.7667 2.7128 0.0000
*CONTROL_POS_SAMPLE 800 37.3693 6.5535 0.0000
*CONTROL_POS_SAMPLE 1600 10.9041 15.4717 0.0000
*CONTROL_POS_SAMPLE 2400 -19.0383 25.5616 0.0000
*CONTROL_POS_SAMPLE 3200 -40.8672 32.9175 0.0000
*CONTROL_POS_SAMPLE 4000 -45.2485 34.3939 0.0000
}
}

Also, when I try to export a particle system, I see nothing useful in the resulting file. My engine is designed to take a bunch of parameters for the system, and then instantiate a particle system with those parameters. I would like to be able to take the exact parameters of the system in 3DS Max and load them into my engine.

This is all I see when exporting a scene with a particle system:

*NODE_NAME "Spray001"
*NODE_TM {
*NODE_NAME "Spray001"
*INHERIT_POS 0 0 0
*INHERIT_ROT 0 0 0
*INHERIT_SCL 0 0 0
*TM_ROW0 1.0000 0.0000 0.0000
*TM_ROW1 0.0000 1.0000 0.0000
*TM_ROW2 0.0000 0.0000 1.0000
*TM_ROW3 17.6095 19.0154 0.0000
*TM_POS 17.6095 19.0154 0.0000
*TM_ROTAXIS 0.0000 0.0000 0.0000
*TM_ROTANGLE 0.0000
*TM_SCALE 1.0000 1.0000 1.0000
*TM_SCALEAXIS 0.0000 0.0000 0.0000
*TM_SCALEAXISANG 0.0000
}
*PROP_MOTIONBLUR 0
*PROP_CASTSHADOW 1
*PROP_RECVSHADOW 1
*WIREFRAME_COLOR 0.5490 0.3451 0.8824
*MESH_ANIMATION {
}


I tried looking for guides on how to do this but have found nothing useful yet.
Advertisement
Export to something like Collada, parse the Collada file (it's xml and well defined) and save the resulting data to your own binary format and load into your engine - you could also consider FBX/Assimp but I haven't used either of those.

There are several threads on gamedev about exporting/importing from DCC tools and converting to one of these formats - it looks daunting but it really isn't when you get into it.

This will tell you most of what you need to know about parsing Collada files and is brilliantly written I think:
<a href='http://thecansin.com/Files/COLLADA.pdf'>http://thecansin.com/Files/COLLADA.pdf</a>

I tried exporting a particle system as Collada, but all it gave me was this: (for reference, the particle system in the scene was just a default Spray system with a few parameters changed). Am I doing something wrong?



<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
<asset>
<contributor>
<author></author>
<authoring_tool>FBX COLLADA exporter</authoring_tool>
<comments></comments>
</contributor>
<created>2013-01-16T20:13:55Z</created>
<keywords></keywords>
<modified>2013-01-16T20:13:55Z</modified>
<revision></revision>
<subject></subject>
<title></title>
<unit meter="0.025400" name="centimeter"></unit>
<up_axis>Y_UP</up_axis>
</asset>
<library_visual_scenes>
<visual_scene id="" name="">
<node name="Spray001" id="Spray001" sid="Spray001">
<matrix sid="matrix">1.000000 0.000000 0.000000 17.609482 0.000000 0.000000 1.000000 0.000000 0.000000 -1.000000 0.000000 -19.015411 0.000000 0.000000 0.000000 1.000000</matrix>
<extra>
<technique profile="FCOLLADA">
<visibility>1.000000</visibility>
</technique>
</extra>
</node>
<extra>
<technique profile="MAX3D">
<frame_rate>30.000000</frame_rate>
</technique>
<technique profile="FCOLLADA">
<start_time>0.000000</start_time>
<end_time>3.333333</end_time>
</technique>
</extra>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#"></instance_visual_scene>
</scene>
</COLLADA>

I may be wrong, but I dont think collada supports exporting particle emitters. I did find this http://www.collada.org/mediawiki/index.php/Particle_emitters_FCOLLADA_extension FCollada extention that looks like it can extend collada to export the particle emitters, but dont have any experience with it.

I'm working on a first person zombie shooter that's set in a procedural open world. I'm using a custom game engine created from scratch with opengl and C++. Follow my development blog for updates on the game and the engine. http://www.Subsurfacegames.com

Your best bet is with Autodesk® FBX® (.FBX extension). They export emitters and animations (just the key-frames) and the SDK makes it easy to load and work with all of this information.

Don’t try to parse model files manually unless there is no other way.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I'm doing everything from scratch for this, so FBX is not an option (wikipedia says the format is not revealed and you have to use Autodesk's importer code).

I'll try the Collada exporter that you linked, thanks.

My engine is from-scratch too. I don’t see how that is related to the Autodesk® FBX® SDK.

You are aware that it is wrong to import directly into your engine from .DAE, .MAX, .3DS, .FBX, etc., right?

You are supposed to make converters from these to your own custom format and then load that by your engine.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Yes I am aware that I should not directly import the intermediate formats to my engine, but it is a necessary step at the moment so I can learn how it works. I need to be able to parse these intermediate formats if I wish to convert the format to what my engine eventually uses.

I currently parse the ASCII model files directly to my engine. It is slow, but it is a necessary step for the engine at the moment because I know very little about how files like this are stored in the real world, and how graphics theory translates to practical use. I don't know what the best way to make my own format for use directly with the engine will be.

It is a better option for me to first load the models directly from human-readable formats so I can understand everything about them. Once I know exactly what's practical to have in a final format and what needs to be stored, or what's better to calculate in real-time instead, I will settle on a format.

.FBX is useless to me for this because I can't open the file and look at it.

Also, Collada is not working very well either. I can't figure out how to export a cube the way it should be exported.

With the ASCII format, 3DS Max would not generate duplicate vertices for non-smoothed faces. So my engine generates additional vertices for faces that are meant to be not smooth based on the smoothing groups.

Collada does not seem to support smoothing groups. Instead it just duplicates every vertex no matter what -- even if I set the entire object to all be in the same smoothing group. If I turn off the duplication, then the triangle list in the exported file still tries to use indices of vertices that weren't output by the exporter.

For example: this is the output of the collada exporter for a model with a cube with all faces set to the same smoothing group:

<triangles count="12"><input semantic="VERTEX" offset="0" source="#Box001-VERTEX"/><input semantic="NORMAL" offset="1" source="#Box001-Normal0"/><input semantic="TEXCOORD" offset="2" set="0" source="#Box001-UV0"/><p> 1 0 1 0 1 0 3 2 3 0 3 0 2 4 2 3 5 3 7 6 7 6 7 6 4 8 4 7 9 7 4 10 4 5 11 5 5 12 11 4 13 10 0 14 8 5 15 11 0 16 8 1 17 9 7 18 15 5 19 14 1 20 12 7 21 15 1 22 12 3 23 13 6 24 19 7 25 18 3 26 16 6 27 19 3 28 16 2 29 17 4 30 23 6 31 22 2 32 20 4 33 23 2 34 20 0 35 21</p></triangles>
The exporter still thinks there are 6 vertices per side of the cube (36 total) even though the output of the vertex list is just 8 vertices total. This is completely broken.
How do I get around this?
EDIT: I think I interpreted those lines wrong -- I think the offset tag means the that for each triangle three of those integers are part of a single vertex description, so every 3rd integer in that list is a vertex index, and the indices in that list that go higher than the number of vertices must refer to the normals.
But I still don't understand why there are more normals than vertices. If they are all smoothed together, why isn't it just exporting a single normal per vertex? Is it possible to correctly reconstruct the model if I use Collada? How can I know whether or not each triangle needs to have its own three distinct vertices whose normals aren't averaged with those of the surrounding faces?
I think it depends on the texture coordinates. If you create an organic shape in 3ds max and uv wrap it correctly, vertices should be shared.

For the cube example, it may be that 3ds max creates it with texture coordinates different on each face, meaning that you'll need duplicated vertices (unless you're using an atlas) and that's what it'll export.

The offset thing, yes that just means that for each consecutive group of 3 indices in the p element, the first is the vertex lookup, the second is the normal lookup and the third is the texture coordinate lookup.

That link I sent explains all this very well.

So is there no way to just have 3DS Max export a list of the exact vertices the triangles should use? Meaning, if I export a cube with each face in a different smoothing group, it will export three vertices per triangle (totaling 2 triangles per face * 6 faces * 3 vertices = 36 vertices), while at the same time any edges in the same smoothing group will not have their vertices duplicated? I've tried every option I could, and it seems that I can either just export a list of non-duplicated vertices and completely rely on smoothing groups for knowing whether my engine should duplicate them, or I can export a list with every single vertex duplicated for each triangle, and then the engine doesn't have to duplicate anything to render the model correctly, but it wastes a lot of memory.

Also, apparently you can export FBX in ASCII. However, the C++ SDK for FBX doesn't work with VS2012 (my main IDE). There's a link for a beta version, but they have to manually add you to it when you email them (they haven't gotten back to me yet). VS2012 lets you edit FBX, Collada, and OBJ models inside the IDE. It's pretty cool.

This topic is closed to new replies.

Advertisement