-
Notifications
You must be signed in to change notification settings - Fork 0
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
325 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { SettingComponent, SettingProps } from "./SettingsComponents"; | ||
import { ButtonGroup } from "../StyledComponents/ButtonGroup"; | ||
import styled from "styled-components"; | ||
import { IconFileUpload } from "@tabler/icons-react"; | ||
import { useDropzone } from "react-dropzone"; | ||
import { Button } from "../Generics/Button"; | ||
|
||
const Body = styled.div` | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
justify-content: stretch; | ||
align-items: stretch; | ||
flex-direction: column; | ||
padding: 0; | ||
margin: 0; | ||
& > div.loaded, | ||
& > div.file, | ||
& img { | ||
flex-grow: 1; | ||
display: block flex; | ||
object-fit: contain; | ||
justify-content: center; | ||
align-items: center; | ||
background: var(--gradient-transparent); | ||
max-height: 180px; | ||
} | ||
& svg { | ||
height: 50%; | ||
width: 50%; | ||
} | ||
`; | ||
|
||
export const ModelUploadSetting: SettingComponent = function ({ onChange, value, def }: SettingProps) { | ||
const { getRootProps, getInputProps } = useDropzone({ | ||
onDrop: (acceptedFiles, fileRejection) => { | ||
console.log(acceptedFiles, fileRejection); | ||
if (acceptedFiles.length >= 1) { | ||
var file = acceptedFiles[0]; | ||
|
||
const reader = new FileReader(); | ||
|
||
reader.onabort = () => console.log("file reading was aborted"); | ||
reader.onerror = () => console.log("file reading has failed"); | ||
|
||
reader.onload = () => { | ||
console.log(reader.result, file.name.split(".").pop()); | ||
onChange({ source: reader.result, ext: file.name.split(".").pop(), name: file.name }); | ||
}; | ||
reader.readAsText(file); | ||
} | ||
}, | ||
accept: { "model/obj": [".obj"] }, | ||
maxFiles: 1, | ||
}); | ||
|
||
return ( | ||
<Body> | ||
{value === null && ( | ||
<div | ||
className="file" | ||
{...getRootProps()}> | ||
<input {...getInputProps()}></input> | ||
<IconFileUpload /> | ||
</div> | ||
)} | ||
{value !== null && <div className="loaded">loaded {value.name}</div>} | ||
|
||
<ButtonGroup hidden={value !== null}> | ||
<Button | ||
label="Reset" | ||
onClick={() => onChange(null)}></Button> | ||
</ButtonGroup> | ||
</Body> | ||
); | ||
}; | ||
ModelUploadSetting.getSize = function (value, def): number { | ||
return 250; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { IconCube } from "@tabler/icons-react"; | ||
import { NodeDefinition } from "../../Types/NodeDefinition"; | ||
import { createVector3 } from "../../Types/vectorDataType"; | ||
import { createDefaultMaterial } from "../../Utils/createDefaultMaterial"; | ||
|
||
export const DrawModel: NodeDefinition = { | ||
id: "DrawModel", | ||
label: "Draw Model", | ||
description: "Draw a 3d model", | ||
icon: IconCube, | ||
tags: ["3D", "Draw"], | ||
dataInputs: [ | ||
{ | ||
id: "material", | ||
type: "material", | ||
defaultValue: createDefaultMaterial(), | ||
}, | ||
{ | ||
id: "position", | ||
type: "vector3", | ||
defaultValue: createVector3(0, 0, 0), | ||
}, | ||
{ | ||
id: "dimension", | ||
type: "vector3", | ||
defaultValue: createVector3(1, 1, 1), | ||
}, | ||
{ | ||
id: "rotation", | ||
type: "vector3", | ||
defaultValue: createVector3(0, 0, 0), | ||
}, | ||
{ | ||
id: "model", | ||
type: "mesh", | ||
defaultValue: null, | ||
}, | ||
], | ||
dataOutputs: [], | ||
executeOutputs: [], | ||
settings: [], | ||
canBeExecuted: true, | ||
execute: (data, context) => { | ||
var model = context.getInputValueModel(data, "model"); | ||
if (model == null) { | ||
return; | ||
} | ||
var material = context.getInputValueMaterial(data, "material"); | ||
|
||
var rotation = context.getInputValueVector3(data, "rotation"); | ||
var position = context.getInputValueVector3(data, "position"); | ||
var dimension = context.getInputValueVector3(data, "dimension"); | ||
context.target.push(); | ||
context.target.translate(...position); | ||
context.target.rotateZ(rotation[2]); | ||
context.target.rotateX(rotation[0]); | ||
context.target.rotateY(rotation[1]); | ||
context.target.scale(...dimension); | ||
if (material) { | ||
context.applyMaterial(material); | ||
} | ||
context.target.model(model); | ||
context.target.pop(); | ||
}, | ||
}; |
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,115 @@ | ||
import { IconList, IconPlus } from "@tabler/icons-react"; | ||
import p5 from "p5"; | ||
import { useTree } from "../../Hooks/useTree"; | ||
import { NodeData } from "../../Types/NodeData"; | ||
import { NodeDefinition } from "../../Types/NodeDefinition"; | ||
import { createVector2, createVector3 } from "../../Types/vectorDataType"; | ||
|
||
const createIndexNode = ({ id, positionX, positionY }: NodeData): void => { | ||
setTimeout(() => { | ||
useTree.getState().createBlackboardNode( | ||
[ | ||
{ | ||
type: "vector2", | ||
key: `${id}-uv`, | ||
id: "uv", | ||
}, | ||
], | ||
"Generate UV", | ||
positionX - 400, | ||
positionY, | ||
id | ||
); | ||
}, 10); | ||
}; | ||
|
||
export const GenerateUVModel: NodeDefinition = { | ||
id: "GenerateUVModel", | ||
description: "Generate a 3D model by mapping a set of 2d coordinate to 3d one", | ||
featureLevel: 0, | ||
icon: IconList, | ||
tags: ["3D"], | ||
dataInputs: [{ id: "pos", type: "vector3", defaultValue: createVector3(0, 0, 0) }], | ||
dataOutputs: [{ id: "model", type: "mesh", defaultValue: null }], | ||
executeOutputs: [], | ||
settings: [ | ||
{ | ||
id: "width", | ||
type: "number", | ||
defaultValue: 10, | ||
}, | ||
{ | ||
id: "height", | ||
type: "number", | ||
defaultValue: 10, | ||
}, | ||
{ id: "when", type: "dropdown", defaultValue: "Once", options: ["Once", "Per frame", "Everytime"] }, | ||
{ | ||
id: "buttons", | ||
type: "buttons", | ||
defaultValue: undefined, | ||
buttons: [ | ||
{ | ||
label: "Create UV node", | ||
icon: IconPlus, | ||
onClick: createIndexNode, | ||
}, | ||
], | ||
}, | ||
], | ||
canBeExecuted: false, | ||
contextMenu: { | ||
"Create the UV node": createIndexNode, | ||
}, | ||
getData: (portId, node, context) => { | ||
const when = node.settings.when; | ||
const keyCache = `${node.id}-image-cache`; | ||
const keyComputed = `${node.id}-is-computed`; | ||
let model = context.blackboard[keyCache]; | ||
|
||
let needRedraw = model === null; | ||
needRedraw ||= when === "Once" && !context.blackboard[keyComputed]; | ||
needRedraw ||= when === "Per frame" && !context.frameBlackboard[keyComputed]; | ||
needRedraw ||= when === "Everytime"; | ||
if (needRedraw) { | ||
const width = node.settings.width; | ||
const height = node.settings.height; | ||
const uvKey = `${node.id}-uv`; | ||
const firstRun = model == null; | ||
model = !firstRun ? model : new p5.Geometry(width, height); | ||
|
||
for (let y = 0; y < height; y++) { | ||
for (let x = 0; x < width; x++) { | ||
var uv = createVector2(x / (width - 1), y / (height - 1)); | ||
context.blackboard[uvKey] = uv; | ||
var pos = context.getInputValueVector3(node, "pos"); | ||
const selfId = y * width + x; | ||
model.vertices[selfId] = new p5.Vector(pos[0], pos[1], pos[2]); | ||
|
||
if (x > 0 && y > 0 && firstRun) { | ||
const upId = (y - 1) * width + x; | ||
const leftId = y * width + (x - 1); | ||
const upLeftId = (y - 1) * width + (x - 1); | ||
const side = (x + y) % 2 === 0; | ||
if (side) { | ||
model.faces.push([selfId, upId, leftId]); | ||
model.faces.push([upId, upLeftId, leftId]); | ||
} else { | ||
model.faces.push([leftId, selfId, upLeftId]); | ||
model.faces.push([selfId, upId, upLeftId]); | ||
} | ||
} | ||
} | ||
} | ||
model.computeNormals(); | ||
model.dirtyFlags.vertices = true; | ||
model.dirtyFlags.vertexNormals = true; | ||
context.blackboard[keyCache] = model; | ||
context.blackboard[keyComputed] = true; | ||
context.frameBlackboard[keyComputed] = true; | ||
return model; | ||
} | ||
|
||
return model; | ||
}, | ||
}; |
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,31 @@ | ||
import { IconPhoto } from "@tabler/icons-react"; | ||
import p5 from "p5"; | ||
import { NodeDefinition } from "../../Types/NodeDefinition"; | ||
|
||
export const UploadModel: NodeDefinition = { | ||
id: "UploadModel", | ||
label: "Upload Model", | ||
icon: IconPhoto, | ||
description: "Upload a 3d Model", | ||
dataInputs: [], | ||
dataOutputs: [{ id: "model", type: "mesh", defaultValue: null }], | ||
tags: ["3d"], | ||
executeOutputs: [], | ||
settings: [{ id: "model", type: "mesh-upload", defaultValue: null }], | ||
getData(portId, data, context) { | ||
if (data.settings.model != null) { | ||
var key = `${data.id}-model-cache`; | ||
if (!context.blackboard[key]) { | ||
new p5((p5) => { | ||
const model = p5.createModel(data.settings.model.source, data.settings.model.ext); | ||
context.blackboard[key] = model; | ||
}); | ||
return null; | ||
} else { | ||
return context.blackboard[key]; | ||
} | ||
} | ||
|
||
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
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 @@ | ||
export type SettingType = "dropdown" | "palette" | "number" | "gradient" | "image-upload" | "image-paint" | "envelope" | "string" | "hidden" | "buttons" | "animationTrack" | "easing-preview" | "code-block"; | ||
export type SettingType = "dropdown" | "palette" | "number" | "gradient" | "image-upload" | "image-paint" | "envelope" | "string" | "hidden" | "buttons" | "animationTrack" | "mesh-upload" | "easing-preview" | "code-block"; |
Oops, something went wrong.