修改沙盘行车逻辑,增加站台模型,修改webworker通信,优化通信判断

This commit is contained in:
sunzhenyu 2019-12-03 13:48:15 +08:00
parent adbb7c3d8d
commit 6f081ca234
34 changed files with 8109 additions and 1074 deletions

View File

@ -1,5 +1,5 @@
export function SetCamera(dom) {
var camera = new THREE.PerspectiveCamera(60, dom.clientWidth/dom.clientHeight, 1, 1500);
var camera = new THREE.PerspectiveCamera(60, dom.clientWidth/dom.clientHeight, 1, 5000);
camera.position.set( 0, 0, 0 );
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

View File

@ -157,7 +157,7 @@ export function JLmapDriving(dom,data,mapId,storemod,translation,routegroup) {
// console.log(spotLight);
// controls3.getObject().add( spotLight );
// 订阅仿真socket
this.Subscribe = new Jl3dDriving(updatemmi,sound,translation,routegroup);
this.Subscribe = new Jl3dDriving(mixers,updatemmi,sound,translation,routegroup);
this.Subscribe.socketon(scope.Subscribe.topic);
var timer = setInterval(function() {
@ -222,15 +222,10 @@ export function JLmapDriving(dom,data,mapId,storemod,translation,routegroup) {
//cctv渲染
if(scope.cctvswitch == true){
renderercctv.render(scene,cameracctv);
}
//相机按键位移
// controls3.update();
delta = clock.getDelta();
for (let i=mixers.length-1; i>=0; i--) {
mixers[i].update( delta );
}
// stats.update();
}
@ -254,7 +249,13 @@ export function JLmapDriving(dom,data,mapId,storemod,translation,routegroup) {
scope.webwork.onmessage = function (event) {
// 更新列车位置
UpdateTrain(camera, trainlisttest);
delta = clock.getDelta();
for (let i=mixers.length-1; i>=0; i--) {
mixers[i].update( delta );
}
if(scope.cctvswitch == true){
renderercctv.render(scene,cameracctv);
}
};
}

View File

@ -7,7 +7,7 @@ import { getToken } from '@/utils/auth';
import router from '@/router';
// 定于仿真socket接口
export function Jl3dDriving(updatemmi,sound,translation,routegroup) {
export function Jl3dDriving(mixers,updatemmi,sound,translation,routegroup) {
let scope = this;
this.map = null;
@ -35,7 +35,6 @@ export function Jl3dDriving(updatemmi,sound,translation,routegroup) {
let stoptimer = null;
let num = 30;
let pointstand = null;
let nextpoints = null;
// run as plane = 01;
// reset = 02;
var datatype = '00';
@ -101,9 +100,6 @@ export function Jl3dDriving(updatemmi,sound,translation,routegroup) {
//
// }
// console.log("recive");
// console.log(data.type);
// console.log(data.body);
switch (data.type) {
case 'Simulation_Driver_Change':
trainlisttest.group.remove(trainlisttest.list[drivingcode]);
@ -191,7 +187,6 @@ export function Jl3dDriving(updatemmi,sound,translation,routegroup) {
// if(sound.volswitch == true){
// sound.setVolume( data.body[tl].v/100 );
// }
if (data.body[tl].atpv) {
updatemmi.updateatpspeed(data.body[tl].atpv);
} else {
@ -341,14 +336,19 @@ export function Jl3dDriving(updatemmi,sound,translation,routegroup) {
drivingcode = code;
updatemmi.updatedrivingcode(drivingcode);
}
// trainlisttest.group.add(trainlisttest.list[code]);
if(trainlisttest.list[code].mixerpush == false){
for(let mi=0,lenmi=trainlisttest.list[code].mixer.length;mi<lenmi;mi++){
mixers.push(trainlisttest.list[code].mixer[mi]);
}
trainlisttest.list[code].mixerpush = true;
}
trainlisttest.group.add(trainlisttest.list[code]);
trainlisttest.list[code].position.y = 0;
trainlisttest.list[code].progress = 0;
// trainlisttest.list[code].oldoffset = data.body[i].sectionOffsetPercent;
trainlisttest.list[code].dispose = false;
trainlisttest.list[code].nowcode = data.body[i].linkCode;
let vexlist = [];
let endrotation = null;
trainlisttest.list[code].pc = 1;
// console.log(data.body[i]);
if (data.body[i].directionType == '02') { // 向右
@ -543,7 +543,6 @@ export function Jl3dDriving(updatemmi,sound,translation,routegroup) {
nextcode = rails.linkrail[data.body[i].linkCode].rconnect;
if(nextcode){
// console.log(rails.linkrail[nextcode].lineleft.points);
nextpoints = rails.linkrail[nextcode].lineleft.points;
trainlisttest.list[code].nextcurve = rails.linkrail[nextcode].lineleft;
trainlisttest.list[code].nextlen = rails.linkrail[nextcode].lengthfact;
}else{

View File

@ -1,13 +1,12 @@
import StompClient from '@/utils/sock';
import { getTrainingCbtcDemon, runDiagramStart, runDiagramOver, setTrainingCbtcInitTime } from '@/api/simulation';
import { creatSubscribe, clearSubscribe, displayTopic, screenTopic } from '@/utils/stomp';
// import { getTrainingCbtcDemon, runDiagramStart, runDiagramOver, setTrainingCbtcInitTime } from '@/api/simulation';
// import { creatSubscribe, clearSubscribe, displayTopic, screenTopic } from '@/utils/stomp';
import { getBaseUrl } from '@/utils/baseUrl'
import { getToken } from '@/utils/auth';
import router from '@/router';
// 定于仿真socket接口
export function Jlmap3dSubscribe(jlmap3d,routegroup) {
export function Jlmap3dSubscribe(jlmap3d,routegroup,jsonwebwork) {
const scope = this;
this.map = null;
@ -32,38 +31,113 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
let driverswitch = false;
const stoptimer = null;
const num = 30;
const pointstand = null;
let stoptimer = null;
let num = 30;
let pointstand = null;
let data = null;
// run as plane = 01;
// reset = 02;
var datatype = '00';
this.teststomp = new StompClient();
this.topic = '/user/queue/simulation/jl3d/'+routegroup;
const header = {'X-Token': getToken() };
let header = {'X-Token': getToken() };
let connectmsg = {
type:'init',
baseurl:getBaseUrl(),
topic:this.topic,
token:getToken(),
};
jsonwebwork.postMessage(connectmsg);
jsonwebwork.onmessage = function (event) {
this.updatamap = function(mapdata, materiallist, nowaction, scene) {
// if(event.data.type == 'Simulation_Driver_Change'){
// drivingcode = event.data.body.code;
// jlmap3d.updatedrivingcode( event.data.body.code);
// }
// if(data.type == 'Simulation_TrainSpeed'){
// trainspeed(data);
// }
// console.log(event);
// if(event.data.type == 'SJL3D_TrainStatus'){
// trainstatus(event.data);
// }
// if(event.data.type == 'Simulation_DeviceStatus'){
// devicestatus(event.data);
// }
if(event.data._type == 'Simulation_Driver_Change'){
drivingcode = event.data.body.code;
jlmap3d.updatedrivingcode( event.data.body.code);
}
if(event.data._type == 'Train'){
// console.log(event.data);
trainstatus(event.data);
}
if (event.data._type== 'Signal' && signallist) {
// console.log(event.data);
signalupdate(event.data);
}
if (event.data._type== 'StationStand' && actions) {
// console.log(event.data);
standupdate(event.data);
}
if (event.data._type == 'Switch' && sectionlist) {
// console.log(event.data);
switchupdate(event.data);
}
// if(event.data._type = ''){
// trainstatus(event.data);
// }
// if(event.data.type == 'Simulation_DeviceStatus'){
// devicestatus(event.data);
// }
if(event.data.type == 'Simulation_Reset'){
simulationreset(event.data);
}
};
// jsonwebwork.onmessage = function (event) {
// console.log(event.data);
// if(event.data.type == 'Simulation_Driver_Change'){
// drivingcode = event.data.body.code;
// jlmap3d.updatedrivingcode( event.data.body.code);
// }
// // if(event.data.type == 'Simulation_TrainSpeed'){
// // trainspeed(event.data);
// // }
// if(event.data.type == 'SJL3D_TrainStatus'){
// trainstatus(event.data);
// }
// if(event.data.type == 'Simulation_DeviceStatus'){
// devicestatus(event.data);
// }
// if(event.data.type == 'Simulation_Reset'){
// simulationreset(event.data);
// }
// };
this.updatamap = function(newsectionlist,newlinklist,newsignallist,newstationstandlist,newtrainlisttest,newrealsectionlist,newrails, materiallist, nowaction, scene) {
// console.log(mapdata);
scope.map = mapdata;
trainlisttest = this.map.trainlisttest;
sectionlist = this.map.sectionlist;
signallist = this.map.signallist;
stationstandlist = this.map.stationstandlist;
sectionlist = this.map.sectionlist;
trainlisttest = newtrainlisttest;
sectionlist = newsectionlist;
signallist = newsignallist;
stationstandlist = newstationstandlist;
materials = materiallist;
scenes = scene;
actions = nowaction;
links = this.map.linklist;
rails = this.map.rails;
links = newlinklist;
rails = newrails;
};
this.socketon = function(topic) {
try {
// console.log("teststomp");
scope.teststomp.subscribe(topic, callback, header);
// scope.teststomp.subscribe(topic, callback, header);
} catch (error) {
console.error('websocket订阅失败');
}
@ -90,8 +164,31 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
// 仿真socket接口回调函数
function callback(Response) {
// 对象化数据
const data = JSON.parse(Response.body);
// jsonwebwork.postMessage(Response.body);
// // 对象化数据
// console.log(Response.body);
// data = JSON.parse(Response.body);
// // console.log(data);
// if(data.type == 'Simulation_Driver_Change'){
// drivingcode = data.body.code;
// jlmap3d.updatedrivingcode( data.body.code);
// }
// // if(data.type == 'Simulation_TrainSpeed'){
// // trainspeed(data);
// // }
// if(data.type == 'SJL3D_TrainStatus'){
// trainstatus(data);
// }
// if(data.type == 'Simulation_DeviceStatus'){
// devicestatus(data);
// }
// if(data.type == 'Simulation_Reset'){
// simulationreset(data);
// }
// data = null;
// console.log(data.type);
// 遍历后台数据
// 判断消息类型
@ -100,124 +197,70 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
//
// }
if (data.type == 'Simulation_Driver_Change') {
drivingcode = data.body.code;
jlmap3d.updatedrivingcode( data.body.code);
// switch (data.type) {
// case 'Simulation_Driver_Change':
// drivingcode = data.body.code;
// jlmap3d.updatedrivingcode( data.body.code);
// break;
// case 'Simulation_TrainSpeed':
// trainspeed(data);
// break;
// case 'SJL3D_TrainStatus':
// trainstatus(data);
// break;
// case 'Simulation_DeviceStatus':
// devicestatus(data);
// break;
// case 'Simulation_Reset':
// simulationreset(data);
// default :
// //TODO
// }
}
if (data.type == 'Simulation_TrainSpeed') {
function trainspeed(data){
if (trainlisttest) {
for (let tl = 0; tl<data.body.length; tl++) {
code = data.body[tl].id;
if(trainlisttest.list[code].speed != data.body[tl].v){
trainlisttest.list[code].speed = data.body[tl].v;
if (trainlisttest.list[code].runMode == '02') {
if (trainlisttest.list[code].isStandTrack == true) {
trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
} else {
trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
}
} else {
trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
// if (trainlisttest.list[code].runMode == '02') {
// if (trainlisttest.list[code].isStandTrack == true) {
// trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
// } else {
// trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
// }
// } else {
//
// trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
// }
}
if (code == drivingcode) {
jlmap3d.updatenowspeed(data.body[tl].v);
if (data.body[tl].atpv) {
jlmap3d.updateatpspeed(data.body[tl].atpv);
} else {
jlmap3d.updateatpspeed(-1);
}
if (data.body[tl].atov) {
jlmap3d.updateatospeed(data.body[tl].atov);
} else {
jlmap3d.updateatospeed(-1);
}
}
}
}
}
if (data.type == 'SJL3D_TrainStatus') {
for (let i=data.body.length-1; i>=0; i--) {
if (data.body[i]._type == 'Train') {
function trainstatus(data){
// for (let i=data.body.length-1; i>=0; i--) {
// console.log(data.body[i]);
// console.log(data.body[i]);
// 遍历列车对象组
if (trainlisttest) {
code = data.body[i].code;
code = data.code;
// 剔除不显示的车
// 找到对应列车
if ( trainlisttest.list[code]) {
if (code == drivingcode) {
driverswitch = data.body[i].runMode;
//更新车组号
jlmap3d.updatetrainnum(data.body[i].groupNumber);
//更新列车
let syncdata = {
type: 'Train',
code: code,
sectionCode: data.body[i].sectionCode,
percent: 0
};
// if (trainlisttest.list[code].isStandTrack == true && trainlisttest.list[code].progress>0.95 && trainlisttest.list[code].speed<=0) {
// if (data.body[i].directionType == '02') {
// syncdata.percent = 1-(sectionlist.sections.datalist[data.body[i].sectionCode].rstop/trainlisttest.list[code].len);
// } else {
// syncdata.percent = sectionlist.sections.datalist[data.body[i].sectionCode].lstop/trainlisttest.list[code].len;
// }
// scope.teststomp.send('/app/topic/simulation/client/drive', syncdata);
// } else {
// if (data.body[i].directionType == '02') {
// syncdata.percent = trainlisttest.list[code].progress;
// } else {
// syncdata.percent = 1 - trainlisttest.list[code].progress;
// }
// scope.teststomp.send('/app/topic/simulation/client/drive', syncdata);
// }
if (data.body[i].parkRemainTime>0) {
jlmap3d.updatestoptime('停站时间:'+parseInt(data.body[i].parkRemainTime));
} else {
if (data.body[i].runMode == '02') {
jlmap3d.updatestoptime('列车自动驾驶中');
} else {
// if (trainlisttest.list[code].isStandTrack == true && trainlisttest.list[code].progress>0.95 && trainlisttest.list[code].speed<=0) {
// // if(stoptimer){
// //
// // }else{
// // stoptimer = setInterval(function(){
// // if(num >=0){
// // jlmap3d.updatestoptime("停站时间:"+num);
// // num --;
// // }
// // },1000);
// // }
//
// } else {
// jlmap3d.updatestoptime('列车人工驾驶中');
// }
}
}
// if(trainlisttest.list[code].speed > 0){
// if(stoptimer){
// clearInterval( stoptimer );
// stoptimer = null;
// num = 30;
// }
// }
}
trainlisttest.list[code].runMode = data.body[i].runMode;
trainlisttest.list[code].runMode = data.runMode;
// 车门开关验证
// if(data.body[i].directionType == "02"){
if (trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == '01') {
// if(data.directionType == "02"){
if (trainlisttest.list[code].doorStatus != data.doorStatus && data.doorStatus == '01') {
// console.log("close");
trainlisttest.list[code].doorStatus = '01';
for (let an=actions[code].top.length-1; an>=0; an--) {
@ -226,7 +269,7 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
actions[code].top[an].timeScale = -1;
actions[code].top[an].play();
}
} else if (trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == '02') {
} else if (trainlisttest.list[code].doorStatus != data.doorStatus && data.doorStatus == '02') {
// console.log("open");
trainlisttest.list[code].doorStatus = '02';
for (let an=actions[code].top.length-1; an>=0; an--) {
@ -237,7 +280,7 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
}
}
// }else{
// if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "01"){
// if(trainlisttest.list[code].doorStatus != data.doorStatus && data.doorStatus == "01"){
// //console.log("close");
// trainlisttest.list[code].doorStatus = "01";
// for(let an=actions[code].down.length-1;an>=0;an--){
@ -246,7 +289,7 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
// actions[code].down[an].timeScale = -1;
// actions[code].down[an].play();
// }
// }else if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "02"){
// }else if(trainlisttest.list[code].doorStatus != data.doorStatus && data.doorStatus == "02"){
// //console.log("open");
// trainlisttest.list[code].doorStatus = "02";
// for(let an=actions[code].down.length-1;an>=0;an--){
@ -258,20 +301,42 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
// }
// }
// 遍历获取所在轨道
if (trainlisttest.list[code].dispose != data.body[i].dispose && data.body[i].dispose == false) {
if (trainlisttest.list[code].dispose != data.dispose && data.dispose == false) {
if (rails.linkrail[data.body[i].linkCode]) {
if (rails.linkrail[data.linkCode]) {
trainlisttest.group.add(trainlisttest.list[code]);
trainlisttest.list[code].position.y = 0;
trainlisttest.list[code].progress = 0;
trainlisttest.list[code].oldoffset = data.body[i].linkOffsetPercent;
// trainlisttest.list[code].progress = 0;
trainlisttest.list[code].dispose = false;
trainlisttest.list[code].nowcode = data.body[i].linkCode;
trainlisttest.list[code].nextcode = rails.linkrail[data.body[i].linkCode].next;
let vexlist = [];
trainlisttest.list[code].nowcode = data.linkCode;
trainlisttest.list[code].nextcode = null;
trainlisttest.list[code].pc = 1;
trainlisttest.list[code].statsstop = 0;
if(trainlisttest.list[code].mixerpush == false){
for(let mi=0,lenmi=trainlisttest.list[code].mixer.length;mi<lenmi;mi++){
jlmap3d.mixers.push(trainlisttest.list[code].mixer[mi]);
}
trainlisttest.list[code].mixerpush = true;
// console.log(trainlisttest.list[code].mixerpush);
}
if (data.body[i].directionType == '02') { // 向右
let point = rails.linkrail[data.body[i].linkCode].lineleft.getPointAt(data.body[i].linkOffsetPercent);
if (data.directionType == '02') { // 向右
if(data.targetStation){
trainlisttest.list[code].stopstation = data.targetStation;
// console.log(rails.stops[data.targetStation].direct2.percent);
trainlisttest.list[code].pc = data.targetLinkPercent/rails.stops[data.targetStation].direct2.percent;
trainlisttest.list[code].targetpercent = rails.stops[data.targetStation].direct2.percent;
trainlisttest.list[code].progress = data.linkOffsetPercent/trainlisttest.list[code].pc;
trainlisttest.list[code].linkOffsetPercent = data.linkOffsetPercent;
trainlisttest.list[code].targetLink = data.targetLink;
// console.log(data.targetLinkPercent);
// console.log(rails.stops[data.targetStation].direct2.percent);
// console.log(trainlisttest.list[code].progress);
// console.log("===================");
let point = rails.linkrail[data.linkCode].lineleft.getPointAt(trainlisttest.list[code].progress);
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].position.x = point.x;
trainlisttest.list[code].position.y = 0;
@ -279,45 +344,64 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
trainlisttest.list[code].children[tl].position.z = point.z;
}
}
trainlisttest.list[code].curve = rails.linkrail[data.linkCode].lineleft;
trainlisttest.list[code].len = rails.linkrail[data.linkCode].lengthfact;
trainlisttest.list[code].status = '02';
trainlisttest.list[code].progress = data.body[i].linkOffsetPercent;
trainlisttest.list[code].curve = rails.linkrail[data.body[i].linkCode].lineleft;
} else if (data.body[i].directionType == '03') { // 向左
let point = rails.linkrail[data.body[i].linkCode].lineright.getPointAt((1-data.body[i].linkOffsetPercent));
} else if (data.directionType == '03') { // 向左
// if(trainlisttest.list[code].rname == "006"){
// console.log("0000000000000000");
// console.log(data.linkOffsetPercent);
// }
if(data.targetStation){
trainlisttest.list[code].stopstation = data.targetStation;
trainlisttest.list[code].pc = data.targetLinkPercent/rails.stops[data.targetStation].direct1.percent;
trainlisttest.list[code].targetpercent = rails.stops[data.targetStation].direct1.percent;
trainlisttest.list[code].progress = 1-(data.linkOffsetPercent/trainlisttest.list[code].pc);
trainlisttest.list[code].linkOffsetPercent = data.linkOffsetPercent;
trainlisttest.list[code].targetLink = data.targetLink;
// console.log(data.targetLinkPercent);
// console.log(rails.stops[data.targetStation].direct1.percent);
// console.log(trainlisttest.list[code].progress);
// console.log("===================");
let point = rails.linkrail[data.linkCode].lineright.getPointAt(trainlisttest.list[code].progress);
trainlisttest.list[code].rotation.y = Math.PI;
trainlisttest.list[code].position.x = point.x;
trainlisttest.list[code].position.y = 0;
for (let tl=0; tl<6; tl++) {
trainlisttest.list[code].children[tl].position.z = -point.z;
}
// if(trainlisttest.list[code].rname == "006"){
// console.log("0000000000000000");
// console.log(data.body[i].linkOffsetPercent);
// }
}
trainlisttest.list[code].curve = rails.linkrail[data.linkCode].lineright;
trainlisttest.list[code].len = rails.linkrail[data.linkCode].lengthfact;
trainlisttest.list[code].status = '03';
trainlisttest.list[code].progress = 1-data.body[i].linkOffsetPercent;
trainlisttest.list[code].curve = rails.linkrail[data.body[i].linkCode].lineright;
// trainlisttest.list[code].curve = rails.linkrail[data.linkCode].lineright;
}
trainlisttest.list[code].len = rails.linkrail[data.body[i].linkCode].lengthfact;
// trainlisttest.list[code].isStandTrack = sectionlist.sections.datalist[data.body[i].sectionCode].isStandTrack;
trainlisttest.list[code].len = rails.linkrail[data.linkCode].lengthfact;
// trainlisttest.list[code].isStandTrack = sectionlist.sections.datalist[data.sectionCode].isStandTrack;
// trainlisttest.list[code].len = sectionlist.sections.datalist[data.body[i].sectionCode].distance;
// trainlisttest.list[code].len = sectionlist.sections.datalist[data.sectionCode].distance;
if(data.body[i].speed == 0){
trainlisttest.list[code].speeds = data.body[i].speed;
if(data.speed == 0){
trainlisttest.list[code].speeds = data.speed;
trainlisttest.list[code].speeds = 0;
// trainlisttest.list[code].startmark = 1;
}else{
trainlisttest.list[code].speeds = data.body[i].speed;
trainlisttest.list[code].speeds = parseFloat(data.body[i].speed*10/36/20/trainlisttest.list[code].len);
trainlisttest.list[code].speeds = data.speed;
trainlisttest.list[code].speeds = parseFloat(data.speed*10/36/20/trainlisttest.list[code].len);
}
}
} else if (trainlisttest.list[code].dispose != data.body[i].dispose && data.body[i].dispose == true) {
} else if (trainlisttest.list[code].dispose != data.dispose && data.dispose == true) {
trainlisttest.group.remove(trainlisttest.list[code]);
trainlisttest.list[code].progress = null;
trainlisttest.list[code].dispose = true;
@ -327,145 +411,143 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
trainlisttest.list[code].speed = 0;
trainlisttest.list[code].position.x = -50000;
trainlisttest.list[code].position.y = -50000;
trainlisttest.list[code].pc = 1;
} else if (trainlisttest.list[code].dispose == data.body[i].dispose && data.body[i].dispose == false) {
} else if (trainlisttest.list[code].dispose == data.dispose && data.dispose == false) {
if (rails.linkrail[data.body[i].linkCode]) {
if (driverswitch == '02' && code == drivingcode) {
jlmap3d.updatenowspeed(data.body[i].speed);
if (data.body[i].atpSpeed) {
jlmap3d.updateatpspeed(data.body[i].atpSpeed);
} else {
jlmap3d.updateatpspeed(-1);
}
if (data.body[i].targetSpeed) {
jlmap3d.updateatospeed(data.body[i].targetSpeed);
} else {
jlmap3d.updateatospeed(-1);
}
if (data.body[i].maLen) {
jlmap3d.updatenowlen(data.body[i].maLen);
} else {
jlmap3d.updatenowlen(0);
}
// if(trainlisttest.list[code].isStandTrack == true){
// pointstand = null;
// if(data.body[i].directionType == "02"){
// pointstand = trainlisttest.list[code].curve.getPointAt(data.body[i].sectionOffsetPercent);
// }else{
// pointstand = trainlisttest.list[code].curve.getPointAt(1-data.body[i].sectionOffsetPercent);
// }
// console.log(data.body[i].sectionOffsetPercent)
// console.log(pointstand.x);
// if(data.){
//
// trainlisttest.list[code].position.x = pointstand.x;
// }
}
if (driverswitch == '05' && code == drivingcode) {
if (data.body[i].maLen) {
jlmap3d.updatenowlen(data.body[i].maLen);
} else {
jlmap3d.updatenowlen(0);
}
}
if(trainlisttest.list[code].nowcode != data.body[i].linkCode){
trainlisttest.list[code].nowcode = data.body[i].linkCode;
trainlisttest.list[code].nextcode = rails.linkrail[data.body[i].linkCode].next;
if (data.body[i].directionType == '02') { // 向右
trainlisttest.list[code].progress = 0;
if (trainlisttest.list[code].status != data.body[i].directionType) {
const rotaposx = trainlisttest.list[code].children[5].matrixWorld.elements[12];
const rotaposz = trainlisttest.list[code].children[0].matrixWorld.elements[14];
if (data.directionType == '02' && trainlisttest.list[code].status != data.directionType) { // 向右
let rotaposx = trainlisttest.list[code].children[5].matrixWorld.elements[12];
let rotaposz = trainlisttest.list[code].children[0].matrixWorld.elements[14];
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].position.x = rotaposx;
for (let tl=0; tl<6; tl++) {
trainlisttest.list[code].children[tl].position.z = rotaposz;
}
trainlisttest.list[code].progress = (rotaposx-rails.linkrail[data.body[i].linkCode].lp.x)/rails.linkrail[data.body[i].linkCode].lengthfact;
}
trainlisttest.list[code].progress = (rotaposx-rails.linkrail[data.linkCode].lp.x)/rails.linkrail[data.linkCode].lengthfact;
trainlisttest.list[code].status = '02';
trainlisttest.list[code].curve = rails.linkrail[data.body[i].linkCode].lineleft;
} else if (data.body[i].directionType == '03') { // 向左
trainlisttest.list[code].progress = 0;
if (trainlisttest.list[code].status != data.body[i].directionType) {
const rotaposx = trainlisttest.list[code].children[5].matrixWorld.elements[12];
const rotaposz = Math.abs(trainlisttest.list[code].children[0].matrixWorld.elements[14]);
trainlisttest.list[code].curve = rails.linkrail[data.linkCode].lineleft;
trainlisttest.list[code].nextcurve = null;
trainlisttest.list[code].len = rails.linkrail[data.linkCode].lengthfact;
} else if (data.directionType == '03'&& trainlisttest.list[code].status != data.directionType) { // 向左
let rotaposx = trainlisttest.list[code].children[5].matrixWorld.elements[12];
let rotaposz = Math.abs(trainlisttest.list[code].children[0].matrixWorld.elements[14]);
trainlisttest.list[code].rotation.y = Math.PI;
trainlisttest.list[code].position.x = rotaposx;
for (let tl=0; tl<6; tl++) {
trainlisttest.list[code].children[tl].position.z = -rotaposz;
}
trainlisttest.list[code].progress = 1-(rotaposx-rails.linkrail[data.body[i].linkCode].lp.x)/rails.linkrail[data.body[i].linkCode].lengthfact;
trainlisttest.list[code].progress = 1-(rotaposx-rails.linkrail[data.linkCode].lp.x)/rails.linkrail[data.linkCode].lengthfact;
trainlisttest.list[code].status = '03';
trainlisttest.list[code].curve = rails.linkrail[data.linkCode].lineright;
trainlisttest.list[code].nextcurve = null;
trainlisttest.list[code].len = rails.linkrail[data.linkCode].lengthfact;
}
if(trainlisttest.list[code].nextcode == null && trainlisttest.list[code].stopstation == data.targetStation){
// if(data.groupNumber == "013"){
// console.log(trainlisttest.list[code].nextcode);
// console.log(trainlisttest.list[code].stopstation);
// console.log(data.targetStation);
// console.log(data.body[i]);
// console.log(trainlisttest.list[code]);
// }
if(trainlisttest.list[code].targetLink != trainlisttest.list[code].nowlink){
let nextcode;
if(data.directionType == '02'){
trainlisttest.list[code].status = '02';
// console.log(rails.linkrail[trainlisttest.list[code].nowcode]);
if(rails.linkrail[trainlisttest.list[code].nowcode]){
nextcode = rails.linkrail[trainlisttest.list[code].nowcode].rconnect;
}
if(nextcode){
trainlisttest.list[code].nextcurve = rails.linkrail[nextcode].lineleft;
trainlisttest.list[code].nextlen = rails.linkrail[nextcode].lengthfact;
}else{
trainlisttest.list[code].nextlen = 0;
}
}else if(data.directionType == '03'){
trainlisttest.list[code].status = '03';
if(rails.linkrail[trainlisttest.list[code].nowcode]){
nextcode = rails.linkrail[trainlisttest.list[code].nowcode].lconnect;
}
if(nextcode){
trainlisttest.list[code].nextcurve = rails.linkrail[nextcode].lineright;
trainlisttest.list[code].nextlen = rails.linkrail[nextcode].lengthfact;
}else{
trainlisttest.list[code].nextlen = 0;
}
}
trainlisttest.list[code].nextcode = nextcode;
}
if(trainlisttest.list[code].curve == null){
trainlisttest.list[code].len = trainlisttest.list[code].nextlen;
trainlisttest.list[code].nowcode = trainlisttest.list[code].nextcode;
trainlisttest.list[code].curve = trainlisttest.list[code].nextcurve;
trainlisttest.list[code].nextcurve = null;
trainlisttest.list[code].nextlen = null;
trainlisttest.list[code].nextcode = null;
}
}
if(trainlisttest.list[code].stopstation != data.targetStation){
if(data.directionType == '02'){
if(data.targetStation){
trainlisttest.list[code].pc = data.targetLinkPercent/rails.stops[data.targetStation].direct2.percent;
trainlisttest.list[code].targetpercent = rails.stops[data.targetStation].direct2.percent;
trainlisttest.list[code].linkOffsetPercent = data.linkOffsetPercent;
trainlisttest.list[code].targetLink = data.targetLink;
}
trainlisttest.list[code].status = '02';
}else if(data.directionType == '03'){
if(data.targetStation){
trainlisttest.list[code].pc = data.targetLinkPercent/rails.stops[data.targetStation].direct1.percent;
trainlisttest.list[code].targetpercent = rails.stops[data.targetStation].direct1.percent;
trainlisttest.list[code].linkOffsetPercent = data.linkOffsetPercent;
trainlisttest.list[code].targetLink = data.targetLink;
}
trainlisttest.list[code].status = '03';
trainlisttest.list[code].curve = rails.linkrail[data.body[i].linkCode].lineright;
}
trainlisttest.list[code].statsstop = 0;
trainlisttest.list[code].stopstation = data.targetStation;
}
// console.log(rails.linkrail[data.body[i].linkCode]);
// console.log(data.body[i].linkCode)
// console.log(nextcode);
trainlisttest.list[code].len = rails.linkrail[data.body[i].linkCode].lengthfact;
}
if(data.body[i].directionType == '02'){
let nextcode = rails.linkrail[data.body[i].linkCode].rconnect;
if(nextcode){
trainlisttest.list[code].nextcurve = rails.linkrail[nextcode].lineright;
}
}else if(data.body[i].directionType == '03'){
let nextcode = rails.linkrail[data.body[i].linkCode].lconnect;
if(nextcode){
trainlisttest.list[code].nextcurve = rails.linkrail[nextcode].lineleft;
}
}
}
}
}
}
}
}
}
if (data.type == 'Simulation_DeviceStatus') {
// console.log(data.body);
for (let i= 0,leni = data.body.length; i<leni; i++) {
// 0xFFFFFF
// 0xCD0000 红
// 0xEEEE00 黄
// 0x32CD32 绿
if (data.body[i]._type == 'Signal' && signallist) {
if (signallist) {
// console.log(data.body[i]);
signalupdate(data.body[i]);
if(trainlisttest.list[code].speed != data.speed){
trainlisttest.list[code].speed = data.speed;
trainlisttest.list[code].speeds = parseFloat(data.speed*10/36/20/trainlisttest.list[code].len);
}
}
if (data.body[i]._type == 'StationStand' && actions) {
if (actions) {
standupdate(data.body[i]);
// }
}
}
if (data.body[i]._type == 'Switch' && sectionlist) {
if (sectionlist) {
switchupdate(data.body[i]);
}
}
}
}
}
function standupdate(data) {
code = data.code;
if ( actions[code]) {
@ -493,7 +575,34 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
}
}
function devicestatus(data){
for (let i= 0,leni = data.body.length; i<leni; i++) {
// 0xFFFFFF
// 0xCD0000 红
// 0xEEEE00 黄
// 0x32CD32 绿
if (data._type == 'Signal' && signallist) {
if (signallist) {
// console.log(data.body[i]);
signalupdate(data.body[i]);
}
}
if (data._type == 'StationStand' && actions) {
if (actions) {
standupdate(data.body[i]);
}
}
if (data._type == 'Switch' && sectionlist) {
if (sectionlist) {
switchupdate(data.body[i]);
}
}
}
}
function signalupdate(data) {
code = data.code;
// console.log(data);
@ -651,5 +760,18 @@ export function Jlmap3dSubscribe(jlmap3d,routegroup) {
}
}
}
function simulationreset(data){
for(let i=0;i<trainlisttest.group.children.length;i++){
trainlisttest.group.children[i].dispose = true;
trainlisttest.group.children[i].stopstation = null;
trainlisttest.group.children[i].pc = null;
trainlisttest.group.children[i].targetpercent = null;
trainlisttest.group.children[i].progress = null;
trainlisttest.group.children[i].linkOffsetPercent = null;
trainlisttest.group.children[i].targetLink = null;
trainlisttest.group.remove(trainlisttest.group.children[i]);
i--;
}
}
}

View File

@ -24,7 +24,7 @@ export function Jlmap3dSubscribe(worker,routegroup) {
this.teststomp = new StompClient();
this.topic = displayTopic;
const header = { group: router.currentRoute.query.group, 'X-Token': getToken() };
console.log( router.currentRoute.query.group);
this.updatamap = function (mapdata, materiallist, nowaction, scene) {
// console.log(mapdata);
scope.map = mapdata;
@ -441,4 +441,5 @@ export function Jlmap3dSubscribe(worker,routegroup) {
}
}
}

View File

@ -0,0 +1,201 @@
export function UpdateTrain(camera,traindata){
if(traindata != undefined ){
for(let j=traindata.group.children.length-1;j>=0;j--){
//判断是否有移动事件
if(traindata.group.children[j].dispose == false){
if(traindata.group.children[j].progress != null){
let trainmodel = traindata.group.children[j];
if(trainmodel.speeds > 0 && trainmodel.speeds){
let speed = null;
if(traindata.group.children[j].progress >=0&&traindata.group.children[j].progress<=1){
// console.log(trainmodel.rname);
// console.log(trainmodel.speeds);
// console.log(trainmodel.progress);
let movecurve = trainmodel.curve;
if(trainmodel.status == "03" && movecurve.points.length>1){
let point = movecurve.getPointAt(traindata.group.children[j].progress);
trainmodel.position.x = point.x;
trainmodel.position.y = 0;
if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.02){
trainmodel.children[0].up = new THREE.Vector3(-1,0,0);
let tangent = movecurve.getTangentAt(traindata.group.children[j].progress).normalize();
trainmodel.children[0].axis.crossVectors(trainmodel.children[0].up, tangent).normalize();
let radians = Math.acos(trainmodel.children[0].up.dot(tangent));
trainmodel.children[0].quaternion.setFromAxisAngle(trainmodel.children[0].axis, radians);
trainmodel.children[0].rotation.x = -Math.PI/2;
trainmodel.children[0].rotation.z = trainmodel.children[0].rotation.y;
trainmodel.children[0].rotation.y = 0;
// console.log(trainmodel.children[0].rotation.x);
// console.log(trainmodel.children[0].rotation.y);
// console.log(trainmodel.children[0].rotation.z);
let rotas = {
posr:point,
rota:trainmodel.children[0].rotation.z
}
trainmodel.children[1].rotalist.push(rotas);
let offsetz = parseFloat(trainmodel.children[0].matrixWorld.elements[14]) - parseFloat(point.z);
trainmodel.children[0].position.z += offsetz;
//trainmodel.position.z = point.z;
}
if(trainmodel.children[1].rotalist.length > 0 || trainmodel.children[2].rotalist.length > 0 || trainmodel.children[3].rotalist.length > 0 || trainmodel.children[4].rotalist.length > 0|| trainmodel.children[5].rotalist.length > 0){
for(let rs = 1;rs<6;rs++){
//console.log(rs);
if(trainmodel.children[rs].rotalist[0]){
let offsetz = parseFloat(trainmodel.children[rs].matrixWorld.elements[14]) - parseFloat(trainmodel.children[rs].rotalist[0].posr.z);
trainmodel.children[rs].position.z += offsetz;
for(let xh=0;xh<trainmodel.children[rs].rotalist.length;xh++){
if((trainmodel.children[rs].matrixWorld.elements[12]-8)<=trainmodel.children[rs].rotalist[0].posr.x){
if(rs != 5){
let asd = trainmodel.children[rs].rotalist[0];
trainmodel.children[rs+1].rotalist.push(asd);
}
trainmodel.children[rs].rotation.z = trainmodel.children[rs].rotalist[0].rota;
trainmodel.children[rs].rotalist.splice(0,1)
xh--;
}else{
xh = trainmodel.children[rs].rotalist.length;
}
}
//console.log(trainmodel.children[rs].rotalist.length);
}
}
}
if(trainmodel.statsstop == 0){
if((1-trainmodel.progress) > trainmodel.targetpercent){
// if(trainmodel.rname == "001"){
// console.log(trainmodel.targetLink);
// console.log(trainmodel.nowcode);
// console.log(1-trainmodel.progress);
// console.log(trainmodel.targetpercent);
// console.log("===============");
// }
trainmodel.progress += trainmodel.speeds;
}else{
trainmodel.statsstop = 1;
}
}
}
if(trainmodel.status == "02" && movecurve.points.length>1){
let point = movecurve.getPointAt(trainmodel.progress);
trainmodel.position.x = point.x;
trainmodel.position.y = 0;
if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.02){
trainmodel.children[0].up = new THREE.Vector3(1,0,0);
let tangent = movecurve.getTangentAt(traindata.group.children[j].progress).normalize();
trainmodel.children[0].axis.crossVectors(trainmodel.children[0].up, tangent).normalize();
let radians = Math.acos(trainmodel.children[0].up.dot(tangent));
trainmodel.children[0].quaternion.setFromAxisAngle(trainmodel.children[0].axis, radians);
trainmodel.children[0].rotation.x = -Math.PI/2;
trainmodel.children[0].rotation.z = trainmodel.children[0].rotation.y;
trainmodel.children[0].rotation.y = 0;
let rotas = {
posr:point,
rota:trainmodel.children[0].rotation.z
}
trainmodel.children[1].rotalist.push(rotas);
let offsetz = parseFloat(point.z) - parseFloat(trainmodel.children[0].matrixWorld.elements[14]);
trainmodel.children[0].position.z += offsetz;
//trainmodel.position.z = point.z;
}
if(trainmodel.children[1].rotalist.length > 0 || trainmodel.children[2].rotalist.length > 0 || trainmodel.children[3].rotalist.length > 0 || trainmodel.children[4].rotalist.length > 0|| trainmodel.children[5].rotalist.length > 0){
for(let rs = 1;rs<6;rs++){
//console.log(rs);
if(trainmodel.children[rs].rotalist[0]){
let offsetz = parseFloat(trainmodel.children[rs].rotalist[0].posr.z) - parseFloat(trainmodel.children[rs].matrixWorld.elements[14]);
trainmodel.children[rs].position.z += offsetz;
for(let xh=0;xh<trainmodel.children[rs].rotalist.length;xh++){
if((trainmodel.children[rs].matrixWorld.elements[12]+8)>=trainmodel.children[rs].rotalist[0].posr.x){
if(rs != 5){
let asd = trainmodel.children[rs].rotalist[0];
trainmodel.children[rs+1].rotalist.push(asd);
}
//let offsetx = trainmodel.children[1].matrixWorld.elements[12]-trainmodel.children[0].children[3].matrixWorld.elements[12];
trainmodel.children[rs].rotation.z = trainmodel.children[rs].rotalist[0].rota;
trainmodel.children[rs].rotalist.splice(0,1)
xh--;
}else{
xh = trainmodel.children[rs].rotalist.length;
}
}
//console.log(trainmodel.children[rs].rotalist.length);
}
}
// console.log(trainmodel.rotalist);
}
if(trainmodel.statsstop == 0){
if(trainmodel.progress < trainmodel.targetpercent){
trainmodel.progress += trainmodel.speeds;
}else{
trainmodel.statsstop = 1;
}
}
}
}else{
if(trainmodel.nextcurve){
// if(trainmodel.status == '02'){
// }else if(trainmodel.status == '03'){
// }
trainmodel.progress = 0;
trainmodel.len = trainmodel.nextlen;
if(trainmodel.nextcode){
trainmodel.nowcode = trainmodel.nextcode;
}
trainmodel.speeds = parseFloat(trainmodel.speed*10/36/25/trainmodel.len);
trainmodel.curve = trainmodel.nextcurve;
trainmodel.nextcurve = null;
trainmodel.nextlen = null;
trainmodel.nextcode = null;
}
// console.log(trainmodel.name);
// console.log(trainmodel.progress);
// console.log(trainmodel.nextcurve);
// if(trainmodel.status == "02"){
// trainmodel.progress = 0;
// }else if(trainmodel.status == "03"){
// trainmodel.progress = 1;
// }
// trainmodel.curve = trainmodel.nextcurve;
}
}
}
}
}
}
}

View File

@ -19,7 +19,7 @@ import { SetLights } from '@/jlmap3d/config/SetLights';
//controls
import { OrbitControls } from '@/jlmap3d/main/control/OrbitControls';
import { DragControls } from '@/jlmap3d/main/control/DragControls';
// import { DragControls } from '@/jlmap3d/main/control/DragControls';
//加载器
import { ModelLoad } from '@/jlmap3d/main/loaders/ModelLoad';
@ -29,7 +29,7 @@ import { getPublishMapVersion, getPublishMapDetail,getPublish3dMapDetail} from '
//utils
// import { UpdateTrain } from '@/jlmap3d/main/utils/UpdateTrain';
import { UpdateTrain } from '@/jlmap3d/main/utils/UpdateTrainTest';
import { UpdateTrain } from '@/jlmap3d/jl3dsimulation/connect/UpdateTrainTest';
// import { ReStart } from '@/jlmap3d/main/utils/ReStart';
import {Stats} from '@/jlmap3d/main/lib/stats.min.js';
@ -53,12 +53,11 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
let camera = SetCamera(dom);
//定义场景(渲染容器)
let scene = SetScene();
//定义镜头操作
let controls = new THREE.OrbitControls(camera);
controls.maxPolarAngle = Math.PI/2;
//controls.minPolarAngle = Math.PI/8;
controls.maxDistance = 1500;
controls.maxDistance = 4800;
//模型加载器
this.assetloader = new AssetLoader();
//替换材质组,例:信号机不同灯光
@ -68,35 +67,86 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
//点击选中的模型
this.selectmodel = null;
//鼠标点击模型切换
this.raycasterswitch = "stand";
this.raycasterswitch = "null";
//选中物体描边方框
this.helpbox = null;
//车门,站台门道岔动画构造器
this.mixers = [];
//模型操作命令组
this.actions = {};
let sectionlist = null;
let linklist = null;
let signallist = null;
let stationstandlist = null;
let trainlisttest = null;
let realsectionlist = null;
let rails = null;
this.webwork = new Worker("../../static/workertest/trainworker.js");
this.jsonwebwork = new Worker("../../static/workertest/jsonworker.js");
//地图模型数据
let mapdata = new Jl3ddata();
//订阅仿真socket
console.log(routegroup);
this.Subscribe = new Jlmap3dSubscribe(this.webwork,routegroup);
// console.log(routegroup);
this.Subscribe = new Jlmap3dSubscribe(scope,routegroup,scope.jsonwebwork);
//连接到通信
//console.log(this.Subscribe.config);
//this.webwork.postMessage(this.Subscribe.teststomp);
this.Subscribe.socketon(scope.Subscribe.topic);
//初始化加载数据和模型
//初始化加载数据和模型getPublishMapDetail
getPublishMapDetail(skinCode).then(data => {
let mapnetdata = data.data;
getPublish3dMapDetail(skinCode).then(netdata => {
ModelLoad(data,scope,netdata.data,mapdata,camera,controls,scene,storemod);
ModelLoad(mapnetdata,scope,netdata.data,mapdata,camera,controls,scene,storemod);
});
//
});
// let stats = new Stats();
// dom.appendChild( stats.dom );
// var timer = setInterval(function() {
// if(trainlisttest){
// if(trainlisttest.group){
// if(trainlisttest.group.children[0]){
// for(let k in rails.switchrail){
// const ddd = storemod.getters['map/getDeviceByCode'](k);
// let switchdata = rails.switchrail[k];
// rails.switchrail[k].locateType = ddd.locateType;
//
// if(ddd.locateType == "01"){
// //1--向左 2--向右
// //__\__ __/__
// if(rails.switchrail[k].directtype == "1"){
// rails.linkrail[switchdata.alink].lconnect = switchdata.blink;
// rails.linkrail[switchdata.blink].rconnect = switchdata.alink;
// }else if(rails.switchrail[k].directtype == "2"){
// rails.linkrail[switchdata.alink].rconnect = switchdata.blink;
// rails.linkrail[switchdata.blink].lconnect = switchdata.alink;
// }
//
// }else if(ddd.locateType == "02"){
// if(rails.switchrail[k].directtype == "1"){
// rails.linkrail[switchdata.alink].lconnect = switchdata.clink;
// rails.linkrail[switchdata.clink].rconnect = switchdata.alink;
// }else if(rails.switchrail[k].directtype == "2"){
// rails.linkrail[switchdata.alink].rconnect = switchdata.clink;
// rails.linkrail[switchdata.clink].lconnect = switchdata.alink;
// }
// }
// }
// clearInterval(timer);
// }
// }
// }
//
// }, 2000);
controls.upscene(scope.animateswitch);
//开启渲染
animate();
startWorker();
startWorker(scope.webwork);
//动画时间
let delta;
//循环渲染函数
@ -107,28 +157,35 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
requestAnimationFrame(animate);
//判断渲染是否开启
if(scope.animateswitch == true){
// if(camera.position.y<4000){
//
// }
//根据相机渲染场景
renderer.render(scene,camera);
// console.log(scope.animateswitch);
//检测动画构造器播放动画
}
// stats.update();
}
}
function startWorker(){
function startWorker(webwork){
if(typeof(Worker)!=="undefined"){
scope.webwork.onmessage = function (event) {
//更新列车位置
UpdateTrain(camera,mapdata.trainlisttest);
UpdateTrain(camera,trainlisttest);
delta = clock.getDelta();
for(let i=scope.mixers.length-1;i>=0;i--){
if ( scope.mixers[i] ){
scope.mixers[i].update( delta );
}
}
renderer.render(scene,camera);
};
}
@ -166,24 +223,24 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
this.showstationmsg = function(showtype){
if(showtype == "show"){
for(let st=0;st<mapdata.stationstandlist.group.children.length;st++){
mapdata.stationstandlist.group.children[st].add(mapdata.stationstandlist.textlist[st]);
for(let st=0;st<stationstandlist.group.children.length;st++){
stationstandlist.group.children[st].add(stationstandlist.textlist[st]);
}
}else{
for(let st=0;st<mapdata.stationstandlist.group.children.length;st++){
mapdata.stationstandlist.group.children[st].remove(mapdata.stationstandlist.textlist[st]);
for(let st=0;st<stationstandlist.group.children.length;st++){
stationstandlist.group.children[st].remove(stationstandlist.textlist[st]);
}
}
};
this.showtrainmsg = function(showtype){
if(showtype == "show"){
for(let st=0;st<mapdata.trainlisttest.textlist.length;st++){
mapdata.trainlisttest.list[mapdata.trainlisttest.textlist[st].tcode].children[0].add(mapdata.trainlisttest.textlist[st]);
for(let st=0;st<trainlisttest.textlist.length;st++){
trainlisttest.list[trainlisttest.textlist[st].tcode].children[0].add(trainlisttest.textlist[st]);
}
}else{
for(let st=0;st<mapdata.trainlisttest.textlist.length;st++){
mapdata.trainlisttest.list[mapdata.trainlisttest.textlist[st].tcode].children[0].remove(mapdata.trainlisttest.textlist[st]);
for(let st=0;st<trainlisttest.textlist.length;st++){
trainlisttest.list[trainlisttest.textlist[st].tcode].children[0].remove(trainlisttest.textlist[st]);
}
}
};
@ -194,14 +251,25 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
this.animateon = function(){
controls.enabled = true;
scope.animateswitch = true;
// scope.animateswitch = true;
};
this.animateoff = function(){
controls.enabled = false;
scope.animateswitch = false;
// scope.animateswitch = false;
};
this.loaderdata = function(loadsectionlist,loadlinklist,loadsignallist,loadstationstandlist,loadtrainlisttest,loadrealsectionlist,loadrails){
sectionlist = loadsectionlist;
linklist = loadlinklist;
signallist = loadsignallist;
stationstandlist = loadstationstandlist;
trainlisttest = loadtrainlisttest;
realsectionlist = loadrealsectionlist;
rails = loadrails;
}
this.eventon = function(){
//raycaster交互模型点击事件
document.getElementById("testjlmap3d").addEventListener( "mousedown", onselect, false );
@ -236,8 +304,9 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
controls.target = new THREE.Vector3(mesh.position.x,mesh.position.y,mesh.children[2].matrixWorld.elements[14]);
}
controls.upmodeldirect(mapdata);
if(stationstandlist && trainlisttest){
controls.upmodeldirect(stationstandlist,trainlisttest);
}
controls.update();
}
@ -267,17 +336,17 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
if(scope.raycasterswitch == "stand"){
//从站台对象组获取点击目标
let intersects1 = raycaster.intersectObjects( mapdata.stationstandlist.textlist);
let intersects1 = raycaster.intersectObjects( stationstandlist.textlist);
//获取最近处点击到的模型对象
if(intersects1[0]){
//遍历对象组获取对象坐标更新相机数据
for(let j=0;j<mapdata.stationstandlist.list.length;j++){
if(intersects1[0].object.name == mapdata.stationstandlist.list[j].mesh.code){
camera.position.x = mapdata.stationstandlist.list[j].mesh.position.x;
camera.position.y = mapdata.stationstandlist.list[j].mesh.position.y+200;
camera.position.z = mapdata.stationstandlist.list[j].mesh.position.z+300;
for(let j=0;j<stationstandlist.list.length;j++){
if(intersects1[0].object.name == stationstandlist.list[j].mesh.code){
camera.position.x = stationstandlist.list[j].mesh.position.x;
camera.position.y = stationstandlist.list[j].mesh.position.y+200;
camera.position.z = stationstandlist.list[j].mesh.position.z+300;
//更新相机方向
controls.target = new THREE.Vector3(mapdata.stationstandlist.list[j].mesh.position.x,mapdata.stationstandlist.list[j].mesh.position.y,mapdata.stationstandlist.list[j].mesh.position.z);
controls.target = new THREE.Vector3(stationstandlist.list[j].mesh.position.x,stationstandlist.list[j].mesh.position.y,stationstandlist.list[j].mesh.position.z);
controls.update();
}
}
@ -285,18 +354,18 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
}
if(scope.raycasterswitch == "train"){
let intersects = raycaster.intersectObjects( mapdata.trainlisttest.textlist);
let intersects = raycaster.intersectObjects( trainlisttest.textlist);
if(intersects[0]){
for(let j=0;j<mapdata.trainlisttest.list.length;j++){
if(intersects[0].object.name == mapdata.trainlisttest.list[j].name){
// console.log(mapdata.trainlisttest.list[j].position.x);
// console.log(mapdata.trainlisttest.list[j].position.y);
// console.log(mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[14]);
camera.position.x = mapdata.trainlisttest.list[j].position.x;
for(let j=0;j<trainlisttest.list.length;j++){
if(intersects[0].object.name == trainlisttest.list[j].name){
// console.log(trainlisttest.list[j].position.x);
// console.log(trainlisttest.list[j].position.y);
// console.log(trainlisttest.list[j].children[2].matrixWorld.elements[14]);
camera.position.x = trainlisttest.list[j].position.x;
camera.position.y = 200;
camera.position.z = mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[14]+300;
camera.position.z = trainlisttest.list[j].children[2].matrixWorld.elements[14]+300;
//console.log(camera.position);
controls.target = new THREE.Vector3(mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[12],mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[13],mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[14]);
controls.target = new THREE.Vector3(trainlisttest.list[j].children[2].matrixWorld.elements[12],trainlisttest.list[j].children[2].matrixWorld.elements[13],trainlisttest.list[j].children[2].matrixWorld.elements[14]);
controls.update();
}
}
@ -304,10 +373,10 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
}
if(scope.raycasterswitch == "section"){
//console.log(mapdata.sectionlist.sections.modellist);
let intersects = raycaster.intersectObjects( mapdata.sectionlist.sections.modellist,true);
//console.log(sectionlist.sections.modellist);
let intersects = raycaster.intersectObjects( sectionlist.sections.modellist,true);
if(intersects[0]){
console.log(intersects[0].object);
// console.log(intersects[0].object);
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );
scene.add( scope.helpbox );
}
@ -315,17 +384,17 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup) {
if(scope.raycasterswitch == "signal"){
let intersects = raycaster.intersectObjects( mapdata.signallist.group.children,true);
let intersects = raycaster.intersectObjects( signallist.group.children,true);
if(intersects[0]){
console.log(intersects[0].object.matrixWorld);
// console.log(intersects[0].object.matrixWorld);
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );
scene.add( scope.helpbox );
}
}
if(scope.raycasterswitch == "switch"){
let intersects = raycaster.intersectObjects( mapdata.sectionlist.switchs.modellist,true);
let intersects = raycaster.intersectObjects( sectionlist.switchs.modellist,true);
if(intersects[0]){
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );

View File

@ -16,7 +16,13 @@
THREE.OrbitControls = function ( object, domElement ) {
this.object = object;
this.data = null;
this.data = {
stationstandlist : null,
trainlisttest : null
};
this.animateswitch = null;
this.scene = null;
this.domElement = ( domElement !== undefined ) ? domElement : document;
@ -122,8 +128,13 @@ THREE.OrbitControls = function ( object, domElement ) {
};
this.upmodeldirect = function(data){
scope.data = data;
this.upmodeldirect = function(newstationstandlist,newtrainlisttest){
scope.data.stationstandlist = newstationstandlist;
scope.data.trainlisttest = newtrainlisttest;
}
this.upscene = function(animateswitch){
scope.animateswitch = animateswitch;
}
// this method is exposed, but perhaps it would be better if we can make it private...
@ -142,7 +153,6 @@ THREE.OrbitControls = function ( object, domElement ) {
return function update() {
if(scope.data){
//站台牌自动跟随相机
if(scope.data.stationstandlist){
for(let i = scope.data.stationstandlist.textlist.length-1; i>=0; i --){
@ -158,8 +168,6 @@ THREE.OrbitControls = function ( object, domElement ) {
}
}
}
var position = scope.object.position;
offset.copy( position ).sub( scope.target );
@ -491,6 +499,9 @@ THREE.OrbitControls = function ( object, domElement ) {
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
rotateStart.copy( rotateEnd );
// if(scope.render){
// scope.render.render(scope.scene,scope.object);
// }
scope.update();
@ -780,7 +791,7 @@ THREE.OrbitControls = function ( object, domElement ) {
if ( scope.enabled === false ) return;
event.preventDefault();
scope.animateswitch = true;
switch ( state ) {
case STATE.ROTATE:
@ -814,7 +825,7 @@ THREE.OrbitControls = function ( object, domElement ) {
function onMouseUp( event ) {
if ( scope.enabled === false ) return;
scope.animateswitch = false;
handleMouseUp( event );
document.removeEventListener( 'mousemove', onMouseMove, false );

View File

@ -36,6 +36,15 @@ let defaultstation = {
picUrl:"",
assetUrl:modelurl+"/models/station/fuzhou/fuzhou.FBX"
}
let defaulttopstation = {
id:"104",
name:"福州车站1",
deviceType:"topstand",
type:"num5",
picUrl:"",
assetUrl:modelurl+"/models/station/fuzhou/topstation.FBX"
}
//modelurl+"/models/station/fuzhou/fuzhou.FBX"
//https://test.joylink.club/oss/models/station/fuzhou/fuzhou.FBX
//https://joylink.club/oss/models/station/fuzhou/fuzhou.FBX
@ -65,7 +74,16 @@ let defaultsuidao = {
deviceType:"suidao",
type:"suidao",
picUrl:"",
assetUrl:"../../static/model/suidao/suidao.FBX"
assetUrl:modelurl+"/models/suidao/suidao.FBX"
}
let defaultbackground = {
id:"16",
name:"background",
deviceType:"background",
type:"background",
picUrl:"",
assetUrl:modelurl+"/models/suidao/background.FBX"
}
//modelurl+"/models/suidao/suidao.FBX"
//https://test.joylink.club/oss/models/suidao/suidao.FBX
@ -134,12 +152,18 @@ export function AssetLoader(){
let station = new AssetModel(defaultstation);
scope.modellist.push(station);
let topstation = new AssetModel(defaulttopstation);
scope.modellist.push(topstation);
let driver = new AssetModel(defaultdriver);
scope.modellist.push(driver);
let suidao = new AssetModel(defaultsuidao);
scope.modellist.push(suidao);
let background = new AssetModel(defaultbackground);
scope.modellist.push(defaultbackground);
let defaultswitch1 = new AssetModel(autoswitch1);
scope.modellist.push(defaultswitch1);
@ -202,6 +226,9 @@ export function AssetLoader(){
let station = new AssetModel(defaultstation);
scope.modellist.push(station);
let topstation = new AssetModel(defaulttopstation);
scope.modellist.push(topstation);
let autorail = new AssetModel(defaultautorail);
scope.modellist.push(autorail);

View File

@ -18,6 +18,7 @@ export function ModelLoad(data,scope,netdata,mapdata,camera,controls,scene,store
//console.log(data);
//console.log(scope);
let sceneload = scene;
let backdata = scope;
let jlmap3ddata = mapdata;
let assetloader = scope.assetloader;
let animateswitch = scope.animateswitch;
@ -25,6 +26,8 @@ export function ModelLoad(data,scope,netdata,mapdata,camera,controls,scene,store
let mixers = scope.mixers;
let actions = scope.actions;
let linklist,sectionlist,signallist,stationstandlist,trainlisttest,realsectionlist,rails;
let loadingInstance = Loading.service({ fullscreen: true });
@ -50,17 +53,17 @@ export function ModelLoad(data,scope,netdata,mapdata,camera,controls,scene,store
// console.log(data);
//初始化轨道和道岔 暂时
lengthfact(data);
jlmap3ddata.linklist = new LinkList();
jlmap3ddata.sectionlist = new SectionList();
linklist = new LinkList();
sectionlist = new SectionList();
//初始化信号机
jlmap3ddata.signallist = new SignalList();
signallist = new SignalList();
//初始化站台
jlmap3ddata.stationstandlist = new StationStandList();
stationstandlist = new StationStandList();
//初始化测试列车
jlmap3ddata.trainlisttest = new TrainList();
trainlisttest = new TrainList();
jlmap3ddata.realsectionlist = new RealSectionList();
jlmap3ddata.rails = new RailList();
realsectionlist = new RealSectionList();
rails = new RailList();
let loaderdata = JSON.parse(netdata.sections);
let switchdata = JSON.parse(netdata.switchs);
let signaldata = JSON.parse(netdata.signals);
@ -71,32 +74,33 @@ export function ModelLoad(data,scope,netdata,mapdata,camera,controls,scene,store
assetloader.assetpromise(sceneload)
.then(function(data){
//console.log(data);
return jlmap3ddata.linklist.loadpromise(loaderdata.link,scene,assetloader);
return linklist.loadpromise(loaderdata.link,scene,assetloader);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.stationstandlist.initpromise(mapdata.stationList,mapdata.stationStandList,sceneload,assetloader,netdata.stands,mixers,actions,"02");
return stationstandlist.initpromise(mapdata.stationList,mapdata.stationStandList,sceneload,assetloader,netdata.stands,mixers,actions,"02");
})
.then(function(data){
//console.log(data);
//console.log(assetloader);
return jlmap3ddata.trainlisttest.initpromise(mapdata.trainList,sceneload,assetloader,mixers,actions,"02");
return trainlisttest.initpromise(mapdata.trainList,sceneload,assetloader,mixers,actions,"02");
})
.then(function(data){
//console.log(data);
return jlmap3ddata.sectionlist.loadpromise(jlmap3ddata,assetloader,loaderdata.section,switchdata,sceneload);
return sectionlist.loadpromise(linklist,assetloader,loaderdata.section,switchdata,sceneload);
})
// .then(function(data){
// //console.log(data);
// return jlmap3ddata.realsectionlist.initpromise(jlmap3ddata,sceneload,assetloader,mixers,actions);
// })
// // .then(function(data){
// // //console.log(data);
// // return realsectionlist.initpromise(jlmap3ddata,sceneload,assetloader,mixers,actions);
// // })
.then(function(data){
//console.log(data);
return jlmap3ddata.signallist.initpromise(mapdata.signalList,sceneload,assetloader,netdata.signals);
return signallist.initpromise(mapdata.signalList,sceneload,assetloader,netdata.signals);
})
.then(function(data){
return new Promise(function(resolve, reject){
jlmap3ddata.rails.init(loaderdata.link,mapdata.linkList,mapdata.sectionList,switchdata,standsdata,sceneload,storemod);
let stopoffset = 61.92;
rails.init(loaderdata.link,mapdata.linkList,mapdata.sectionList,switchdata, stationstandlist.list,sceneload,storemod,stopoffset);
resolve("loadrail");
});
@ -106,23 +110,33 @@ export function ModelLoad(data,scope,netdata,mapdata,camera,controls,scene,store
if(scope.assetloader.modellist[mn].name && scope.assetloader.modellist[mn].name == "suidao"){
// scope.assetloader.modellist[mn].mesh.rotation.x = Math.PI/2;
// console.log(scope.assetloader.modellist[mn].mesh.position);
scope.assetloader.modellist[mn].mesh.name = "suidao";
scene.add(scope.assetloader.modellist[mn].mesh);
}
if(scope.assetloader.modellist[mn].name && scope.assetloader.modellist[mn].name == "background"){
// scope.assetloader.modellist[mn].mesh.rotation.x = Math.PI/2;
// console.log(scope.assetloader.modellist[mn].mesh.position);
scope.assetloader.modellist[mn].mesh.name = "background";
// console.log(scope.assetloader.modellist[mn].mesh);
scene.add(scope.assetloader.modellist[mn].mesh);
}
}
scope.animateswitch = true;
// scope.animateswitch = true;
mapdata = jlmap3ddata;
//console.log(scope);
//更新相机方向
scope.updatecamera(mapdata.stationstandlist.group.children[0],"station");
scope.Subscribe.updatamap(mapdata,scope.materiallist,scope.actions,scope.sceneload);
updatemenulist(mapdata.stationstandlist.list,mapdata.trainlisttest.list);
backdata.loaderdata(sectionlist,linklist,signallist,stationstandlist,trainlisttest,realsectionlist,rails);
scope.updatecamera(stationstandlist.group.children[0],"station");
//
scope.Subscribe.updatamap(sectionlist,linklist,signallist,stationstandlist,trainlisttest,realsectionlist,rails,scope.materiallist,scope.actions,scope.sceneload);
//
updatemenulist(stationstandlist.list,trainlisttest.list);
scope.webwork.postMessage("on");
scope.jsonwebwork.postMessage("connect");
// console.log(sceneload);
loadingInstance.close();
});

View File

@ -18,7 +18,6 @@ export function ModelLoad(data,scope,netdata,sectionlist,linklist,signallist,sta
//console.log(data);
//console.log(scope);
let sceneload = scene;
// let jlmap3ddata = mapdata;
let backdata = scope;
let assetloader = scope.assetloader;
let animateswitch = scope.animateswitch;
@ -97,8 +96,9 @@ export function ModelLoad(data,scope,netdata,sectionlist,linklist,signallist,sta
})
.then(function(data){
return new Promise(function(resolve, reject){
let stopoffset = 64;
rails.init(loaderdata.link,mapdata.linkList,mapdata.sectionList,switchdata,
stationstandlist.list,sceneload,storemod);
stationstandlist.list,sceneload,storemod,stopoffset);
resolve("loadrail");
});

View File

@ -80,6 +80,8 @@ function linkhelp(data,scene){
for(let i=0;i<data.length;i++){
// console.log("link");
// console.log(data[i]);
let testmesh2 = autorail.clone(true);
testmesh2.code = data[i].code;
testmesh2.name = data[i].name;

View File

@ -10,7 +10,7 @@ export function RailList(){
this.setrail = function(){
};
this.init = function(linkdata,linklist,sectiondata,switchdata,standsdata,scene,storemod){
this.init = function(linkdata,linklist,sectiondata,switchdata,standsdata,scene,storemod,stopoffset){
for(let i=0;i<linkdata.length;i++){
scope.linkrail[linkdata[i].code] = {
lp:linkdata[i].rail[0],
@ -132,53 +132,41 @@ export function RailList(){
for(let i=0;i<switchdata.length;i++){
const ddd = storemod.getters['map/getDeviceByCode'](switchdata[i].code);
scope.switchrail[switchdata[i].code].locateType = ddd.locateType;
if(ddd.locateType == "01"){
//1--向左 2--向右
//__\__ __/__
if(scope.switchrail[switchdata[i].code].directtype == "1"){
scope.linkrail[switchdata[i].alink].lconnect = switchdata[i].blink;
scope.linkrail[switchdata[i].blink].rconnect = switchdata[i].alink;
}else if(scope.switchrail[switchdata[i].code].directtype == "2"){
scope.linkrail[switchdata[i].alink].rconnect = switchdata[i].blink;
scope.linkrail[switchdata[i].blink].lconnect = switchdata[i].alink;
}
}else if(ddd.locateType == "02"){
if(switchdata[i].directtype == "1"){
scope.linkrail[switchdata[i].alink].lconnect = switchdata[i].clink;
scope.linkrail[switchdata[i].clink].rconnect = switchdata[i].alink;
}else if(switchdata[i].directtype == "2"){
scope.linkrail[switchdata[i].alink].rconnect = switchdata[i].clink;
scope.linkrail[switchdata[i].clink].lconnect = switchdata[i].alink;
}
}
// const ddd = storemod.getters['map/getDeviceByCode'](switchdata[i].code);
// scope.switchrail[switchdata[i].code].locateType = ddd.locateType;
// if(ddd.locateType == "01"){
// //1--向左 2--向右
// //__\__ __/__
// if(scope.switchrail[switchdata[i].code].directtype == "1"){
// scope.linkrail[switchdata[i].alink].lconnect = switchdata[i].blink;
// scope.linkrail[switchdata[i].blink].rconnect = switchdata[i].alink;
// }else if(scope.switchrail[switchdata[i].code].directtype == "2"){
// scope.linkrail[switchdata[i].alink].rconnect = switchdata[i].blink;
// scope.linkrail[switchdata[i].blink].lconnect = switchdata[i].alink;
// }
// }else if(ddd.locateType == "02"){
// if(switchdata[i].directtype == "1"){
// scope.linkrail[switchdata[i].alink].lconnect = switchdata[i].clink;
// scope.linkrail[switchdata[i].clink].rconnect = switchdata[i].alink;
// }else if(switchdata[i].directtype == "2"){
// scope.linkrail[switchdata[i].alink].rconnect = switchdata[i].clink;
// scope.linkrail[switchdata[i].clink].lconnect = switchdata[i].alink;
// }
// }
if(scope.linkrail[switchdata[i].blink].lp.x < switchdata[i].position.x){
// scope.linkrail[switchdata[i].blink].points.push(new THREE.Vector3(switchdata[i].position.x-2,switchdata[i].position.y,switchdata[i].position.z));
// scope.linkrail[switchdata[i].blink].points.push(new THREE.Vector3(switchdata[i].position.x,switchdata[i].position.y,switchdata[i].position.z));
// scope.linkrail[switchdata[i].blink].points.push(new THREE.Vector3(switchdata[i].position.x+1.5,switchdata[i].position.y,switchdata[i].position.z));
//
scope.switchrail[switchdata[i].code].directtype = "1";
}else{
// scope.linkrail[switchdata[i].blink].points.splice(0,0,new THREE.Vector3(switchdata[i].position.x+2,switchdata[i].position.y,switchdata[i].position.z));
// scope.linkrail[switchdata[i].blink].points.splice(0,0,new THREE.Vector3(switchdata[i].position.x,switchdata[i].position.y,switchdata[i].position.z));
// scope.linkrail[switchdata[i].blink].points.splice(0,0,new THREE.Vector3(switchdata[i].position.x-1.5,switchdata[i].position.y,switchdata[i].position.z));
//
scope.switchrail[switchdata[i].code].directtype = "2";
}
if(scope.linkrail[switchdata[i].clink].lp.x < switchdata[i].position.x){
// // scope.linkrail[switchdata[i].clink].points.push(new THREE.Vector3(switchdata[i].position.x-3.5,switchdata[i].position.y,switchdata[i].position.z+0.02));
// scope.linkrail[switchdata[i].clink].points.push(new THREE.Vector3(switchdata[i].position.x,switchdata[i].position.y,switchdata[i].position.z));
// scope.linkrail[switchdata[i].clink].points.push(new THREE.Vector3(switchdata[i].position.x+1.5,switchdata[i].position.y,switchdata[i].position.z));
//
scope.switchrail[switchdata[i].code].directtype = "1";
}else{
// // scope.linkrail[switchdata[i].clink].points.splice(0,0,new THREE.Vector3(switchdata[i].position.x+3.5,switchdata[i].position.y,switchdata[i].position.z-0.02));
// scope.linkrail[switchdata[i].clink].points.splice(0,0,new THREE.Vector3(switchdata[i].position.x,switchdata[i].position.y,switchdata[i].position.z));
// scope.linkrail[switchdata[i].clink].points.splice(0,0,new THREE.Vector3(switchdata[i].position.x-1.5,switchdata[i].position.y,switchdata[i].position.z));
//
scope.switchrail[switchdata[i].code].directtype = "2";
}
}
@ -259,15 +247,15 @@ export function RailList(){
// let circle2 = new THREE.Mesh( geometry, material );
let num = scope.linkrail[linklist[j].code].lineleft.points.length-1;
let lengthfacts = scope.linkrail[linklist[j].code].lineleft.points[num].x - scope.linkrail[linklist[j].code].lineleft.points[0].x;
let directoffset1 = standsdata[k].position.x-64-scope.linkrail[linklist[j].code].lineleft.points[0].x;
let directoffset1 = standsdata[k].position.x-stopoffset-scope.linkrail[linklist[j].code].lineleft.points[0].x;
stop.direct1.percent = directoffset1/lengthfacts;
// circle1.position.x = standsdata[k].position.x+64;
// circle1.position.x = standsdata[k].position.x+stopoffset;
// circle1.position.y = 5;
// circle1.position.z = scope.linkrail[linklist[j].code].points[0].z;
// circle1.rotation.x = -Math.PI/2;
//
// circle2.position.x = standsdata[k].position.x-64;
// circle2.position.x = standsdata[k].position.x-stopoffset;
// circle2.position.y = 5;
// circle2.position.z = scope.linkrail[linklist[j].code].points[0].z;
// circle2.rotation.x = -Math.PI/2;
@ -282,7 +270,7 @@ export function RailList(){
let num = scope.linkrail[linklist[j].code].lineleft.points.length-1;
let lengthfacts = scope.linkrail[linklist[j].code].lineleft.points[num].x - scope.linkrail[linklist[j].code].lineleft.points[0].x;
let directoffset2 = parseInt(standsdata[k].position.x+64-scope.linkrail[linklist[j].code].lineleft.points[0].x);
let directoffset2 = parseInt(standsdata[k].position.x+stopoffset-scope.linkrail[linklist[j].code].lineleft.points[0].x);
// console.log(directoffset2);
stop.direct2.percent = directoffset2/lengthfacts;
// console.log("test");
@ -294,9 +282,9 @@ export function RailList(){
// console.log(lengthfacts);
// console.log("........................");
// console.log(standsections[i].leftStopPointOffset);
// console.log(standsdata[n].position.x-64-scope.linkrail[linklist[j].code].lineleft.points[0].x);
// console.log(standsdata[n].position.x-stopoffset-scope.linkrail[linklist[j].code].lineleft.points[0].x);
// console.log("........................");
// console.log(standsdata[n].position.x+64);
// console.log(standsdata[n].position.x+stopoffset);
// console.log(scope.linkrail[linklist[j].code].lineleft.getPointAt(stop.direct1.percent).x);
// console.log("sectoffsetright");
// console.log(scope.linkrail[linklist[j].code]);
@ -305,16 +293,16 @@ export function RailList(){
// console.log(lengthfacts);
// console.log("........................");
// console.log(standsections[i].rightStopPointOffset);
// console.log(standsdata[k].position.x+64-scope.linkrail[linklist[j].code].lineleft.points[0].x);
// console.log(standsdata[k].position.x+stopoffset-scope.linkrail[linklist[j].code].lineleft.points[0].x);
// console.log("........................");
// console.log(standsdata[k].position.x+64);
// console.log(standsdata[k].position.x+stopoffset);
// console.log(scope.linkrail[linklist[j].code].lineleft.getPointAt(stop.direct2.percent).x);
// circle1.position.x = standsdata[k].position.x+64;
// circle1.position.x = standsdata[k].position.x+stopoffset;
// circle1.position.y = 5;
// circle1.position.z = scope.linkrail[linklist[j].code].points[0].z;
// circle1.rotation.x = -Math.PI/2;
// //
// circle2.position.x = standsdata[k].position.x-64;
// circle2.position.x = standsdata[k].position.x-stopoffset;
// circle2.position.y = 5;
// circle2.position.z = scope.linkrail[linklist[j].code].points[0].z;
// circle2.rotation.x = -Math.PI/2;

View File

@ -96,6 +96,7 @@ export function RealSectionList(data) {
}
if(name[0] == "Singal"){
console.log();
newmesh.remove(newmesh.children[i]);
i = i-1;
}

View File

@ -2,7 +2,7 @@ import {SectionModel} from '@/jlmap3d/edit/editmodel/SectionModel.js';
import {SwitchModel} from '@/jlmap3d/edit/editmodel/SwitchModel.js';
export function SectionList() {
const scope = this;
let scope = this;
this.type = 'sectionlist';
@ -30,7 +30,7 @@ export function SectionList() {
for (let i=0; i<sectiondata.length; i++) {
if (sectiondata[i].type == '01') {
// 初始化区段对象数据
const newsection = new SectionModel(sectiondata);
let newsection = new SectionModel(sectiondata);
newsection.name = sectiondata[i].code;
newsection.code = sectiondata[i].code;
newsection.index = i;
@ -50,11 +50,11 @@ export function SectionList() {
}
// 定义区分道岔组
const switchlist = [];
let switchlist = [];
// 遍历道岔数据
for (let i=0; i<switchdata.length; i++) {
// 道岔信息
const newswitch = {
let newswitch = {
code: null,
pa: null,
pb: null,
@ -89,7 +89,7 @@ export function SectionList() {
// 遍历道岔信息组合轨道
for (let i=0; i<switchlist.length; i++) {
// 道岔对象组
const newswitch = new SwitchModel();
let newswitch = new SwitchModel();
newswitch.name = switchlist[i].code;
newswitch.code = switchlist[i].code;
@ -110,25 +110,25 @@ export function SectionList() {
scene.add(switchgroup);
let linkdata = linklist;
for(let i=0;i<sectiondata.length;i++){
if(sectiondata[i].type == "01"){
//初始化区段对象数据
let newsection = new SectionModel(sectiondata);
newsection.name = sectiondata[i].code;
newsection.code = sectiondata[i].code;
newsection.index = i;
newsection.isStandTrack = sectiondata[i].isStandTrack;
newsection.relStandCode = sectiondata[i].relStandCode;
newsection.type = sectiondata[i].type;
newsection.offsetRight = sectiondata[i].offsetRight;
newsection.offsetLeft = sectiondata[i].offsetLeft;
newsection.linkCode = sectiondata[i].linkCode;
scope.sections.datalist.push(newsection);
// scope.sections.modellist.push("");
}
}
// for(let i=0;i<sectiondata.length;i++){
// if(sectiondata[i].type == "01"){
// //初始化区段对象数据
// let newsection = new SectionModel(sectiondata);
//
// newsection.name = sectiondata[i].code;
// newsection.code = sectiondata[i].code;
// newsection.index = i;
// newsection.isStandTrack = sectiondata[i].isStandTrack;
// newsection.relStandCode = sectiondata[i].relStandCode;
// newsection.type = sectiondata[i].type;
// newsection.offsetRight = sectiondata[i].offsetRight;
// newsection.offsetLeft = sectiondata[i].offsetLeft;
// newsection.linkCode = sectiondata[i].linkCode;
//
// scope.sections.datalist.push(newsection);
// // scope.sections.modellist.push("");
// }
// }
let autosuidao;
for(let i=0;i<assetloader.modellist.length;i++){
@ -139,7 +139,8 @@ export function SectionList() {
for(let i = 0;i < sectiondata.length;i++){
let testmesh1 = autosuidao.clone(true);
// let testmesh1 = autosuidao.clone(true);
let testmesh1 = {};
testmesh1.code = sectiondata[i].code;
testmesh1.name = sectiondata[i].code;
if(sectiondata[i].relStandCode){
@ -153,42 +154,42 @@ export function SectionList() {
testmesh1.leftpoint = sectiondata[i].leftpoint;
testmesh1.isStandTrack = sectiondata[i].isStandTrack;
testmesh1.lengthfact = sectiondata[i].lengthfact;
for(let i=0;i<testmesh1.rightlist.length;i++){
testmesh1.geometry.attributes.position.array[testmesh1.rightlist[i]*3] = testmesh1.lengthfact;
testmesh1.geometry.attributes.uv.array[testmesh1.rightlist[i]*2] = (testmesh1.geometry.attributes.position.array[3]-testmesh1.geometry.attributes.position.array[0])/15.3;
}
let newsuidao = new THREE.BufferGeometry();
newsuidao.copy(testmesh1.geometry);
testmesh1.geometry = newsuidao;
testmesh1.geometry.attributes.position.needsUpdate = true;
testmesh1.geometry.attributes.uv.needsUpdate = true;
testmesh1.geometry.computeBoundingSphere();
testmesh1.geometry.center();
testmesh1.position.x = sectiondata[i].position.x;
testmesh1.position.y = sectiondata[i].position.y;
testmesh1.position.z = sectiondata[i].position.z;
testmesh1.rotation.x = -Math.PI/2;
testmesh1.rotation.z = sectiondata[i].rotation._z;
// for(let i=0;i<testmesh1.rightlist.length;i++){
// testmesh1.geometry.attributes.position.array[testmesh1.rightlist[i]*3] = testmesh1.lengthfact;
// testmesh1.geometry.attributes.uv.array[testmesh1.rightlist[i]*2] = (testmesh1.geometry.attributes.position.array[3]-testmesh1.geometry.attributes.position.array[0])/15.3;
// }
// let newsuidao = new THREE.BufferGeometry();
// newsuidao.copy(testmesh1.geometry);
// testmesh1.geometry = newsuidao;
// testmesh1.geometry.attributes.position.needsUpdate = true;
// testmesh1.geometry.attributes.uv.needsUpdate = true;
// testmesh1.geometry.computeBoundingSphere();
// testmesh1.geometry.center();
// testmesh1.position.x = sectiondata[i].position.x;
// testmesh1.position.y = sectiondata[i].position.y;
// testmesh1.position.z = sectiondata[i].position.z;
// testmesh1.rotation.x = -Math.PI/2;
// testmesh1.rotation.z = sectiondata[i].rotation._z;
//
// let newsection = new SectionModel(sectiondata);
//
// newsection.name = sectiondata[i].code;
// newsection.code = sectiondata[i].code;
// newsection.isStandTrack = sectiondata[i].isStandTrack;
// newsection.relStandCode = sectiondata[i].relStandCode;
// newsection.linkCode = sectiondata[i].linkCode;
let newsection = new SectionModel(sectiondata);
// scope.sections.datalist.push(newsection);
newsection.name = sectiondata[i].code;
newsection.code = sectiondata[i].code;
newsection.isStandTrack = sectiondata[i].isStandTrack;
newsection.relStandCode = sectiondata[i].relStandCode;
newsection.linkCode = sectiondata[i].linkCode;
scope.sections.datalist.push(newsection);
if(testmesh1.isStandTrack == false){
sectiongroup.add(testmesh1);
}else{
scope.standtrack.push(testmesh1);
var box = new THREE.BoxHelper( testmesh1, 0xff0000 );
sectiongroup.add( box );
}
//
// if(testmesh1.isStandTrack == false){
// sectiongroup.add(testmesh1);
//
// }else{
// scope.standtrack.push(testmesh1);
// var box = new THREE.BoxHelper( testmesh1, 0xff0000 );
// sectiongroup.add( box );
// }
scope.sections.modellist.push(testmesh1);
}
@ -202,8 +203,7 @@ export function SectionList() {
switchmesh2 = assetloader.modellist[i].mesh;
}
}
// switchmesh1.rotation.x = Math.PI/2;
// switchmesh2.rotation.z = Math.PI/2;
for(let i=0;i<switchdata.length;i++){
let newswitch = {
code:switchdata[i].code,

View File

@ -20,19 +20,20 @@ export function SignalList() {
netsignal = JSON.parse(netdata);
haddata = true;
}
let selectmesh = null;
for(let j=0;j<assetloader.modellist.length;j++){
if(assetloader.modellist[j].deviceType == "signal"){
selectmesh = assetloader.modellist[j].mesh;
}
}
for(let i=0;i<data.length;i++){
let newsignal = new SignalModel(data[i]);
let num;
if(haddata == false){
for(let j=0;j<assetloader.modellist.length;j++){
if(assetloader.modellist[j].deviceType == "signal"){
num = j;
}
}
let newmesh = assetloader.modellist[num].mesh.clone(true);
let newmesh = selectmesh.clone(true);
for(let j=0;j<newmesh.children.length;j++){
newmesh.children[j].material.map.uuid = data[i].code+j;
console.log(newmesh.children[j].material.map.uuid);

View File

@ -24,6 +24,20 @@ export function StationStandList() {
scope.group.name = "station";
scene.add(scope.group);
let selectmesh = null;
let topstationmesh = null;
let num = null;
for(let j=0;j<assetloader.modellist.length;j++){
if(assetloader.modellist[j].deviceType == "stand"){
num = j;
selectmesh = assetloader.modellist[num].mesh;
}
if(assetloader.modellist[j].deviceType == "topstand"){
topstationmesh = assetloader.modellist[j].mesh;
}
}
// console.log(haddata);
//遍历车站数据
for(let i=0;i<stationdata.length;i++){
@ -65,11 +79,7 @@ export function StationStandList() {
let num;
if(haddata == false){
for(let j=0;j<assetloader.modellist.length;j++){
if(assetloader.modellist[j].deviceType == "stand"){
num = j;
}
}
map[k].mesh = assetloader.modellist[num].mesh.clone(true);
map[k].id = assetloader.modellist[num].id;
map[k].mesh.code = map[k].code;
@ -107,7 +117,7 @@ export function StationStandList() {
if(assetloader.modellist[j].id == netstand[netnum].modelid){
num = j;
map[k].index = netnum;
j = assetloader.modellist.length;
// j = assetloader.modellist.length;
}
}
@ -116,10 +126,8 @@ export function StationStandList() {
}
}
map[k].mesh = assetloader.modellist[num].mesh.clone(true);
let newclip = assetloader.modellist[num].mesh.animations[ 0 ];
map[k].mesh = selectmesh.clone(true);
let newclip = selectmesh.animations[ 0 ];
for(let j=0;j<map[k].mesh.children.length;j++){
@ -140,7 +148,6 @@ export function StationStandList() {
mixers.push(mixer);
}
if(map[k].mesh.children[j].name == "down"){
let newclip = assetloader.modellist[num].mesh.animations[ 0 ];
map[k].mesh.children[j].animations = [];
map[k].mesh.children[j].animations.push(newclip.clone());
@ -167,6 +174,7 @@ export function StationStandList() {
map[k].mesh.position.x = netstand[map[k].index].position.x;
map[k].mesh.position.y = netstand[map[k].index].position.y;
map[k].mesh.position.z = netstand[map[k].index].position.z;
// map[k].mesh.rotation.x = netstand[map[k].index].rotation._x;
// map[k].mesh.rotation.y = netstand[map[k].index].rotation._y;
// map[k].mesh.rotation.z = netstand[map[k].index].rotation._z;
@ -189,19 +197,19 @@ export function StationStandList() {
textgeometry.dispose();
textmaterial.dispose();
textt.dispose();
let newtopstation = topstationmesh.clone(true);
newtopstation.position.x = map[k].mesh.position.x;
newtopstation.position.z = map[k].mesh.position.z;
scene.add(newtopstation);
}
}
map[k].type = "station";
map[k].rname = stationdata[map[k].num].runPlanName;
map[k].kmmark = stationdata[map[k].num].kmPost;
scope.group.add(map[k].mesh);
}
}
@ -236,7 +244,7 @@ function getTextCanvas(text){
ctx.drawImage(stationcanvas,0,0,256,512);
ctx.font = "20px Verdana";
ctx.fillText("车站名称: "+text.runPlanName, 20,58);
ctx.fillText("车站名称: "+text.name, 20,58);
ctx.fillText("漫游", 30,100);
ctx.fillText("信息", 114,100);

View File

@ -9,19 +9,16 @@ export function TrainList() {
this.list = {};
this.group = new THREE.Group();
this.group.name = "train";
this.textlist = [];
this.initpromise = function(data,scene,assetloader,mixers,actionss,mode){
return new Promise(function(resolve, reject){
//遍历列车数据
for(let i=0;i<data.length;i++){
let newmesh,ntracks1,ntracks2,tclip,fclip;
let selectmesh,ntracks1,ntracks2,tclip,fclip;
for(let n=assetloader.modellist.length-1;n>=0;n--){
if(assetloader.modellist[n].deviceType == "train"){
newmesh = assetloader.modellist[n].mesh.clone(true);
selectmesh = assetloader.modellist[n].mesh
ntracks1 = assetloader.modellist[n].animations.slice(24,52);
@ -34,21 +31,34 @@ export function TrainList() {
n = 0;
}
}
//遍历列车数据
// console.log(data.length);
for(let i=0;i<data.length;i++){
actionss[data[i].code] = {
top:[],
down:[]
};
let newmesh = selectmesh.clone(true);
newmesh.mixer = [];
// console.log("-------------------------");
// console.log(data[i]);
for(let j=0;j<newmesh.children.length;j++){
if(newmesh.children[j].name == "c1" || newmesh.children[j].name == "c6"){
for(let n=0;n<newmesh.children[j].children.length;n++){
// console.log("===================");
for(let n=0,lenn = newmesh.children[j].children.length;n<lenn;n++){
if(newmesh.children[j].children[n].name == "top"){
newmesh.children[j].children[n].animations = [];
newmesh.children[j].children[n].animations.push(tclip.clone());
let mixer = new THREE.AnimationMixer( newmesh.children[j].children[n] );
mixers.push(mixer);
// console.log(n);
// console.log(newmesh.children[j].children[n]);
newmesh.mixer.push(mixer);
newmesh.mixerpush = false;
// mixers.push(mixer);
let action = mixer.clipAction( newmesh.children[j].children[n].animations[ 0 ] );
//action.play();
action.setLoop(THREE.LoopOnce);
@ -61,7 +71,10 @@ export function TrainList() {
newmesh.children[j].children[n].animations = [];
newmesh.children[j].children[n].animations.push(tclip.clone());
let mixer = new THREE.AnimationMixer( newmesh.children[j].children[n] );
mixers.push(mixer);
newmesh.mixer.push(mixer);
newmesh.mixerpush = false;
// mixers.push(mixer);
let action = mixer.clipAction( newmesh.children[j].children[n].animations[ 0 ] );
//action.play();
action.setLoop(THREE.LoopOnce);
@ -70,12 +83,14 @@ export function TrainList() {
}
}
}else{
for(let n=0;n<newmesh.children[j].children.length;n++){
for(let n=0,lenn = newmesh.children[j].children.length;n<lenn;n++){
if(newmesh.children[j].children[n].name == "top"){
newmesh.children[j].children[n].animations = [];
newmesh.children[j].children[n].animations.push(fclip.clone());
let mixer = new THREE.AnimationMixer( newmesh.children[j].children[n] );
mixers.push(mixer);
newmesh.mixer.push(mixer);
newmesh.mixerpush = false;
// mixers.push(mixer);
let action = mixer.clipAction( newmesh.children[j].children[n].animations[ 0 ] );
//action.play();
action.setLoop(THREE.LoopOnce);
@ -87,7 +102,9 @@ export function TrainList() {
newmesh.children[j].children[n].animations = [];
newmesh.children[j].children[n].animations.push(fclip.clone());
let mixer = new THREE.AnimationMixer( newmesh.children[j].children[n] );
mixers.push(mixer);
newmesh.mixer.push(mixer);
newmesh.mixerpush = false;
// mixers.push(mixer);
let action = mixer.clipAction( newmesh.children[j].children[n].animations[ 0 ] );
//action.play();
action.setLoop(THREE.LoopOnce);
@ -100,12 +117,13 @@ export function TrainList() {
newmesh.children[j].code = data[i].code;
newmesh.children[j].axis = new THREE.Vector3();
newmesh.children[j].up = new THREE.Vector3(1, 0, 0);
newmesh.axis = new THREE.Vector3();
newmesh.up = new THREE.Vector3(1, 0, 0);
// newmesh.axis = new THREE.Vector3();
// newmesh.up = new THREE.Vector3(1, 0, 0);
// var pos = new THREE.Mesh( geometryp, materialp);
// pos.position.x = -73.5;
// newmesh.children[j].add( pos );
newmesh.children[j].rotalist = [];
// console.log(newmesh);
}
//
// // newmesh.children[4].add(newmesh.children[5]);
@ -122,7 +140,11 @@ export function TrainList() {
if(mode == "02"){
let textgeometry = new THREE.PlaneBufferGeometry( 150, 100, 1 );
let textt = new THREE.CanvasTexture(getTextCanvas(data[i]));
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map:textt ,transparent: true} );
let textmaterial = new THREE.MeshBasicMaterial( {
side: THREE.DoubleSide,
map:textt ,transparent: true,
alphaTest:0.1
} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = data[i].code;
textplane.position.x = 0;
@ -165,6 +187,11 @@ export function TrainList() {
scope.list[data[i].code] = newmesh;
//scene.add(newmesh);
}
// console.log(selectmesh);
// for(let i=0,leni=selectmesh.children.length;i<leni;i++){
// selectmesh.children[i].geometry.dispose();
// selectmesh.children[i].material.dispose();
// }
scene.add(scope.group);
resolve("loadedtrain");
});

View File

@ -10,6 +10,7 @@ const Login = () => import('@/views/login/index');
const Jlmap3dedit = () => import('@/views/jlmap3d/edit/jlmap3dedit');
const Jlmap3d = () => import('@/views/jlmap3d/drive/jl3ddrive');
const Jlmap3dSandbox = () => import('@/views/jlmap3d/simulation/jl3dsimulation');
const Display = () => import('@/views/display/index');
const DesignDisplay = () => import('@/views/display/designIndex');
@ -270,6 +271,11 @@ export const constantRoutes = [
component: Jlmap3dedit,
hidden: true
},
{
path: '/jlmap3d/sandbox',
component: Jlmap3dSandbox,
hidden: true
},
{
path: '/401',
component: Error401,

View File

@ -41,7 +41,7 @@
<menu-system-time ref="menuSystemTime" :offset="offset" :right="right" :group="group" />
</div>
<Jl3d-Simulation v-show="simulationShow" ref="Jl3dSimulation" :panel-show="simulationShow" @showpanel="showpanel" />
<!-- <Jl3d-Simulation v-show="simulationShow" ref="Jl3dSimulation" :panel-show="simulationShow" @showpanel="showpanel" /> -->
<Jl3d-Drive v-show="drivingShow" ref="Jl3dDrive" :panel-show="drivingShow" @showdriving="showdriving" />
<scheduling v-if="isShowScheduling" ref="scheduling" :group="group" />
@ -72,9 +72,9 @@ import { EventBus } from '@/scripts/event-bus';
import Vue from 'vue';
//
import Jl3dSimulation from '@/views/jlmap3d/simulation/jl3dsimulation';
// import Jl3dSimulation from '@/views/jlmap3d/simulation/jl3dsimulation';
import Jl3dDrive from '@/views/jlmap3d/drive/jl3ddrive';
import { getToken } from '@/utils/auth';
export default {
name: 'DisplayDraft',
components: {
@ -88,7 +88,7 @@ export default {
MenuScript,
MenuSchema,
MenuSystemTime,
Jl3dSimulation,
// Jl3dSimulation,
Jl3dDrive,
Scheduling
},
@ -526,9 +526,15 @@ export default {
this.drivingShow = true;
this.$refs.Jl3dDrive.show(this.mapId, this.group);
} else {
this.panelShow = false;
this.simulationShow = true;
this.$refs.Jl3dSimulation.show(this.mapId, this.group);
let routeData = this.$router.resolve({
  path:'/jlmap3d/sandbox',
query:{
mapid:this.mapId,
group:this.group,
token:getToken(),
}
});
window.open(routeData.href, '_blank','noopener noreferrer');
}
},
showScheduling() {

View File

@ -143,6 +143,7 @@ export default {
beforeDestroy() {
if (this.jlmap3d) {
this.jlmap3d.webwork.postMessage('off');
this.jlmap3d.webwork.terminate();
this.jlmap3d.endsocket();
this.jlmap3d.dispose();
this.jlmap3d = null;

View File

@ -74,7 +74,10 @@ export default {
mapdata: null,
jlmap3d: null,
selectmodel: null
selectmodel: null,
mapid:null,
group:null,
token:null
};
},
watch: {
@ -94,6 +97,8 @@ export default {
// console.log("destroy");
if (this.jlmap3d) {
this.jlmap3d.webwork.postMessage('off');
this.jlmap3d.webwork.terminate();
this.jlmap3d.jsonwebwork.terminate();
this.jlmap3d.dispose();
this.jlmap3d = null;
// this.$destroy();
@ -102,12 +107,19 @@ export default {
mounted() {
window.updatemenulist = this.updatemenulist;
// this.init();
this.getParams();
// console.log("");
},
methods: {
getParams:function(){
var routerParams = this.$route.query.group
this.mapid = this.$route.query.mapid;
this.group = this.$route.query.group;
this.token = this.$route.query.token;
this.init(this.mapid,this.group);
},
show: function (skinCode,group) {
// console.log(skinCode);
// console.log(this.jlmap3d);
if (this.jlmap3d == null) {
this.init(skinCode,group);
} else {
@ -170,10 +182,10 @@ export default {
},
back() {
this.$emit('showpanel');
this.jlmap3d.eventoff();
this.jlmap3d.animateoff();
window.close();
// this.$emit('showpanel');
// this.jlmap3d.eventoff();
// this.jlmap3d.animateoff();
// this.jlmap3d = null;
}

View File

@ -8,7 +8,6 @@
<el-form ref="form" label-width="130px" size="mini">
<div class="displaylist" v-for="(station,index) in stationlist" @click="stationselect(index,station)" v-show="station.type==stationtype" >
<div >
<p>车站:{{station.rname}}</p>
<p>车站编号:{{station.name}}</p>
</div>
</div>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,720 @@
importScripts('sockjs.js');
// import { getToken } from '@/utils/auth';
// import { getBaseUrl } from '@/utils/baseUrl';
// import SockJS from 'sockjs-client';
// const websocketUrl = 'ws://test.joylink.club/jlcloud/joylink-websocket?token=';
// const websocketUrl = `http://192.168.3.6:9000/joylink-websocket?token=`;
let websocketUrl = null;
let token = null;
var StompClient = function (headers,token) {
let scope = this;
this.url = websocketUrl + token;
this.headers = headers || {};
this.connect();
};
StompClient.prototype = {
socket: null,
clientIns: null,
subscribeMap: null,
url: '',
status: false,
sockStatus: 0,
headers: {
// 'X-Token': getToken()
},
count: 0,
topic: '',
onmessage: null,
checkTimer: null,
// 连接服务端
connect() {
return new Promise((resolve, reject) => {
try {
// 断开已有连接
if (this.clientIns && this.clientIns.connected) {
this.clientIns.disconnect();
this.clientIns = null;
}
// 建立连接对象(还未发起连接)
this.socket = new SockJS(websocketUrl + token);
// 获取 STOMP 子协议的客户端对象
this.clientIns = Stomp.over(this.socket);
this.closeStompDebug();
// 向服务器发起websocket连接并发送CONNECT帧
this.clientIns.connect({ 'X-Token': token }, () => {
console.info('连接成功.');
this.count = 0;
this.status = true;
// 恢复订阅
if (this.topic && this.onmessage) {
this.unsubscribe(this.topic);
this.subscribe(this.topic, this.onmessage, this.headers);
}
resolve(this);
}, () => {
if (this.checkTimer) {
clearInterval(this.checkTimer);
this.checkTimer = null;
}
});
} catch (err) {
reject(err);
}
});
},
logOut(err) {
if (err.code == 50008 || err.code == 50014) {
this.url = websocketUrl + token;
this.status = false;
this.count++;
this.reconnect(this.count);
}
},
// 恢复链接
reconnect(count) {
console.info(`尝试第${count || 1}次连接.`);
this.connect().then(() => { }).catch(() => {
this.count++;
this.reconnect(this.count);
});
},
closeStompDebug() {
if (this.clientIns) {
this.clientIns.debug = undefined;
}
},
// 订阅指定的topic
subscribe(topic, onmessage, headers) {
this.topic = topic;
this.onmessage = onmessage;
this.headers = headers;
if (this.status) {
if (!this.subscribeMap) {
this.subscribeMap = new Map();
}
try {
var subscription = this.subscribeMap.get(topic);
if (!subscription) {
subscription = this.clientIns.subscribe(topic, onmessage, headers); // 接收消息通过 subscribe() 方法实现
this.subscribeMap.set(topic, subscription);
}
} catch (err) {
setTimeout(() => {
this.subscribe(topic, onmessage, headers);
}, 300);
}
} else {
setTimeout(() => {
this.subscribe(topic, onmessage, headers);
}, 300);
}
},
unsubscribe(topic) {
if (this.subscribeMap) {
const subscription = this.subscribeMap.get(topic);
if (subscription) {
subscription.unsubscribe();
this.subscribeMap.delete(topic);
console.log('取消订阅');
}
}
},
// 发送消息
send(url, msg) {
if (this.status) {
if (msg) {
msg = JSON.stringify(msg);
}
try {
this.clientIns.send(url, {}, msg);
} catch (err) {
this.status = false;
this.send(url, msg);
}
} else {
setTimeout(() => {
this.send(url, msg);
}, 300);
}
},
disconnect() {
if (this.checkTimer) {
clearInterval(this.checkTimer);
this.checkTimer = null;
}
if (this.clientIns && this.clientIns.connected) {
this.clientIns.disconnect();
this.clientIns = null;
}
this.status = false;
console.log('断开连接');
}
};
var Byte, Client, Frame, Stomp,
__hasProp = {}.hasOwnProperty,
__slice = [].slice;
Byte = {
LF: '\x0A',
NULL: '\x00'
};
Frame = (function() {
var unmarshallSingle;
function Frame(command, headers, body) {
this.command = command;
this.headers = headers != null ? headers : {};
this.body = body != null ? body : '';
}
Frame.prototype.toString = function() {
var lines, name, skipContentLength, value, _ref;
lines = [this.command];
skipContentLength = this.headers['content-length'] === false ? true : false;
if (skipContentLength) {
delete this.headers['content-length'];
}
_ref = this.headers;
for (name in _ref) {
if (!__hasProp.call(_ref, name)) continue;
value = _ref[name];
lines.push("" + name + ":" + value);
}
if (this.body && !skipContentLength) {
lines.push("content-length:" + (Frame.sizeOfUTF8(this.body)));
}
lines.push(Byte.LF + this.body);
return lines.join(Byte.LF);
};
Frame.sizeOfUTF8 = function(s) {
if (s) {
return encodeURI(s).match(/%..|./g).length;
} else {
return 0;
}
};
unmarshallSingle = function(data) {
var body, chr, command, divider, headerLines, headers, i, idx, len, line, start, trim, _i, _j, _len, _ref, _ref1;
divider = data.search(RegExp("" + Byte.LF + Byte.LF));
headerLines = data.substring(0, divider).split(Byte.LF);
command = headerLines.shift();
headers = {};
trim = function(str) {
return str.replace(/^\s+|\s+$/g, '');
};
_ref = headerLines.reverse();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
idx = line.indexOf(':');
headers[trim(line.substring(0, idx))] = trim(line.substring(idx + 1));
}
body = '';
start = divider + 2;
if (headers['content-length']) {
len = parseInt(headers['content-length']);
body = ('' + data).substring(start, start + len);
} else {
chr = null;
for (i = _j = start, _ref1 = data.length; start <= _ref1 ? _j < _ref1 : _j > _ref1; i = start <= _ref1 ? ++_j : --_j) {
chr = data.charAt(i);
if (chr === Byte.NULL) {
break;
}
body += chr;
}
}
return new Frame(command, headers, body);
};
Frame.unmarshall = function(datas) {
var data;
return (function() {
var _i, _len, _ref, _results;
_ref = datas.split(RegExp("" + Byte.NULL + Byte.LF + "*"));
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
data = _ref[_i];
if ((data != null ? data.length : void 0) > 0) {
_results.push(unmarshallSingle(data));
}
}
return _results;
})();
};
Frame.marshall = function(command, headers, body) {
var frame;
frame = new Frame(command, headers, body);
return frame.toString() + Byte.NULL;
};
return Frame;
})();
Client = (function() {
var now;
function Client(ws) {
this.ws = ws;
this.ws.binaryType = "arraybuffer";
this.counter = 0;
this.connected = false;
this.heartbeat = {
outgoing: 10000,
incoming: 10000
};
this.maxWebSocketFrameSize = 16 * 1024;
this.subscriptions = {};
}
Client.prototype.debug = function(message) {
var _ref;
return typeof window !== "undefined" && window !== null ? (_ref = window.console) != null ? _ref.log(message) : void 0 : void 0;
};
now = function() {
if (Date.now) {
return Date.now();
} else {
return new Date().valueOf;
}
};
Client.prototype._transmit = function(command, headers, body) {
var out;
out = Frame.marshall(command, headers, body);
if (typeof this.debug === "function") {
this.debug(">>> " + out);
}
while (true) {
if (out.length > this.maxWebSocketFrameSize) {
this.ws.send(out.substring(0, this.maxWebSocketFrameSize));
out = out.substring(this.maxWebSocketFrameSize);
if (typeof this.debug === "function") {
this.debug("remaining = " + out.length);
}
} else {
return this.ws.send(out);
}
}
};
Client.prototype._setupHeartbeat = function(headers) {
var serverIncoming, serverOutgoing, ttl, v, _ref, _ref1;
if ((_ref = headers.version) !== Stomp.VERSIONS.V1_1 && _ref !== Stomp.VERSIONS.V1_2) {
return;
}
_ref1 = (function() {
var _i, _len, _ref1, _results;
_ref1 = headers['heart-beat'].split(",");
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
v = _ref1[_i];
_results.push(parseInt(v));
}
return _results;
})(), serverOutgoing = _ref1[0], serverIncoming = _ref1[1];
if (!(this.heartbeat.outgoing === 0 || serverIncoming === 0)) {
ttl = Math.max(this.heartbeat.outgoing, serverIncoming);
if (typeof this.debug === "function") {
this.debug("send PING every " + ttl + "ms");
}
this.pinger = Stomp.setInterval(ttl, (function(_this) {
return function() {
_this.ws.send(Byte.LF);
return typeof _this.debug === "function" ? _this.debug(">>> PING") : void 0;
};
})(this));
}
if (!(this.heartbeat.incoming === 0 || serverOutgoing === 0)) {
ttl = Math.max(this.heartbeat.incoming, serverOutgoing);
if (typeof this.debug === "function") {
this.debug("check PONG every " + ttl + "ms");
}
return this.ponger = Stomp.setInterval(ttl, (function(_this) {
return function() {
var delta;
delta = now() - _this.serverActivity;
if (delta > ttl * 2) {
if (typeof _this.debug === "function") {
_this.debug("did not receive server activity for the last " + delta + "ms");
}
return _this.ws.close();
}
};
})(this));
}
};
Client.prototype._parseConnect = function() {
var args, connectCallback, errorCallback, headers;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
headers = {};
switch (args.length) {
case 2:
headers = args[0], connectCallback = args[1];
break;
case 3:
if (args[1] instanceof Function) {
headers = args[0], connectCallback = args[1], errorCallback = args[2];
} else {
headers.login = args[0], headers.passcode = args[1], connectCallback = args[2];
}
break;
case 4:
headers.login = args[0], headers.passcode = args[1], connectCallback = args[2], errorCallback = args[3];
break;
default:
headers.login = args[0], headers.passcode = args[1], connectCallback = args[2], errorCallback = args[3], headers.host = args[4];
}
return [headers, connectCallback, errorCallback];
};
Client.prototype.connect = function() {
var args, errorCallback, headers, out;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
out = this._parseConnect.apply(this, args);
headers = out[0], this.connectCallback = out[1], errorCallback = out[2];
if (typeof this.debug === "function") {
this.debug("Opening Web Socket...");
}
this.ws.onmessage = (function(_this) {
return function(evt) {
var arr, c, client, data, frame, messageID, onreceive, subscription, _i, _len, _ref, _results;
data = typeof ArrayBuffer !== 'undefined' && evt.data instanceof ArrayBuffer ? (arr = new Uint8Array(evt.data), typeof _this.debug === "function" ? _this.debug("--- got data length: " + arr.length) : void 0, ((function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = arr.length; _i < _len; _i++) {
c = arr[_i];
_results.push(String.fromCharCode(c));
}
return _results;
})()).join('')) : evt.data;
_this.serverActivity = now();
if (data === Byte.LF) {
if (typeof _this.debug === "function") {
_this.debug("<<< PONG");
}
return;
}
if (typeof _this.debug === "function") {
_this.debug("<<< " + data);
}
_ref = Frame.unmarshall(data);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
frame = _ref[_i];
switch (frame.command) {
case "CONNECTED":
if (typeof _this.debug === "function") {
_this.debug("connected to server " + frame.headers.server);
}
_this.connected = true;
_this._setupHeartbeat(frame.headers);
_results.push(typeof _this.connectCallback === "function" ? _this.connectCallback(frame) : void 0);
break;
case "MESSAGE":
subscription = frame.headers.subscription;
onreceive = _this.subscriptions[subscription] || _this.onreceive;
if (onreceive) {
client = _this;
messageID = frame.headers["message-id"];
frame.ack = function(headers) {
if (headers == null) {
headers = {};
}
return client.ack(messageID, subscription, headers);
};
frame.nack = function(headers) {
if (headers == null) {
headers = {};
}
return client.nack(messageID, subscription, headers);
};
_results.push(onreceive(frame));
} else {
_results.push(typeof _this.debug === "function" ? _this.debug("Unhandled received MESSAGE: " + frame) : void 0);
}
break;
case "RECEIPT":
_results.push(typeof _this.onreceipt === "function" ? _this.onreceipt(frame) : void 0);
break;
case "ERROR":
_results.push(typeof errorCallback === "function" ? errorCallback(frame) : void 0);
break;
default:
_results.push(typeof _this.debug === "function" ? _this.debug("Unhandled frame: " + frame) : void 0);
}
}
return _results;
};
})(this);
this.ws.onclose = (function(_this) {
return function() {
var msg;
msg = "Whoops! Lost connection to " + _this.ws.url;
if (typeof _this.debug === "function") {
_this.debug(msg);
}
_this._cleanUp();
return typeof errorCallback === "function" ? errorCallback(msg) : void 0;
};
})(this);
return this.ws.onopen = (function(_this) {
return function() {
if (typeof _this.debug === "function") {
_this.debug('Web Socket Opened...');
}
headers["accept-version"] = Stomp.VERSIONS.supportedVersions();
headers["heart-beat"] = [_this.heartbeat.outgoing, _this.heartbeat.incoming].join(',');
return _this._transmit("CONNECT", headers);
};
})(this);
};
Client.prototype.disconnect = function(disconnectCallback, headers) {
if (headers == null) {
headers = {};
}
this._transmit("DISCONNECT", headers);
this.ws.onclose = null;
this.ws.close();
this._cleanUp();
return typeof disconnectCallback === "function" ? disconnectCallback() : void 0;
};
Client.prototype._cleanUp = function() {
this.connected = false;
if (this.pinger) {
Stomp.clearInterval(this.pinger);
}
if (this.ponger) {
return Stomp.clearInterval(this.ponger);
}
};
Client.prototype.send = function(destination, headers, body) {
if (headers == null) {
headers = {};
}
if (body == null) {
body = '';
}
headers.destination = destination;
return this._transmit("SEND", headers, body);
};
Client.prototype.subscribe = function(destination, callback, headers) {
var client;
if (headers == null) {
headers = {};
}
if (!headers.id) {
headers.id = "sub-" + this.counter++;
}
headers.destination = destination;
this.subscriptions[headers.id] = callback;
this._transmit("SUBSCRIBE", headers);
client = this;
return {
id: headers.id,
unsubscribe: function() {
return client.unsubscribe(headers.id);
}
};
};
Client.prototype.unsubscribe = function(id) {
delete this.subscriptions[id];
return this._transmit("UNSUBSCRIBE", {
id: id
});
};
Client.prototype.begin = function(transaction) {
var client, txid;
txid = transaction || "tx-" + this.counter++;
this._transmit("BEGIN", {
transaction: txid
});
client = this;
return {
id: txid,
commit: function() {
return client.commit(txid);
},
abort: function() {
return client.abort(txid);
}
};
};
Client.prototype.commit = function(transaction) {
return this._transmit("COMMIT", {
transaction: transaction
});
};
Client.prototype.abort = function(transaction) {
return this._transmit("ABORT", {
transaction: transaction
});
};
Client.prototype.ack = function(messageID, subscription, headers) {
if (headers == null) {
headers = {};
}
headers["message-id"] = messageID;
headers.subscription = subscription;
return this._transmit("ACK", headers);
};
Client.prototype.nack = function(messageID, subscription, headers) {
if (headers == null) {
headers = {};
}
headers["message-id"] = messageID;
headers.subscription = subscription;
return this._transmit("NACK", headers);
};
return Client;
})();
Stomp = {
VERSIONS: {
V1_0: '1.0',
V1_1: '1.1',
V1_2: '1.2',
supportedVersions: function() {
return '1.1,1.0';
}
},
client: function(url, protocols) {
var klass, ws;
if (protocols == null) {
protocols = ['v10.stomp', 'v11.stomp'];
}
klass = Stomp.WebSocketClass || WebSocket;
ws = new klass(url, protocols);
return new Client(ws);
},
over: function(ws) {
return new Client(ws);
},
Frame: Frame
};
if (typeof exports !== "undefined" && exports !== null) {
exports.Stomp = Stomp;
}
if (typeof window !== "undefined" && window !== null) {
Stomp.setInterval = function(interval, f) {
return window.setInterval(f, interval);
};
Stomp.clearInterval = function(id) {
return window.clearInterval(id);
};
window.Stomp = Stomp;
}
let data = null;
let topic = null;
let header = null;
function timedCount(){
onmessage = (e) => {
// data = JSON.parse(e.data);
// // console.log(data);
// if(data.type == 'Simulation_TrainSpeed'){
//
// }else{
// postMessage(data);
// }
//
// console.log(e.data);
if(e.data.type == "init"){
topic = e.data.topic;
header = {'X-Token': e.data.token };
token = e.data.token;
websocketUrl = e.data.baseurl+'/joylink-websocket?token=';
}
if(e.data == "connect"){
let teststomp = new StompClient(header,token);
teststomp.subscribe(topic, callback, header);
}
}
function callback(Response) {
// console.log(Response);
data = JSON.parse(Response.body);
// console.log(data);
if(data.type == 'SJL3D_TrainStatus'){
for (let i=0,leni = data.body.length; i<leni; i++) {
postMessage(data.body[i]);
}
}
if(data.type == 'Simulation_DeviceStatus'){
for (let i= 0,leni = data.body.length; i<leni; i++) {
postMessage(data.body[i]);
}
}
if(data.type == 'Simulation_Reset'){
postMessage(data);
}
}
}
timedCount();

5818
static/workertest/sockjs.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long