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

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) {
const scope = this;
this.teststomp = new StompClient();
let start = true;
let topic = '/user/queue/simulation/jl3d/'+routegroup;
let header = {'X-Token': getToken() };
@ -30,11 +30,60 @@ export function PassflowConnect(deviceaction,toptrain,downtrain,routegroup,passe
function callback(Response) {
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.body.type == "PSD"){
jl3d.changespeed(30);
if(data.body.code == passerStation.nowStation.toppsd){
if(data.body.open == 0){
passerAi.passerout("top","end");

View File

@ -73,11 +73,14 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
this.mixers = [];
this.showmodel = null;
this.humanWaitIn = [];
this.humanWaitOut = [];
this.allStationData = [];
this.humanWaitTop = 0;
this.humanWaitDown = 0;
this.humanInSpeed = 0;
this.humanOutSpeed = 0;
let waitForCreatIn = [];
let waitForCreatOutTop = [];
let waitForCreatOutDown = [];
//定义相机
camerass = new THREE.PerspectiveCamera(70, dom.offsetWidth / dom.offsetHeight, 0.01, 1000);
camerass.position.set(0, 80, 40);
@ -124,8 +127,6 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
this.modelmanager = new ModelManager();
// let loadingInstance = Loading.service({ fullscreen: true });
this.nowstation = null;
let stationlist = [];
let socktest = null;
let passerStation = new PasserStation();
@ -156,12 +157,14 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
scene.add(monitor);
getPublishMapDetail(skinCode).then(netdata => {
scope.switchviews('freeview');
passerHuman.initHumans(scope.modelmanager.man1.mesh,scope.modelmanager.man2.mesh);
scene.add(humanlist);
scene.add(topWaitPassers);
scene.add(downWaitPassers);
scene.add(outStationPassers);
passerStation.initStationList(netdata.data.stationList,netdata.data.stationStandList,netdata.data.psdList);
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(){
clearInterval(checkobject);
//进站控制
startWorker();
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){
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();
}
this.changespeed = function(creatspeed){
scope.humanInSpeed = creatspeed;
updatePasserSpeed(creatspeed);
passerWebWork.postMessage(["changespeed",creatspeed/30]);
this.updateNowStationData = function(){
for(let i=0;i<passerStation.nowStation.topspeed;i++){
let newIn = {
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(){
@ -261,18 +319,20 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
// actions[an].play();
// }
setTimeout(function(){
passerAi.initPasser(humanlist,topWaitPassers,downWaitPassers,passerHuman);
passerAi.initPasser(humanlist,topWaitPassers,downWaitPassers,passerHuman,scope);
aiswitch = 0;
}, 2000);
}
function startWorker(){
passerAi.initPasser(humanlist,topWaitPassers,downWaitPassers,passerHuman);
let updateaianimate = setInterval(
function(){
// console.log("?");
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);
passerAi.aiUpdate(humanlist,topWaitPassers,downWaitPassers,outStationPassers,passerHuman,passerCheckDoor,deviceaction);
// passerZone.zoneActionCheck(humanlist,passerHuman,passerCheckDoor,deviceaction);
@ -310,38 +370,20 @@ export function Jl3dTrafficPlan(dom,skinCode,routegroup,viewMap) {
passerWebWork.onmessage = function (event) {
if(aiswitch == 0){
// 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;
//1--top
//2-- down
if(direct == 1){
passerHuman.newHumanCreate(humanlist,passerZone.getzoneposition("enter1"),0);
if(direct == 1){
passerHuman.newHumanCreate(humanlist,passerZone.getzoneposition("enter1"),0,waitForCreatIn[0].overGoal);
}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);
}
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;
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;
if(mantype == 1){
@ -61,6 +61,10 @@ export function PasserHuman() {
let mixer = new THREE.AnimationMixer( newhuman );
newhuman.position.copy(position);
if(overGoal){
newhuman.overGoal = overGoal;
}
if(newhuman.direct == "top"){
newhuman.rotation.y = Math.PI;
}

View File

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

View File

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

View File

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

View File

@ -2,15 +2,10 @@ export function getBaseUrl() {
let BASE_API;
if (process.env.NODE_ENV === 'development') {
// 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'; // 袁琪
<<<<<<< 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.114:9000'; // 旭强
// BASE_API = 'http://192.168.8.119:9000'; // 张赛
>>>>>>> db3660a0eb4a43be2f1a1d92596ec156b7bda701
// BASE_API = 'http://192.168.8.110:9000'; // 杜康
// BASE_API = 'http://b29z135112.zicp.vip';
// BASE_API = 'http://2925963m2a.zicp.vip'; // 杜康

View File

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

View File

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