-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
379 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,178 @@ | ||
package generator | ||
|
||
import ( | ||
"flag" | ||
"io" | ||
"os" | ||
|
||
"github.com/EliCDavis/jbtf" | ||
"github.com/EliCDavis/polyform/nodes" | ||
) | ||
|
||
type FileParameterNode struct { | ||
Name string | ||
DefaultValue []byte | ||
CLI *CliParameterNodeConfig[string] | ||
|
||
version int | ||
appliedProfile []byte | ||
} | ||
|
||
func (in *FileParameterNode) Node() nodes.Node { | ||
return in | ||
} | ||
|
||
func (in FileParameterNode) Port() string { | ||
return "Out" | ||
} | ||
|
||
func (vn FileParameterNode) SetInput(input string, output nodes.Output) { | ||
panic("input can not be set") | ||
} | ||
|
||
func (pn *FileParameterNode) DisplayName() string { | ||
return pn.Name | ||
} | ||
|
||
func (pn *FileParameterNode) ApplyMessage(msg []byte) (bool, error) { | ||
pn.version++ | ||
pn.appliedProfile = msg | ||
return true, nil | ||
} | ||
|
||
func (pn *FileParameterNode) ToMessage() []byte { | ||
return pn.Value() | ||
} | ||
|
||
func (pn *FileParameterNode) Value() []byte { | ||
if pn.appliedProfile != nil { | ||
return pn.appliedProfile | ||
} | ||
|
||
if pn.CLI != nil && pn.CLI.value != nil && *pn.CLI.value != "" { | ||
f, err := os.Open(*pn.CLI.value) | ||
if err != nil { | ||
return nil | ||
} | ||
defer f.Close() | ||
|
||
pn.appliedProfile, err = io.ReadAll(f) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return pn.appliedProfile | ||
} | ||
return pn.DefaultValue | ||
} | ||
|
||
func (pn *FileParameterNode) Schema() ParameterSchema { | ||
return ParameterSchemaBase{ | ||
Name: pn.Name, | ||
Type: "[]uint8", | ||
} | ||
} | ||
|
||
func (pn *FileParameterNode) Dependencies() []nodes.NodeDependency { | ||
return nil | ||
} | ||
|
||
func (pn *FileParameterNode) State() nodes.NodeState { | ||
return nodes.Processed | ||
} | ||
|
||
type FileNodeOutput struct { | ||
Val *FileParameterNode | ||
} | ||
|
||
func (sno FileNodeOutput) Value() []byte { | ||
return sno.Val.Value() | ||
} | ||
|
||
func (sno FileNodeOutput) Node() nodes.Node { | ||
return sno.Val | ||
} | ||
|
||
func (sno FileNodeOutput) Port() string { | ||
return "Out" | ||
} | ||
|
||
func (tn *FileParameterNode) Outputs() []nodes.Output { | ||
return []nodes.Output{ | ||
{ | ||
Type: "[]uint8", | ||
NodeOutput: FileNodeOutput{ | ||
Val: tn, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (tn *FileParameterNode) Out() FileNodeOutput { | ||
return FileNodeOutput{ | ||
Val: tn, | ||
} | ||
} | ||
|
||
func (tn FileParameterNode) Inputs() []nodes.Input { | ||
return []nodes.Input{} | ||
} | ||
|
||
func (pn FileParameterNode) Version() int { | ||
return pn.version | ||
} | ||
|
||
func (pn FileParameterNode) initializeForCLI(set *flag.FlagSet) { | ||
if pn.CLI == nil { | ||
return | ||
} | ||
pn.CLI.value = set.String(pn.CLI.FlagName, "", pn.CLI.Usage) | ||
} | ||
|
||
// CUSTOM JTF Serialization =================================================== | ||
|
||
type fileNodeGraphSchema struct { | ||
Name string `json:"name"` | ||
CurrentValue *jbtf.Bytes `json:"currentValue"` | ||
DefaultValue *jbtf.Bytes `json:"defaultValue"` | ||
CLI *CliParameterNodeConfig[string] `json:"cli"` | ||
} | ||
|
||
func (pn *FileParameterNode) ToJSON(encoder *jbtf.Encoder) ([]byte, error) { | ||
schema := fileNodeGraphSchema{ | ||
Name: pn.Name, | ||
CLI: pn.CLI, | ||
} | ||
|
||
if pn.Value() != nil { | ||
schema.CurrentValue = &jbtf.Bytes{ | ||
Data: pn.Value(), | ||
} | ||
} | ||
|
||
if schema.DefaultValue != nil { | ||
schema.DefaultValue = &jbtf.Bytes{ | ||
Data: pn.DefaultValue, | ||
} | ||
} | ||
|
||
return encoder.Marshal(schema) | ||
} | ||
|
||
func (pn *FileParameterNode) FromJSON(decoder jbtf.Decoder, body []byte) (err error) { | ||
gn, err := jbtf.Decode[fileNodeGraphSchema](decoder, body) | ||
if err != nil { | ||
return | ||
} | ||
|
||
pn.Name = gn.Name | ||
pn.CLI = gn.CLI | ||
|
||
if gn.DefaultValue != nil { | ||
pn.DefaultValue = gn.DefaultValue.Data | ||
} | ||
if gn.CurrentValue != nil { | ||
pn.appliedProfile = gn.CurrentValue.Data | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
export class FileParameterNode { | ||
|
||
constructor(lightNode, nodeManager, id, parameterData, app) { | ||
this.lightNode = lightNode; | ||
this.id = id; | ||
this.app = app; | ||
this.lightNode.title = parameterData.name; | ||
|
||
this.lightNode.onDropFile = (file) => { | ||
// console.log(file) | ||
var reader = new FileReader(); | ||
reader.onload = (evt) => { | ||
console.log(evt.target.result) | ||
nodeManager.nodeParameterChanged({ | ||
id: id, | ||
data: evt.target.result, | ||
binary: true | ||
}); | ||
} | ||
reader.readAsArrayBuffer(file); | ||
|
||
const url = URL.createObjectURL(file); | ||
// this.loadImage(this._url, function (img) { | ||
// that.size[1] = (img.height / img.width) * that.size[0]; | ||
// }); | ||
// this.loadImgFromURL(url); | ||
} | ||
} | ||
|
||
loadImgFromURL(url) { | ||
// const img = document.createElement("img"); | ||
// img.src = url; | ||
// img.onload = () => { | ||
// // if (callback) { | ||
// // callback(this); | ||
// // } | ||
// // console.log("Image loaded, size: " + img.width + "x" + img.height); | ||
// // this.dirty = true; | ||
// // that.boxcolor = "#9F9";f | ||
// // that.setDirtyCanvas(true); | ||
// this.lightNode.widgets[0].image = img | ||
// this.lightNode.setSize(this.lightNode.computeSize()); | ||
// }; | ||
// img.onerror = () => { | ||
// console.log("error loading the image:" + url); | ||
// } | ||
} | ||
|
||
update(parameterData) { | ||
console.log("image parameter", parameterData) | ||
const curVal = parameterData.currentValue; | ||
// this.app.RequestManager.getParameterValue(this.id, (response) => { | ||
// const url = URL.createObjectURL(response); | ||
// this.loadImgFromURL(url) | ||
// }) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.