# 3D Studio file madness!

Hello!

I need some help with loading a .3ds file. The problem is when i load the object i want it to be centered around origo even if it wasn’t that in the scene. I have found a transformation matrix (chunk 4160) that i think can be used to do the job, but i have no clue how to use it… Does anyone have a clue?

// Peter - Thanx!

I really don’t know, but I could guess that you’ll have to inverse that matrix (1/ for every component that is multiplied) and the multiplicate it with the vertices.
But I’m totally unsure about that.

What I do is just transform the vertexes on
their own without looking at extra data. This
is very easy; just calculate the “center
weight” for your vertexes with the weighting
function of your choice, and then translate
with the negative of that result.

I e, if your mesh only had two vertexes:

(1, 4, 4) and (9, 6, 8)

the linear center weight would be
(5, 5, 6)

Thus, you translate all your vertexes by
(-5, -5, -6) to end up with

(-4, -1, -2) (4, 1, 2)

If you have some specific constraints (such
as the bottom-most vertex always needs to be
at Z 0) you can easily add that to your
weighting function.

This works fine, because all the other data
(texture U/V, normals, etc) is location-
independent.

Btw: I also inspect the mesh data to
calculate normals, because I haven’t found a
description of the format which includes
normal information. My current method
calculates the normal of each triangle, and
then averages/normalizes them for all the
triangles connecting each vertex.

But it isn’t guaranteed that the weight off all objects’ vertices is really the center of it.

Umm… there is no single “center” of an
object. It all depends on what you want the
“center” to be, and thus how you choose
your weighting function will of course be
dependent on how you define “center”.

Or does 3dsMax have some “center” definition
for its models? I don’t own it, and have
only seen it used briefly, and I didn’t
notice any “center” moniker or gizmo…

Working with object centers (what is refered to as pivot points in Max) in a .3ds file is a headache ! We’ve developped a .3ds loader for our engine with the 3DSFTK library found (but not sure it’s still there) at the Autodesk FTP site. There isn’t in the format description a clear explanation of how the object pivot position, local matrix and keyframe position/orientations really mix together to get the correct object frame.
First of all, I think you should define what you mean by “the center of an object”. If its just, as it was mentioned, the barycenter of the object then, fine. But if its the pivot point defined in MAX, well, good luck! If you succeed in finding a method for computing the correct object frame that works for any model, I’d love to know.

Working with object centers (what is refered to as pivot points in Max) in a .3ds file is a headache ! We’ve developped a .3ds loader for our engine with the 3DSFTK library found (but not sure it’s still there) at the Autodesk FTP site. There isn’t in the format description a clear explanation of how the object pivot position, local matrix and keyframe position/orientations really mix together to get the correct object frame.
First of all, I think you should define what you mean by “the center of an object”. If its just, as it was mentioned, the barycenter of the object then, fine. But if its the pivot point defined in MAX, well, good luck! If you succeed in finding a method for computing the correct object frame that works for any model, I’d love to know.

Thanx for your feedback…

At first i had a weighting function but then i thougt it looked unprofessional so i wanted to do it a more professional way. But I’ll think i will go back to my weighting funktion where i calculate the object center.

When i was refering to a “center of an object” i thougt of a cube. There’s no problem to find the center of that one. But as mentiond above, what is the center of a more complex model, and will that center coincide with that center i want to have.

I dont really know yet… time will tell!

// Peter - THanx…

If you use no keyframes, and position the object with its pivot point over the origin, you’ll have the center defined as (0,0,0) obviously…