From 0242df73ebf501ec057a1807ab2faeca878c3c50 Mon Sep 17 00:00:00 2001 From: Lucio Zambon <lucio.zambon@elettra.eu> Date: Fri, 14 Mar 2025 02:35:34 +0000 Subject: [PATCH] Update panther.js --- panther.js | 83 ++++++++---------------------------------------------- 1 file changed, 11 insertions(+), 72 deletions(-) diff --git a/panther.js b/panther.js index 63bf01d..9721d33 100644 --- a/panther.js +++ b/panther.js @@ -842,7 +842,7 @@ function initVar(name, defaultVal) { return document.location.search.indexOf(name)>-1? document.location.search.split(name+'=')[1].split('&')[0]: defaultVal; } - const tourSpeed = 20; // speed [m/s] + const tourSpeed = initVar('tourSpeed', 10); // speed [m/s] let tourPeriod = initVar('tourPeriod', 10); let alphaPerPeriod = 0.009; const tourBackets = initVar('tourBackets', 15); @@ -883,14 +883,15 @@ if (showBackets) for (let backet=0; backet<tourBackets; backet++) { placeBacket(backet, nodes, section, pos); } - console.log(nodes, section, step, maxSteps, pos, alpha/Math.PI*180); - const beta = alpha>alphaPerPeriod? alphaPerPeriod: alpha; - if (alpha>alphaPerPeriod) alpha = alpha - alphaPerPeriod; else alpha = 0; + // console.log(nodes, section, step, maxSteps, pos, alpha/Math.PI*180); + const beta = Math.abs(alpha)>alphaPerPeriod? Math.sign(alpha)*alphaPerPeriod: alpha; + if (Math.abs(alpha)>alphaPerPeriod) alpha = alpha - Math.sign(alpha)*alphaPerPeriod; else alpha = 0; tourCamera(bx + pos/d * (ex - bx), tourHight, bz + pos/d * (ez - bz), -beta); // -Math.PI/2 if (pos+tourSpeed*tourPeriod*9>=d && alpha==0) { const ns2 = ns+1>=nodes.length? 0: ns+1; - alpha = Math.atan2(nodes[ns2].z - nodes[ns].z, nodes[ns2].x - nodes[ns].x) - + alpha = alpha + Math.atan2(nodes[ns2].z - nodes[ns].z, nodes[ns2].x - nodes[ns].x) - Math.atan2(nodes[ns].z - nodes[section].z, nodes[ns].x - nodes[section].x); + if (alpha<-Math.PI) alpha = 2*Math.PI+alpha; console.log(alpha/Math.PI*180); } if (pos+tourSpeed*tourPeriod>=d) { @@ -899,71 +900,8 @@ pos = pos+tourSpeed*tourPeriod - d; } else pos = pos+tourSpeed*tourPeriod; - const alphaFactor = 0.77; // facility=='sr'? 0.77: 9; - if (params.tour) setTimeout(tour, tourPeriod, nodes, section, pos, (alpha<0? 2*Math.PI+alpha: alpha)*alphaFactor, step, maxSteps); - } - } - function tour2(facility, section, pos, alpha, step, maxSteps) { - if (step==maxSteps) { - alphaPerPeriod = 0.008; - if (facility=='preinjector') { - facility = 'booster'; - const preinjRotate = initVar('preinjRotate', 0.5); - camera.rotateY(-Math.PI*preinjRotate); - section = 0; - pos = 3000; - step = 0; - maxSteps = 40; - console.log('camera.rotateY()', -180*preinjRotate, maxSteps); - alphaPerPeriod = 0.1; - tourPeriod = 3000; - } - else if (facility=='booster') { - facility = 'bts'; - section = 0; - pos = 0; - step = 0; - maxSteps = 3; - } - else if (facility=='bts') { - facility = 'sr'; - const srRotate = initVar('srRotate', 1); - camera.rotateY(-Math.PI*srRotate); - section = 0; - pos = 0; - step = 0; - camera.rotateY(-Math.PI*1.5); - maxSteps = 3000; - } - } - if (typeof lattice[facility] != 'undefined') { - const ns = section+1>=lattice[facility].sections.length? 0: section+1; - const bx = lattice[facility].sections[section].start.x; - const bz = lattice[facility].sections[section].start.z; - const ex = lattice[facility].sections[ns].start.x; - const ez = lattice[facility].sections[ns].start.z; - const d = Math.sqrt((ex - bx)*(ex - bx) + (ez - bz)*(ez - bz)); - if (showBackets) for (let backet=0; backet<tourBackets; backet++) { - placeBacket(backet, facility, section, pos); - } - console.log(facility, section, step, maxSteps, pos, alpha/Math.PI*180); - const beta = alpha>alphaPerPeriod? alphaPerPeriod: alpha; - if (alpha>alphaPerPeriod) alpha = alpha - alphaPerPeriod; else alpha = 0; - tourCamera(bx + pos/d * (ex - bx), tourHight, bz + pos/d * (ez - bz), -beta); // -Math.PI/2 - if (pos+tourSpeed*tourPeriod*9>=d && alpha==0) { - const ns2 = ns+1>=lattice[facility].sections.length? 0: ns+1; - alpha = Math.atan2(lattice[facility].sections[ns2].start.z - lattice[facility].sections[ns].start.z, lattice[facility].sections[ns2].start.x - lattice[facility].sections[ns].start.x) - - Math.atan2(lattice[facility].sections[ns].start.z - lattice[facility].sections[section].start.z, lattice[facility].sections[ns].start.x - lattice[facility].sections[section].start.x); - console.log(alpha/Math.PI*180); - } - if (pos+tourSpeed*tourPeriod>=d) { - step++; - section = ns; - pos = pos+tourSpeed*tourPeriod - d; - } - else pos = pos+tourSpeed*tourPeriod; - const alphaFactor = facility=='sr'? 0.77: 12; - if (params.tour) setTimeout(tour, tourPeriod, facility, section, pos, (alpha<0? 2*Math.PI+alpha: alpha)*alphaFactor, step, maxSteps); + const alphaFactor = initVar('alphaFactor', 0.77); // facility=='sr'? 0.77: 0.99; + if (params.tour) setTimeout(tour, tourPeriod, nodes, section, pos, alpha*alphaFactor, step, maxSteps); } } function preTour(step, steps, facility, section, cameraPos, preFactor) { @@ -982,13 +920,14 @@ else if (params.tour) { const nodes = []; if (facility.indexOf(',')>-1) { + // camera.rotateX(-Math.PI/24); camera.rotateZ(Math.PI/24); const f = facility.split(','); for (let j=0; j<f.length; j++) { const start = f[j].indexOf(':')>-1? f[j].split(':')[1]: 0; const stop = f[j].indexOf(':')>-1? f[j].split(':')[2]: lattice[f[j].split(':')[0]].sections.length; for (let i=start; i<stop; i++) {nodes.push(lattice[f[j].split(':')[0]].sections[i % lattice[f[j].split(':')[0]].sections.length].start);} } - if (1) { + if (false) { const cMaterials = [new THREE.MeshBasicMaterial({ color: 0xff0000}),new THREE.MeshBasicMaterial({ color: 0x00ff00}),new THREE.MeshBasicMaterial({ color: 0x0000ff})]; for (let pi=0, k=0; pi<nodes.length; pi++, k++) { const sphere = new THREE.Mesh(sphereGeometry,cMaterials[k % 3].clone()); @@ -1010,7 +949,7 @@ console.log(lattice); const facility = initVar('facility', 'sr'); const f0 = facility.split(',')[0].split(':')[0]; - const preFactor = f0 == 'sr'? 10: (f0 == 'preinjector'? 2.1: 1); + const preFactor = f0 == 'sr'? 9: (f0 == 'preinjector'? 2.1: 1); const section = f0 == 'sr'? 30: (f0 == 'preinjector'? 0: 0); if (showBackets && backets.length==0) for (let pi=1; pi<=tourBackets; pi++) { const sphere = new THREE.Mesh(sphereGeometry,normalMaterial.clone()); -- GitLab