From 249a68f9e1c5cf5c16fd0b4efe5cbba94e8f1cf2 Mon Sep 17 00:00:00 2001 From: Lucio Zambon <lucio.zambon@elettra.eu> Date: Thu, 9 May 2024 02:23:13 +0000 Subject: [PATCH] Update panther.js --- panther.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/panther.js b/panther.js index 378fd04..f4f45b8 100644 --- a/panther.js +++ b/panther.js @@ -164,13 +164,20 @@ }); } function readBpms() { - // for (let facility in lattice) { if (lattice[facility].bpm) readBpm(facility);} fetch(conf.bpmUrl) .then((response) => {return response.json();}) .then((data) => { for (let facility in data) { updateBpm(data[facility], facility); } + bpmTimes[bpmTimeIndex] = + new Date(); + bpmTimeIndex = (bpmTimeIndex + 1) % bpmTimeLen; + if (bpmWait > 0) setTimeout(readBpms, bpmWait); + if (bpmTimes[bpmTimeIndex] > 0) { + const bpmfreq = 1000 / (+ new Date() - bpmTimes[bpmTimeIndex]) * bpmTimeLen; + $('#bpmfreq').val(bpmfreq.toPrecision(2) + ' fps'); + // console.log(bpmfreq); + } }); } function bpmPath(data, facility) { @@ -178,7 +185,7 @@ if (len>bpmPoints[facility].length) len = bpmPoints[facility].length; // if (data!=-1) console.log('bpmDbg', len, facility, data, bpmPoints[facility].length); const bpmCurve = []; - const bpmFactor = 0.000002; + const bpmFactor = conf.bpmFactor[facility]; for (let i=0; i<len; i++) { const j = (i + 1) % len; const tx = bpmPoints[facility][i][0].x * (1+(data.Hor? data.Hor[j]*0.02*bpmFactor*params.bpmZoomX: 0)); @@ -190,6 +197,10 @@ return new THREE.CatmullRomCurve3(bpmCurve); } let bpmInited = false; + const bpmTimeLen = 100; + let bpmTimeIndex = 0; + const bpmTimes = new Array(bpmTimeLen).fill(0); + const bpmWait = document.location.search.indexOf('bpmWait=')>-1? document.location.search.split('bpmWait=')[1].split('&')[0]-0: 0; function bpmAdd(facility) { console.log('bpmDbg(), facility:', facility); if (lattice[facility] && lattice[facility].bpm && (document.location.search.indexOf('&bpm')>-1 || document.location.search.indexOf('?bpm')>-1)) { @@ -200,7 +211,14 @@ const material = new THREE.MeshBasicMaterial({color: 0x8000ff, transparent: true, opacity: 0.5,}); bpmMesh[facility] = new THREE.Mesh(bpmGeometry, material); facilities[facility].add(bpmMesh[facility]); - if (!bpmInited) {bpmInited=true; readBpms(); if (document.location.search.indexOf('bpm=')==-1) setInterval(readBpms, 300);} + if (!bpmInited) { + bpmInited = true; + readBpms(); + if (document.location.search.indexOf('bpm=')==-1 && bpmWait==0) setInterval(readBpms, 300); + bpmTimes[bpmTimeIndex] = + new Date(); + bpmTimeIndex = (bpmTimeIndex + 1) % bpmTimeLen; + if (bpmWait > 0) setTimeout(readBpms, bpmWait); + } } console.log('bpmDbg(), bpmMesh:', bpmMesh, bpmMesh[facility]); } @@ -242,6 +260,7 @@ if (lattice[i].bpm && (typeof params.bpm == 'undefined')) { params.bpm = document.location.search.indexOf('&bpm')>-1 || document.location.search.indexOf('?bpm')>-1; gui.add(params, 'bpm').onChange(function() {toggleParam('bpm');}); if (params.bpm) { + $('.controller.boolean:last').append('<input id="bpmfreq" type="text" spellcheck="false" aria-labelledby="lil-gui-name-6">'); params.bpmZoomX = 1; gui.add(params, 'bpmZoomX', 0.1, 10); params.bpmZoomY = 1; @@ -435,9 +454,9 @@ mycomp.position.set(params.highlightScale*(lattice[facility].sections[i].start.x + tang*d / den) + offset[0], y + offset[1], params.highlightScale*(lattice[facility].sections[i].start.z + d / den + offset[2])); if (mycomp.rotatedX) {mycomp.rotateZ(Math.atan(-tang));} else mycomp.rotateY(Math.atan(tang)); window.names.push(lattice[facility].sections[i].components[m].name); - if (lattice[facility].sections[i].components[m].devices) { - // console.log('mycomp.devices',lattice[facility].sections[i].components[m].devices); - for (let j=0; j<lattice[facility].sections[i].components[m].devices.length; j++) {names.push(lattice[facility].sections[i].components[m].devices[j]); alias.push([myname,lattice[facility].sections[i].components[m].devices[j]]);} + if (lattice[facility].sections[i].components[m].embedded) { + // console.log('mycomp.embedded',lattice[facility].sections[i].components[m].embedded); + for (let j=0; j<lattice[facility].sections[i].components[m].embedded.length; j++) {names.push(lattice[facility].sections[i].components[m].embedded[j]); alias.push([myname,lattice[facility].sections[i].components[m].embedded[j]]);} } if (id[1]) {window.names.push(id[1]); alias.push(id);} mycomp.magnetType = magnet; -- GitLab