From 96ffe64eb65ed19eb94aa3289e6c148cfbe4297d Mon Sep 17 00:00:00 2001 From: sunzhenyu Date: Tue, 13 Oct 2020 18:11:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=89=E7=BB=B4vr=E9=80=9A?= =?UTF-8?q?=E5=8F=B7=E4=B8=8A=E4=B8=8B=E8=BD=A6=E5=88=87=E6=8D=A2=E7=AB=99?= =?UTF-8?q?=E5=8F=B0bug=EF=BC=8C=E5=88=86=E7=A6=BB=E4=B8=89=E7=BB=B4vr?= =?UTF-8?q?=E9=80=9A=E5=8F=B7=E4=B8=AD=E5=86=97=E6=9D=82=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86vr=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jl3dFaultDeviceVr/jl3dFaultDeviceVr.js | 658 +++++++----------- .../jl3dFaultDeviceVr/utils/vrPathFinder.js | 68 ++ .../jl3dFaultDeviceVr/utils/vrText.js | 63 ++ .../jl3dTrainRescue/jl3dTrainRescueVr.js | 2 +- src/jlmap3d/jl3dpassflow/jl3dpassflownew.js | 2 +- .../localvoice/localVoice.js} | 4 +- .../utils => utils/pathfinder}/AStar.js | 0 .../utils => utils/pathfinder}/BinaryHeap.js | 0 .../utils => utils/pathfinder}/Builder.js | 0 .../utils => utils/pathfinder}/Channel.js | 0 .../utils => utils/pathfinder}/Pathfinding.js | 0 .../pathfinder}/PathfindingHelper.js | 0 .../utils => utils/pathfinder}/Utils.js | 0 .../utils => utils/pathfinder}/index.js | 0 static/workertest/vrwebworker.js | 25 +- 15 files changed, 401 insertions(+), 421 deletions(-) create mode 100644 src/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/utils/vrPathFinder.js create mode 100644 src/jlmap3d/jl3dmaintainer/jl3dFaultDeviceVr/utils/vrText.js rename src/jlmap3d/{jl3dmaintainer/jl3dFaultDeviceVr/utils/vrVoice.js => utils/localvoice/localVoice.js} (91%) rename src/jlmap3d/{jl3dpassflow/utils => utils/pathfinder}/AStar.js (100%) rename src/jlmap3d/{jl3dpassflow/utils => utils/pathfinder}/BinaryHeap.js (100%) rename src/jlmap3d/{jl3dpassflow/utils => utils/pathfinder}/Builder.js (100%) rename src/jlmap3d/{jl3dpassflow/utils => utils/pathfinder}/Channel.js (100%) rename src/jlmap3d/{jl3dpassflow/utils => utils/pathfinder}/Pathfinding.js (100%) rename src/jlmap3d/{jl3dpassflow/utils => utils/pathfinder}/PathfindingHelper.js (100%) rename src/jlmap3d/{jl3dpassflow/utils => utils/pathfinder}/Utils.js (100%) rename src/jlmap3d/{jl3dpassflow/utils => utils/pathfinder}/index.js (100%) 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