diff --git a/panther.js b/panther.js index bc8f3e05d5cf209ef361e9d23dceca0267aaf67c..653b32f933cc28a05b0012bd61cb2360ca5cb23f 100644 --- a/panther.js +++ b/panther.js @@ -857,12 +857,12 @@ camera.rotateY(ry); renderer.render(scene, camera); } - function placeBacket(backet, facility, section, pos) { - 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; + function placeBacket(backet, nodes, section, pos) { + const ns = section+1>=nodes.length? 0: section+1; + const bx = nodes[section].x; + const bz = nodes[section].z; + const ex = nodes[ns].x; + const ez = nodes[ns].z; const d = Math.sqrt((ex - bx)*(ex - bx) + (ez - bz)*(ez - bz)); const bpos = pos+(backet+1)*tourBacketsDistance; if (bpos>d) { @@ -872,7 +872,38 @@ backets[backet].position.set(bx + bpos/d * (ex - bx), 1200, bz + bpos/d * (ez - bz)); } } - function tour(facility, section, pos, alpha, step, maxSteps) { + function tour(nodes, section, pos, alpha, step, maxSteps) { + if (nodes.length>0) { + const ns = section+1>=nodes.length? 0: section+1; + const bx = nodes[section].x; + const bz = nodes[section].z; + const ex = nodes[ns].x; + const ez = nodes[ns].z; + const d = Math.sqrt((ex - bx)*(ex - bx) + (ez - bz)*(ez - bz)); + 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; + 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) - + Math.atan2(nodes[ns].z - nodes[section].z, nodes[ns].x - nodes[section].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 = 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') { @@ -880,7 +911,7 @@ const preinjRotate = initVar('preinjRotate', 0.5); camera.rotateY(-Math.PI*preinjRotate); section = 0; - pos = 0; + pos = 3000; step = 0; maxSteps = 40; console.log('camera.rotateY()', -180*preinjRotate, maxSteps); @@ -931,35 +962,49 @@ pos = pos+tourSpeed*tourPeriod - d; } else pos = pos+tourSpeed*tourPeriod; - const alphaFactor = facility=='sr'? 0.77: 0.6; + const alphaFactor = facility=='sr'? 0.77: 9; if (params.tour) setTimeout(tour, tourPeriod, facility, section, pos, (alpha<0? 2*Math.PI+alpha: alpha)*alphaFactor, step, maxSteps); } } function preTour(step, steps, facility, section, cameraPos, preFactor) { console.log(step, facility, section, lattice); - const pos = facility=='preinjector'? -20000: 0; - const maxSteps = facility=='preinjector'? 3: 10000; - const bx = (lattice[facility].sections[section].start.x-pos)*tourTransverse; - const bz = (lattice[facility].sections[section].start.z)*tourTransverse; + const f0 = facility.split(',')[0]; + const pos = f0=='preinjector'? -20000: 0; + const maxSteps = f0=='preinjector'? 3: 10000; + const bx = (lattice[f0].sections[section].start.x-pos)*tourTransverse; + const bz = (lattice[f0].sections[section].start.z)*tourTransverse; if (step > 0) { camera.position.set(cameraPos[0] + (steps-step+1)*(bx-cameraPos[0])/steps, cameraPos[1] + (steps-step+1)*(tourHight-cameraPos[1])/steps, cameraPos[2] + (steps-step+1)*(bz-cameraPos[2])/steps); camera.rotateY(Math.PI/steps/preFactor); // camera.rotateX(2.21/steps); camera.rotateZ(-2.41/steps); setTimeout(preTour, tourPeriod*(step<10? 10/step: (step==steps? 100: 1)), step-1, steps, facility, section, cameraPos, preFactor); } - else if (params.tour) setTimeout(tour, tourPeriod*2, facility, section, pos, 0, 0, maxSteps); + else if (params.tour) { + const nodes = []; + if (facility.indexOf(',')>-1) { + const f = facility.split(','); + for (let j=0; j<f.length; j++) { + for (let i=0; i<lattice[f[j]].sections.length; i++) {nodes.push(lattice[f[j]].sections[i].start);} + } + } + else { + for (let i=0; i<lattice[facility].sections.length; i++) {nodes.push(lattice[facility].sections[i].start);} + } + setTimeout(tour, tourPeriod*2, nodes, section, pos, 0, 0, maxSteps); + } } function switchTour() { console.log(lattice); const facility = initVar('facility', 'sr'); - const preFactor = facility == 'sr'? 10: (facility == 'preinjector'? 2.1: 1); - const section = facility == 'sr'? 30: (facility == 'preinjector'? 0: 0); + const f0 = facility.split(',')[0]; + const preFactor = f0 == 'sr'? 10: (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()); - const bx = lattice[facility].sections[0].start.x; - const bz = lattice[facility].sections[0].start.z; - const ex = lattice[facility].sections[1].start.x; - const ez = lattice[facility].sections[1].start.z; + const bx = lattice[f0].sections[0].start.x; + const bz = lattice[f0].sections[0].start.z; + const ex = lattice[f0].sections[1].start.x; + const ez = lattice[f0].sections[1].start.z; const d = Math.sqrt((ex - bx)*(ex - bx) + (ez - bz)*(ez - bz)); sphere.position.set(bx + pi*tourBacketsDistance/d * (ex - bx), 1200, bz + pi*tourBacketsDistance/d * (ez - bz)); sphere.name = 'backet'+pi; @@ -968,7 +1013,7 @@ sphere.scale.z = tourBacketSize; // sphere.visible = false; backets.push(sphere); - facilities[facility].add(sphere); + facilities[f0].add(sphere); } const cameraPos = typeof conf.default_camera_init[machine] == 'undefined'? conf.default_camera_init.default: conf.default_camera_init[machine]; cameraPos[1] = cameraPos[1]*2; @@ -1206,6 +1251,7 @@ window.setFar = setFar; const canvas = document.querySelector('#c'); renderer = new THREE.WebGLRenderer({antialias: false, canvas, logarithmicDepthBuffer: true}); + renderer.shadowMap.enabled = false; // global shadow disable // renderer = new WebGPURenderer(); renderer.setPixelRatio(window.devicePixelRatio); @@ -1238,14 +1284,26 @@ window.setFar = setFar; camera.updateMatrixWorld(true); setFar(params.far); - const dirLight1 = new THREE.DirectionalLight(0xffffff, 3); - dirLight1.position.set(1, 1, 1); + + const dirLight1 = new THREE.DirectionalLight(0xffffff, 5); + dirLight1.position.set(0, 10, 0); // zenith light scene.add(dirLight1); - const dirLight2 = new THREE.DirectionalLight(0x888888, 3); - dirLight2.position.set(-1, -1, -1); + /*const dirLight2 = new THREE.DirectionalLight(0xffffff, 5); + dirLight2.position.set(0, -10, 0); // nadir light scene.add(dirLight2); - const ambientLight = new THREE.AmbientLight(0xffffff, 2); - scene.add(ambientLight); + const dirLight3 = new THREE.DirectionalLight(0xffffff, 2); + dirLight3.position.set(10, 5, 0); // right light + scene.add(dirLight3); + const dirLight4 = new THREE.DirectionalLight(0xffffff, 2); + dirLight4.position.set(-10, 5, 0); // left light + scene.add(dirLight4);*/ + const dirLight5 = new THREE.DirectionalLight(0xffffff, 5); + dirLight5.position.set(0, 5, 10); // front light + scene.add(dirLight5); + + /*const ambientLight = new THREE.AmbientLight(0xffffff, 1); + scene.add(ambientLight);*/ + // postprocessing (derived from https://github.com/mrdoob/three.js/blob/master/examples/webgl_postprocessing_outline.html) composer = new EffectComposer(renderer);