graflow 1.0

This commit is contained in:
STEINNI
2025-12-22 16:38:45 +00:00
parent 0b708c2dbd
commit 906dd7b317
8 changed files with 327 additions and 245 deletions
+85
View File
@@ -0,0 +1,85 @@
<style>
.bzgf-node {
border-width:2px;
border-style: solid;
border-radius: 6px;
width: 160px;
height: 80px;
color: black;
text-align: center;
position: absolute;
padding: .5em;
}
.bzgf-node .title {
font-weight: bold;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 2em;
color: white;
}
.bzgf-node .body { margin-top: 2em; }
.bzgf-node .body input {
width:4em;
font-size: .9em;
border-radius: 6px;
border: 1px solid #CCC;
}
.bzgf-node .port{
position: absolute;
height: 10px;
width: 10px;
border: 1px solid black;
border-radius: 10px;
}
.bzgf-node .port[data-type="in"] { background: #0F0; }
.bzgf-node .port[data-type="out"] { background: #FF0; }
.bzgf-node [data-direction="w"]{ left: -7px; top: 50%; }
.bzgf-node [data-direction="e"]{ right: -7px; top: 50%;}
.bzgf-node [data-direction="n"]{ top: -7px; left: 50%;}
.bzgf-node [data-direction="s"]{ bottom: -7px; left: 50%;}
.bzgf-node[data-nodetype="inc"]{
background: #DFD;
border-color: #090;
}
.bzgf-node[data-nodetype="inc"] .title{ background: #090; }
.bzgf-node[data-nodetype="factor"]{
background: #DDF;
border-color: #009;
}
.bzgf-node[data-nodetype="factor"] .title{ background: #009; }
.bzgf-wire{
stroke: #0AF;
stroke-width: 2;
}
</style>
<template>
<div class="bzgf-node" data-nodetype="inc">
<div class="title">Increment</div>
<div class="port" data-type="in" data-id="inp1" data-direction="w"></div>
<div class="port" data-type="in" data-id="inp2" data-direction="s"></div>
<div class="port" data-type="out" data-id="out1" data-direction="e"></div>
<div class="body">
<input type="text" value="1">
</div>
</div>
</template>
<template>
<div class="bzgf-node" data-nodetype="factor">
<div class="title">Multiply</div>
<div class="port" data-type="in" data-id="inp1" data-direction="w"></div>
<div class="port" data-type="in" data-id="inp2" data-direction="s"></div>
<div class="port" data-type="out" data-id="out1" data-direction="e"></div>
<div class="body">
<input type="text" value="0.5">
</div>
</div>
</template>
+5 -228
View File
@@ -5,236 +5,13 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="https://threejs.org/examples/main.css">
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/examples/jsm/loaders/FontLoader.js": "https://unpkg.com/three@0.160.0/examples/jsm/loaders/FontLoader.js",
"three/examples/jsm/geometries/TextGeometry.js": "https://unpkg.com/three@0.160.0/examples/jsm/geometries/TextGeometry.js",
"three/examples/jsm/loaders/RGBELoader.js": "https://unpkg.com/three@0.160.0/examples/jsm/loaders/RGBELoader.js",
"three/examples/jsm/controls/OrbitControls.js": "https://unpkg.com/three@0.160.0/examples/jsm/controls/OrbitControls.js",
"three/examples/jsm/libs/tween.module.js": "https://unpkg.com/three@0.160.0/examples/jsm/libs/tween.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
</script>
<link type="text/css" rel="stylesheet" href="../../thirdparty/buildoz/buildoz.css">
<script src="../../thirdparty/buildoz/buildoz.js"></script>
<script src="../../thirdparty/buildoz/bzGraflow.js"></script>
</head>
<body>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - FBXLoader<br />
Character and animation from <a href="https://www.mixamo.com/" target="_blank" rel="noopener">Mixamo</a>
</div>
<script type="module">
import * as THREE from 'three';
import Stats from 'three/addons/libs/stats.module.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { FBXLoader } from 'three/addons/loaders/FBXLoader.js';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
const manager = new THREE.LoadingManager();
let camera, scene, renderer, stats, object, loader, guiMorphsFolder;
let mixer;
const clock = new THREE.Clock();
const params = {
asset: 'Samba Dancing'
};
const assets = [
'Samba Dancing',
'morph_test',
'monkey',
'monkey_embedded_texture',
'vCube',
];
init();
function init() {
const container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.set( 100, 200, 300 );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xa0a0a0 );
scene.fog = new THREE.Fog( 0xa0a0a0, 200, 1000 );
const hemiLight = new THREE.HemisphereLight( 0xffffff, 0x444444, 5 );
hemiLight.position.set( 0, 200, 0 );
scene.add( hemiLight );
const dirLight = new THREE.DirectionalLight( 0xffffff, 5 );
dirLight.position.set( 0, 200, 100 );
dirLight.castShadow = true;
dirLight.shadow.camera.top = 180;
dirLight.shadow.camera.bottom = - 100;
dirLight.shadow.camera.left = - 120;
dirLight.shadow.camera.right = 120;
scene.add( dirLight );
// scene.add( new THREE.CameraHelper( dirLight.shadow.camera ) );
// ground
const mesh = new THREE.Mesh( new THREE.PlaneGeometry( 2000, 2000 ), new THREE.MeshPhongMaterial( { color: 0x999999, depthWrite: false } ) );
mesh.rotation.x = - Math.PI / 2;
mesh.receiveShadow = true;
scene.add( mesh );
const grid = new THREE.GridHelper( 2000, 20, 0x000000, 0x000000 );
grid.material.opacity = 0.2;
grid.material.transparent = true;
scene.add( grid );
loader = new FBXLoader( manager );
loadAsset( params.asset );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.shadowMap.enabled = true;
container.appendChild( renderer.domElement );
const controls = new OrbitControls( camera, renderer.domElement );
controls.target.set( 0, 100, 0 );
controls.update();
window.addEventListener( 'resize', onWindowResize );
// stats
stats = new Stats();
container.appendChild( stats.dom );
const gui = new GUI();
gui.add( params, 'asset', assets ).onChange( function ( value ) {
loadAsset( value );
} );
guiMorphsFolder = gui.addFolder( 'Morphs' ).hide();
}
function loadAsset( asset ) {
loader.load( 'models/ffbxbx/' + asset + '.fbx', function ( group ) {
if ( object ) {
object.traverse( function ( child ) {
if ( child.isSkinnedMesh ) {
child.skeleton.dispose();
}
if ( child.material ) {
const materials = Array.isArray( child.material ) ? child.material : [ child.material ];
materials.forEach( material => {
if ( material.map ) material.map.dispose();
material.dispose();
} );
}
if ( child.geometry ) child.geometry.dispose();
} );
scene.remove( object );
}
//
object = group;
if ( object.animations && object.animations.length ) {
mixer = new THREE.AnimationMixer( object );
const action = mixer.clipAction( object.animations[ 0 ] );
action.play();
} else {
mixer = null;
}
guiMorphsFolder.children.forEach( ( child ) => child.destroy() );
guiMorphsFolder.hide();
object.traverse( function ( child ) {
if ( child.isMesh ) {
child.castShadow = true;
child.receiveShadow = true;
if ( child.morphTargetDictionary ) {
guiMorphsFolder.show();
const meshFolder = guiMorphsFolder.addFolder( child.name || child.uuid );
Object.keys( child.morphTargetDictionary ).forEach( ( key ) => {
meshFolder.add( child.morphTargetInfluences, child.morphTargetDictionary[ key ], 0, 1, 0.01 );
} );
}
}
} );
scene.add( object );
} );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
//
function animate() {
const delta = clock.getDelta();
if ( mixer ) mixer.update( delta );
renderer.render( scene, camera );
stats.update();
}
</script>
<bz-graflow flow="/app/assets/json/bzGraflow/testFlow1.json"></bz-graflow>
</body>
</html>
+30
View File
@@ -0,0 +1,30 @@
{
"nodesFile": "/app/assets/html/bzGraflow/nodesTest1.html",
"flow": {
"nodes":[
{ "nodeType": "inc",
"id": "aze",
"coords": { "x": 20, "y": 10}
},
{ "nodeType": "factor",
"id": "qsd",
"coords": { "x": 270, "y": 50}
},
{ "nodeType": "inc",
"id": "wcx",
"coords": { "x": 520, "y": 50}
},
{ "nodeType": "inc",
"id": "ert",
"coords": { "x": 150, "y": 350}
}
],
"links": [
{ "from": ["aze", "out1"], "to": ["qsd", "inp1"] },
{ "from": ["qsd", "out1"], "to": ["wcx", "inp1"] },
{ "from": ["qsd", "out1"], "to": ["ert", "inp2"] },
{ "from": ["ert", "out1"], "to": ["aze", "inp2"] }
]
}
}
+18 -7
View File
@@ -228,7 +228,7 @@ class Intro{
this.matEE.defines = this.matEE.defines || {}
this.matEE.defines.USE_UV = ""
this.matEE.onBeforeCompile = shader => {
shader.uniforms.uReveal = { value: 0 }
shader.uniforms.uReveal = { value: -0.3 }
shader.uniforms.uTime = { value: 0 };
shader.fragmentShader = shader.fragmentShader
.replace(
@@ -241,15 +241,26 @@ class Intro{
.replace(
`#include <envmap_fragment>`,
`#include <envmap_fragment>
if ((uReveal-vUv.x) < (1.0-uReveal)){
float random = fract(sin(dot(gl_FragCoord.xy + vec2(uTime) , vec2(12.9898,78.233))) * 43758.5453);
if(random > 0.1) discard;
}
float bandWidth = 0.20;
if (vUv.x > uReveal) {
float d = (vUv.x - uReveal) / bandWidth; // 0 at front, grows to the right
if (d < 1.0) { // inside noisy band
float density = smoothstep(1.0, 0.0, d);
float random = fract( sin(dot(gl_FragCoord.xy + vec2(uTime), vec2(12.9898,78.233))) * 43758.5453 );
if (random > density) discard;
} else {
// fully hidden
discard;
}
}
`
)
this.matEE.userData.shader = shader
}
this.planeEE = new THREE.Mesh(geo, this.matEE)
this.planeEE.scale.set(.2, .2, 1)
this.planeEE.position.set(0,-0.8,.1)
@@ -269,7 +280,7 @@ class Intro{
requestAnimationFrame(this.animate.bind(this))
if (this.matEE.userData.shader) {
if(this.matEE.userData.shader.uniforms.uReveal.value<1){
this.matEE.userData.shader.uniforms.uReveal.value += 0.01
this.matEE.userData.shader.uniforms.uReveal.value += 0.005
this.matEE.userData.shader.uniforms.uTime.value = Math.floor(performance.now() / 200)
}
}
+1
View File
@@ -40,6 +40,7 @@ body[eicapp] {
min-height: 100vh;
box-sizing: border-box;
background: repeating-linear-gradient( -45deg, #000, #333 10px, #000 10px, #333 20px );
overflow: hidden;
}
.helperBotCanvas{
display: block;
+13 -9
View File
@@ -168,27 +168,31 @@ class HelperBot{
const delay = Math.max(Math.abs(dx), Math.abs(dy), Math.abs(dz)) * moveDelay
const ax = (dy>0.5) ? -10 : ((dy<-0.5) ? 10 : 0 )
const ay = (dx>0.5) ? 10 : ((dx<-0.5) ? -10 : 0 )
console.log( this.mecha.position.x, this.mecha.position.y)
console.log(dx,dy,ax,ay)
//TODO : fix jerks when rotation tweens overlap
// console.log( this.mecha.position.x, this.mecha.position.y)
// console.log(dx,dy,ax,ay)
const rotationDelay = Math.min(delay/4, 500)
this.rotateBot({x: ax, y: ay, z: 0}, rotationDelay)
const rotationDelay = delay/4;
if(rotationDelay>400) this.rotateBot({x: ax, y: ay, z: 0}, rotationDelay)
let chkpt1 = true, chkpt2 = true, chkpt3 = true
this.animate = false; console.log('stopped!')
const startTime = Date.now()
this.translateBot(position, delay, null, () => {
this.translateBot(position, delay, () => {
this.animate = true ; console.log('started!')
},
() => {
const t = (Date.now()-startTime)/delay
if(chkpt1 && (t >= 0.2)){ //Time to stop accelerating
this.rotateBot({x: 0, y: 0, z: 0}, rotationDelay)
if(rotationDelay>400) this.rotateBot({x: 0, y: 0, z: 0}, rotationDelay)
chkpt1 = false
}
if(chkpt2 && (t >= 0.7)){ //Time to brake
this.rotateBot({x: -ax, y: -ay, z: 0}, rotationDelay)
if(rotationDelay>400) this.rotateBot({x: -ax, y: -ay, z: 0}, rotationDelay)
chkpt2 = false
}
if(chkpt3 && (t >= 0.9)){ //Time to restore
this.rotateBot({x: 0, y: 0, z: 0}, rotationDelay)
if(rotationDelay>400) this.rotateBot({x: 0, y: 0, z: 0}, rotationDelay)
chkpt3 = false
}
})
+16 -1
View File
@@ -186,4 +186,19 @@ bz-slidepane[side="right"] div.handle {
background: repeating-linear-gradient( to right, rgba(255,255,255,1) 0, rgba(255,255,255,1) 2px, rgba(0,0,0,0.2) 3px, rgba(0,0,0,0.2) 4px );
transform: translateY(-50%);
cursor: ew-resize;
}
}
bz-graflow {
position: relative;
display: block;
width: 100vw;
height: 100vh;
}
bz-graflow .bzgf-wires-container,
bz-graflow .bzgf-nodes-container{
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
bz-graflow .bzgf-nodes-container{ z-index:10; }
bz-graflow .bzgf-wires-container{ z-index:9; }
+159
View File
@@ -0,0 +1,159 @@
class BZgraflow extends Buildoz{
constructor(){
super()
this.defaultAttrs = { }
this.stagedNodes = { }
this.stagedWires = { }
}
static _loadedNodeStyles = new Set() // Allow multi instances or re-loadNodes, but avoid reinjecting same styles !
connectedCallback() {
super.connectedCallback()
const flowUrl = this.getBZAttribute('flow')
if(!flowUrl) {
console.warn('BZgraflow: No flow URL !?')
return
}
this.loadFlow(flowUrl) // Let it load async while we coat
this.nodesContainer = document.createElement('div')
this.nodesContainer.classList.add('bzgf-nodes-container')
this.wiresContainer = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
this.wiresContainer.classList.add('bzgf-wires-container')
this.append(this.wiresContainer)
this.append(this.nodesContainer)
}
async loadFlow(url){
const res = await fetch(url+'?'+crypto.randomUUID())
const buf = await res.text()
let flowObj
try{
flowObj = JSON.parse(buf)
} catch(err){
console.error('Could not parse flow JSON!?', err)
return
}
if(!flowObj.nodesFile){
console.error('No nodesFile in JSON!?')
return
}
await this.loadNodes(flowObj.nodesFile)
this.flow = flowObj.flow
this.refresh()
}
async loadNodes(url) {
const res = await fetch(url+'?'+crypto.randomUUID())
const html = await res.text()
// Get nodes
const doc = new DOMParser().parseFromString(html, 'text/html')
this.nodesRegistry = {}
for(const tpl of doc.querySelectorAll('template')){
const rootEl = tpl.content.querySelector('.bzgf-node')
if(!rootEl) continue
this.nodesRegistry[rootEl.dataset.nodetype] = rootEl
}
// Now load styles (once)
if(!BZgraflow._loadedNodeStyles.has(url)) {
const styles = doc.querySelectorAll('style')
styles.forEach(styleEl => {
const style = document.createElement('style')
style.textContent = styleEl.textContent
document.head.appendChild(style)
})
BZgraflow._loadedNodeStyles.add(url)
}
}
addNode(type, id, x, y){
const nodeDef = this.nodesRegistry[type]
this.stagedNodes[id] = nodeDef.cloneNode(true)
this.stagedNodes[id].style.left = `${x}px`
this.stagedNodes[id].style.top = `${y}px`
this.stagedNodes[id].dataset.id = id
const portEls = this.stagedNodes[id].querySelectorAll('.port')
this.stagedNodes[id].ports = Object.fromEntries(Array.from(portEls).map(item => ([item.dataset.id, { ...item.dataset, el:item }])))
this.nodesContainer.append(this.stagedNodes[id])
return(this.stagedNodes[id])
}
addWire(idNode1, idPort1, idNode2, idPort2){
const node1 = this.stagedNodes[idNode1]
const port1 = node1.ports[idPort1]
const node2 = this.stagedNodes[idNode2]
const port2 = node2.ports[idPort2]
const id = `${node1.dataset.id}_${node2.dataset.id}`
const bb1 = port1.el.getBoundingClientRect()
const bb2 = port2.el.getBoundingClientRect()
const x1 = Math.floor(bb1.x + (bb1.width/2))
const y1 = Math.floor(bb1.y + (bb1.height/2))
const x2 = Math.floor(bb2.x + (bb2.width/2))
const y2 = Math.floor(bb2.y + (bb2.height/2))
console.log('====>', x1, y1, x2, y2)
this.stagedWires[id] = document.createElementNS('http://www.w3.org/2000/svg', 'path')
this.stagedWires[id].setAttribute('d', this.bezier(x1, y1, port1.direction , x2, y2, port2.direction, 60))
this.stagedWires[id].setAttribute('fill', 'none')
this.stagedWires[id].classList.add('bzgf-wire')
this.stagedWires[id].dataset.id = id
this.wiresContainer.append(this.stagedWires[id])
return(this.stagedWires[id])
}
refresh(){
let x = 0
let y = 0
for(const node of this.flow.nodes){
const nodeEl = this.addNode(node.nodeType, node.id , node.coords.x, node.coords.y)
}
for(const link of this.flow.links){
const [nodeId1, portId1] = link.from
const [nodeId2, portId2] = link.to
this.addWire(nodeId1, portId1, nodeId2, portId2)
}
}
bezier(x1, y1, dir1, x2, y2, dir2, tensionMin=60) {
const dirVect = {
n: { x: 0, y: -1 },
s: { x: 0, y: 1 },
e: { x: 1, y: 0 },
w: { x: -1, y: 0 },
}
const dist = Math.abs(x2 - x1) + Math.abs(y2 - y1)
let tension = dist * 0.4
if (tension < tensionMin) tension = tensionMin
const c1x = x1 + (dirVect[dir1].x * tension)
const c1y = y1 + (dirVect[dir1].y * tension)
const c2x = x2 + (dirVect[dir2].x * tension)
const c2y = y2 + (dirVect[dir2].y * tension)
return `M ${x1} ${y1} C ${c1x} ${c1y}, ${c2x} ${c2y}, ${x2} ${y2}`
}
/*
portPosition(nodeEl, portEl) {
const nodeRect = nodeEl.getBoundingClientRect()
const portRect = portEl.getBoundingClientRect()
const canvasRect = this.canvas.getBoundingClientRect()
return {
x: portRect.left - canvasRect.left + portRect.width / 2,
y: portRect.top - canvasRect.top + portRect.height / 2
}
}
*/
}
Buildoz.define('graflow', BZgraflow)