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'; import { ZoneManager } from '@/jlmap3d/jl3dpassflow/model/zonemanager.js'; import {Materialload} from '@/jlmap3d/main/loaders/Materialload.js'; import { getPublishMapVersion, getPublishMapDetail,getPublish3dMapDetail} from '@/api/jlmap3d/load3ddata'; import { PassflowConnect } from '@/jlmap3d/jl3dpassflow/connect/passflowconnect.js'; import StompClient from '@/utils/sock'; import store from '@/store/index_APP_TARGET'; // import { Loading } from 'element-ui'; let clock = new THREE.Clock(); let delta; let scene,camerass,renderer; let rendermode = 0; let aiswitch = 0; let mixers = []; let testmesh1,testmesh2; let humans = []; let checkdoor1 = []; let checkdoor2 = []; let station; let zhajiinmodel; let zhajioutmodel; let monitor; let ids = 0; let humanlist = new THREE.Group(); let originhuman1 = null; let originhuman2 = null; let originanima1 = null; let originanima2 = null; let toptrain = null; let downtrain = 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(); //老版本临时ai控制 let olddataai = false; 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); } let windowWidth = window.innerWidth ; let windowHeight = window.innerHeight; let views4 = [ { left: 0, bottom: 0, width: 0.24, 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.25, bottom: 0, width: 0.24, 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.24, 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.75, bottom: 0, width: 0.24, height: 0.5, background: new THREE.Color( 0.5, 0.7, 0.7 ), eye: [ -7,17,2], up: [-7, 10, 8], fov: 60 } ]; let views2 = [ { 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: 60 }, { 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: 60 }, ]; export function Jl3dpassflow(dom,skinCode,routegroup,viewMap) { let scope = this; initView(viewMap); this.dom = dom; this.nowcode = null; this.animateswitch = false; this.signallights = []; this.mixers = []; this.showmodel = null; //替换材质组(站台的) this.stationtexture = []; //初始化webgl渲染 renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setClearColor(new THREE.Color(0x000000)); renderer.setSize(dom.offsetWidth, dom.offsetHeight); windowWidth = dom.offsetWidth ; windowHeight = 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 ( let ii = 0; ii < views4.length; ++ ii ) { let view = views4[ ii ]; let 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; } for ( let ii = 0; ii < views2.length; ++ ii ) { let view = views2[ ii ]; let 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); let 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); let 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); // // let 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(); //上车控制开关 let toppasserin = false; let downpasserin = false; //下车控制开关 let toppasseron = false; let downpasseron = false; let loader = new THREE.OBJLoader(); // load a resource loader.load( // resource URL '../../static/jl3d/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 { this.modelmanager.loadpromise(JSON.parse(netdata3d.data.assets).cctvAssetList, scope.mixers).then(function (data) { // console.log(scope.modelmanager); initstationanimation(scope.modelmanager.station.mesh); initzhajiinaimation(scope.modelmanager.zhajiin.mesh); initzhajioutanimation(scope.modelmanager.zhajiout.mesh); inittrain(scope.modelmanager.train.mesh); scene.add(scope.modelmanager.section.mesh); // scene.add(scope.modelmanager.train.mesh); level = scope.modelmanager.station.mesh; monitor = scope.modelmanager.monitor.mesh; scene.add(monitor); Materialload(scope,JSON.parse(netdata3d.data.assets).stationTextureList[0]); getPublishMapDetail(skinCode).then(netdata => { scope.switchviews(4); inithumans(); initstationlist(netdata.data.stationList,netdata.data.stationStandList,netdata.data.psdList); socktest = new PassflowConnect(scope,deviceaction,toptrain,downtrain,routegroup); }); // loadingInstance.close(); store.dispatch('app/animationsClose'); animate(); }) }); function initView(viewMap){ if(viewMap == "normal"){ views4 = [ { 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 } ]; views2 = [ { left: 0, bottom: 0, width: 0.5, height: 1, background: new THREE.Color( 0.5, 0.5, 0.7 ), eye: [ 3.7, 16, 26 ], up: [3.7, 10 ,16 ], fov: 60 }, { left: 0.5, bottom: 0, width: 0.5, height: 1, background: new THREE.Color( 0.7, 0.5, 0.5 ), eye: [ -60, 6,11], up: [ -59, 5.9,11 ], fov: 60 }, ]; }else{ views4 = [ { left: 0, bottom: 0, width: 0.24, 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.25, bottom: 0, width: 0.24, 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.24, 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.75, bottom: 0, width: 0.24, height: 0.5, background: new THREE.Color( 0.5, 0.7, 0.7 ), eye: [ -7,17,2], up: [-7, 10, 8], fov: 60 } ]; views2 = [ { 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: 60 }, { 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: 60 }, ]; } } function inithumans(){ originhuman1 = scope.modelmanager.man1.mesh; originhuman1.progress = 1; // scene.add(originhuman1); originhuman2 = scope.modelmanager.man2.mesh; let mixer1 = new THREE.AnimationMixer( originhuman1 ); let mixer2 = new THREE.AnimationMixer( originhuman2 ); originanima1 = originhuman1.animations[ 0 ]; originanima2 = originhuman2.animations[ 0 ]; originhuman1.remove(originhuman1.children[2]); scene.add(humanlist); // scene.add(scope.modelmanager.man1.mesh); } let checkobject = setInterval(function(){ // console.log(originhuman1); if(originhuman1){ clearInterval(checkobject); //进站控制 startWorker(); stationwebwork.postMessage("on"); passerwebwork.postMessage("on"); }; },1000); this.changestation = function(stationname){ for(let i=0,leni=stationlist.length;i=0;an--){ toptrain.action.top[an].reset(); toptrain.action.top[an].time = toptrain.action.top[an]._clip.duration; toptrain.action.top[an].timeScale = -1; toptrain.action.top[an].play(); } for(let an=toptrain.action.down.length-1;an>=0;an--){ toptrain.action.down[an].reset(); toptrain.action.down[an].time = toptrain.action.down[an]._clip.duration; toptrain.action.down[an].timeScale = -1; toptrain.action.down[an].play(); } // for(let an=actions.length-1;an>=0;an--){ // actions[an].reset(); // actions[an].time = actions[an]._clip.duration; // actions[an].timeScale = -1; // actions[an].play(); // } setTimeout(function(){ initpasser(); aiswitch = 0; }, 2000); } this.uncache = function(uncachemodel){ if(uncachemodel){ uncachemodel.mixer.uncacheAction(); uncachemodel.traverse( function ( child ) { if ( child.isMesh ) { child.geometry.dispose(); child.material.dispose(); } } ); } } this.passerout = function(direct){ // console.log(direct); if(direct == "top"){ // console.log("toppasser"); // console.log(stationzon.list["standtop"]); toppasseron = true; setTimeout(function(){ toppasseron = false toppasserin = true; setTimeout(function(){ toppasserin = false; }, 20000); }, 5000); } if(direct == "down"){ // console.log("downpasser"); // console.log(stationzon.list["standdown"]); downpasseron = true; setTimeout(function(){ downpasseron = false; downpasserin = true; setTimeout(function(){ downpasserin = false; }, 20000); }, 5000); } } this.switchviews = function(viewmode){ if(viewmode == 4){ rendermode = 4; } if(viewmode == 2){ rendermode = 2; } if(viewmode == 1){ rendermode = 1; } if(viewmode == "auto"){ rendermode = 0; renderer.setViewport( 0, 0, scope.dom.offsetWidth, scope.dom.offsetHeight ); renderer.setScissor( 0, 0, scope.dom.offsetWidth, scope.dom.offsetHeight ); renderer.setScissorTest( false ); renderer.setSize(scope.dom.offsetWidth, scope.dom.offsetHeight); camerass.aspect = dom.offsetWidth / dom.offsetHeight; camerass.updateProjectionMatrix(); } } function initpasser(){ for(let i=0;i<3;i++){ newhumancreate(stationzon.getinitposition("enter1"),0); } for(let i=0;i<3;i++){ newhumancreate(stationzon.getinitposition("enter2"),0); } for(let i=0;i<3;i++){ newhumancreate(stationzon.getinitposition("security"),1); } // for(let i=0;i<2;i++){ // // newhumancreate(stationzon.getinitposition("entergate"),3); // } for(let i=0;i<6;i++){ let standdata = stationzon.getstandposition("standtop"); newhumancreate(standdata.point,4,"top",standdata.door); } for(let i=0;i<6;i++){ let standdata = stationzon.getstandposition("standdown"); newhumancreate(standdata.point,4,"down",standdata.door); } // for(let i=0;i<5;i++){ // // newhumancreate(stationzon.getinitposition("exitgate"),6); // } } function startWorker(){ initpasser(); passerwebwork.onmessage = function (event) { if(aiswitch == 0){ moveanimateupdate(); passerai(); delta = clock.getDelta(); // tick(delta); for(let i=mixers.length-1;i>=0;i--){ if(mixers[i]._actions[0].isRunning()){ mixers[i].update( delta ); } } for(let i=humanlist.children.length-1;i>=0;i--){ if(humanlist.children[i].mixer._actions[0].isRunning()){ humanlist.children[i].mixer.update( delta ); } } } }; stationwebwork.onmessage = function (event) { if(aiswitch == 0){ // console.log(humanlist.children.length); if(humanlist.children.length < 80){ let 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); } if(toppasseron){ for(let i=0,leni=stationzon.list["standtop"].doorpoints.length;i=1){ //更新模型坐标 if(humanlist.children[i].status == 1){ humanlist.children[i].progress = 1; humanlist.children[i].action.stop(); humanlist.children[i].status = 0; if(humanlist.children[i].stage == 8){ scope.uncache(humanlist.children[i]); humanlist.remove(humanlist.children[i]); i--; }else if(humanlist.children[i].stage == 7){ humanlist.children[i].stage = 8; } // else if(humanlist.children[i].stage == 6){ // // humanlist.children[i].stage = 7; // // } else if(humanlist.children[i].stage == 5){ humanlist.children[i].stage = 7; }else if(humanlist.children[i].stage == 4){ scope.uncache(humanlist.children[i]); humanlist.remove(humanlist.children[i]); i--; }else if(humanlist.children[i].stage == 3){ humanlist.children[i].stage = 4; if(olddataai){ humanlist.children[i].stage = 5; } }else if(humanlist.children[i].stage == 2){ humanlist.children[i].stage = 3; }else if(humanlist.children[i].stage == 1){ humanlist.children[i].stage = 2; }else 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,direct,door){ let 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; if(direct){ if(direct == "top"){ newhuman.rotation.y = Math.PI; } newhuman.direct = direct; }else{ newhuman.direct = null; } newhuman.doorstatus = null; if(door){ newhuman.door = door; }else{ newhuman.door = null; } newhuman.action = mixer.clipAction( newhuman.animations[ 0 ] ); newhuman.mixer = mixer; newhuman.runrail = null; newhuman.speed = 0; newhuman.mixer = mixer; humanlist.add(newhuman); // console.log(humanlist.children.length); } function initstationlist(stationdata,standdata,psddata){ let list = []; if(psddata){ for(let i=0,leni = standdata.length;i0){ let stationobject = { code : list[k][0].stationCode, name : k, toppsd:null, downpsd:null, topsection:null, downsection:null, }; if(list[k][0].position.y