How to add grouping feature to custom mesh file format

Started by
7 comments, last by Vortez 10 years, 2 months ago

Im planning on adding some "grouping" feature to my custom file format of 3d models (i made an exporter for 3ds max) but im not sure how, so i would like to hear your sugestion.

Btw the file format is binary.

Im also attaching the file format spec in case that would help.

The file format is pretty simple, you have the file header at the top, and for each objects, the object header and data block .

What method should i use, when exporting multiples mesh, to know if they're grouped or not, i know ill probably need something like a tree i guess (ill figure the 3ds part myself, the question is file format specific).

Advertisement

Maybe i should assign an id to every objects, and add some fields like parent, numchildrens, childrens[], next/prev sibling ect?

First: I am not at all saying you shouldn't be designing a custom file format. It's usually the right thing to do if you want to load/save data derived from another more general file format (you mention 3ds Max).

The direction of the data flow you're asking about is confusing. Just for clarity, do you want to export data (say, from a modeling program) or import data (into an application) to support rendering a mesh? The reason I ask is that a good file format for importing data can be an excellent addition to an application. That can be supplemented by one or more conversion routines, separate from the application itself, to change (for instance) 3ds Max files to something better for your specific needs.

I'm suggesting you should know why you're doing something, i.e., what you want the result to be, before you decide how to do it. You don't mention why you want a custom file format. As your decisions should be based on that, it's difficult to make suggestions to help you go in the right direction.

So.. what's the purpose for your particular file format? Speed in loading/saving to reduce disk access time? File size?

Do you want it to be flexible (i.e., load any type data in any type of arrangement), or are you looking to save/load data in a specific fashion to fit the specific needs of your application?


when exporting multiples mesh, to know if they're grouped or not

What do you mean by "grouped?"

If you're exporting data, you should already know. Or, are you asking how you can tell from the 3ds Max file whether meshes are "grouped" because you want to do something similar?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

The thing is, the exporter/importer descripted in the attached file already exist, i want to expand on it.

What i mean by grouping is, you know, when your in studio max, you can group stuffs(meshs) together in a scene, and then group two or mores other groups together ect, like directory and file in windows explorer for example.

I know the file format seem a bit weird but, it's not that bad actually. im basically exporting mesh data in 3 groups, indexed data for curved stuffs, non-indexed data for blocky stuff (ie cubes), and studio max data required for the importer only. Having both indexed and non indexed vertices might seem like a weird choice at first, but it has it's use. I can choose which mode to use when loading them in my engine. I just made a compromise to use them both instead of only one in the file format, so i can use one code path when importing later, i kinda choosed more flexibility at the little cost of a bigger file size if you want. also, since the file format support compression internally, this is not a big problem.

The thing with cubes is, if your vertices are indexed, you can't use per face lighting, which look wierd, and you can't texture each face independently either, but a sphere for example don't usually require per-face lighthing and using the same texture uv on a sphere work usually well, but not a cube, that's why i export both way.

But, all this dosen't really matter for the question im asking, it's just to clarify the format i used.

It appears your question is either studio max or 3ds specific, rather than a General Programming question. Though someone with specific studio max API knowledge or a better familiarity with the 3ds format may find your post here, you may want to consider having a moderator move it to a more appropriate forum.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Im not asking for the code to do this, just what is the best way that i could use to save the different meshs parent/neighborg/childs hiearchy relationship in the file.

In other words, how do you save/load a tree to/from a file?

This is not specific to 3DS Max or Maya; groups exist in a variety of other formats, including FBX.
Support for groups is necessary for modeling the way things are animated in authoring tools (since you can group a pair of objects and then start animating the group, causing the both to move, etc.) within your engine, and it is an error for any custom 3D file format not to have support for groups.


Exporting them is trivial depending on how you have set up your format.
Something else that is necessary to replay animations properly is support for a hierarchy (a scene graph) inside the model data. The arm needs to know it is a child of the body etc.
If this system is not yet in place, place it.


Next every object in the file is part of the scene graph. They all inherit from CEntity or CUnknown or CNode or whatever.
Properties common to all objects in the file will exist as a member of that base class. That means basically a type, name, unique ID, a transformation, and a parent ID.


Every object can parent any other object so any missing objects, such as a light or in this case a group will cause problems. So you need to export all the objects, even if temporarily you aren’t using them. Any objects you don’t use, let it fall back to being a group in your file format until eventually you get to it.


A group is just the CEntity or CNode—whatever—that returns a “GROUP” ID type. Serializing it is otherwise the same.



There is nothing special about exporting a tree/hierarchy to a file; I’ve just described it. You export the unique ID on each object along with its parent ID.
When loading, load everything linearly and then connect them within your run-time structures via actual pointers to loaded objects (for parenting and childing). Parents are found by searching the linear list for the proper ID.
Note that the shared base mesh does not need any form of actual parenting; it is not a run-time structure. Mesh instances need the parenting data only.

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

As L. Spiro said, Index is enough, and for save/load it's easy using them, x86/x64 same size, you don't need pointer for that.

Take care about group, sometimes you can have problem during export, but the problem is fast found.

The scene is always exported in recursive way so the parent is always valid in order.

Ok, thank you for your answers, ill look forward into that.

This topic is closed to new replies.

Advertisement