修改三维客流人物坐动画,修改重置动作bug

This commit is contained in:
sunzhenyu 2020-12-01 10:26:15 +08:00
parent e44138953a
commit 01993cf65e
7 changed files with 214 additions and 81 deletions

View File

@ -112,7 +112,7 @@ export function Jl3dTrafficTrain(dom,skinCode,routegroup,viewMap,initCode) {
camerass.position.z = -0.016;
controls.target = new THREE.Vector3(camerass.position.x+0.5,camerass.position.y-0.1,camerass.position.z);
controls.update();
controls.enabled = false;
// controls.enabled = false;
this.selectmodel = null;
// let mouse = new THREE.Vector2();
@ -140,17 +140,19 @@ export function Jl3dTrafficTrain(dom,skinCode,routegroup,viewMap,initCode) {
passerTrain.toptrain.position.x = 0;
passerTrain.toptrain.position.y = 0;
passerTrain.toptrain.position.z = 0;
// passerTrain.downtrain.position.z = 40;
getPublishMapDetail(skinCode).then(netdata => {
scope.switchviews('freeview');
passerHuman.initHumans(scope.modelmanager.man1.mesh,scope.modelmanager.man2.mesh);
passerHuman.init(scope.modelmanager.man1.mesh,scope.modelmanager.man2.mesh,scope.modelmanager.seat.mesh);
scene.add(humanlist);
socktest = new TrainConnect(scope,deviceaction,passerTrain.toptrain,routegroup,passerAi);
store.dispatch('app/animationsClose');
let checkobject = setInterval(function(){
store.dispatch('app/animationsClose');
clearInterval(checkobject);
//进站控制
@ -339,6 +341,7 @@ export function Jl3dTrafficTrain(dom,skinCode,routegroup,viewMap,initCode) {
let trainDataList = getnum(scope.trainList[k].num,6);
// nowTrunk.code = newCode;
scope.nowTrunk.numList = trainDataList;
scope.trainList[k].text = k+"(现有乘客"+scope.trainList[k].num+"人)";
updateTrainNum(trainDataList);
}
// i = scope.trainList.length;

View File

@ -67,6 +67,14 @@ export function ModelManager(){
action:null
};
this.seat = {
code:null,
screenDoorOpenStatus:"01",
animations:null,
mesh:null,
action:null
};
//读取模型
this.loadpromise = function (data,mixers,loadmode){
mode = loadmode;
@ -96,6 +104,9 @@ export function ModelManager(){
if(data[i].type == "cctvSection"){
initlist.push(fbxpromise(data[i],mixers,scope.section));
}
if(data[i].type == "seat"){
initlist.push(fbxpromise(data[i],mixers,scope.seat));
}
}
//promise按顺序加载
return new Promise(function(resolve, reject){

View File

@ -5,14 +5,14 @@ var Staticmodel = [
name: "人物1",
deviceType: "man1",
type: "man1",
url: BASE_ASSET_API + "/MODEL/2020-07-16/1-9933.FBX"
url: BASE_ASSET_API + "/MODEL/2020-11-30/447-44484.fbx"
},
{
id: "2",
name: "人物2",
deviceType: "man2",
type: "man2",
url: BASE_ASSET_API + "/MODEL/2020-07-16/2-87850.FBX"
url: BASE_ASSET_API + "/MODEL/2020-11-30/448-11525.fbx"
},
{
id: "7",
@ -21,6 +21,14 @@ var Staticmodel = [
type: "cctvTrain",
url: BASE_ASSET_API + "/MODEL/2020-11-16/48-14909.FBX"
},
{
id: "8",
name: "seat",
deviceType: "seat",
type: "seat",
url: JL3D_LOCAL_STATIC + "/trafficplan/seatposition.FBX"
},
];

View File

@ -4,7 +4,7 @@ export function PasserHuman() {
let trunkManager = new PasserTrunkManager();
let waitGroup = new THREE.Group();
this.nowTrunk = "";
this.nowTrunk = 0+'';
this.speed = "0";
@ -14,7 +14,7 @@ export function PasserHuman() {
let originanima1 = null;
let originanima2 = null;
//初始化人物模型动画
this.initHumans = function(object1,object2,mixers,deviceaction,scene){
this.init = function(object1,object2,seatmesh,mixers,deviceaction,scene){
originhuman1 = object1;
originhuman1.progress = 1;
// scene.add(originhuman1);
@ -22,38 +22,22 @@ export function PasserHuman() {
let mixer1 = new THREE.AnimationMixer( originhuman1 );
let mixer2 = new THREE.AnimationMixer( originhuman2 );
originanima1 = originhuman1.animations[ 0 ];
originanima2 = originhuman2.animations[ 0 ];
originanima1 = originhuman1.animations;
originanima2 = originhuman2.animations;
originhuman1.remove(originhuman1.children[2]);
for(let i=0;i<220;i++){
let newhuman;
createHumanModel(newhuman,waitGroup,mixers,new THREE.Vector3(0,0,0));
}
for(let i=0;i<seatmesh.children.length;i++){
seatmesh.children[i].position.x = -seatmesh.children[i].position.x;
}
trunkManager.initTrunkSeat(seatmesh);
// console.log(waitGroup);
}
//创建新的进站乘客
// this.newInHuman= function(humanlist,position){
// if(scope.humanWaitIn.length != 0){
// let newhuman;
// createHumanModel(newhuman,humanlist,position,scope.humanWaitIn[0].stage,scope.humanWaitIn[0].direct,scope.humanWaitIn[0].door);
// scope.humanWaitIn.shift();
// }
// }
// //创建新的出站乘客
// this.newOutHuman = function(humanlist,position){
// if(scope.humanWaitOut.length != 0){
// let newhuman;
// createHumanModel(newhuman,humanlist,position,scope.humanWaitOut[0].stage,scope.humanWaitOut[0].direct,scope.humanWaitOut[0].door);
// scope.humanWaitOut.shift();
// }
//
// }
//创建新的乘客
// this.newHumanCreate = function(humanlist,position,stage,direct,door){
// let newhuman;
// createHumanModel(newhuman,humanlist,position,stage,direct,door);
// }
function createHumanModel(newhuman,humanlist,mixers,position,stage,direct,door){
let mantype = Math.floor(Math.random()*(3-1+1))+1;
@ -61,13 +45,14 @@ export function PasserHuman() {
if(mantype == 1){
newhuman = THREE.SkeletonUtils.clone( originhuman1 );
newhuman.animations = [];
newhuman.animations.push(originanima1.clone());
newhuman.animations.push(originanima1[0].clone());
newhuman.animations.push(originanima1[1].clone());
}else{
newhuman = THREE.SkeletonUtils.clone( originhuman2 );
newhuman.animations = [];
newhuman.animations.push(originanima2.clone());
newhuman.animations.push(originanima2[0].clone());
newhuman.animations.push(originanima2[1].clone());
}
let mixer = new THREE.AnimationMixer( newhuman );
newhuman.position.copy(position);
@ -89,8 +74,20 @@ export function PasserHuman() {
}else{
newhuman.door = null;
}
newhuman.seat = null;
newhuman.progress = 1;
newhuman.action = mixer.clipAction( newhuman.animations[ 0 ] );
for(let i=0;i<2;i++){
if(newhuman.animations[i].name == "walk"){
newhuman.action = mixer.clipAction( newhuman.animations[ i ] );
}
if(newhuman.animations[i].name == "SITDOWN"){
newhuman.actionDown = mixer.clipAction( newhuman.animations[ i ] );
newhuman.actionDown.setLoop(THREE.LoopOnce);
newhuman.actionDown.clampWhenFinished = true;
}
}
// newhuman.action = mixer.clipAction( newhuman.animations[ 0 ] );
newhuman.mixer = mixer;
newhuman.runrail = null;
newhuman.speed = 0;
@ -108,7 +105,7 @@ export function PasserHuman() {
// enable当前动画开关
// speed动画速度
// console.log(curve);
model.actionDown.stop();
model.action.play();
model.progress = 0;
model.runrail = curve;
@ -121,6 +118,10 @@ export function PasserHuman() {
//更新模型坐标
humanlist.children[i].progress = 1;
humanlist.children[i].action.stop();
if(humanlist.children[i].seat){
humanlist.children[i].actionDown.play();
}
if(humanlist.children[i].status == 1){
@ -154,8 +155,13 @@ export function PasserHuman() {
this.resetPasser = function(humanlist){
let passerlength = humanlist.children.length;
for(let i=0;i<passerlength;i++){
humanlist.children[0].actionDown.stop();
// humanlist.children[0].action.play();
// humanlist.children[0].action.stop();
humanlist.children[0].seat = null;
waitGroup.add(humanlist.children[0]);
}
trunkManager.reSeats(scope.nowTrunk);
}
this.initTrainRail = function(humanlist,inNum,leaveNum,direct){
@ -165,16 +171,6 @@ export function PasserHuman() {
// console.log(inPasser);
// console.log(outPasser);
// let outPassers = inNum[scope.nowTrunk].num;
for(let i=0;i<inPasser.length;i++){
for(let j=0;j<inPasser[i];j++){
setTimeout(function(){
scope.createInPasser(humanlist,direct);
}, Math.random()*1000*i);
}
}
let created = 0;
for(let i=0;i<outPasser.length;i++){
for(let j=0;j<outPasser[i];j++){
@ -185,16 +181,32 @@ export function PasserHuman() {
}
}
for(let i=0;i<inPasser.length;i++){
for(let j=0;j<inPasser[i];j++){
setTimeout(function(){
scope.createInPasser(humanlist,direct);
}, Math.random()*1000*i);
}
}
}
this.createInPasser = function(humanlist,direct){
waitGroup.children[0].progress = 0;
waitGroup.children[0].status = 0;
waitGroup.children[0].actionDown.stop();
waitGroup.children[0].action.play();
let points = [];
let point1 = trunkManager.getDoorRandomPos(scope.nowTrunk,direct);
let overpoint = trunkManager.getTrunkRandomPos(scope.nowTrunk);
waitGroup.children[0].position.copy(point1);
points.push(point1);
if(direct == 1){
@ -203,7 +215,18 @@ export function PasserHuman() {
points.push(new THREE.Vector3(point1.x,point1.y,point1.z-0.5));
}
let newPos = trunkManager.getSeatRandomPos(scope.nowTrunk);
if(newPos){
waitGroup.children[0].seat = newPos.seat;
points.push(newPos.pos[0]);
points.push(newPos.pos[1]);
}else{
waitGroup.children[0].seat = null;
let overpoint = trunkManager.getTrunkRandomPos(scope.nowTrunk);
points.push(overpoint);
}
let curve = new THREE.CatmullRomCurve3(points);
@ -217,10 +240,14 @@ export function PasserHuman() {
humanlist.children[created].progress = 0;
humanlist.children[created].status = 1;
humanlist.children[created].actionDown.stop();
humanlist.children[created].action.play();
let points = [];
let point1 = new THREE.Vector3(humanlist.children[created].position.x,humanlist.children[created].position.y,humanlist.children[created].position.z);
if(humanlist.children[created].seat){
trunkManager.reSeat(scope.nowTrunk,humanlist.children[created].seat)
}
let overpoint = trunkManager.getDoorRandomPos(scope.nowTrunk,direct);
points.push(point1);
@ -239,13 +266,41 @@ export function PasserHuman() {
}
this.setNowTrunkPasser = function(humanlist,num,trunknum){
// let array = getnum(num,6);
// console.log(array);
// console.log(trunknum);
if(num){
// for(let i=0;i<array.length;i++){
// console.log(trunkManager.trunk[trunknum].seats);
for(let j=0;j<num;j++){
if(j<trunkManager.trunk[trunknum].seats.length){
let newPos = trunkManager.getSeatRandomPos(trunknum);
waitGroup.children[0].seat = newPos.seat;
waitGroup.children[0].zone = trunkManager.trunk[trunknum].name;
waitGroup.children[0].position.x = newPos.pos[0].x;
waitGroup.children[0].position.y = newPos.pos[0].y;
if(newPos.pos[0].z<0){
waitGroup.children[0].position.z = newPos.pos[0].z+0.4;
waitGroup.children[0].rotation.y = 0;
}else{
waitGroup.children[0].position.z = newPos.pos[0].z-0.4;
waitGroup.children[0].rotation.y = Math.PI;
}
// console.log(waitGroup.children[0].actionDown);
// waitGroup.children[0].actionDown.play();
waitGroup.children[0].action.stop();
waitGroup.children[0].actionDown.reset();
waitGroup.children[0].actionDown.time = waitGroup.children[0].actionDown._clip.duration;
waitGroup.children[0].actionDown.timeScale = 1;
waitGroup.children[0].actionDown.play();
}else{
let pos = trunkManager.getTrunkRandomPos(trunknum);
waitGroup.children[0].seat = null;
waitGroup.children[0].zone = trunkManager.trunk[trunknum].name;
waitGroup.children[0].position.x = pos.x;
waitGroup.children[0].position.y = pos.y;
@ -256,6 +311,8 @@ export function PasserHuman() {
}else{
waitGroup.children[0].rotation.y = 0;
}
}
humanlist.add(waitGroup.children[0]);
}
// }

View File

@ -16,6 +16,7 @@ export function PasserTrunkManager(data) {
new THREE.Vector3(11.6,1.22,1.6),
new THREE.Vector3(16,1.22,1.6)
],
seats:null,
},
{
name:"trunk2",
@ -31,6 +32,7 @@ export function PasserTrunkManager(data) {
new THREE.Vector3(33,1.22,1.6),
new THREE.Vector3(37,1.22,1.6),
],
seats:null,
},
{
name:"trunk3",
@ -46,6 +48,7 @@ export function PasserTrunkManager(data) {
new THREE.Vector3(54,1.22,1.6),
new THREE.Vector3(58,1.22,1.6)
],
seats:null,
},
{
name:"trunk4",
@ -61,6 +64,7 @@ export function PasserTrunkManager(data) {
new THREE.Vector3(75,1.22,1.6),
new THREE.Vector3(79,1.22,1.6)
],
seats:null,
},
{
name:"trunk5",
@ -76,6 +80,7 @@ export function PasserTrunkManager(data) {
new THREE.Vector3(97,1.22,1.6),
new THREE.Vector3(101,1.22,1.6)
],
seats:null,
},
{
name:"trunk6",
@ -91,9 +96,28 @@ export function PasserTrunkManager(data) {
new THREE.Vector3(118.5,1.22,1.6),
new THREE.Vector3(122.5,1.22,1.6),
],
seats:null,
}
];
this.initTrunkSeat = function(seatModel){
for(let i=0;i<seatModel.children.length;i++){
seatModel.children[i].position.x = -seatModel.children[i].position.x;
for(let j=0;j<seatModel.children[i].children.length;j++){
seatModel.children[i].children[j].isDown = false;
}
}
scope.trunk[0].seats = seatModel.getObjectByName("C6").children;
scope.trunk[1].seats = seatModel.getObjectByName("C5").children;
scope.trunk[2].seats = seatModel.getObjectByName("C4").children;
scope.trunk[3].seats = seatModel.getObjectByName("C3").children;
scope.trunk[4].seats = seatModel.getObjectByName("C2").children;
scope.trunk[5].seats = seatModel.getObjectByName("C1").children;
}
var rand = (min,max) => Math.round(Math.random()*(max-min))+min;
this.getDoorRandomPos = function(trunkNum,direct){
@ -108,15 +132,55 @@ export function PasserTrunkManager(data) {
return newPos;
}
this.getSeatRandomPos = function(index){
for(let i=0;i<scope.trunk[index].seats.length;i++){
if(scope.trunk[index].seats[i].isDown == false){
scope.trunk[index].seats[i].isDown = true;
let seatWorldPosition = scope.trunk[index].seats[i].getWorldPosition();
let offset = scope.trunk[index].position.x;
let newPos = {
pos:[new THREE.Vector3(-seatWorldPosition.x+offset,1.22,seatWorldPosition.y)],
seat:i,
};
if(seatWorldPosition.y<0){
newPos.pos.push(new THREE.Vector3(-seatWorldPosition.x+offset,1.22,seatWorldPosition.y+0.4));
}else{
newPos.pos.push(new THREE.Vector3(-seatWorldPosition.x+offset,1.22,seatWorldPosition.y-0.4));
}
return newPos;
}
}
return null;
}
this.getTrunkRandomPos = function(index){
let newPos = new THREE.Vector3(
scope.trunk[index].position.x+RandomNum(-11,11),
1.22,
scope.trunk[index].position.z+RandomNum(-1.28,1.28));
scope.trunk[index].position.z+RandomNum(-1,1));
return newPos;
}
this.reSeat = function(index,seat){
scope.trunk[index].seats[seat].isDown = false;
}
this.reSeats = function(index){
for (let i=0;i<scope.trunk.length;i++){
for(let j=0;j<scope.trunk[i].seats.length;j++){
scope.trunk[i].seats[j].isDown = false;
}
}
}
function RandomNum(Min, Max) {
var Range = Max - Min;
var Rand = Math.random();

View File

@ -117,6 +117,7 @@ export default {
data() {
return {
initCode:null,
nowCode:null,
isActive:0,
beforeUnloadTime:'',
gapTime:'',
@ -190,7 +191,7 @@ export default {
unloadHandler(){
this.gapTime=new Date().getTime()-this.beforeUnloadTime;
//
alert("netdata");
// alert("netdata");
if(this.gapTime<=5){
deletePassenger(this.$route.query.group,this.initCode).then(netdata => {
alert(netdata);
@ -199,7 +200,8 @@ export default {
},
init: function (code) {
// let mapdata = this.$store.state.socket.device;
this.value = code;
this.nowCode = code;
this.value = this.nowCode;
const dom = document.getElementById('jl3d');
this.jl3d = new Jl3dTrafficTrain(dom, this.$route.query.mapid, this.$route.query.group, 'normal',code);
},
@ -211,17 +213,7 @@ export default {
updateValue(newcode){
this.value = newcode;
},
switchrender() {
if (this.renderswitch == true) {
this.rendermode = '退出监控';
this.renderswitch = false;
this.jl3d.switchviews('freeview');
} else {
this.rendermode = '监控视角';
this.renderswitch = true;
this.jl3d.switchviews('4views');
}
},
// updateTrainCode(codeData){
// this.jl3d.updateNowTrainCode(codeData);
// },
@ -242,13 +234,11 @@ export default {
},
updateTrainCode(selVal) {
// console.log(selVal);
// this.jl3d.changeTrain(selVal);
this.isActive=0;
this.jl3d.updateNowTrainCode(selVal);
this.jl3d.switchcamera(0+'');
this.value = selVal;
// let oldgroupnum = this.groupnum;
// this.value = selVal;
},
@ -258,7 +248,7 @@ export default {
for(let i = 0;i<this.takelist.length;i++){
this.allPassers = this.allPassers + this.takelist[i].num;
}
this.value = this.nowCode+"(现有乘客"+this.allPassers+"人)";
},
getnum(num,pnum){
let re = [];

Binary file not shown.