Skip to content

Commit e322539

Browse files
authored
Merge pull request #4 from Patch2PDF/coordinate-system-fix
Coordinate system fix
2 parents 795e31c + d8ed99a commit e322539

6 files changed

Lines changed: 21 additions & 18 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ See below for examples
1818
```go
1919
RasterizerConfig{
2020
RenderLabels: false,
21-
Rotation: rasterizer.Rotation{Alpha: 80, Beta: 0, Gamma: 200},
21+
Rotation: rasterizer.Rotation{Alpha: 10, Beta: 0, Gamma: -20},
2222
OverrideColors: OverrideColorMap{},
2323
CanvasConfig: CanvasConfig{
2424
Width: 4000,
@@ -37,7 +37,7 @@ RasterizerConfig{
3737
```go
3838
RasterizerConfig{
3939
RenderLabels: true,
40-
Rotation: rasterizer.Rotation{Alpha: 90, Beta: 0, Gamma: 180},
40+
Rotation: rasterizer.Rotation{Alpha: 0, Beta: 0, Gamma: 0},
4141
OverrideColors: OverrideColorMap{},
4242
CanvasConfig: CanvasConfig{
4343
Width: 4000,

examples/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ func main() {
9595
LabelFontSize: 10,
9696
}
9797

98-
rotation1 := MeshTypes.GenerateRotationMatrix(80, 0, 200)
98+
rotation1 := MeshTypes.GenerateRotationMatrix(10, 0, -20)
9999
canvas1, err := rasterizer.Draw(&stage_model, rasterizer.RasterizerConfig{RenderLabels: false, Rotation: rotation1, OverrideColors: overrideColors, CanvasConfig: canvasConfig})
100100
if err != nil {
101101
log.Fatal(err)
102102
}
103103

104-
rotation2 := MeshTypes.GenerateRotationMatrix(90, 0, 180)
104+
rotation2 := MeshTypes.GenerateRotationMatrix(0, 0, 0)
105105
rotation2 = rotation2.ReverseTransformation(rotation1)
106106
rasterizer.SaveCanvasAsPNGFile("side.png", canvas1)
107107
canvas2, err := rasterizer.Draw(&stage_model, rasterizer.RasterizerConfig{RenderLabels: true, Rotation: rotation2, OverrideColors: overrideColors, CanvasConfig: canvasConfig})

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ go 1.25.6
55
require (
66
github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.2.0
77
github.com/Patch2PDF/GDTF-Parser v0.4.1
8-
github.com/Patch2PDF/MVR-Parser v0.3.1
8+
github.com/Patch2PDF/MVR-Parser v0.3.2
99
)
1010

11-
require golang.org/x/text v0.34.0 // indirect
11+
require golang.org/x/text v0.35.0 // indirect
1212

1313
require (
1414
github.com/qmuntal/gltf v0.28.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.2.0 h1:ykkdyTIl++IaxBbgo2WFF3/k4jy7I
22
github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.2.0/go.mod h1:zAcGHlYdE75hdFo624nQfQHTzw9+NfPJT8Eo2mB1lI8=
33
github.com/Patch2PDF/GDTF-Parser v0.4.1 h1:RLmzQwIHGuEYc6C6hNtWA3HOpjhUizhkg36u0Px1a7E=
44
github.com/Patch2PDF/GDTF-Parser v0.4.1/go.mod h1:2l8WWbsYr4D0Uo069HMh9tImKtaUzy2+OeUpl7IN+S4=
5-
github.com/Patch2PDF/MVR-Parser v0.3.1 h1:lg9MieoOL93Bm+huKz1yMlJWuFLzHyJ+afZj1S8UKbs=
6-
github.com/Patch2PDF/MVR-Parser v0.3.1/go.mod h1:2ekLlUhkPCkDli56afCQT/9EGdE/llx3NCF5E1+YiXc=
5+
github.com/Patch2PDF/MVR-Parser v0.3.2 h1:Kpq6BUs31KSUhLEg/f16gnRh1t5YD5Y94WeTo9NRGcY=
6+
github.com/Patch2PDF/MVR-Parser v0.3.2/go.mod h1:2ekLlUhkPCkDli56afCQT/9EGdE/llx3NCF5E1+YiXc=
77
github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg=
88
github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
99
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=
1212
golang.org/x/image v0.36.0/go.mod h1:YsWD2TyyGKiIX1kZlu9QfKIsQ4nAAK9bdgdrIsE7xy4=
1313
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
1414
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
15-
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
16-
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
15+
golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8=
16+
golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=

model_manipulation.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ func normalizeAndRotateStageModel(canvas *Canvas, stageModel *StageModel, rotati
9191
height := float64(canvas.height - 1)
9292

9393
// normalizing to canvas dimensions
94-
diff := theoretical_max.Sub(theoretical_min)
95-
scale := width / diff.X
96-
if scale*diff.Y >= float64(canvas.height) {
97-
scale = height / diff.Y
94+
// NOTE: stagemodel coordinate system is z for up and x for right position
95+
visualWidth := theoretical_max.X - theoretical_min.X
96+
visualHeight := math.Abs(theoretical_max.Z - theoretical_min.Z)
97+
scale := width / visualWidth
98+
if scale*visualHeight > height {
99+
scale = height / visualHeight
98100
}
99101
centeringMatrix = centeringMatrix.MulScalar(scale)
100102
centeringMatrix.X03 += width / 2
101-
centeringMatrix.X13 += height / 2
103+
centeringMatrix.X23 -= height / 2
102104

103105
rotateAndTranslateStageModel(stageModel, centeringMatrix)
104106
}

triangle.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ type Triangle struct {
2121
}
2222

2323
func NewTriangleFromMeshTriangle(triangle MeshTypes.Triangle) Triangle {
24+
// NOTE: mesh coordinate system is z for up and x for right position
2425
return Triangle{
25-
Point{x: math.Round(triangle.V0.Position.X), y: math.Round(triangle.V0.Position.Y), z: triangle.V0.Position.Z},
26-
Point{x: math.Round(triangle.V1.Position.X), y: math.Round(triangle.V1.Position.Y), z: triangle.V1.Position.Z},
27-
Point{x: math.Round(triangle.V2.Position.X), y: math.Round(triangle.V2.Position.Y), z: triangle.V2.Position.Z},
26+
Point{x: (triangle.V0.Position.X), y: -(triangle.V0.Position.Z), z: -triangle.V0.Position.Y},
27+
Point{x: (triangle.V1.Position.X), y: -(triangle.V1.Position.Z), z: -triangle.V1.Position.Y},
28+
Point{x: (triangle.V2.Position.X), y: -(triangle.V2.Position.Z), z: -triangle.V2.Position.Y},
2829
}
2930
}
3031

0 commit comments

Comments
 (0)