增加三维客流站台通信逻辑

This commit is contained in:
sunzhenyu 2020-11-13 09:36:14 +08:00
parent 6ef0a46870
commit eb6151db35
9 changed files with 184 additions and 75 deletions

View File

@ -7,7 +7,7 @@ import store from '@/store/index_APP_TARGET';
export function PassflowConnect(deviceaction,toptrain,downtrain,routegroup,passerStation,passerAi,jl3d) { export function PassflowConnect(deviceaction,toptrain,downtrain,routegroup,passerStation,passerAi,jl3d) {
const scope = this; const scope = this;
this.teststomp = new StompClient(); this.teststomp = new StompClient();
let start = true;
let topic = '/user/queue/simulation/jl3d/'+routegroup; let topic = '/user/queue/simulation/jl3d/'+routegroup;
let header = {'X-Token': getToken() }; let header = {'X-Token': getToken() };
@ -30,11 +30,60 @@ export function PassflowConnect(deviceaction,toptrain,downtrain,routegroup,passe
function callback(Response) { function callback(Response) {
const data = JSON.parse(Response.body); const data = JSON.parse(Response.body);
// console.log(data);
/** 站台客流当前人数信息 */
if(data.type == "STAND_PFI"){
let newStandData = data.body;
let count = 0;
for(let j=0;j<passerStation.stationlist.length;j++){
count = 0;
for(let i=0;i<newStandData.length;i++){
if(passerStation.stationlist[j].topstand == newStandData[i].standCode){
passerStation.stationlist[j].topspeed = newStandData[i].to;
passerStation.stationlist[j].toppassers = newStandData[i].num;
count++;
}
if(passerStation.stationlist[j].downstand == newStandData[i].standCode){
passerStation.stationlist[j].downspeed = newStandData[i].to;
passerStation.stationlist[j].downpassers = newStandData[i].num;
count++;
}
if(count == 2){
i = newStandData.length;
}
}
}
jl3d.updateNowStationData();
if(start){
start = false;
jl3d.initTrafficStart();
}
// jl3d.allStationData = data.body;
}
if(data.type == "TRAIN_PFI_BL"){
if(toptrain.nowcode == data.body.code){
console.log(data);
//根据上下车人数创建人
jl3d.updateNowLeaveData("top",data.body.out);
}
if(downtrain.nowcode == data.body.code){
console.log(data);
//根据上下车人数创建人
jl3d.updateNowLeaveData("down",data.body.out);
}
}
if(data.type == "DeviceCtrl_3D"){ if(data.type == "DeviceCtrl_3D"){
if(data.body.type == "PSD"){ if(data.body.type == "PSD"){
jl3d.changespeed(30);
if(data.body.code == passerStation.nowStation.toppsd){ if(data.body.code == passerStation.nowStation.toppsd){
if(data.body.open == 0){ if(data.body.open == 0){
passerAi.passerout("top","end"); passerAi.passerout("top","end");

View File

@ -73,11 +73,14 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
this.mixers = []; this.mixers = [];
this.showmodel = null; this.showmodel = null;
this.humanWaitIn = []; this.allStationData = [];
this.humanWaitOut = []; this.humanWaitTop = 0;
this.humanWaitDown = 0;
this.humanInSpeed = 0; this.humanInSpeed = 0;
this.humanOutSpeed = 0; this.humanOutSpeed = 0;
let waitForCreatIn = [];
let waitForCreatOutTop = [];
let waitForCreatOutDown = [];
//定义相机 //定义相机
camerass = new THREE.PerspectiveCamera(70, dom.offsetWidth / dom.offsetHeight, 0.01, 1000); camerass = new THREE.PerspectiveCamera(70, dom.offsetWidth / dom.offsetHeight, 0.01, 1000);
camerass.position.set(0, 80, 40); camerass.position.set(0, 80, 40);
@ -124,8 +127,6 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
this.modelmanager = new ModelManager(); this.modelmanager = new ModelManager();
// let loadingInstance = Loading.service({ fullscreen: true }); // let loadingInstance = Loading.service({ fullscreen: true });
this.nowstation = null;
let stationlist = []; let stationlist = [];
let socktest = null; let socktest = null;
let passerStation = new PasserStation(); let passerStation = new PasserStation();
@ -156,12 +157,14 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
scene.add(monitor); scene.add(monitor);
getPublishMapDetail(skinCode).then(netdata => { getPublishMapDetail(skinCode).then(netdata => {
scope.switchviews('freeview'); scope.switchviews('freeview');
passerHuman.initHumans(scope.modelmanager.man1.mesh,scope.modelmanager.man2.mesh); passerHuman.initHumans(scope.modelmanager.man1.mesh,scope.modelmanager.man2.mesh);
scene.add(humanlist); scene.add(humanlist);
scene.add(topWaitPassers); scene.add(topWaitPassers);
scene.add(downWaitPassers); scene.add(downWaitPassers);
scene.add(outStationPassers); scene.add(outStationPassers);
passerStation.initStationList(netdata.data.stationList,netdata.data.stationStandList,netdata.data.psdList); passerStation.initStationList(netdata.data.stationList,netdata.data.stationStandList,netdata.data.psdList);
socktest = new PassflowConnect(deviceaction,passerTrain.toptrain,passerTrain.downtrain,routegroup,passerStation,passerAi,scope); socktest = new PassflowConnect(deviceaction,passerTrain.toptrain,passerTrain.downtrain,routegroup,passerStation,passerAi,scope);
@ -170,6 +173,7 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
let checkobject = setInterval(function(){ let checkobject = setInterval(function(){
clearInterval(checkobject); clearInterval(checkobject);
//进站控制 //进站控制
startWorker(); startWorker();
passerWebWork.postMessage(["on"]); passerWebWork.postMessage(["on"]);
@ -180,15 +184,69 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
}) })
}); });
this.initTrafficStart = function(){
scope.humanWaitTop = passerStation.nowStation.toppassers;
scope.humanWaitDown = passerStation.nowStation.downpassers;
scope.humanInSpeed = 0;
scope.humanOutSpeed = 0;
passerHuman.speed = scope.humanInSpeed;
passerAi.initPasser(humanlist,topWaitPassers,downWaitPassers,passerHuman,scope);
updatePasserData(humanlist.children.length,topWaitPassers.children.length,downWaitPassers.children.length,outStationPassers.children.length,passerHuman.speed);
}
this.changestation = function(stationname){ this.changestation = function(stationname){
passerStation.changestation(stationname); passerStation.changestation(stationname);
scope.humanWaitTop = passerStation.nowStation.toppassers;
scope.humanWaitDown = passerStation.nowStation.downpassers;
passerHuman.speed = passerStation.nowStation.topspeed + passerStation.nowStation.downspeed;
updatePasserData(humanlist.children.length,topWaitPassers.children.length,downWaitPassers.children.length,outStationPassers.children.length,passerHuman.speed);
scope.resetscene(); scope.resetscene();
} }
this.changespeed = function(creatspeed){ this.updateNowStationData = function(){
scope.humanInSpeed = creatspeed; for(let i=0;i<passerStation.nowStation.topspeed;i++){
updatePasserSpeed(creatspeed); let newIn = {
passerWebWork.postMessage(["changespeed",creatspeed/30]); overGoal:"top",
};
waitForCreatIn.push(newIn);
}
for(let i=0;i<passerStation.nowStation.downspeed;i++){
let newIn = {
overGoal:"down",
};
waitForCreatIn.push(newIn);
}
scope.humanInSpeed = passerStation.nowStation.topspeed+passerStation.nowStation.downspeed;
passerHuman.speed = scope.humanInSpeed;
passerWebWork.postMessage(["changespeed",scope.humanInSpeed/30]);
}
this.updateNowLeaveData = function(direct,outNum){
if(direct == "top"){
waitForCreatOutTop = getnum(outNum,17);
console.log(waitForCreatOutTop);
for(let i=0;i<waitForCreatOutTop.length;i++){
for(let j=0;j<waitForCreatOutTop[i];j++){
setTimeout(function(){
passerHuman.newHumanCreate(outStationPassers,passerZone.list["standtop"].doorpoints[i],5,"top",i);
}, Math.random()*1000*j);
}
}
}else{
waitForCreatOutDown = getnum(outNum,17);
for(let i=0;i<waitForCreatOutDown.length;i++){
for(let j=0;j<waitForCreatOutDown[i];j++){
setTimeout(function(){
passerHuman.newHumanCreate(outStationPassers,passerZone.list["standdown"].doorpoints[j],5,"down",j);
}, Math.random()*1000*i);
}
}
}
} }
this.resetscene = function(){ this.resetscene = function(){
@ -261,18 +319,20 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
// actions[an].play(); // actions[an].play();
// } // }
setTimeout(function(){ setTimeout(function(){
passerAi.initPasser(humanlist,topWaitPassers,downWaitPassers,passerHuman); passerAi.initPasser(humanlist,topWaitPassers,downWaitPassers,passerHuman,scope);
aiswitch = 0; aiswitch = 0;
}, 2000); }, 2000);
} }
function startWorker(){ function startWorker(){
passerAi.initPasser(humanlist,topWaitPassers,downWaitPassers,passerHuman);
let updateaianimate = setInterval( let updateaianimate = setInterval(
function(){ function(){
// console.log("?"); // console.log("?");
if(aiswitch == 0){ if(aiswitch == 0){
updatePasserData(humanlist.children.length,topWaitPassers.children.length,downWaitPassers.children.length,outStationPassers.children.length,passerHuman.speed);
passerHuman.moveAnimateUpdate(humanlist,topWaitPassers,downWaitPassers,outStationPassers,passerHuman); passerHuman.moveAnimateUpdate(humanlist,topWaitPassers,downWaitPassers,outStationPassers,passerHuman);
passerAi.aiUpdate(humanlist,topWaitPassers,downWaitPassers,outStationPassers,passerHuman,passerCheckDoor,deviceaction); passerAi.aiUpdate(humanlist,topWaitPassers,downWaitPassers,outStationPassers,passerHuman,passerCheckDoor,deviceaction);
// passerZone.zoneActionCheck(humanlist,passerHuman,passerCheckDoor,deviceaction); // passerZone.zoneActionCheck(humanlist,passerHuman,passerCheckDoor,deviceaction);
@ -310,38 +370,20 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
passerWebWork.onmessage = function (event) { passerWebWork.onmessage = function (event) {
if(aiswitch == 0){ if(aiswitch == 0){
// console.log(humanlist.children.length); // console.log(humanlist.children.length);
updatePasserData(humanlist.children.length,topWaitPassers.children.length,downWaitPassers.children.length,outStationPassers.children.length);
if(humanlist.children.length < 100){ this.allStationData = [];
console.log("create");
if(waitForCreatIn.length>0){
let direct = Math.floor(Math.random()*(3-1+1))+1; let direct = Math.floor(Math.random()*(3-1+1))+1;
//1--top //1--top
//2-- down //2-- down
if(direct == 1){ if(direct == 1){
passerHuman.newHumanCreate(humanlist,passerZone.getzoneposition("enter1"),0); passerHuman.newHumanCreate(humanlist,passerZone.getzoneposition("enter1"),0,waitForCreatIn[0].overGoal);
}else{ }else{
passerHuman.newHumanCreate(humanlist,passerZone.getzoneposition("enter2"),0); passerHuman.newHumanCreate(humanlist,passerZone.getzoneposition("enter2"),0,waitForCreatIn[0].overGoal);
} }
waitForCreatIn.shift();
} }
if(outStationPassers.children.length < 100){
if(passerAi.toppasseron){
for(let i=0,leni=passerZone.list["standtop"].doorpoints.length;i<leni;i++ ){
setTimeout(function(){
passerHuman.newHumanCreate(outStationPassers,passerZone.list["standtop"].doorpoints[i],5,"top",i);
}, Math.random()*1000);
}
}
if(passerAi.downpasseron){
for(let i=0,leni=passerZone.list["standdown"].doorpoints.length;i<leni;i++ ){
setTimeout(function(){
passerHuman.newHumanCreate(outStationPassers,passerZone.list["standdown"].doorpoints[i],5,"down",i);
}, Math.random()*1000);
}
}
}
} }
}; };
} }
@ -384,4 +426,15 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
passerRender.changeRenderMode(viewmode); passerRender.changeRenderMode(viewmode);
} }
function getnum(num,pnum){
let re = [];
let base = Math.floor(num/pnum);
let reset = num%pnum;
for(let i=0;i<pnum;i++){
let nownum = base+(i<reset?1:0);
re.push(nownum);
}
return re;
}
} }

View File

@ -40,12 +40,12 @@ export function PasserHuman() {
} }
//创建新的乘客 //创建新的乘客
this.newHumanCreate = function(humanlist,position,stage,direct,door){ this.newHumanCreate = function(humanlist,position,stage,direct,door,overGoal){
let newhuman; let newhuman;
createHumanModel(newhuman,humanlist,position,stage,direct,door); createHumanModel(newhuman,humanlist,position,stage,direct,door,overGoal);
} }
function createHumanModel(newhuman,humanlist,position,stage,direct,door){ function createHumanModel(newhuman,humanlist,position,stage,direct,door,overGoal){
let mantype = Math.floor(Math.random()*(3-1+1))+1; let mantype = Math.floor(Math.random()*(3-1+1))+1;
if(mantype == 1){ if(mantype == 1){
@ -60,6 +60,10 @@ export function PasserHuman() {
let mixer = new THREE.AnimationMixer( newhuman ); let mixer = new THREE.AnimationMixer( newhuman );
newhuman.position.copy(position); newhuman.position.copy(position);
if(overGoal){
newhuman.overGoal = overGoal;
}
if(newhuman.direct == "top"){ if(newhuman.direct == "top"){
newhuman.rotation.y = Math.PI; newhuman.rotation.y = Math.PI;

View File

@ -10,7 +10,7 @@ export function PasserStation() {
this.stationlist = []; this.stationlist = [];
this.nowStation = null; this.nowStation = "";
for(let i=0;i<22;i++){ for(let i=0;i<22;i++){
let sl = { let sl = {
@ -117,21 +117,31 @@ export function PasserStation() {
let stationobject = { let stationobject = {
code : list[k][0].stationCode, code : list[k][0].stationCode,
name : k, name : k,
topspeed:0,
downspeed:0,
toppassers:0,
downpassers:0,
toppsd:null, toppsd:null,
downpsd:null, downpsd:null,
topsection:null, topsection:null,
downsection:null, downsection:null,
topstand:null,
downstand:null
}; };
if(list[k][0].position.y<list[k][1].position.y){ if(list[k][0].position.y<list[k][1].position.y){
stationobject.toppsd = list[k][0].name; stationobject.toppsd = list[k][0].name;
stationobject.downpsd = list[k][1].name; stationobject.downpsd = list[k][1].name;
stationobject.topsection = list[k][0].standTrackCode; stationobject.topsection = list[k][0].standTrackCode;
stationobject.downsection = list[k][1].standTrackCode; stationobject.downsection = list[k][1].standTrackCode;
stationobject.topstand = list[k][0].code;
stationobject.downstand = list[k][1].code;
}else{ }else{
stationobject.toppsd = list[k][1].name; stationobject.toppsd = list[k][1].name;
stationobject.downpsd = list[k][0].name; stationobject.downpsd = list[k][0].name;
stationobject.topsection = list[k][1].standTrackCode; stationobject.topsection = list[k][1].standTrackCode;
stationobject.downsection = list[k][0].standTrackCode; stationobject.downsection = list[k][0].standTrackCode;
stationobject.topstand = list[k][1].code;
stationobject.downstand = list[k][0].code;
} }
scope.stationlist.push(stationobject); scope.stationlist.push(stationobject);
} }

View File

@ -6,7 +6,7 @@ export function PasserHuman() {
this.nowTrunk = ""; this.nowTrunk = "";
this.speed = "0";
//初始人物模型和动画 //初始人物模型和动画
let originhuman1 = null; let originhuman1 = null;

View File

@ -60,25 +60,14 @@ export function PasserAi(zone,finder) {
} }
//初始化加载人物 //初始化加载人物
this.initPasser = function(humanlist,topWaitPassers,downWaitPassers,passerHuman){ this.initPasser = function(humanlist,topWaitPassers,downWaitPassers,passerHuman,jl3d){
for(let i=0;i<3;i++){
passerHuman.newHumanCreate(humanlist,passerZone.getinitposition("enter1"),0);
} for(let i=0;i<jl3d.humanWaitTop;i++){
for(let i=0;i<3;i++){
passerHuman.newHumanCreate(humanlist,passerZone.getinitposition("enter2"),0);
}
for(let i=0;i<3;i++){
passerHuman.newHumanCreate(humanlist,passerZone.getinitposition("security"),1);
}
// for(let i=0;i<2;i++){
// // passerHuman.newHumanCreate(humanlist,passerZone.getinitposition("entergate"),3);
// }
for(let i=0;i<6;i++){
let standdata = passerZone.getstandposition("standtop"); let standdata = passerZone.getstandposition("standtop");
passerHuman.newHumanCreate(topWaitPassers,standdata.point,4,"top",standdata.door); passerHuman.newHumanCreate(topWaitPassers,standdata.point,4,"top",standdata.door);
} }
for(let i=0;i<6;i++){ for(let i=0;i<jl3d.humanWaitDown;i++){
let standdata = passerZone.getstandposition("standdown"); let standdata = passerZone.getstandposition("standdown");
passerHuman.newHumanCreate(downWaitPassers,standdata.point,4,"down",standdata.door); passerHuman.newHumanCreate(downWaitPassers,standdata.point,4,"down",standdata.door);
} }
@ -243,7 +232,7 @@ export function PasserAi(zone,finder) {
//1--top //1--top
//2-- down //2-- down
if(direct == 1){ if(humanlist.children[i].overGoal == "top"){
targetPosition = passerZone.getstandposition("standtop"); targetPosition = passerZone.getstandposition("standtop");
path = pathFinder.find(points[0],targetPosition.point); path = pathFinder.find(points[0],targetPosition.point);
humanlist.children[i].direct = "top"; humanlist.children[i].direct = "top";

View File

@ -2,15 +2,10 @@ export function getBaseUrl() {
let BASE_API; let BASE_API;
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
// BASE_API = 'https://joylink.club/jlcloud'; // BASE_API = 'https://joylink.club/jlcloud';
// BASE_API = 'https://test.joylink.club/jlcloud'; BASE_API = 'https://test.joylink.club/jlcloud';
// BASE_API = 'http://192.168.8.107:9000'; // 袁琪 // BASE_API = 'http://192.168.8.107:9000'; // 袁琪
<<<<<<< HEAD // BASE_API = 'http://192.168.8.129:9000'; // 旭强
BASE_API = 'http://192.168.8.129:9000'; // 旭强
// BASE_API = 'http://192.168.8.109:9000'; // 张赛 // BASE_API = 'http://192.168.8.109:9000'; // 张赛
=======
// BASE_API = 'http://192.168.8.114:9000'; // 旭强
// BASE_API = 'http://192.168.8.119:9000'; // 张赛
>>>>>>> db3660a0eb4a43be2f1a1d92596ec156b7bda701
// BASE_API = 'http://192.168.8.110:9000'; // 杜康 // BASE_API = 'http://192.168.8.110:9000'; // 杜康
// BASE_API = 'http://b29z135112.zicp.vip'; // BASE_API = 'http://b29z135112.zicp.vip';
// BASE_API = 'http://2925963m2a.zicp.vip'; // 杜康 // BASE_API = 'http://2925963m2a.zicp.vip'; // 杜康

View File

@ -71,7 +71,7 @@ export default {
allPassers:"30人", allPassers:"30人",
topWaitPassers:"12人", topWaitPassers:"12人",
downWaitPassers:"13人", downWaitPassers:"13人",
nowInStationPassers:"15 人/30s", nowInStationPassers:"0 人/30s",
nowOutStationPassers:"0 人", nowOutStationPassers:"0 人",
} }
}, },
@ -89,15 +89,18 @@ export default {
handleClose(key, keyPath) { handleClose(key, keyPath) {
console.log(key, keyPath); console.log(key, keyPath);
}, },
updatePasserData(humanlistdata,topWaitPassersdata,downWaitPassersdata,outStationPassersdata){ updatePasserData(humanlistdata,topWaitPassersdata,downWaitPassersdata,outStationPassersdata,speed){
this.topWaitPassers = topWaitPassersdata+"人"; this.topWaitPassers = topWaitPassersdata+"人";
this.downWaitPassers = downWaitPassersdata+"人"; this.downWaitPassers = downWaitPassersdata+"人";
// this.nowOutStationPassers = outStationPassersdata+""; // this.nowOutStationPassers = outStationPassersdata+"";
if(speed == undefined){
this.nowInStationPassers = 0 + "人/30s";
}else{
this.nowInStationPassers = speed + "人/30s";
}
this.allPassers = humanlistdata+topWaitPassersdata+downWaitPassersdata+outStationPassersdata+"人"; this.allPassers = humanlistdata+topWaitPassersdata+downWaitPassersdata+outStationPassersdata+"人";
}, },
updatePasserSpeed(data){
this.nowInStationPassers = data+"人/30s";
},
updatePasserOut(data){ updatePasserOut(data){
}, },
@ -105,7 +108,6 @@ export default {
mounted() { mounted() {
//this.init(); //this.init();
window.updatePasserData = this.updatePasserData; window.updatePasserData = this.updatePasserData;
window.updatePasserSpeed = this.updatePasserSpeed;
} }
} }
</script> </script>

View File

@ -7,7 +7,7 @@ function timedCount(){
if(e.data[0] == "on"){ if(e.data[0] == "on"){
// console.log("on"); // console.log("on");
update = setInterval("stationupdate()", 2000); update = "1";
} }
if(e.data[0] == "off"){ if(e.data[0] == "off"){
@ -16,9 +16,16 @@ function timedCount(){
// console.log(e.data); // console.log(e.data);
if(e.data[0] == "changespeed"){ if(e.data[0] == "changespeed"){
if(update){ if(update){
console.log(e.data[1]);
clearInterval(update); clearInterval(update);
let speed = 1000/e.data[1]; if(e.data[1] == 0){
update = setInterval("stationupdate()", speed);
}else{
let speed = 900/e.data[1];
console.log(speed);
update = setInterval("stationupdate()", speed);
}
} }
} }