Skip to content

Commit bec33d8

Browse files
authored
Normal Texturing + SDF Meshing + Embeddable friendly (#123)
* embeddable friendly * New Circle, Grid, and repeat pattern nodes. Fixes. New Quad Sphere. * drawing/texturing/normals cleanup, new draw spheres node * examples updated * golfball example, dewarping quadsphere UVs, abstracting UVs concepts * SDF nodes * Marching cubes optimizations * Multi point line SDF
1 parent 42fd970 commit bec33d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2512
-542
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ Packages that have spawned from polyform's undertaking and have since been refac
7575
- [sfm](https://github.com/EliCDavis/sfm) - Utilities for interacting with reconstruction data from different SFM programs
7676
- [bitlib](https://github.com/EliCDavis/bitlib) - Utilities for reading and writing binary data
7777

78+
## Contributing
79+
80+
Learn how to [create your own nodes](./docs/guides/CreatingNodes/README.md) for others to use.
81+
7882
## Procedural Generation Examples
7983

8084
You can at the different projects under the [examples](/examples/) folder for different examples on how to procedurally generate meshes.

cmd/polyform/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/EliCDavis/polyform/drawing/texturing"
1919
_ "github.com/EliCDavis/polyform/drawing/texturing"
2020
_ "github.com/EliCDavis/polyform/drawing/texturing/normals"
21+
_ "github.com/EliCDavis/polyform/drawing/texturing/pattern"
2122

2223
_ "github.com/EliCDavis/polyform/formats/colmap"
2324
_ "github.com/EliCDavis/polyform/formats/gltf"
@@ -42,6 +43,7 @@ import (
4243
_ "github.com/EliCDavis/polyform/math/geometry"
4344
_ "github.com/EliCDavis/polyform/math/noise"
4445
_ "github.com/EliCDavis/polyform/math/quaternion"
46+
_ "github.com/EliCDavis/polyform/math/sdf"
4547
_ "github.com/EliCDavis/polyform/math/trig"
4648
_ "github.com/EliCDavis/polyform/math/trs"
4749
_ "github.com/EliCDavis/polyform/math/unit"
@@ -50,6 +52,7 @@ import (
5052

5153
_ "github.com/EliCDavis/polyform/modeling"
5254
_ "github.com/EliCDavis/polyform/modeling/extrude"
55+
_ "github.com/EliCDavis/polyform/modeling/marching"
5356
_ "github.com/EliCDavis/polyform/modeling/meshops"
5457
_ "github.com/EliCDavis/polyform/modeling/meshops/gausops"
5558
_ "github.com/EliCDavis/polyform/modeling/primitives"

docs/resources/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,7 @@ Resources either directly contributing to the code, or are just interesting find
163163
- Morton Encoding
164164
- [_"Morton encoding/decoding through bit interleaving: Implementations"_ Jeroen Baert's Blog](https://www.forceflow.be/2013/10/07/morton-encodingdecoding-through-bit-interleaving-implementations/)
165165
- [Code](https://github.com/Forceflow/libmorton)
166+
- Quad Spheres
167+
- [_"Wraparound square tile maps on a sphere"_ by Redblob](https://www.redblobgames.com/x/1938-square-tiling-of-sphere/)
168+
- [_"Mapping a Cube to a Sphere"_ by Harry van Langen](https://hvlanalysis.blogspot.com/2023/05/mapping-cube-to-sphere.html?m=1)
169+
- [_"Survey of Cube Mapping Methods in Interactive Computer Graphics"_ by M. Lambers](https://marlam.de/publications/cubemaps/lambers2019cubemaps.pdf)

drawing/coloring/operations.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,11 @@ func Interpolate(a, b color.Color, t float64) color.Color {
236236
A: uint8(aVal),
237237
}
238238
}
239+
240+
func Greyscale(c color.Color) float64 {
241+
r, g, b, _ := c.RGBA()
242+
rF := float64(r >> 8)
243+
gF := float64(g >> 8)
244+
bF := float64(b >> 8)
245+
return (rF + gF + bF) / (255 * 3)
246+
}

drawing/texturing/blur.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func convolve1DGaussian[T any](space vector.Space[T], src Texture[T], dst Textur
118118
func RadialGaussianBlur[T any](space vector.Space[T], src Texture[T], radius int, sigma float64) Texture[T] {
119119
kernel := gaussianKernel(radius, sigma)
120120

121-
tmp := NewTexture[T](src.width, src.height)
122-
out := NewTexture[T](src.width, src.height)
121+
tmp := Empty[T](src.width, src.height)
122+
out := Empty[T](src.width, src.height)
123123

124124
// Horizontal then vertical
125125
convolve1DGaussian(space, src, tmp, kernel, true)

drawing/texturing/color.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func DivideColor(a, b Texture[coloring.Color]) (*Texture[coloring.Color], error)
99
return nil, ErrMismatchDimensions
1010
}
1111

12-
result := NewTexture[coloring.Color](a.width, a.height)
12+
result := Empty[coloring.Color](a.width, a.height)
1313
a.ScanParallel(func(x, y int, v coloring.Color) {
1414
other := b.Get(x, y)
1515
result.Set(x, y, coloring.Color{
@@ -25,7 +25,7 @@ func DivideColor(a, b Texture[coloring.Color]) (*Texture[coloring.Color], error)
2525

2626
func MaxColor(a Texture[coloring.Color], other float64) Texture[coloring.Color] {
2727

28-
result := NewTexture[coloring.Color](a.width, a.height)
28+
result := Empty[coloring.Color](a.width, a.height)
2929
a.ScanParallel(func(x, y int, v coloring.Color) {
3030
result.Set(x, y, coloring.Color{
3131
R: max(v.R, other),
@@ -40,7 +40,7 @@ func MaxColor(a Texture[coloring.Color], other float64) Texture[coloring.Color]
4040

4141
func ClampColor(a Texture[coloring.Color], minimum, maximum float64) Texture[coloring.Color] {
4242

43-
result := NewTexture[coloring.Color](a.width, a.height)
43+
result := Empty[coloring.Color](a.width, a.height)
4444
a.ScanParallel(func(x, y int, v coloring.Color) {
4545
result.Set(x, y, coloring.Color{
4646
R: min(max(v.R, minimum), maximum),

drawing/texturing/errors.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package texturing
22

3-
import "errors"
3+
import (
4+
"errors"
5+
"fmt"
6+
7+
"github.com/EliCDavis/vector/vector2"
8+
)
49

510
var ErrMismatchDimensions = errors.New("mismatch texture resolutions")
11+
12+
type InvalidDimension vector2.Vector[int]
13+
14+
func (id InvalidDimension) Error() string {
15+
v := vector2.Vector[int](id)
16+
return fmt.Sprintf("invalid texture dimensions %dx%d", v.X(), v.Y())
17+
}

drawing/texturing/float.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func OneMinus(in Texture[float64]) Texture[float64] {
10-
result := NewTexture[float64](in.width, in.height)
10+
result := Empty[float64](in.width, in.height)
1111
for y := range in.height {
1212
for x := range in.width {
1313
result.Set(x, y, 1-in.Get(x, y))
@@ -47,7 +47,7 @@ func (n MultiplyFloat1Node) Result(out *nodes.StructOutput[Texture[float64]]) {
4747
return
4848
}
4949

50-
result := NewTexture[float64](textures[0].Width(), textures[0].Height())
50+
result := Empty[float64](textures[0].Width(), textures[0].Height())
5151
for y := range result.Height() {
5252
for x := range result.Width() {
5353
v := textures[0].Get(x, y)

drawing/texturing/gradient.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type RadialGradient[T any] struct {
1818
}
1919

2020
func (rg RadialGradient[T]) Texture() Texture[T] {
21-
tex := NewTexture[T](rg.Width, rg.Height)
21+
tex := Empty[T](rg.Width, rg.Height)
2222
center := vector2.New(rg.Width, rg.Height).
2323
ToFloat64().
2424
Scale(0.5)
@@ -45,7 +45,7 @@ func (n RadialGradientNode[T]) LinearGradient(out *nodes.StructOutput[Texture[T]
4545
height := nodes.TryGetOutputValue(out, n.Height, 1)
4646

4747
if n.Gradient == nil {
48-
out.Set(NewTexture[T](width, height))
48+
out.Set(Empty[T](width, height))
4949
return
5050
}
5151

@@ -69,7 +69,7 @@ type LinearGradient[T any] struct {
6969
}
7070

7171
func (lg LinearGradient[T]) Texture() Texture[T] {
72-
tex := NewTexture[T](lg.Width, lg.Height)
72+
tex := Empty[T](lg.Width, lg.Height)
7373

7474
boxCenter := vector3.New(lg.Width, lg.Height, 0).
7575
ToFloat64().
@@ -109,7 +109,7 @@ func (n LinearGradientNode[T]) LinearGradient(out *nodes.StructOutput[Texture[T]
109109
height := nodes.TryGetOutputValue(out, n.Height, 1)
110110

111111
if n.Gradient == nil {
112-
out.Set(NewTexture[T](width, height))
112+
out.Set(Empty[T](width, height))
113113
return
114114
}
115115

@@ -124,7 +124,7 @@ func (n LinearGradientNode[T]) LinearGradient(out *nodes.StructOutput[Texture[T]
124124
}
125125

126126
func ApplyGradient[T any](time Texture[float64], gradient coloring.Gradient[T]) Texture[T] {
127-
result := NewTexture[T](time.width, time.height)
127+
result := Empty[T](time.width, time.height)
128128
for y := range result.height {
129129
for x := range result.width {
130130
result.Set(x, y, gradient.Sample(time.Get(x, y)))
@@ -145,7 +145,7 @@ func (n ApplyGradientNode[T]) Texture(out *nodes.StructOutput[Texture[T]]) {
145145

146146
time := nodes.GetOutputValue(out, n.Time)
147147
if n.Gradient == nil {
148-
out.Set(NewTexture[T](time.Width(), time.Height()))
148+
out.Set(Empty[T](time.Width(), time.Height()))
149149
return
150150
}
151151

drawing/texturing/noise.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func texture(
3434
out.CaptureError(fmt.Errorf("invalid height dimension: %d", height))
3535
return
3636
}
37-
t := NewTexture[float64](width, height)
37+
t := Empty[float64](width, height)
3838

3939
scale := nodes.TryGetOutputValue(out, Scale, vector2.One[float64]())
4040
offset := nodes.TryGetOutputValue(out, Offset, 0)

0 commit comments

Comments
 (0)