From 6512133f86cf9f3d7eabcc103cbbfc17c661e486 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Thu, 2 Nov 2023 18:15:05 +0100 Subject: [PATCH] bugfix: XRWG-lines --- example/aframe/sandbox/index.html | 2 +- example/assets/AnimatedCube.bin | Bin 1860 -> 0 bytes example/assets/AnimatedCube.gltf | 262 --------------------- example/assets/AnimatedCube_NLA.gltf | 160 ------------- src/3rd/js/three/xrf/dynamic/XRWG-lines.js | 54 ++--- src/3rd/js/three/xrf/t.js | 44 ++-- 6 files changed, 57 insertions(+), 465 deletions(-) delete mode 100644 example/assets/AnimatedCube.bin delete mode 100644 example/assets/AnimatedCube.gltf delete mode 100644 example/assets/AnimatedCube_NLA.gltf diff --git a/example/aframe/sandbox/index.html b/example/aframe/sandbox/index.html index 81a8eee..50c10b9 100644 --- a/example/aframe/sandbox/index.html +++ b/example/aframe/sandbox/index.html @@ -34,7 +34,7 @@ - + diff --git a/example/assets/AnimatedCube.bin b/example/assets/AnimatedCube.bin deleted file mode 100644 index 72f7d2d52ad79f8cb5a71f1640e51bd91ddd4a08..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1860 zcmcIiNm2tb3~bhfJ?uMSx#vc4;9!1+Pke|YHN}&70;pxn<1wC04xp+;Qg=(1lmImE zLzEMXZdSj8IFF~S%d*u)mLv4dUgVS;@e;1EYR#tBYw zhI3rt5?8p!4W_uo9q#cE-(Ww!rJiwb{`LJzof`+e#)6sNWpTo+Z&6FW)Hu`fjf^*~ zdE?5Qcx{GKXE{Ay)5X7@6$xNr5u&Fq$W jJ-NI#=d3p8wU=*eI-KBURa|)MnRMJOei9aE4n2MVd$l|d diff --git a/example/assets/AnimatedCube.gltf b/example/assets/AnimatedCube.gltf deleted file mode 100644 index ff117b0..0000000 --- a/example/assets/AnimatedCube.gltf +++ /dev/null @@ -1,262 +0,0 @@ -{ - "accessors" : [ - { - "bufferView" : 0, - "byteOffset" : 0, - "componentType" : 5126, - "count" : 3, - "max" : [ - 2.000000 - ], - "min" : [ - 0.000000 - ], - "type" : "SCALAR" - }, - { - "bufferView" : 1, - "byteOffset" : 0, - "componentType" : 5126, - "count" : 3, - "max" : [ - 0.000000, - 1.000000, - 0.000000, - 1.000000 - ], - "min" : [ - 0.000000, - -8.742278e-008, - 0.000000, - -1.000000 - ], - "type" : "VEC4" - }, - { - "bufferView" : 2, - "byteOffset" : 0, - "componentType" : 5123, - "count" : 36, - "max" : [ - 35 - ], - "min" : [ - 0 - ], - "type" : "SCALAR" - }, - { - "bufferView" : 3, - "byteOffset" : 0, - "componentType" : 5126, - "count" : 36, - "max" : [ - 1.000000, - 1.000000, - 1.000001 - ], - "min" : [ - -1.000000, - -1.000000, - -1.000000 - ], - "type" : "VEC3" - }, - { - "bufferView" : 4, - "byteOffset" : 0, - "componentType" : 5126, - "count" : 36, - "max" : [ - 1.000000, - 1.000000, - 1.000000 - ], - "min" : [ - -1.000000, - -1.000000, - -1.000000 - ], - "type" : "VEC3" - }, - { - "bufferView" : 5, - "byteOffset" : 0, - "componentType" : 5126, - "count" : 36, - "max" : [ - 1.000000, - -0.000000, - -0.000000, - 1.000000 - ], - "min" : [ - 0.000000, - -0.000000, - -1.000000, - -1.000000 - ], - "type" : "VEC4" - }, - { - "bufferView" : 6, - "byteOffset" : 0, - "componentType" : 5126, - "count" : 36, - "max" : [ - 1.000000, - 1.000000 - ], - "min" : [ - -1.000000, - -1.000000 - ], - "type" : "VEC2" - } - ], - "animations" : [ - { - "channels" : [ - { - "sampler" : 0, - "target" : { - "node" : 0, - "path" : "rotation" - } - } - ], - "name" : "animation_AnimatedCube", - "samplers" : [ - { - "input" : 0, - "interpolation" : "LINEAR", - "output" : 1 - } - ] - } - ], - "asset" : { - "generator" : "VKTS glTF 2.0 exporter", - "version" : "2.0" - }, - "bufferViews" : [ - { - "buffer" : 0, - "byteLength" : 12, - "byteOffset" : 0 - }, - { - "buffer" : 0, - "byteLength" : 48, - "byteOffset" : 12 - }, - { - "buffer" : 0, - "byteLength" : 72, - "byteOffset" : 60, - "target" : 34963 - }, - { - "buffer" : 0, - "byteLength" : 432, - "byteOffset" : 132, - "target" : 34962 - }, - { - "buffer" : 0, - "byteLength" : 432, - "byteOffset" : 564, - "target" : 34962 - }, - { - "buffer" : 0, - "byteLength" : 576, - "byteOffset" : 996, - "target" : 34962 - }, - { - "buffer" : 0, - "byteLength" : 288, - "byteOffset" : 1572, - "target" : 34962 - } - ], - "buffers" : [ - { - "byteLength" : 1860, - "uri" : "AnimatedCube.bin" - } - ], - "images" : [ - { - "uri" : "AnimatedCube_BaseColor.png" - }, - { - "uri" : "AnimatedCube_MetallicRoughness.png" - } - ], - "materials" : [ - { - "name" : "AnimatedCube", - "pbrMetallicRoughness" : { - "baseColorTexture" : { - "index" : 0 - }, - "metallicRoughnessTexture" : { - "index" : 1 - } - } - } - ], - "meshes" : [ - { - "name" : "AnimatedCube", - "primitives" : [ - { - "attributes" : { - "NORMAL" : 4, - "POSITION" : 3, - "TANGENT" : 5, - "TEXCOORD_0" : 6 - }, - "indices" : 2, - "material" : 0, - "mode" : 4 - } - ] - } - ], - "nodes" : [ - { - "mesh" : 0, - "name" : "AnimatedCube", - "rotation" : [ - 0.000000, - -1.000000, - 0.000000, - 0.000000 - ] - } - ], - "samplers" : [ - {} - ], - "scene" : 0, - "scenes" : [ - { - "nodes" : [ - 0 - ] - } - ], - "textures" : [ - { - "sampler" : 0, - "source" : 0 - }, - { - "sampler" : 0, - "source" : 1 - } - ] -} \ No newline at end of file diff --git a/example/assets/AnimatedCube_NLA.gltf b/example/assets/AnimatedCube_NLA.gltf deleted file mode 100644 index dbedcd5..0000000 --- a/example/assets/AnimatedCube_NLA.gltf +++ /dev/null @@ -1,160 +0,0 @@ -{ - "asset":{ - "generator":"Khronos glTF Blender I/O v3.5.30", - "version":"2.0" - }, - "scene":0, - "scenes":[ - { - "name":"Scene", - "nodes":[ - 0 - ] - } - ], - "nodes":[ - { - "mesh":0, - "name":"AnimatedCube" - } - ], - "animations":[ - { - "channels":[ - { - "sampler":0, - "target":{ - "node":0, - "path":"rotation" - } - } - ], - "name":"walk", - "samplers":[ - { - "input":4, - "interpolation":"LINEAR", - "output":5 - } - ] - } - ], - "materials":[ - { - "name":"AnimatedCube", - "pbrMetallicRoughness":{} - } - ], - "meshes":[ - { - "name":"AnimatedCube", - "primitives":[ - { - "attributes":{ - "POSITION":0, - "TEXCOORD_0":1, - "NORMAL":2 - }, - "indices":3, - "material":0 - } - ] - } - ], - "accessors":[ - { - "bufferView":0, - "componentType":5126, - "count":36, - "max":[ - 1, - 1, - 1.0000009536743164 - ], - "min":[ - -1, - -1, - -1 - ], - "type":"VEC3" - }, - { - "bufferView":1, - "componentType":5126, - "count":36, - "type":"VEC2" - }, - { - "bufferView":2, - "componentType":5126, - "count":36, - "type":"VEC3" - }, - { - "bufferView":3, - "componentType":5123, - "count":36, - "type":"SCALAR" - }, - { - "bufferView":4, - "componentType":5126, - "count":3, - "max":[ - 2 - ], - "min":[ - 0 - ], - "type":"SCALAR" - }, - { - "bufferView":5, - "componentType":5126, - "count":3, - "type":"VEC4" - } - ], - "bufferViews":[ - { - "buffer":0, - "byteLength":432, - "byteOffset":0, - "target":34962 - }, - { - "buffer":0, - "byteLength":288, - "byteOffset":432, - "target":34962 - }, - { - "buffer":0, - "byteLength":432, - "byteOffset":720, - "target":34962 - }, - { - "buffer":0, - "byteLength":72, - "byteOffset":1152, - "target":34963 - }, - { - "buffer":0, - "byteLength":12, - "byteOffset":1224 - }, - { - "buffer":0, - "byteLength":48, - "byteOffset":1236 - } - ], - "buffers":[ - { - "byteLength":1284, - "uri":"data:application/octet-stream;base64,AACAPwAAgL8AAIA/AACAvwAAgL8AAIC/AACAPwAAgL8AAIC/AACAvwAAgD8AAIC/7/9/PwAAgD8IAIA/AACAPwAAgD/v/3+/AACAPwAAgD/v/3+/AACAPwAAgL8AAIA/AACAPwAAgL8AAIC/7/9/PwAAgD8IAIA/AACAvwAAgL8AAIA/AACAPwAAgL8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AAAAAgL8AAACAAAAAAAAAgL8AAACAAAAAAAAAgD8AAACAAAAAAAAAgD8AAACAAAAAAAAAgD8AAACAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAAAAgAAAAAAAAIA/AAAAgAAAAAAAAIA/AAAAgAAAAAAAAIA/AACAvwAAAAAAAACAAACAvwAAAAAAAACAAACAvwAAAAAAAACAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAABAAIAAwAEAAUABgAHAAgACQAKAAsADAANAA4ADwAQABEAEgATABQAFQAWABcAGAAZABoAGwAcAB0AHgAfACAAIQAiACMAAAAAAAAAgD8AAABAAAAAAAAAAAAAAACAAACAPwAAAIAAAIC/AAAAAC69OzMAAAAALr27MwAAAIAAAIA/" - } - ] -} diff --git a/src/3rd/js/three/xrf/dynamic/XRWG-lines.js b/src/3rd/js/three/xrf/dynamic/XRWG-lines.js index 88ef1b0..effb442 100644 --- a/src/3rd/js/three/xrf/dynamic/XRWG-lines.js +++ b/src/3rd/js/three/xrf/dynamic/XRWG-lines.js @@ -1,5 +1,21 @@ +xrf.addEventListener('dynamicKey', (opts) => { + let {scene,id,match,v} = opts + if( !scene ) return + let remove = [] + // erase previous lines + xrf.focusLine.lines.map( (line) => line.parent.remove(line) ) + xrf.focusLine.points = [] + xrf.focusLine.lines = [] -const drawLineToMesh = (opts) => { + //scene.traverse( (n) => n.selection ? remove.push(n) : false ) + //remove.map( (n) => scene.remove(n.selection) ) + // drawlines + match.map( (w) => { + w.nodes.map( (mesh) => xrf.drawLineToMesh({ ...opts, mesh}) ) + }) +}) + +xrf.drawLineToMesh = (opts) => { let {scene,mesh,frag,id} = opts let oldSelection // Selection of Interest if predefined_view matches object name @@ -19,9 +35,9 @@ const drawLineToMesh = (opts) => { return center; } - xrf.camera.updateMatrixWorld(true); // always keeps me diving into the docs :] - xrf.camera.getWorldPosition(from) - from.y -= 0.5 // originate from the heart chakra! :p + xrf.camera.getCam().updateMatrixWorld(true); // always keeps me diving into the docs :] + xrf.camera.getCam().getWorldPosition(from) + from.y = 0.5 // originate from the heart chakra! :p const points = [from, getCenterPoint(mesh) ] const geometry = new THREE.BufferGeometry().setFromPoints( points ); let line = new THREE.Line( geometry, xrf.focusLine.material ); @@ -35,32 +51,14 @@ const drawLineToMesh = (opts) => { } } -xrf.addEventListener('dynamicKey', (opts) => { - let {scene,id,match,v} = opts - if( !scene ) return - let remove = [] - // erase previous lines - xrf.focusLine.lines.map( (line) => scene.remove(line) ) - xrf.focusLine.points = [] - xrf.focusLine.lines = [] - - scene.traverse( (n) => n.selection ? remove.push(n) : false ) - remove.map( (n) => scene.remove(n.selection) ) - // drawlines - match.map( (w) => { - w.nodes.map( (mesh) => drawLineToMesh({ ...opts, mesh}) ) - }) -}) - xrf.addEventListener('render', (opts) => { - let model = xrf.model - if( !model || !model.clock ) return // update focusline - let {time} = opts - xrf.focusLine.material.color.r = (1.0 + Math.sin( model.clock.getElapsedTime()*10 ))/2 - xrf.focusLine.material.dashSize = 0.2 + 0.02*Math.sin( model.clock.getElapsedTime() ) - xrf.focusLine.material.gapSize = 0.1 + 0.02*Math.sin( model.clock.getElapsedTime() *3 ) - xrf.focusLine.material.opacity = (0.25 + 0.15*Math.sin( model.clock.getElapsedTime() * 3 )) * xrf.focusLine.opacity; + let {time,model} = opts + if( !xrf.clock ) return + xrf.focusLine.material.color.r = (1.0 + Math.sin( xrf.clock.getElapsedTime()*10 ))/2 + xrf.focusLine.material.dashSize = 0.2 + 0.02*Math.sin( xrf.clock.getElapsedTime() ) + xrf.focusLine.material.gapSize = 0.1 + 0.02*Math.sin( xrf.clock.getElapsedTime() *3 ) + xrf.focusLine.material.opacity = (0.25 + 0.15*Math.sin( xrf.clock.getElapsedTime() * 3 )) * xrf.focusLine.opacity; if( xrf.focusLine.opacity > 0.0 ) xrf.focusLine.opacity -= time*0.2 if( xrf.focusLine.opacity < 0.0 ) xrf.focusLine.opacity = 0 }) diff --git a/src/3rd/js/three/xrf/t.js b/src/3rd/js/three/xrf/t.js index 11ca61a..f632a7b 100644 --- a/src/3rd/js/three/xrf/t.js +++ b/src/3rd/js/three/xrf/t.js @@ -13,7 +13,7 @@ xrf.frag.t = function(v, opts){ if( v.y != undefined || v.z != undefined ) mixer.updateLoop( v ) // play animations - mixer.play( v.x != 0 ) + mixer.play( v ) }) } @@ -73,7 +73,7 @@ xrf.addEventListener('parseModel', (opts) => { anim.action.setLoop( THREE.LoopOnce, ) anim.action.timeScale = mixer.timeScale anim.action.enabled = true - anim.action.play() + if( t.x != 0 ) anim.action.play() } }) mixer.setTime(mixer.loop.timeStart) @@ -122,21 +122,37 @@ xrf.addEventListener('render', (opts) => { let model = xrf.model let {time} = opts if( !model ) return - if( xrf.mixers.length ) xrf.mixers.map( (m) => m.isPlaying ? m.update( time ) : false ) + if( xrf.mixers.length ){ + xrf.mixers.map( (m) => m.isPlaying ? m.update( time ) : false ) - // update camera if possible - if( model.cameras && model.cameras.length && xrf.mixers.length ){ + // update active camera in case selected by dynamicKey in URI + if( xrf.model.camera && model.mixer.isPlaying ){ - let cam = xrf.camera.getCam() - // cam.fov = model.cameras[0].fov (why is blender not exporting radians?) - cam.far = model.cameras[0].far - cam.near = model.cameras[0].near + let cam = xrf.camera.getCam() + // cam.fov = model.cameras[0].fov (why is blender not exporting radians?) + cam.far = model.cameras[0].far + cam.near = model.cameras[0].near - let rig = xrf.camera - rig.position.copy( model.cameras[0].position ) - rig.position.y -= rig.offsetY // VR/AR compensate camera rig - //rig.rotation.copy( model.cameras[0].rotation ) + let rig = xrf.camera + rig.position.copy( model.cameras[0].position ) + rig.position.y -= rig.offsetY // VR/AR compensate camera rig + //rig.rotation.copy( model.cameras[0].rotation ) - rig.updateProjectionMatrix() + rig.updateProjectionMatrix() + } } }) + +xrf.addEventListener('dynamicKey', (opts) => { + // select active camera if any + let {id,match,v} = opts + console.dir(opts) + match.map( (w) => { + w.nodes.map( (node) => { + if( node.isCamera ){ + console.log("setting camera to "+node.name) + xrf.model.camera = node + } + }) + }) +})