From a68ffe12d03a728c6bc92a468ca271062ba26d4b Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Wed, 25 Oct 2023 17:32:19 +0200 Subject: [PATCH] update documentation --- make | 11 ++++---- shell.nix | 1 + src/3rd/js/three/xrf/dynamic/XRWG-lines.js | 21 +++++++-------- .../{predefinedView.js => dynamic/index.js} | 8 ++++-- src/3rd/js/three/xrf/dynamic/texture.js | 26 +++++++++++++++++++ src/xrfragment/Parser.hx | 4 --- test/generated/test.js | 8 ++---- test/generated/test.py | 4 --- 8 files changed, 50 insertions(+), 33 deletions(-) rename src/3rd/js/three/xrf/{predefinedView.js => dynamic/index.js} (87%) create mode 100644 src/3rd/js/three/xrf/dynamic/texture.js diff --git a/make b/make index ec2dbb9..bb9f6f4 100755 --- a/make +++ b/make @@ -66,11 +66,12 @@ build_js(){ cat dist/xrfragment.js > dist/xrfragment.module.js echo "export default xrfragment;" >> dist/xrfragment.module.js # add THREE - cat dist/xrfragment.js \ - src/3rd/js/*.js \ - src/3rd/js/three/*.js \ - src/3rd/js/three/xrmacro/*.js \ - src/3rd/js/three/xrf/*.js \ + cat dist/xrfragment.js \ + src/3rd/js/*.js \ + src/3rd/js/three/*.js \ + src/3rd/js/three/xrmacro/*.js \ + src/3rd/js/three/xrf/*.js \ + src/3rd/js/three/xrf/dynamic/*.js \ src/3rd/js/three/xrf/src/*.js > dist/xrfragment.three.js # add THREE module cat dist/xrfragment.three.js > dist/xrfragment.three.module.js diff --git a/shell.nix b/shell.nix index 44bb5ab..92842b3 100644 --- a/shell.nix +++ b/shell.nix @@ -4,6 +4,7 @@ # nativeBuildInputs is usually what you want -- tools you need to run nativeBuildInputs = with pkgs.buildPackages; [ + haxe mmark xml2rfc diff --git a/src/3rd/js/three/xrf/dynamic/XRWG-lines.js b/src/3rd/js/three/xrf/dynamic/XRWG-lines.js index 93b0295..88ef1b0 100644 --- a/src/3rd/js/three/xrf/dynamic/XRWG-lines.js +++ b/src/3rd/js/three/xrf/dynamic/XRWG-lines.js @@ -1,8 +1,7 @@ -const drawLineToMesh = (frag,scene,mesh) => { - let id = frag.string +const drawLineToMesh = (opts) => { + let {scene,mesh,frag,id} = opts let oldSelection - if(!id) return id // important: ignore empty strings // Selection of Interest if predefined_view matches object name if( mesh.visible && mesh.material){ xrf.emit('focus',{...opts,frag}) @@ -12,12 +11,12 @@ const drawLineToMesh = (frag,scene,mesh) => { let from = new THREE.Vector3() let getCenterPoint = (mesh) => { - var geometry = mesh.geometry; - geometry.computeBoundingBox(); - var center = new THREE.Vector3(); - geometry.boundingBox.getCenter( center ); - mesh.localToWorld( center ); - return center; + var geometry = mesh.geometry; + geometry.computeBoundingBox(); + var center = new THREE.Vector3(); + geometry.boundingBox.getCenter( center ); + mesh.localToWorld( center ); + return center; } xrf.camera.updateMatrixWorld(true); // always keeps me diving into the docs :] @@ -37,7 +36,6 @@ const drawLineToMesh = (frag,scene,mesh) => { } xrf.addEventListener('dynamicKey', (opts) => { - console.dir(opts) let {scene,id,match,v} = opts if( !scene ) return let remove = [] @@ -50,7 +48,7 @@ xrf.addEventListener('dynamicKey', (opts) => { remove.map( (n) => scene.remove(n.selection) ) // drawlines match.map( (w) => { - w.nodes.map( (mesh) => drawLineToMesh( v, scene, mesh ) ) + w.nodes.map( (mesh) => drawLineToMesh({ ...opts, mesh}) ) }) }) @@ -66,4 +64,3 @@ xrf.addEventListener('render', (opts) => { 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/predefinedView.js b/src/3rd/js/three/xrf/dynamic/index.js similarity index 87% rename from src/3rd/js/three/xrf/predefinedView.js rename to src/3rd/js/three/xrf/dynamic/index.js index 0d07bb5..b5dc0e0 100644 --- a/src/3rd/js/three/xrf/predefinedView.js +++ b/src/3rd/js/three/xrf/dynamic/index.js @@ -14,10 +14,11 @@ xrf.frag.updatePredefinedView = (opts) => { for ( let i in frag ) { let v = frag[i] let id = v.string || v.fragment - if( id == '#' ) return + if( id == '#' || !id ) return let match = xrf.XRWG.match(id) if( v.is( xrf.XRF.PV_EXECUTE ) ){ + console.log("pv_execute") scene.XRF_PV_ORIGIN = v.string // evaluate aliases match.map( (w) => { @@ -29,6 +30,9 @@ xrf.frag.updatePredefinedView = (opts) => { } }) xrf.emit('dynamicKey',{ ...opts,v,frag,id,match,scene }) + }else{ + console.log("non pv_execute") + xrf.emit('dynamicKeyValue',{ ...opts,v,frag,id,match,scene }) } } } @@ -36,7 +40,7 @@ xrf.frag.updatePredefinedView = (opts) => { // react to enduser typing url xrf.addEventListener('hash', (opts) => { - let frag = xrf.URI.parse( opts.hash, xrf.XRF.NAVIGATOR | xrf.XRF.PV_OVERRIDE | xrf.XRF.METADATA ) + let frag = xrf.URI.parse( opts.hash ) xrf.frag.updatePredefinedView({frag,scene:xrf.scene}) }) diff --git a/src/3rd/js/three/xrf/dynamic/texture.js b/src/3rd/js/three/xrf/dynamic/texture.js new file mode 100644 index 0000000..d77669c --- /dev/null +++ b/src/3rd/js/three/xrf/dynamic/texture.js @@ -0,0 +1,26 @@ +xrf.addEventListener('dynamicKeyValue', (opts) => { + let {scene,match,v} = opts + let materialName = v.fragment + scene.traverse( (mesh) => { + if( mesh.material){ + if( mesh.material.map && mesh.material.name == materialName ){ + let mat = mesh.material + if( v.x != undefined ){ + mat.map.offset.x = v.x + mat.map.offset.y = v.y + mat.map.rotation = v.z + }else{ + let driver = xrf.scene.getObjectByName(v.string) + if( !driver ) return + xrf.addEventListener('render', (opts) => { + let model = xrf.model + if( !model || !model.clock ) return + mat.map.offset.x = driver.position.x + mat.map.offset.y = driver.position.y + mat.map.rotation = driver.position.z + }) + } + } + } + }) +}) diff --git a/src/xrfragment/Parser.hx b/src/xrfragment/Parser.hx index eb0e128..0545cd8 100644 --- a/src/xrfragment/Parser.hx +++ b/src/xrfragment/Parser.hx @@ -71,10 +71,6 @@ class Parser { store.set(key, v ); return true; } - if( key.split(".").length > 1 && value.split(".").length > 1 ){ - store.set(key, new XRF(key, XRF.ASSET | XRF.PV_OVERRIDE | XRF.T_STRING | XRF.PROP_BIND ) ); - return true; - } // regular fragments: var v:XRF = new XRF(key, Frag.get(key)); diff --git a/test/generated/test.js b/test/generated/test.js index 63c70d1..cdebd43 100644 --- a/test/generated/test.js +++ b/test/generated/test.js @@ -359,19 +359,15 @@ xrfragment_Parser.parse = function(key,value,store) { store[key] = v; return true; } - if(key.split(".").length > 1 && value.split(".").length > 1) { - store[key] = new xrfragment_XRF(key,xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE | xrfragment_XRF.T_STRING | xrfragment_XRF.PROP_BIND); - return true; - } var v = new xrfragment_XRF(key,Frag_h[key]); if(Object.prototype.hasOwnProperty.call(Frag_h,key)) { if(!v.validate(value)) { - console.log("src/xrfragment/Parser.hx:83:","⚠ fragment '" + key + "' has incompatible value (" + value + ")"); + console.log("src/xrfragment/Parser.hx:79:","⚠ fragment '" + key + "' has incompatible value (" + value + ")"); return false; } store[key] = v; if(xrfragment_Parser.debug) { - console.log("src/xrfragment/Parser.hx:87:","✔ " + key + ": " + v.string); + console.log("src/xrfragment/Parser.hx:83:","✔ " + key + ": " + v.string); } } else { if(typeof(value) == "string") { diff --git a/test/generated/test.py b/test/generated/test.py index 2c7ad11..319e28f 100644 --- a/test/generated/test.py +++ b/test/generated/test.py @@ -1436,10 +1436,6 @@ class xrfragment_Parser: v.validate(key) setattr(store,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),v) return True - if ((len(key.split(".")) > 1) and ((len(value.split(".")) > 1))): - value1 = xrfragment_XRF(key,(((xrfragment_XRF.ASSET | xrfragment_XRF.PV_OVERRIDE) | xrfragment_XRF.T_STRING) | xrfragment_XRF.PROP_BIND)) - setattr(store,(("_hx_" + key) if ((key in python_Boot.keywords)) else (("_hx_" + key) if (((((len(key) > 2) and ((ord(key[0]) == 95))) and ((ord(key[1]) == 95))) and ((ord(key[(len(key) - 1)]) != 95)))) else key)),value1) - return True v = xrfragment_XRF(key,Frag.h.get(key,None)) if (key in Frag.h): if (not v.validate(value)):