Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module github.com/Patch2PDF/Stagemodel-Rasterizer
go 1.25.6

require (
github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.1.0
github.com/Patch2PDF/GDTF-Parser v0.4.0
github.com/Patch2PDF/MVR-Parser v0.3.0
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
)

require golang.org/x/text v0.34.0 // indirect

require (
github.com/qmuntal/gltf v0.28.0 // indirect
golang.org/x/image v0.36.0
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sync v0.20.0 // indirect
)

// replace github.com/Patch2PDF/GDTF-Mesh-Reader/v2 => ../GDTF-Mesh-Reader
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.1.0 h1:Do1+QFw7sNf6B1lE8T9rokVGQQ3I1EhYqK7OPL4ep1Q=
github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.1.0/go.mod h1:zAcGHlYdE75hdFo624nQfQHTzw9+NfPJT8Eo2mB1lI8=
github.com/Patch2PDF/GDTF-Parser v0.4.0 h1:ZdZDxIjm4K63tTVtf48K0sYJCyppuID1m4P2b4QfvM8=
github.com/Patch2PDF/GDTF-Parser v0.4.0/go.mod h1:i3hZmZ2wIJ294MllgqQ+wQn4RtuYIWL1KLSn9Gseqdw=
github.com/Patch2PDF/MVR-Parser v0.3.0 h1:bdvRFxkTc0oK2uxo7o0SK0JMtcdJu+/e2nsKNmODE80=
github.com/Patch2PDF/MVR-Parser v0.3.0/go.mod h1:DwJgsZcqTyn+eD3KG6OVUwHvpK56HjXFqGdI/UY4z+E=
github.com/Patch2PDF/GDTF-Mesh-Reader/v2 v2.2.0 h1:ykkdyTIl++IaxBbgo2WFF3/k4jy7IwcQ5FsXWBG4Zhg=
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/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=
github.com/qmuntal/gltf v0.28.0/go.mod h1:YoXZOt0Nc0kIfSKOLZIRoV4FycdC+GzE+3JgiAGYoMs=
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.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
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=
24 changes: 17 additions & 7 deletions triangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,26 @@ func (triangle Triangle) boundingTriangle(canvas *Canvas, color color.NRGBA, per
return 0, 0, 0, 0, fmt.Errorf("Triangle has 0 height")
}

total_area := triangle.signed_triangle_area()
total_area := math.Abs(triangle.signed_triangle_area()) // absolute to disable backface culling
if total_area < 1 {
return 0, 0, 0, 0, fmt.Errorf("Triangle area is less than 1 pixel") // backface culling + discarding triangles that cover less than a pixel // TODO: test / improve
return 0, 0, 0, 0, fmt.Errorf("Triangle area is less than 1 pixel") // discarding triangles that cover less than a pixel
}

// TODO: add canvas bounds check (via min/max with canvas bounds?)
bbminx = int(math.Min(math.Min(triangle.a.x, triangle.b.x), triangle.c.x))
bbminy = int(math.Min(math.Min(triangle.a.y, triangle.b.y), triangle.c.y))
bbmaxx = int(math.Max(math.Max(triangle.a.x, triangle.b.x), triangle.c.x))
bbmaxy = int(math.Max(math.Max(triangle.a.y, triangle.b.y), triangle.c.y))
// outer min / max resembles a canvas bounds check (0 to width/height)
borders := canvas.canvas.Rect
minx := math.Min(math.Min(triangle.a.x, triangle.b.x), triangle.c.x)
miny := math.Min(math.Min(triangle.a.y, triangle.b.y), triangle.c.y)
maxx := math.Max(math.Max(triangle.a.x, triangle.b.x), triangle.c.x)
maxy := math.Max(math.Max(triangle.a.y, triangle.b.y), triangle.c.y)

bbminx = max(int(math.Floor(minx)), borders.Min.X)
bbminy = max(int(math.Floor(miny)), borders.Min.Y)
bbmaxx = min(int(math.Ceil(maxx)), borders.Max.X-1)
bbmaxy = min(int(math.Ceil(maxy)), borders.Max.Y-1)

if bbminx > bbmaxx || bbminy > bbmaxy {
return
}

inv_total_area := 1 / total_area

Expand Down