Skip to content

Commit e004d84

Browse files
committed
cli flags fixed
1 parent cb02fda commit e004d84

File tree

9 files changed

+131
-56
lines changed

9 files changed

+131
-56
lines changed

drawing/coloring/colors.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package coloring
2+
3+
func Black() WebColor {
4+
return WebColor{0, 0, 0, 255}
5+
}
6+
7+
func White() WebColor {
8+
return WebColor{255, 255, 255, 255}
9+
}
10+
11+
func Red() WebColor {
12+
return WebColor{255, 0, 0, 255}
13+
}
14+
15+
func Green() WebColor {
16+
return WebColor{0, 255, 0, 255}
17+
}
18+
19+
func Blue() WebColor {
20+
return WebColor{0, 0, 255, 255}
21+
}

drawing/coloring/colors_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package coloring_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/EliCDavis/polyform/drawing/coloring"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestColor(t *testing.T) {
11+
tests := map[string]struct {
12+
input coloring.WebColor
13+
wantR byte
14+
wantG byte
15+
wantB byte
16+
wantA byte
17+
}{
18+
"black": {input: coloring.Black(), wantR: 0, wantG: 0, wantB: 0, wantA: 255},
19+
"white": {input: coloring.White(), wantR: 255, wantG: 255, wantB: 255, wantA: 255},
20+
"red": {input: coloring.Red(), wantR: 255, wantG: 0, wantB: 0, wantA: 255},
21+
"green": {input: coloring.Green(), wantR: 0, wantG: 255, wantB: 0, wantA: 255},
22+
"blue": {input: coloring.Blue(), wantR: 0, wantG: 0, wantB: 255, wantA: 255},
23+
}
24+
25+
for name, tc := range tests {
26+
t.Run(name, func(t *testing.T) {
27+
assert.Equal(t, tc.wantR, tc.input.R)
28+
assert.Equal(t, tc.wantG, tc.input.G)
29+
assert.Equal(t, tc.wantB, tc.input.B)
30+
assert.Equal(t, tc.wantA, tc.input.A)
31+
})
32+
}
33+
}

examples/crop-pointcloud/main.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -152,27 +152,34 @@ func (bn BaloonNode) Process() (modeling.Mesh, error) {
152152
Transform(meshops.CustomTransformer{
153153
Func: func(m modeling.Mesh) (results modeling.Mesh, err error) {
154154
posData := m.Float3Attribute(modeling.PositionAttribute)
155+
scaleData := m.Float3Attribute(modeling.ScaleAttribute)
155156
count := posData.Len()
156157

157158
newPos := make([]vector3.Float64, count)
159+
newScale := make([]vector3.Float64, count)
158160

159161
baloonPos := bn.Position.Data()
160162
baloonRadius := bn.Radius.Data()
161163
baloonStrength := bn.Strength.Data()
162164

163165
for i := 0; i < count; i++ {
164166
curPos := posData.At(i)
167+
curScale := scaleData.At(i)
165168
dir := curPos.Sub(baloonPos)
166169
len := dir.Length()
167170

168171
if len <= baloonRadius {
169172
newPos[i] = baloonPos.Add(dir.Scale(baloonStrength))
173+
newScale[i] = curScale.Exp().Scale(baloonStrength).Log()
170174
} else {
171175
newPos[i] = curPos
176+
newScale[i] = curScale
172177
}
173178
}
174179

175-
return m.SetFloat3Attribute(modeling.PositionAttribute, newPos), nil
180+
return m.
181+
SetFloat3Attribute(modeling.PositionAttribute, newPos).
182+
SetFloat3Attribute(modeling.ScaleAttribute, newScale), nil
176183
},
177184
}), nil
178185
}
@@ -187,7 +194,11 @@ func main() {
187194
Mesh: (&PointcloudNode{
188195
Path: (&generator.ParameterNode[string]{
189196
Name: "Pointcloud Path",
190-
DefaultValue: "C:/dev/projects/sfm/gaussian-splatting/output/84e0f0cd-f/point_cloud/iteration_30000/point_cloud.ply",
197+
DefaultValue: "./point_cloud/iteration_30000/point_cloud.ply",
198+
CLI: &generator.CliParameterNodeConfig[string]{
199+
FlagName: "splat",
200+
Usage: "Path to the guassian splat to load (PLY file)",
201+
},
191202
}),
192203
MinOpacity: &generator.ParameterNode[float64]{
193204
Name: "Minimum Opacity",
@@ -234,9 +245,9 @@ func main() {
234245
Description: "Crop and Scale portions of Gaussian Splat data",
235246
Authors: []generator.Author{{Name: "Eli C Davis"}},
236247
WebScene: &room.WebScene{
237-
Background: coloring.WebColor{0, 0, 0, 255},
248+
Background: coloring.Black(),
238249
Fog: room.WebSceneFog{
239-
Color: coloring.WebColor{0, 0, 0, 255},
250+
Color: coloring.Black(),
240251
Near: 5,
241252
Far: 25,
242253
},

formats/splat/write.go

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/binary"
55
"fmt"
66
"io"
7-
"log"
87
"math"
98

109
"github.com/EliCDavis/bitlib"
@@ -36,7 +35,6 @@ func Write(out io.Writer, mesh modeling.Mesh) error {
3635
}
3736

3837
count := mesh.PrimitiveCount()
39-
log.Println(count)
4038

4139
posData := mesh.Float3Attribute(modeling.PositionAttribute)
4240
scaleData := mesh.Float3Attribute(modeling.ScaleAttribute)

generator/app.go

+8-38
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"flag"
99
"fmt"
1010
"io"
11+
"log"
1112
"os"
1213
"path"
1314
"path/filepath"
@@ -17,20 +18,6 @@ import (
1718
"github.com/EliCDavis/polyform/nodes"
1819
)
1920

20-
type producerCache map[string]Artifact
21-
22-
func (pc producerCache) Lookup(producer string) Artifact {
23-
if pc == nil {
24-
return nil
25-
}
26-
27-
if artifact, ok := pc[producer]; ok {
28-
return artifact
29-
}
30-
31-
return nil
32-
}
33-
3421
type App struct {
3522
Name string
3623
Version string
@@ -43,23 +30,6 @@ type App struct {
4330
nodeIDs map[nodes.Node]string
4431
}
4532

46-
func writeJSONError(out io.Writer, err error) error {
47-
var d struct {
48-
Error string `json:"error"`
49-
} = struct {
50-
Error string `json:"error"`
51-
}{
52-
Error: err.Error(),
53-
}
54-
data, err := json.Marshal(d)
55-
if err != nil {
56-
return err
57-
}
58-
59-
_, err = out.Write(data)
60-
return err
61-
}
62-
6333
func writeProducersToZip(path string, producers map[string]nodes.NodeOutput[Artifact], zw *zip.Writer) error {
6434
if producers == nil {
6535
panic("can't write nil producers")
@@ -103,19 +73,19 @@ func (a App) getParameters() []Parameter {
10373
for p := range parameterSet {
10474
uniqueParams = append(uniqueParams, p)
10575
}
76+
77+
log.Printf("Params found %v", uniqueParams)
10678
return uniqueParams
10779
}
10880

10981
func recurseDependenciesType[T any](dependent nodes.Dependent) []T {
11082
allDependencies := make([]T, 0)
11183
for _, dep := range dependent.Dependencies() {
112-
subDependent, ok := dep.(nodes.Dependent)
113-
if ok {
114-
subDependencies := recurseDependenciesType[T](subDependent)
115-
allDependencies = append(allDependencies, subDependencies...)
116-
}
84+
subDependent := dep.Dependency()
85+
subDependencies := recurseDependenciesType[T](subDependent)
86+
allDependencies = append(allDependencies, subDependencies...)
11787

118-
ofT, ok := dep.(T)
88+
ofT, ok := subDependent.(T)
11989
if ok {
12090
allDependencies = append(allDependencies, ofT)
12191
}
@@ -296,7 +266,7 @@ func (a *App) Run() error {
296266
Aliases: []string{"serve"},
297267
Run: func() error {
298268
serveCmd := flag.NewFlagSet("serve", flag.ExitOnError)
299-
// a.initialize(serveCmd)
269+
a.initialize(serveCmd)
300270
hostFlag := serveCmd.String("host", "localhost", "interface to bind to")
301271
portFlag := serveCmd.String("port", "8080", "port to serve over")
302272

generator/app_server.go

+17
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ import (
1717
"github.com/EliCDavis/polyform/generator/room"
1818
)
1919

20+
func writeJSONError(out io.Writer, err error) error {
21+
var d struct {
22+
Error string `json:"error"`
23+
} = struct {
24+
Error string `json:"error"`
25+
}{
26+
Error: err.Error(),
27+
}
28+
data, err := json.Marshal(d)
29+
if err != nil {
30+
return err
31+
}
32+
33+
_, err = out.Write(data)
34+
return err
35+
}
36+
2037
type pageData struct {
2138
Title string
2239
Version string

generator/html/js/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ textureEquirec.colorSpace = THREE.SRGBColorSpace;
6868
// scene.background = textureEquirec;
6969
scene.fog = new THREE.Fog(viewportSettings.fog.color, viewportSettings.fog.near, viewportSettings.fog.far);
7070

71+
const viewerContainer = new THREE.Group();
72+
scene.add(viewerContainer);
7173

7274
const renderer = new THREE.WebGLRenderer({ antialias: RenderingConfiguration.AntiAlias });
7375
renderer.setPixelRatio(window.devicePixelRatio);
@@ -138,7 +140,8 @@ const App = {
138140
Renderer: renderer,
139141
MeshGenFolder: panel.addFolder("Mesh Generation"),
140142
Scene: scene,
141-
OrbitControls: orbitControls
143+
OrbitControls: orbitControls,
144+
ViewerScene: viewerContainer
142145
}
143146

144147
const requestManager = new RequestManager();
@@ -168,11 +171,11 @@ schemaManager.subscribe((schema) => {
168171
ErrorManager.ClearError();
169172

170173
if (producerScene != null) {
171-
scene.remove(producerScene)
174+
viewerContainer.remove(producerScene)
172175
}
173176

174177
producerScene = new THREE.Group();
175-
scene.add(producerScene);
178+
viewerContainer.add(producerScene);
176179
schema.producers.forEach(producer => {
177180
const fileExt = producer.split('.').pop().toLowerCase();
178181

@@ -192,7 +195,7 @@ schemaManager.subscribe((schema) => {
192195

193196
// We have to do this weird thing because the pivot of the scene
194197
// Isn't always the center of the AABB
195-
gltf.scene.position.set(0, - mid + aabbHalfHeight, 0)
198+
producerScene.position.set(0, - mid + aabbHalfHeight, 0)
196199

197200
const objects = [];
198201

@@ -299,7 +302,7 @@ schemaManager.subscribe((schema) => {
299302
// We have to do this weird thing because the pivot of the scene
300303
// Isn't always the center of the AABB
301304
guassianSplatViewer.splatMesh.position.set(0, - mid + aabbHalfHeight, 0)
302-
305+
producerScene.position.set(0, - mid + aabbHalfHeight, 0)
303306
// let v = new THREE.Vector3()
304307
// guassianSplatViewer.splatMesh.getSplatCenter(0, v)
305308
// console.log(v);

generator/html/js/node.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ class NodeVector3Parameter {
4343
constructor(nodeManager, id, parameterData, app) {
4444
const control = new TransformControls(app.Camera, app.Renderer.domElement);
4545
control.setMode('translate');
46+
control.setSpace("local");
4647

4748
this.mesh = new THREE.Group();
48-
this.mesh.position.x = parameterData.currentValue.x;
49-
this.mesh.position.y = parameterData.currentValue.y;
50-
this.mesh.position.z = parameterData.currentValue.z;
49+
5150

5251
// control.addEventListener('change', () => {
5352
// });
@@ -69,9 +68,13 @@ class NodeVector3Parameter {
6968
}
7069
});
7170

72-
app.Scene.add(this.mesh);
71+
app.ViewerScene.add(this.mesh);
7372
control.attach(this.mesh);
74-
app.Scene.add(control)
73+
app.ViewerScene.add(control)
74+
75+
this.mesh.position.x = parameterData.currentValue.x;
76+
this.mesh.position.y = parameterData.currentValue.y;
77+
this.mesh.position.z = parameterData.currentValue.z;
7578
}
7679

7780
update(parameterData) {
@@ -88,7 +91,7 @@ class NodeVector3ArryParameter {
8891
this.guiFolder = app.MeshGenFolder;
8992
this.guiFolderData = guiFolderData;
9093
this.app = app;
91-
this.scene = app.Scene;
94+
this.scene = app.ViewerScene;
9295
this.allPositionControls = [];
9396
this.allPositionControlsMeshes = [];
9497

@@ -138,6 +141,7 @@ class NodeVector3ArryParameter {
138141
newPositionControl(pos) {
139142
const control = new TransformControls(this.app.Camera, this.app.Renderer.domElement);
140143
control.setMode('translate');
144+
control.space = "local";
141145

142146
const mesh = new THREE.Group();
143147
mesh.position.x = pos.x;

generator/parameter_node.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ func (pn ParameterNode[T]) initializeForCLI(set *flag.FlagSet) {
105105
if pn.CLI == nil {
106106
return
107107
}
108+
switch cli := any(pn.CLI).(type) {
109+
case *CliParameterNodeConfig[string]:
110+
cli.value = set.String(cli.FlagName, (any(pn.DefaultValue)).(string), cli.Usage)
111+
112+
case *CliParameterNodeConfig[float64]:
113+
cli.value = set.Float64(cli.FlagName, (any(pn.DefaultValue)).(float64), cli.Usage)
114+
115+
case *CliParameterNodeConfig[bool]:
116+
cli.value = set.Bool(cli.FlagName, (any(pn.DefaultValue)).(bool), cli.Usage)
117+
118+
case *CliParameterNodeConfig[int]:
119+
cli.value = set.Int(cli.FlagName, (any(pn.DefaultValue)).(int), cli.Usage)
120+
121+
case *CliParameterNodeConfig[int64]:
122+
cli.value = set.Int64(cli.FlagName, (any(pn.DefaultValue)).(int64), cli.Usage)
123+
default:
124+
panic(fmt.Errorf("parameter node %s has a type that can not be initialized on the command line. Please up a issue on github.com/EliCDavis/polyform", pn.DisplayName()))
125+
126+
}
108127

109-
panic("parameter node initializeForCLI is unimplemented")
110128
}

0 commit comments

Comments
 (0)