import { Staticmodel } from '@/jlmap3d/jl3dpassflow/config.js'; //loader import { FBXLoader } from '@/jlmap3d/main/loaders/FBXLoader'; import { OBJLoader } from '@/jlmap3d/main/loaders/OBJLoader'; import { OrbitControls } from '@/jlmap3d/main/control/OrbitControls'; import { ModelManager } from '@/jlmap3d/jl3dpassflow/loader.js'; import { SkeletonUtils } from '@/jlmap3d/main/utils/SkeletonUtils.js'; import { Pathfinding } from '@/jlmap3d/jl3dpassflow/utils/Pathfinding.js'; // const Pathfinding = window.threePathfinding.Pathfinding; import { ZoneManager } from '@/jlmap3d/jl3dpassflow/model/zonemanager.js'; import StompClient from '@/utils/sock'; import { Loading } from 'element-ui'; // const Pathfinding = window.threePathfinding.Pathfinding; var clock = new THREE.Clock(); let delta; let scene,camerass,renderer; let rendermode = 0; var mixers = []; var testmesh1,testmesh2; var humans = []; var checkdoor1 = []; var checkdoor2 = []; var station; var zhajiinmodel; var zhajioutmodel; var monitor; let ids = 0; let humanlist = new THREE.Group(); let originhuman1 = null; let originhuman2 = null; let originanima1 = null; let originanima2 = null; let zhajiin = []; let zhajiout = []; let deviceaction = []; let passerwebwork = new Worker("../../static/workertest/passsimulation/passer.js"); let stationwebwork = new Worker("../../static/workertest/passsimulation/station.js"); let stationzon = new ZoneManager(); for(let i=0;i<5;i++){ checkdoor1[i]={ id:"c1"+i, status:0, pos:[], max:10 }; } for(let i=0;i<5;i++){ let zhaji = { id:"in0"+(i+1), status:0, waiting:0 } zhajiin.push(zhaji); } for(let i=0;i<5;i++){ let zhaji = { id:"out0"+(i+1), status:0, waiting:0 } zhajiout.push(zhaji); } let stationleft = []; let stationright = []; for(let i=0;i<22;i++){ let sl = { id:"left"+i, status:0, waiting:0 } stationleft.push(sl); } for(let i=0;i<22;i++){ let sr = { id:"right"+i, status:0, waiting:0 } stationright.push(sr); } var windowWidth = window.innerWidth ; var windowHeight = window.innerHeight; var views = [ { left: 0, bottom: 0, width: 0.5, height: 0.5, background: new THREE.Color( 0.5, 0.5, 0.7 ), eye: [ 3.7, 16, 26 ], up: [3.7, 10 ,16 ], fov: 30 }, { left: 0, bottom: 0.5, width: 0.5, height: 0.5, background: new THREE.Color( 0.5, 0.5, 0.7 ), eye: [ 3.7,17,-4 ], up: [ 3.7, 10 ,16], fov: 30 }, { left: 0.5, bottom: 0, width: 0.5, height: 0.5, background: new THREE.Color( 0.7, 0.5, 0.5 ), eye: [ -60, 6,11], up: [ -59, 5.9,11 ], fov: 45 }, { left: 0.5, bottom: 0.5, width: 0.5, height: 0.5, background: new THREE.Color( 0.5, 0.7, 0.7 ), eye: [ -7,17,2], up: [-7, 10, 8], fov: 60 } ]; export function Jl3dpassflow(dom) { var scope = this; this.dom = dom; this.nowcode = null; this.animateswitch = false; this.signallights = []; this.mixers = []; this.showmodel = null; //初始化webgl渲染 renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setClearColor(new THREE.Color(0x000000)); renderer.setSize(dom.offsetWidth, dom.offsetHeight); this.dom.appendChild(renderer.domElement); //定义相机 camerass = new THREE.PerspectiveCamera(70, dom.offsetWidth / dom.offsetHeight, 0.01, 1000); camerass.position.set(0, 80, 40); camerass.aspect = dom.offsetWidth / dom.offsetHeight; camerass.updateProjectionMatrix(); for ( var ii = 0; ii < views.length; ++ ii ) { var view = views[ ii ]; var camera = new THREE.PerspectiveCamera( view.fov, window.innerWidth / window.innerHeight, 1, 200 ); camera.position.fromArray( view.eye ); camera.lookAt( view.up[0],view.up[1],view.up[2] ); view.camera = camera; } //定义场景(渲染容器) scene = new THREE.Scene(); scene.background = new THREE.Color(0xa0a0a0); var mesh = new THREE.Mesh(new THREE.PlaneBufferGeometry(200, 200), new THREE.MeshPhongMaterial({ color: 0x999999, depthWrite: false })); mesh.rotation.x = - Math.PI / 2; mesh.receiveShadow = true; scene.add(mesh); var grid = new THREE.GridHelper(200, 20, 0x000000, 0x000000); grid.material.opacity = 0.2; grid.material.transparent = true; scene.add(grid); //定义全局光 let ambientLight = new THREE.AmbientLight(0xffffff, 1.3); scene.add(ambientLight); // // var spotLight = new THREE.SpotLight(0xffffff); // spotLight.position.set(-50, 60, 15); // spotLight.castShadow = true; // spotLight.shadow.mapSize.width = 1024; // spotLight.shadow.mapSize.height = 1024; // scene.add(spotLight); this.controls = new THREE.OrbitControls(camerass, dom); this.controls.maxPolarAngle = Math.PI / 2; this.controls.minPolarangle = Math.PI / 5; this.controls.maxDistance = 800; this.controls.screenSpacePanning = true; this.controls.update(); this.selectmodel = null; const ZONE = 'level'; const SPEED = 10; const OFFSET = 0.2; THREE.Pathfinding = Pathfinding; let level, navmesh; let groupID, path; let playerPosition = new THREE.Vector3( -3.5, 0.5, 5.5 ); let targetPosition = new THREE.Vector3(); let pathfinder = new THREE.Pathfinding(); let mouse = new THREE.Vector2(); let raycaster = new THREE.Raycaster(); var loader = new THREE.OBJLoader(); // load a resource loader.load( // resource URL '../../static/model/path/path.obj', // called when resource is loaded function ( object ) { // console.time('createZone()'); const zone = THREE.Pathfinding.createZone(object.children[0].geometry); // console.timeEnd('createZone()'); pathfinder.setZoneData( ZONE, zone ); const navWireframe = new THREE.Mesh(object.children[0].geometry, new THREE.MeshBasicMaterial({ color: 0x808080, wireframe: true })); navWireframe.position.y = OFFSET / 2; // scene.add(navWireframe); navmesh = object.children[0]; // scene.add(navmesh); // Set the player's navigation mesh group groupID = pathfinder.getGroup( ZONE, playerPosition ); }, // called when loading is in progresses function ( xhr ) { console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' ); }, // called when loading has errors function ( error ) { console.log( 'An error happened' ); } ); document.addEventListener( 'mouseup', onDocumentMouseUp, false ); function onDocumentMouseUp (event) { mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1; mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1; camerass.updateMatrixWorld(); raycaster.setFromCamera( mouse, camerass ); const intersects = raycaster.intersectObject( navmesh ); if ( !intersects.length ) return; console.log(intersects[0].point); targetPosition.copy( intersects[0].point ); // Teleport on ctrl/cmd click or RMB. if (event.metaKey || event.ctrlKey || event.button === 2) { path = null; originhuman1.position.copy( playerPosition.copy( targetPosition ) ); return; } path = pathfinder.findPath( playerPosition, targetPosition, ZONE, groupID ); let points = []; points.push(new THREE.Vector3(originhuman1.position.x,originhuman1.position.y,originhuman1.position.z)); for(let i=0;i=0;i--){ if(mixers[i]._actions[0].isRunning()){ mixers[i].update( delta ); } } }; stationwebwork.onmessage = function (event) { // console.log("stationwebwork"); // if(humans.length<200){ var direct = Math.floor(Math.random()*(3-1+1))+1; //1--top //2-- down if(direct == 1){ newhumancreate(stationzon.getzoneposition("enter1"),0); }else{ newhumancreate(stationzon.getzoneposition("enter2"),0); } // } }; } //循环渲染函数 function animate() { // console.log(rendermode); if(rendermode == 0){ renderer.render(scene, camerass); scope.controls.update(); }else{ monitorrender(); } // delta = clock.getDelta(); // tick(delta); requestAnimationFrame(animate); } function passerai(){ for(let i=0;i=1){ // let point = humans[i].runrail.curve.getPointAt(1); //更新模型坐标 if(humanlist.children[i].status == 1){ // humanlist.children[i].runrail.enable = false; humanlist.children[i].progress = 1; // humanlist.children[i].mixer.runplay = false; humanlist.children[i].action.stop(); humanlist.children[i].status = 0; // if(humanlist.children[i].stage == 4){ // // humanlist.remove(humanlist.children[i].mesh); // // humans.splice(i,1); // } // if(humanlist.children[i].stage == 6){ humanlist.remove(humanlist.children[i]); // humanlist.children[i].stage = 7; } if(humanlist.children[i].stage == 5){ humanlist.children[i].stage = 6; } if(humanlist.children[i].stage == 4){ humanlist.children[i].stage = 5; } if(humanlist.children[i].stage == 3){ humanlist.children[i].stage = 4; } // if(humanlist.children[i].stage == 2){ humanlist.children[i].stage = 3; } if(humanlist.children[i].stage == 1){ humanlist.children[i].stage = 2; } if(humanlist.children[i].stage == 0){ // // console.log(humans[i].doors); // zhajiin[humanlist.children[i].doors].waiting = 0; humanlist.children[i].stage = 1; } } }else{ //根据动画进度获取动画轨迹上点 // console.log(i); // console.log(humanlist.children[i].runrail); // console.log(humanlist.children[i].progress); let point = humanlist.children[i].runrail.getPointAt(humanlist.children[i].progress); //更新模型坐标 humanlist.children[i].position.x = point.x; humanlist.children[i].position.y = point.y; humanlist.children[i].position.z = point.z; if((humanlist.children[i].progress+0.001)<1){ let tangent = humanlist.children[i].runrail.getPointAt(humanlist.children[i].progress+0.001); humanlist.children[i].lookAt(new THREE.Vector3(tangent.x,humanlist.children[i].position.y,tangent.z)); } humanlist.children[i].progress += humanlist.children[i].speed; point = null; } } } } function newhumancreate(position,stage,){ var mantype = Math.floor(Math.random()*(3-1+1))+1; let newhuman; if(mantype == 1){ newhuman = THREE.SkeletonUtils.clone( originhuman1 ); newhuman.animations = []; newhuman.animations.push(originanima1.clone()); }else{ newhuman = THREE.SkeletonUtils.clone( originhuman2 ); newhuman.animations = []; newhuman.animations.push(originanima2.clone()); } let mixer = new THREE.AnimationMixer( newhuman ); newhuman.position.copy(position); newhuman.status = 0; newhuman.stage = stage; newhuman.direct = null; newhuman.doorstatus = null; newhuman.doors = null; newhuman.action = mixer.clipAction( newhuman.animations[ 0 ] ); newhuman.mixer = mixer; newhuman.runrail = null; newhuman.speed = 0; mixers.push(mixer); humanlist.add(newhuman); } function initstationanimation(object){ let mixer = new THREE.AnimationMixer( object ); let newclip = object.animations[ 0 ]; for(let j=0;j