cuddlyogre / ExportLDraw

LDraw Import and Exporter for Blender 2.82+
GNU General Public License v2.0
49 stars 12 forks source link

Incorrect vertex positions with "Preserve file structure" #32

Open ScanMountGoat opened 1 year ago

ScanMountGoat commented 1 year ago

image

Preserving the file structure results in inaccurate vertex positions for some models on import as mentioned in the README. The main issue is that Blender often stores a decomposed version of the matrix instead of the matrix itself. This means the transformation must be representable as a translation, rotation, and scale vector (no shearing). These vectors are also the values you edit in the UI. You can set a matrix with shear to the object's transform, but Blender will still convert it to its internal representation. The final reconstructed transform won't always match the original matrix.

Shearing matrices work fine when transforming vertices directly since the matrix is "baked" into the vertex positions themselves. The easiest way is to use something like mesh.data.transform(matrix). This is obviously problematic if you want to preserve this matrix for exporting. This shouldn't be an issue for custom parts since you can always create an equivalent part with transforms that are representable by Blender.

https://blender.stackexchange.com/questions/15240/relationship-between-global-vertex-coordinates-and-mesh-objects-matrix-attribut/32608#32608

cuddlyogre commented 1 year ago

I'll look more into this.