diff --git a/src/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/jl3dFaultDeviceVr.js b/src/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/jl3dFaultDeviceVr.js index 22ebd9a42..7bd1dea90 100644 --- a/src/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/jl3dFaultDeviceVr.js +++ b/src/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/jl3dFaultDeviceVr.js @@ -2,8 +2,7 @@ import { Staticmodel } from '@/jlmap3d/jl3ddevice/config.js'; import { JL3D_LOCAL_STATIC } from '@/api/jlmap3d/assets3d.js'; //loader import { FBXLoader } from '@/jlmap3d/main/loaders/FBXLoader'; -import { OBJLoader } from '@/jlmap3d/main/loaders/OBJLoader'; -import { Pathfinding } from '@/jlmap3d/jl3dpassflow/utils/Pathfinding.js'; + import { OrbitControls } from '@/jlmap3d/main/control/OrbitControls'; import { ModelManagerVR } from '@/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/utils/vrloader.js'; @@ -11,7 +10,9 @@ import { VRButton } from '@/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/utils/VRBut import { VrGui } from '@/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/utils/vrgui.js'; import { TrainControl } from '@/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/utils/trainControl.js'; import { MoveanimateVr } from '@/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/utils/moveanimatevr.js'; -import { VrVoice } from '@/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/utils/vrVoice.js'; +import { VrPathFinder } from '@/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/utils/vrPathFinder.js'; + +import { LocalVoice } from '@/jlmap3d/utils/localvoice/localVoice.js'; import { Textconfig } from '@/jlmap3d/jl3ddevice/component/textconfig.js'; import {Materialload} from '@/jlmap3d/main/loaders/Materialload.js'; @@ -35,6 +36,22 @@ let vrPlane; //vrUI面板控制状态 let vrPlaneStatus = false; +//vr导航寻路 +let navStatus = false; +let pathPoints = []; +let targetPosition = new THREE.Vector3(); +var textureNav = new THREE.TextureLoader().load( JL3D_LOCAL_STATIC+'/vrtest/daohang.png' ); +textureNav.wrapS = THREE.RepeatWrapping; +textureNav.wrapT=THREE.RepeatWrapping; +textureNav.repeat.x = 40; +textureNav.repeat.y = 2; +var materialNav = new THREE.MeshBasicMaterial( { + map: textureNav, + + transparent: true, +} ); +let pathFinderVr = new VrPathFinder(); + let tempMatrix = new THREE.Matrix4(); let nowdevice = null; @@ -58,35 +75,13 @@ let positionStatus = "dm"; //列车地板 let floors = []; //设定声音 -let voiceModel = new VrVoice(); +let voiceModel = new LocalVoice(); voiceModel.localVoiceInit(); export function jl3dFaultDeviceVr(dom,group,skinCode) { var scope = this; - const ZONE = 'level'; - const SPEED = 10; - const OFFSET = 0.2; - THREE.Pathfinding = Pathfinding; - let groupID,path,level,navmesh; - let pathPoints = []; - let playerPosition = new THREE.Vector3( -3.5, 0.5, 5.5 ); - let targetPosition = new THREE.Vector3(); - let pathFinder = new THREE.Pathfinding(); - var textureNav = new THREE.TextureLoader().load( JL3D_LOCAL_STATIC+'/vrtest/daohang.png' ); - textureNav.wrapS = THREE.RepeatWrapping; - textureNav.wrapT=THREE.RepeatWrapping; - textureNav.repeat.x = 40; - textureNav.repeat.y = 2; - var materialNav = new THREE.MeshBasicMaterial( { - map: textureNav, - - transparent: true, - } ); - let navMesh; - let navStatus = false; - let switchModel; this.dom = dom; @@ -120,8 +115,6 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { this.renderer.setClearColor(new THREE.Color(0x000000)); this.renderer.setPixelRatio( window.devicePixelRatio ); this.renderer.setSize(window.innerWidth, window.innerHeight); - // this.renderer.shadowMap.enabled = true; - // this.renderer.shadowMap.type = THREE.PCFSoftShadowMap; this.renderer.gammaInput = true; this.renderer.gammaOutput = true; this.renderer.vr.enabled = true; @@ -164,78 +157,21 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { raycastervr = new THREE.Raycaster(); - - - - - - let loaderObj = new THREE.OBJLoader(); - - // load a resource - loaderObj.load( - // resource URL - JL3D_LOCAL_STATIC+'/vrtest/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; - - // scene.add(navmesh); - // movegroup.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' ); - - } - ); - - - let moveanima = new MoveanimateVr(scope); //定义全局光 let ambientLight = new THREE.AmbientLight(0xffffff, 1.3); this.scene.add(ambientLight); + //鼠标轨道相机控制 this.controls = new THREE.OrbitControls(scope.camera, dom); - // this.controls.maxPolarAngle = Math.PI / 2; - // this.controls.minPolarangle = Math.PI / 5; this.controls.maxDistance = 600; - // this.controls.screenSpacePanning = true; this.controls.target.set( 0, 1.6, 0 ); - this.controls.update(); - + //鼠标点击事件 document.addEventListener( "mousedown", onselect, false ); - let vrwebworker = new Worker(JL3D_LOCAL_STATIC+"/workertest/vrwebworker.js"); let connectmsg = { @@ -247,7 +183,7 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { vrwebworker.postMessage(connectmsg); vrwebworker.onmessage = function (event) { - + //获取故障信息 if(event.data.type == "Device_Fault_Set_3D"){ let newfault = { code:event.data.body.code, @@ -292,11 +228,12 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { } faultList.push(newfault) - updateFaultList(); + vrPlane.updataFaultList(faultList); return; } + //在车上时 if(event.data.type == "takeTopTrain"){ for(let i=0,leni=stationList.length;i { let mapnetdata = netdata.data; @@ -533,13 +474,9 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { // switchModel.position.set(switchPos.x,switchPos.y,switchPos.z); human.position.set(switchModel.matrixWorld.elements[12],switchModel.matrixWorld.elements[13],switchModel.matrixWorld.elements[14]); - initstationanimation(scope.modelmanager.stationIn.mesh); initstationanimation(scope.modelmanager.stationOut.mesh); - - - // scope.modelmanager.otherDevice.mesh.scale.set(0.1,0.1,0.1); if(scope.nowstation.inside == true){ scope.nowStationModel = scope.modelmanager.stationOut.mesh; @@ -551,11 +488,14 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { trainControl.inittrain(scope.scene,scope.modelmanager.train.mesh,scope.modelmanager.train.animations,mixers); floors.push(trainControl.toptrain.floor); floors.push(trainControl.downtrain.floor); - floors.push(navmesh.children[0]); + let detectedVRDevices; let timer=setInterval(function(){ + if(pathFinderVr.navmesh){ + floors.push(pathFinderVr.navmesh.children[0]); + } if(scope.stationtexture["stationlist"]){ vrPlane.setStationPlane(stationList,scope.stationtexture); @@ -593,15 +533,11 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { } },1000); - - }); }); - }); - function onselect(event){ //定义光线 let raycaster = new THREE.Raycaster(); @@ -699,8 +635,8 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { } if(object.name == "nav"){ - if(navMesh){ - scope.scene.remove( navMesh ); + if(pathFinderVr.navmesh){ + scope.scene.remove( pathFinderVr.navmesh ); } if(navStatus){ navStatus = false; @@ -709,23 +645,17 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { pathPoints = []; let startPoint = new THREE.Vector3(human.position.x,human.position.y-0.6,human.position.z); pathPoints.push(new THREE.Vector3(human.position.x,human.position.y,human.position.z)); - groupID = pathFinder.getGroup( ZONE, startPoint ); targetPosition = new THREE.Vector3(switchModel.matrixWorld.elements[12],-5.596,switchModel.matrixWorld.elements[14]); - // - // console.log(pathPoints[0]); - // console.log(targetPosition); - // console.log(ZONE); - // console.log(groupID); - let path = pathFinder.findPath( startPoint, targetPosition, ZONE, groupID ); + let path = pathFinderVr.find(startPoint,targetPosition); if(path){ for(let i=0;i 0){ + if(positionStatus == "dm"){ + if(vrPlaneStatus){ + var intersection = clickGui[ 0 ]; + var object = intersection.object; + if(object.name == "buttonHome"){ + vrPlane.homeButtonClick(); + } - if(vrPlaneStatus){ - var intersection = clickGui[ 0 ]; - var object = intersection.object; + if(object.name == "buttonStationList"){ + vrPlane.stationListButtonClick(); + } - if(object.name == "buttonHome"){ - vrPlane.homeButtonClick(); - } + if(object.name == "buttonFaultList"){ + vrPlane.faultListButtonClick(); + } - if(object.name == "buttonStationList"){ - vrPlane.stationListButtonClick(); - } - - if(object.name == "buttonFaultList"){ - vrPlane.faultListButtonClick(); - } - - // if(object.name == "buttonPrevious"){ - // vrPlane.previousButtonClick(); - // } - // - // if(object.name == "buttonNext"){ - // vrPlane.nextButtonClick(); - // } - if(object.name == "stationList"){ - for(let i=0,leni=stationList.length;i { + resolve(response); + if(response.code == 200){ + + nowdevice = null; + } + }).catch(error => { + }); } + } } - - if(object.name == "faultList"){ - for(let i=0,leni=faultList.length;i { - resolve(response); - if(response.code == 200){ - - nowdevice = null; - } - }).catch(error => { - }); - } - - } } - - - }else{ var intersections = getIntersections( controller ); // console.log(intersections); @@ -929,15 +852,15 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { if(positionStatus != intersection.object.name){ positionStatus = intersection.object.name; - if(intersection.object.name == "dm"){ + if(positionStatus == "dm"){ scope.scene.add(human); vrwebworker.postMessage("takeStation"); } - if(intersection.object.name == "topfloor"){ + if(positionStatus == "topfloor"){ trainControl.toptrain.add(human); vrwebworker.postMessage("takeTopTrain"); } - if(intersection.object.name == "downfloor"){ + if(positionStatus == "downfloor"){ trainControl.downtrain.add(human); vrwebworker.postMessage("takeDownTrain"); } @@ -972,81 +895,73 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { }; vrwebworker.postMessage(postData); - // var object = intersection.object; - // // object.matrix.premultiply( tempMatrix ); - // // object.matrix.decompose( object.position, object.quaternion, object.scale ); - // // object.material.emissive.b = 1; - // // controller.add( object ); - // - // // controller.userData.selected = object; - // // console.log(object.matrixWorld.elements); - // human.position.set( intersection.point.x, intersection.point.y+0.6, intersection.point.z ); - } } } - function onSelectEnd( event ) { - var controller = event.target; - if ( controller.userData.selected !== undefined ) { - // var object = controller.userData.selected; - // object.matrix.premultiply( controller.matrixWorld ); - // object.matrix.decompose( object.position, object.quaternion, object.scale ); - // object.material.emissive.b = 0; - // group.add( object ); - controller.userData.selected = undefined; - } - } + function onSelectEnd( event ) { + var controller = event.target; + if ( controller.userData.selected !== undefined ) { + // var object = controller.userData.selected; + // object.matrix.premultiply( controller.matrixWorld ); + // object.matrix.decompose( object.position, object.quaternion, object.scale ); + // object.material.emissive.b = 0; + // group.add( object ); + controller.userData.selected = undefined; + } + } - function onControlModelStart( event ) { - // var controller = event.target; - // var intersections = getIntersections( controller ); - // if ( intersections.length > 0 ) { - // - // // for(){} - // // console.log(intersections); - // var intersection = intersections[ 0 ]; - // // console.log(intersection); - // // tempMatrix.getInverse( controller.matrixWorld ); - // // - // // var object = intersection.object; - // // object.matrix.premultiply( tempMatrix ); - // // object.matrix.decompose( object.position, object.quaternion, object.scale ); - // // object.material.emissive.b = 1; - // // controller.add( object ); - // - // } + function onControlModelStart( event ) { + // var controller = event.target; + // var intersections = getIntersections( controller ); + // if ( intersections.length > 0 ) { + // + // // for(){} + // // console.log(intersections); + // var intersection = intersections[ 0 ]; + // // console.log(intersection); + // // tempMatrix.getInverse( controller.matrixWorld ); + // // + // // var object = intersection.object; + // // object.matrix.premultiply( tempMatrix ); + // // object.matrix.decompose( object.position, object.quaternion, object.scale ); + // // object.material.emissive.b = 1; + // // controller.add( object ); + // + // } - } + } - - function onControlModelEnd( event ) { - var controller = event.target; - if ( controller.userData.selected !== undefined ) { - // var object = controller.userData.selected; - // object.matrix.premultiply( controller.matrixWorld ); - // object.matrix.decompose( object.position, object.quaternion, object.scale ); - // // object.material.emissive.b = 0; - // group.add( object ); - // controller.userData.selected = undefined; - } - } + function onControlModelEnd( event ) { + var controller = event.target; + if ( controller.userData.selected !== undefined ) { + // var object = controller.userData.selected; + // object.matrix.premultiply( controller.matrixWorld ); + // object.matrix.decompose( object.position, object.quaternion, object.scale ); + // // object.material.emissive.b = 0; + // group.add( object ); + // controller.userData.selected = undefined; + } + } function squeezeStart(){ scope.modelmanager.otherDevice.action.play(); - if(vrPlaneStatus){ - vrPlaneStatus = false; - - // vrPlane.group.position.copy(circle.position); - vrPlane.group.position.set(10000,10000,10000); - scope.scene.remove( vrPlane.group ); + if(positionStatus == "dm"){ + if(vrPlaneStatus){ + vrPlaneStatus = false; + // vrPlane.group.position.copy(circle.position); + vrPlane.group.position.set(10000,10000,10000); + scope.scene.remove( vrPlane.group ); + }else{ + vrPlaneStatus = true; + vrPlane.group.position.copy(circle.position); + vrPlane.group.lookAt(human.position); + scope.scene.add( vrPlane.group ); + } }else{ - vrPlaneStatus = true; - vrPlane.group.position.copy(circle.position); - vrPlane.group.lookAt(human.position); - scope.scene.add( vrPlane.group ); } + } this.animationmsgshowon = function(nowobject){ @@ -1138,7 +1053,6 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { } ); - function intersectObjects( controller ) { var intersections = getIntersections( controller ); @@ -1155,7 +1069,6 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { function animate() { - scope.renderer.setAnimationLoop( render ); } @@ -1166,7 +1079,7 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { let delta = clock.getDelta(); if (mixers) { for (let i = 0; i < mixers.length; i++) { - if (mixers[i]) { + if (mixers[i]._actions[0].isRunning()) { mixers[i].update(delta); } } @@ -1182,7 +1095,6 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { }; this.updateaction = function (data) { - console.log(data); if (data.type == "SWITCH") { if (data.normal == "0") { scope.modelmanager.otherDevice.normalPosition = "0"; @@ -1197,12 +1109,9 @@ export function jl3dFaultDeviceVr(dom,group,skinCode) { scope.modelmanager.otherDevice.action.timeScale = -1; scope.modelmanager.otherDevice.action.play(); } - } - } - function getdevicemsg(selectname){ // console.log(selectname); for(let i=0,leni=scope.devicetext.devicelist.length;i