Skip to content

Commit

Permalink
Splat/SPZ refactor, file nodes now upload data on file drop
Browse files Browse the repository at this point in the history
  • Loading branch information
EliCDavis committed Jan 27, 2025
1 parent afbacec commit b6fe0c3
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 63 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ go run ./cmd/polyform ./examples/graphs/ufo.json edit
- [stl](/formats/stl/) - STL file format
- [colmap](/formats/colmap/) - Utilities for loading COLMAP reconstruction data
- [opensfm](/formats/opensfm/) - Utilities for loading OpenSFM reconstruction data
- [splat](/formats/splat/) - Guassian splatting's SPLAT format
- [splat](/formats/splat/) - Mkkellogg's SPLAT format
- [spz](/formats/spz/) - Niantic Scaniverse's [SPZ format](https://scaniverse.com/news/spz-gaussian-splat-open-source-file-format)
- [potree](/formats/potree/) - Potree V2 file format
- Modeling
Expand Down Expand Up @@ -84,11 +84,11 @@ This was my [submission for ProcJam 2022](https://elicdavis.itch.io/evergreen-tr

### Other Examples

| | |
| ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------- |
| [[Source Here](/examples/graphs/ufo.json)] ![ufo](/examples/graphs/ufo.png) | [[Source Here](/examples/candle/main.go)] ![candle](/examples/candle/candle.png) |
| [[Source Here](/examples/terrain/main.go)] ![terrain](/examples/terrain/terrain.png) | [[Source Here](/examples/covid/main.go)] ![terrain](/examples/covid/covid.png) |
| [[Source Here](/examples/plumbob/main.go)] ![plumbob](/examples/plumbob/plumbob.png) | [[Source Here](/examples/oreo/main.go)] ![oreo](/examples/oreo/oreo.png) |
| | |
| ------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
| [[Source Here](/examples/graphs/ufo.json)] ![ufo](/examples/graphs/ufo.png) | [[Source Here](/examples/candle/main.go)] ![candle](/examples/candle/candle.png) |
| [[Source Here](/examples/terrain/main.go)] ![terrain](/examples/terrain/terrain.png) | [[Source Here](/examples/covid/main.go)] ![terrain](/examples/covid/covid.png) |
| [[Source Here](/examples/plumbob/main.go)] ![plumbob](/examples/plumbob/plumbob.png) | [[Source Here](/examples/oreo/main.go)] ![oreo](/examples/oreo/oreo.png) |


## Developing
Expand Down
2 changes: 2 additions & 0 deletions cmd/polyform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
// Import these so they register their nodes with the generator
_ "github.com/EliCDavis/polyform/formats/gltf"
_ "github.com/EliCDavis/polyform/formats/ply"
_ "github.com/EliCDavis/polyform/formats/splat"
_ "github.com/EliCDavis/polyform/formats/spz"
_ "github.com/EliCDavis/polyform/generator/artifact/basics"
_ "github.com/EliCDavis/polyform/generator/parameter"
_ "github.com/EliCDavis/polyform/math"
Expand Down
2 changes: 1 addition & 1 deletion examples/edit-gaussian-splats/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func main() {
XrEnabled: true,
},
Files: map[string]nodes.NodeOutput[artifact.Artifact]{
"mesh.ply": ply.NewSplatPlyNode(pointcloud.Out()),
"mesh.ply": ply.NewPlyNode(pointcloud.Out()),
"info.txt": basics.NewTextNode(&InfoNode{
Data: InfoNodeData{
Original: pointcloud.Out(),
Expand Down
52 changes: 12 additions & 40 deletions formats/ply/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,33 @@ package ply
import (
"fmt"
"io"
"log"

"github.com/EliCDavis/polyform/formats/splat"
"github.com/EliCDavis/polyform/generator"
"github.com/EliCDavis/polyform/generator/artifact"
"github.com/EliCDavis/polyform/modeling"
"github.com/EliCDavis/polyform/nodes"
"github.com/EliCDavis/polyform/refutil"
)

// ============================================================================

func init() {
factory := &refutil.TypeFactory{}

refutil.RegisterType[SplatNode](factory)
refutil.RegisterType[ArtifactNode](factory)

generator.RegisterTypes(factory)
}

type Splat struct {
Mesh modeling.Mesh
}

func (sa Splat) Write(w io.Writer) error {
return splat.Write(w, sa.Mesh)
}

func (Splat) Mime() string {
return "application/octet-stream"
}

type SplatNode = nodes.Struct[artifact.Artifact, SplatNodeData]

type SplatNodeData struct {
In nodes.NodeOutput[modeling.Mesh]
}

func (pn SplatNodeData) Process() (artifact.Artifact, error) {
return Splat{Mesh: pn.In.Value()}, nil
}

func NewSplatNode(meshNode nodes.NodeOutput[modeling.Mesh]) nodes.NodeOutput[artifact.Artifact] {
return (&SplatNode{
Data: SplatNodeData{
In: meshNode,
},
}).Out()
}

// ============================================================================

type SplatPly struct {
Mesh modeling.Mesh
}

func (sa SplatPly) Write(w io.Writer) error {

log.Println("Writer...")

writers := []PropertyWriter{
Vector3PropertyWriter{
ModelAttribute: modeling.PositionAttribute,
Expand Down Expand Up @@ -123,19 +95,19 @@ func (SplatPly) Mime() string {
return "application/octet-stream"
}

type SplatPlyNode = nodes.Struct[artifact.Artifact, SplatPlyNodeData]
type ArtifactNode = nodes.Struct[artifact.Artifact, ArtifactNodeData]

type SplatPlyNodeData struct {
type ArtifactNodeData struct {
In nodes.NodeOutput[modeling.Mesh]
}

func (pn SplatPlyNodeData) Process() (artifact.Artifact, error) {
func (pn ArtifactNodeData) Process() (artifact.Artifact, error) {
return SplatPly{Mesh: pn.In.Value()}, nil
}

func NewSplatPlyNode(meshNode nodes.NodeOutput[modeling.Mesh]) nodes.NodeOutput[artifact.Artifact] {
return (&SplatPlyNode{
Data: SplatPlyNodeData{
func NewPlyNode(meshNode nodes.NodeOutput[modeling.Mesh]) nodes.NodeOutput[artifact.Artifact] {
return (&ArtifactNode{
Data: ArtifactNodeData{
In: meshNode,
},
}).Out()
Expand Down
53 changes: 53 additions & 0 deletions formats/splat/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package splat

import (
"io"

"github.com/EliCDavis/polyform/generator"
"github.com/EliCDavis/polyform/generator/artifact"
"github.com/EliCDavis/polyform/modeling"
"github.com/EliCDavis/polyform/nodes"
"github.com/EliCDavis/polyform/refutil"
)

func init() {
factory := &refutil.TypeFactory{}

refutil.RegisterType[ArtifactNode](factory)

generator.RegisterTypes(factory)
}

type Splat struct {
Mesh modeling.Mesh
}

func (sa Splat) Write(w io.Writer) error {
return Write(w, sa.Mesh)
}

func (Splat) Mime() string {
return "application/octet-stream"
}

type ArtifactNode = nodes.Struct[artifact.Artifact, ArtifactNodeData]

type ArtifactNodeData struct {
In nodes.NodeOutput[modeling.Mesh]
}

func (pn ArtifactNodeData) Description() string {
return "Mkkellogg's SPLAT format for their three.js Gaussian Splat Viewer"
}

func (pn ArtifactNodeData) Process() (artifact.Artifact, error) {
return Splat{Mesh: pn.In.Value()}, nil
}

func NewSplatNode(meshNode nodes.NodeOutput[modeling.Mesh]) nodes.NodeOutput[artifact.Artifact] {
return (&ArtifactNode{
Data: ArtifactNodeData{
In: meshNode,
},
}).Out()
}
40 changes: 40 additions & 0 deletions formats/spz/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package spz

import (
"bytes"

"github.com/EliCDavis/polyform/generator"
"github.com/EliCDavis/polyform/modeling"
"github.com/EliCDavis/polyform/nodes"
"github.com/EliCDavis/polyform/refutil"
)

func init() {
factory := &refutil.TypeFactory{}
refutil.RegisterType[ReadNode](factory)
generator.RegisterTypes(factory)
}

type ReadNode = nodes.Struct[modeling.Mesh, ReadNodeData]

type ReadNodeData struct {
Data nodes.NodeOutput[[]byte]
}

func (gad ReadNodeData) Process() (modeling.Mesh, error) {
if gad.Data == nil {
return modeling.EmptyMesh(modeling.PointTopology), nil
}

data := gad.Data.Value()
if len(data) == 0 {
return modeling.EmptyMesh(modeling.PointTopology), nil
}

cloud, err := Read(bytes.NewReader(data))
if err != nil {
return modeling.EmptyMesh(modeling.PointTopology), err
}

return cloud.Mesh, nil
}
2 changes: 1 addition & 1 deletion generator/app_swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestSwaggerFromGraph_MultipleParametersSingleProducer(t *testing.T) {
Version: "1.0.0",
Description: "Example graph that contains multiple parameters",
Files: map[string]nodes.NodeOutput[artifact.Artifact]{
"example.glb": ply.NewSplatNode(
"example.glb": ply.NewPlyNode(
&meshops.CropAttribute3DNode{
Data: meshops.CropAttribute3DNodeData{
AABB: &parameter.AABB{
Expand Down
2 changes: 1 addition & 1 deletion generator/graph/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (i *Instance) Schema() schema.GraphInstance {
for _, registeredType := range registeredTypes {
nodeInstance, ok := i.typeFactory.New(registeredType).(nodes.Node)
if !ok {
panic("Registered type is somehow not a node. Not sure how we got here :/")
panic(fmt.Errorf("Registered type %q is not a node. Not sure how we got here :/", registeredType))
}
if nodeInstance == nil {
panic("New registered type")
Expand Down
13 changes: 7 additions & 6 deletions generator/html/js/nodes/file_parameter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

export class FileParameterNodeController {

constructor(lightNode, nodeManager, id, parameterData, app) {
this.lightNode = lightNode;
constructor(flowNode, nodeManager, id, parameterData, app) {
this.flowNode = flowNode;
this.id = id;
this.app = app;
this.lightNode.setTitle(parameterData.name);
this.flowNode.setTitle(parameterData.name);

this.lightNode.onDropFile = (file) => {
// console.log(file)
this.flowNode.addFileDropListener((file) => {
console.log("AAAHHHHHHHH", file)
var reader = new FileReader();
reader.onload = (evt) => {
console.log(evt.target.result)
Expand All @@ -25,7 +25,8 @@ export class FileParameterNodeController {
// that.size[1] = (img.height / img.width) * that.size[0];
// });
// this.loadImgFromURL(url);
}
});

}

loadImgFromURL(url) {
Expand Down
20 changes: 12 additions & 8 deletions generator/html/server.html
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
nodes: {
"Parameters/int": {
title: "Int Parameter",
subTitle: "Int",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand All @@ -398,6 +399,7 @@
},
"Parameters/float64": {
title: "Float64 Parameter",
subTitle: "Float64",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand All @@ -423,6 +425,7 @@
},
"Parameters/geometry.AABB": {
title: "AABB Parameter",
subTitle: "AABB",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand Down Expand Up @@ -490,6 +493,7 @@
},
"Parameters/image.Image": {
title: "Image Parameter",
subTitle: "Image",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand All @@ -514,6 +518,7 @@
},
"Parameters/[]uint8": {
title: "[]uint8 Parameter",
subTitle: "File",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand All @@ -522,22 +527,16 @@
type: "[]uint8"
}
],
widgets: [
{
type: "image",
config: {
}
}
],
style: ParameterStyle,
metadata: {
typeData: {
type: "github.com/EliCDavis/polyform/generator/parameter.Value[[]uint8]"
type: "github.com/EliCDavis/polyform/generator/parameter.File"
}
}
},
"Parameters/coloring.WebColor": {
title: "Color Parameter",
subTitle: "Color",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand All @@ -563,6 +562,7 @@
},
"Parameters/vector3.Vector[float64]": {
title: "Vector3 Parameter",
subTitle: "Vector3",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand Down Expand Up @@ -600,6 +600,7 @@
},
"Parameters/[]vector3.Vector[float64]": {
title: "Vector3 Array Parameter",
subTitle: "Vector3 Array",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand All @@ -617,6 +618,7 @@
},
"Parameters/vector2.Vector[float64]": {
title: "Vector2 Parameter",
subTitle: "Vector2 Array",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand Down Expand Up @@ -648,6 +650,7 @@
},
"Parameters/bool": {
title: "Bool Parameter",
subTitle: "Bool",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand All @@ -673,6 +676,7 @@
},
"Parameters/string": {
title: "String Parameter",
subTitle: "String",
canEditTitle: true,
canEditInfo: true,
outputs: [
Expand Down
Loading

0 comments on commit b6fe0c3

Please sign in to comment.