From 75244d578fe95faa4f9491bbc5a3b24b07f8643c Mon Sep 17 00:00:00 2001 From: Jannik-Hm Date: Wed, 11 Mar 2026 13:38:41 +0100 Subject: [PATCH 1/3] fixed rasterizer working in wrong coordinate system (same rotation matrices now produce different results) + removed early rounding to reduce errors --- model_manipulation.go | 12 +++++++----- triangle.go | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/model_manipulation.go b/model_manipulation.go index 5692c3a..383c7ed 100644 --- a/model_manipulation.go +++ b/model_manipulation.go @@ -91,14 +91,16 @@ func normalizeAndRotateStageModel(canvas *Canvas, stageModel *StageModel, rotati height := float64(canvas.height - 1) // normalizing to canvas dimensions - diff := theoretical_max.Sub(theoretical_min) - scale := width / diff.X - if scale*diff.Y >= float64(canvas.height) { - scale = height / diff.Y + // NOTE: stagemodel coordinate system is z for up and x for right position + visualWidth := theoretical_max.X - theoretical_min.X + visualHeight := math.Abs(theoretical_max.Z - theoretical_min.Z) + scale := width / visualWidth + if scale*visualHeight > height { + scale = height / visualHeight } centeringMatrix = centeringMatrix.MulScalar(scale) centeringMatrix.X03 += width / 2 - centeringMatrix.X13 += height / 2 + centeringMatrix.X23 -= height / 2 rotateAndTranslateStageModel(stageModel, centeringMatrix) } diff --git a/triangle.go b/triangle.go index a10996e..a267a6e 100644 --- a/triangle.go +++ b/triangle.go @@ -21,10 +21,11 @@ type Triangle struct { } func NewTriangleFromMeshTriangle(triangle MeshTypes.Triangle) Triangle { + // NOTE: mesh coordinate system is z for up and x for right position return Triangle{ - Point{x: math.Round(triangle.V0.Position.X), y: math.Round(triangle.V0.Position.Y), z: triangle.V0.Position.Z}, - Point{x: math.Round(triangle.V1.Position.X), y: math.Round(triangle.V1.Position.Y), z: triangle.V1.Position.Z}, - Point{x: math.Round(triangle.V2.Position.X), y: math.Round(triangle.V2.Position.Y), z: triangle.V2.Position.Z}, + Point{x: (triangle.V0.Position.X), y: -(triangle.V0.Position.Z), z: -triangle.V0.Position.Y}, + Point{x: (triangle.V1.Position.X), y: -(triangle.V1.Position.Z), z: -triangle.V1.Position.Y}, + Point{x: (triangle.V2.Position.X), y: -(triangle.V2.Position.Z), z: -triangle.V2.Position.Y}, } } From 14f83f55f60c703070af770eea9754e6b4f30f15 Mon Sep 17 00:00:00 2001 From: Jannik-Hm Date: Wed, 11 Mar 2026 13:39:08 +0100 Subject: [PATCH 2/3] updated example and readme with new rotation matrices --- README.md | 4 ++-- examples/main.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c6c1b82..339c0e6 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ See below for examples ```go RasterizerConfig{ RenderLabels: false, - Rotation: rasterizer.Rotation{Alpha: 80, Beta: 0, Gamma: 200}, + Rotation: rasterizer.Rotation{Alpha: 10, Beta: 0, Gamma: -20}, OverrideColors: OverrideColorMap{}, CanvasConfig: CanvasConfig{ Width: 4000, @@ -37,7 +37,7 @@ RasterizerConfig{ ```go RasterizerConfig{ RenderLabels: true, - Rotation: rasterizer.Rotation{Alpha: 90, Beta: 0, Gamma: 180}, + Rotation: rasterizer.Rotation{Alpha: 0, Beta: 0, Gamma: 0}, OverrideColors: OverrideColorMap{}, CanvasConfig: CanvasConfig{ Width: 4000, diff --git a/examples/main.go b/examples/main.go index 341e2dd..15e7932 100644 --- a/examples/main.go +++ b/examples/main.go @@ -95,13 +95,13 @@ func main() { LabelFontSize: 10, } - rotation1 := MeshTypes.GenerateRotationMatrix(80, 0, 200) + rotation1 := MeshTypes.GenerateRotationMatrix(10, 0, -20) canvas1, err := rasterizer.Draw(&stage_model, rasterizer.RasterizerConfig{RenderLabels: false, Rotation: rotation1, OverrideColors: overrideColors, CanvasConfig: canvasConfig}) if err != nil { log.Fatal(err) } - rotation2 := MeshTypes.GenerateRotationMatrix(90, 0, 180) + rotation2 := MeshTypes.GenerateRotationMatrix(0, 0, 0) rotation2 = rotation2.ReverseTransformation(rotation1) rasterizer.SaveCanvasAsPNGFile("side.png", canvas1) canvas2, err := rasterizer.Draw(&stage_model, rasterizer.RasterizerConfig{RenderLabels: true, Rotation: rotation2, OverrideColors: overrideColors, CanvasConfig: canvasConfig}) From d8ed99afee3fe029bbda58b2c20b326423636313 Mon Sep 17 00:00:00 2001 From: Jannik-Hm Date: Wed, 11 Mar 2026 14:51:38 +0100 Subject: [PATCH 3/3] bump dependencies --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 679048c..4f16a8d 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ go 1.25.6 require ( github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.2.0 github.com/Patch2PDF/GDTF-Parser v0.4.1 - github.com/Patch2PDF/MVR-Parser v0.3.1 + github.com/Patch2PDF/MVR-Parser v0.3.2 ) -require golang.org/x/text v0.34.0 // indirect +require golang.org/x/text v0.35.0 // indirect require ( github.com/qmuntal/gltf v0.28.0 // indirect diff --git a/go.sum b/go.sum index b3c6a5d..16a6ab3 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.2.0 h1:ykkdyTIl++IaxBbgo2WFF3/k4jy7I github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.2.0/go.mod h1:zAcGHlYdE75hdFo624nQfQHTzw9+NfPJT8Eo2mB1lI8= github.com/Patch2PDF/GDTF-Parser v0.4.1 h1:RLmzQwIHGuEYc6C6hNtWA3HOpjhUizhkg36u0Px1a7E= github.com/Patch2PDF/GDTF-Parser v0.4.1/go.mod h1:2l8WWbsYr4D0Uo069HMh9tImKtaUzy2+OeUpl7IN+S4= -github.com/Patch2PDF/MVR-Parser v0.3.1 h1:lg9MieoOL93Bm+huKz1yMlJWuFLzHyJ+afZj1S8UKbs= -github.com/Patch2PDF/MVR-Parser v0.3.1/go.mod h1:2ekLlUhkPCkDli56afCQT/9EGdE/llx3NCF5E1+YiXc= +github.com/Patch2PDF/MVR-Parser v0.3.2 h1:Kpq6BUs31KSUhLEg/f16gnRh1t5YD5Y94WeTo9NRGcY= +github.com/Patch2PDF/MVR-Parser v0.3.2/go.mod h1:2ekLlUhkPCkDli56afCQT/9EGdE/llx3NCF5E1+YiXc= github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg= github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/qmuntal/gltf v0.28.0 h1:C4A1temWMPtcI2+qNfpfRq8FEJxoBGUN3ZZM8BCc+xU= @@ -12,5 +12,5 @@ golang.org/x/image v0.36.0 h1:Iknbfm1afbgtwPTmHnS2gTM/6PPZfH+z2EFuOkSbqwc= golang.org/x/image v0.36.0/go.mod h1:YsWD2TyyGKiIX1kZlu9QfKIsQ4nAAK9bdgdrIsE7xy4= golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= -golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= -golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= +golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= +golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=