1
\$\begingroup\$

I'm writing a class that reads an obj file, indexes each mesh and creates a VAO and GameObject of the appropriate type. I've stumbled on a design issue. Objects of the same name (Tree_A001, Tree_A002) are currently skipped over, and their min and max extents are used to calculate their centre, and therefore where to position the a copy of that mesh. Not only does this mean I've read in the mesh twice, just to ignore all the data as soon as I've got the min and max, but in my case I have 230 trees. It works but takes 12-15 seconds to read in the file itself, and I've not been able to gleam the rotation or scale of said object. I understand that comparing the min and max extents of the duplicate mesh to the original could let me get the scale, but as soon as the mesh is rotated in the scene file then it breaks. I'd like to do something more efficient than this however, and I'm stuck on what do to. What is the done thing in professional games, that allows multiple objects to be placed in a 3d modelling software, and their individual position rotation and scale to be kept? I've experimented with using single triangles to represent the position and scale etc but it makes designing the scene much harder as you can't see what you're placing. Thanks for any advice

\$\endgroup\$
  • \$\begingroup\$ Are you talking about 230 individual tree objects, or several instances of an object? \$\endgroup\$ – Jay Mar 13 at 4:59
  • \$\begingroup\$ They are the same original mesh, but they are copies and have individual scales and rotations. My rending engine supports instanced rendering with each instance having individual rotation, scale and position. \$\endgroup\$ – Will Hain Mar 13 at 10:11
0
\$\begingroup\$

There are a couple of issues here, but it looks like they are all solvable for you.

A good starting point is to distinguish between a Scene and a Mesh. A Scene might contain many Meshes. The Mesh here is the obj file and the Scene is a list including, for example,

"meshname.obj", position(x,y,z), scale(x,y,z), rotation, ...

and so on for each object in the scene.

From here, you can identify the mesh object by it's filename, load it once, and place instances of it at each location as specified by the scene file.

Also, while you load it you can check the data in place to calculate the extents of the bounding box. That is, load the model from disk into a buffer, use the buffer to calculate extents, use the same buffer to build the VBOs.

Calculating the center point may or may not be necessary anymore. What I would do in this situation is export each obj file individually from the modelling package, with the pivot point at the origin of the model. That way it doesn't need to be calculated at run-time, the zero point for each model is already where I want it. It sounds like you tried to export a whole scene as an obj, but you really want to split up the scene and just the individual elements are obj.

Finally, you can do this kind of thing in Blender using scene export plugins. This will depend on your engine and your modelling program, but it can be done. Many games develop a custom editor to handle this kind of thing.

\$\endgroup\$
  • \$\begingroup\$ Alright, do you happen to know if there is a plugin for 3DS Max that would achieve this? Thanks for your advice, the idea of having a seperate scene file from the mesh data is definitely appealing to me. I'm also toying with the idea, since I'm already working out positions from meshes, to move this functionality into a separate script that I can run once and generate such a scene file. Thanks. \$\endgroup\$ – Will Hain Mar 13 at 11:45
  • \$\begingroup\$ I haven't used 3ds max for such a long time sorry. \$\endgroup\$ – Jay Mar 13 at 11:50
  • \$\begingroup\$ Okay. Probably going to ask a new question as it's a little out of scope, but do you know how I would go about comparing meshes of the same shape to extract their rotation and scale? Obviously if I'm placing in trees etc in my 3ds max scene, then exporting a file with the details of each copies transformations, I'll need to get this data from just the vertex data \$\endgroup\$ – Will Hain Mar 13 at 12:09
  • \$\begingroup\$ No, you don't extract the rotation and scale from the vertex data. The info should be in the object data in your modelling program. You just need to find a way to export this data for each item. When you export a file it shouldn't be a single obj file for the whole scene. \$\endgroup\$ – Jay Mar 13 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.