Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Advanced 3DS loading

Started by Xarragon Jun 20, 2004 at 5:55 PM 6 replies 4.9k views
Original Post
Xarragon
Xarragon
Hello, I'm currently trying to load 3DS files for a game demo I'm working on. It wasn't much of a trouble to load and render the mesh and textures, but I had more advanced features in mind. Simply put, I need to load the hierarchy and transforms for the objects as well, as in my game demo, I have hierarchtical models, animated by modifying the object transforms... Loading the hierarchy wasn't much of a problem, but getting the transforms wasn't as easy... According to the MAXSDK documentation, the pivot point of each object serves as a local coordinate system. I have tried loading both the local transforms from the EDIT3DS-chunk (0x4160) and the keyframe-pivot-chunk (0xb020). When I evaluate these coordinates during debug, they are identical to what i get in the transform-type-in in MAX (by pressing F12) when an object is selected (not subobject level). The coordinates were relative to the scene origin, so in order to get the offset position from its parent, I loaded the info into the hierarchtical structure, and, starting at the root's children nodes, traversed down and for each object, I subtracted its translation coordinate by that of its parent. This would in effect give me the vector to translate with to move from the parents coordinate-frame to the childs coordinate-frame (excluding rotations for now). However, it seems the pivot points are different from what I set them to be inside MAX. The following screenshots shows in-MAX and in-game rendering of the model, and its pivot point (rendered at 0,0,0 in-game). In-editor-screen: http://home7.swipnet.se/~w-70134/game/model_max.jpg In-game-screen: http://home7.swipnet.se/~w-70134/game/model_ingame.jpg Sorry for the pimpy background color folks :-). As you can see, the origin/pivot is offset from its position in MAX. It doesn't seem to be the origin in the max workspace either. Does anyone have any information on how to calculate correct hierarchy offsets and rotations? I'm defining the hierarchy by using the usual "select and link" tool in max. Thanks in advance for any help, and kudos to Ben Humphrey at gametutorials.com for his 3ds loading tutorial.
Xarragonxarragon@swipnet.se
iNsAn1tY
iNsAn1tY
I've been thinking about this exact problem a lot recently. The model I'm having made at the moment (for a demo) is hierarchical, with one part needing to rotate about another at a local point. Loading the meshes from the 3DS files is relatively simple, but (and I haven't looked into this a lot), I don't think that obtaining the local transforms is. I believe that the 3D artist is using a standard 3DS Max command called Attach to connect the two separate meshes, but I'm not sure how I'd go about extracting this information from the *.max or *.3ds file. I was looking at writing a custom exporter (I was browsing the Max SDK, and got about half-way through the exporter documentation and tutorial), but I haven't figured out how much time that would take yet. It might be viable, if I do it, I'll write a tutorial on it.

I'll know more in a day or two when I have the model, and can being starting to load it...

EDIT: As a side note, in the Max SDK exporter tutorial, it shows how Max stores it's objects internally, as a series of nodes, the world being the root node. When you write an exporter, you loop through the tree, visiting every node, and extracting the geometric data. Now, I think (and I stress think, I didn't get al lthe way through the tutorial or documentation) that when you attach one object to another, it becomes a child of the object it's attached to, and therefore becomes a child node on the tree. This might be a way of obtaining the links you're looking for without having to guess with the incomplete *.3ds documentation. You'd loop through, find your base model, then read it's child nodes and the models they contain, and get your local transforms that way.

[Edited by - iNsAn1tY on June 21, 2004 1:45:30 PM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
Xarragon
Xarragon
I have indeed successfully extracted the hierarchy and rebuilt it in my run-time model format as a tree, with stl vectors for holding childrens. The hierarchtical information is stored in the keyframe chunk, as a bunch of nodes, which associates each object in the file (pointed out by the object name, an asciiz-string) with an integer.
This number can be used to rebuild the hierarchy, its really quite simple, I was planning to write some tutorial or publish my source etc, once I got the issue of the pivot points worked out.

I have acctually failed to see a single demo/loader that can render a hierarchtical model correctly. I loaded up my model into a loader, i think it was acctually from the tutorial here on gamedev.net, and the objects was not correctly positioned there either...

I'll try to re-export using Milkshape, in case it is an issue with MAX's exporting. Otherwise I'll try to work it out the hard way I guess... I must say I'm starting to think of doing some sort of hack instead, and simply use separate .3ds for each part, and set the offsets manually, or some combination...

Xarragonxarragon@swipnet.se
Xarragon
Xarragon
Luck smiles upon me, I seem to have found something related to the task: http://thorkildsen.no/faqsys/docs/3dscoo~1.pdf
Xarragonxarragon@swipnet.se
iNsAn1tY
iNsAn1tY
So what you're essentially saying is that 3DS Max is not saving your pivot points correctly (or at least, in the way you expect it to)? Are you positive that you're loading the co-ordinates for the pivots correctly? Is there anything else in the chunks that could be having an effect on them? Is the parent's pivot point at (0, 0, 0)? If not, did you subtract the translation of the pivot point of the parent at the top of the hierarchy from the origin before you started on the child nodes?

EDIT: I've learnt quite a bit in the past few hours, and if you read my first post, it sounds a bit dumb. Anyway, in the first post, I put Attach. Chances are, it's Select and Link. I've never used 3DS Max before, and I'm having to learn a little of it as I go along in order to load the models it makes. Tonight has been most instructive. I'm starting on that 3DS loader I need tomorrow, and chances are I'll run into the same problem you've encountered sometime around Wednesday. Guess we'll have to solve it (unless someone pops up here with the answer between now and then).

Do you think it might be a good idea to code an exporter anyway, assuming that it doesn't take up too much time and effort? There's a template for one in the Max SDK tutorials, and from the cursory glance I gave it, anyone with moderate C++/Win32 experience could knock one out (well, a basic one, at least). Something to consider, perhaps...

EDIT2:
Quote:
Original post by Xarragon
Otherwise I'll try to work it out the hard way I guess... I must say I'm starting to think of doing some sort of hack instead, and simply use separate .3ds for each part, and set the offsets manually, or some combination...

I have quite a bit of experience with Quake III's MD3 format, and that's the method it uses. You have separate files for the head model, torso model and legs model. In the head model, at the neck, there is a single, orphan face named "tag_head". In the torso, there is another orphan tag also called "tag_head". When the models are loaded, the tags are found, and links are established between the models at the position the tags indicate. There are also "tag_torso" and "tag_weapon" tags. The legs model is the parent, the torso attaches to it, and the head attaches to the torso. The weapon also attachs to the torso.

[Edited by - iNsAn1tY on June 21, 2004 6:45:53 PM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
Xarragon
Xarragon
Well, I have acctually planned to make an exporter of my own now, but I'll give 3DS one last try before I scrap it, since I've put condsiderable time into my 3ds loader.

I did try to import the model into Milkshape (using ASC and 3DS).
When I imported as 3DS, the model parts were offseted incorrectly as in-game, but when i fixed them and re-exported, they worked fine in-game (as for orientation). When using ASC, the hierarchy and object info were lost. If you read the PDF i linked to, it seems that the pivot offset/coordinates are ignored when exporting.

Anyhow, it would be enlightening as to the coordinates stored in the 3ds are in world-frame, object-frame or parent-frame format, and how to turn it into local coordinate information.

Othwerwise, there is an example 3ds exporter in the SDK, so one should be able to look at it and figure out just what information is written to the file.

What I have gotten out of the file, by experimenting, is the location of the objects, in world-frame (max scene) space. This information is the same that I get when inspecting an objects translation data manually (f12). But as said, when exporting, the pivot data seems to be missing. Not sure though, I'll play some more with it tonight, but I have some calculus homework to attend to right now... Yuck! :-(
Xarragonxarragon@swipnet.se
Xarragon
Xarragon
Anyways, the format I was planning on doing would have animation by rotation and translation of the rigid model parts. The rotations would be stored as quaternions, and translations as a vector. Then I would slerp between the keyframes to create the in-betweening frames, and yield the animation.

There is not much need for animation in my demo, but some simple effects, like moving parts of the gun model back for recoil effects or such would be nice.

Is there any problems with this approach? I know it makes the model animations limited, but as I said, I don't need very sophisticated animations...
Xarragonxarragon@swipnet.se
iNsAn1tY
iNsAn1tY
The tag method doesn't have too many drawbacks, apart from the major one, which is placing the tags in the first place. It's a decent method for linking multiple models, where each model can have it's own animations, eg. the recoil on a weapon model.

I'm going back to the Max SDK to see if writing an exporter is worth it. Like I said, it might make a decent tutorial if it comes together...

Good luck with your calculus :)
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.