Search code examples
coordinate-systemscoordinate-transformationmaxscript

Pivot and/or coordinate system bug in mesh-exporting (MaxScript)?


I have an problem with position exporting to text file, I guess it's related to pivots and coordinate system.

To illustrate it, I made two scenes in 3ds max that looks the same, but are different: enter image description here

For simplification, you can consider only X-axis. At first one the pivot of sphere has been change (moved by [-50,0,0] from default position) and sphere position has been set to [0,0,0]. At second, the sphere pivot is at default position (center of the sphere) and sphere's position is [50,0,0]). The rest of spheres are just the point of reference.

After exporting with my script both spheres have exact same vertices' position. But I guess that the first one should have all vertices' positions transformed by [-50,0,0] offset as the pivot has been changed (it's the center of object space, isn't it?).

Both scenes should look like the second one: enter image description here

The position of spheres are ok as such ([0,0,0] for both) and the relative positions of vertices (to each other) are also good (they still form a sphere). But because of the problem I've mentioned in previous paragraph (no difference in vertices positions), the first scene renders incorrectly - with sphere "visible" at [0,0,0] instead of [50,0,0]. So the pivot change affected the object position but not the vertices position (they are not relative to pivot?).

My code:

--create vertices array (with duplicates, 3 vertices for each face)
for f = 1 to (meshOp.getNumFaces eMesh) do (

    face = getFace eMesh f

    for i = 1 to 3 do ( --for each of 3 vertices in face (triangle)
        vertexPos = (getvert eMesh face[i]) * (inverse eMesh.objecttransform)  --vertex position in object space (including rotation)

Solution

  • So, basically you want sort of an node space positions, not world positions, but relative to the node pivot, right?

    The node pivot transform would only be overlapping with the object transform if you would reset xform/rebuild the mesh, otherwise its relative position/rotation/scale to the object itself is only stored as objectOffsetPos, objectOffsetRot and objectOffsetScale. You have to understand the difference between node and object here, there can be one object and multiple nodes referencing the same object (instances), with different transforms and different properties including pivot pos/rot/scale. As you are using inverse eMesh.objectTransform, it will always return the same value with different pivot positions, you'd have to use eMesh.transform instead.