加入站台,闸机动画。修改人物路线,拆分进出闸机模型

This commit is contained in:
sunleking 2020-02-21 19:10:45 +08:00
parent de8084b9bb
commit 3850d57b4e
5 changed files with 381 additions and 98 deletions

View File

@ -24,16 +24,24 @@ var Staticmodel = {
picUrl: "",
assetUrl: "../../static/model/passflow/station.FBX"
},
zhaji: {
zhajiin: {
id: "4",
name: "闸机",
deviceType: "zhaji",
deviceType: "zhajiin",
type: "hrb",
picUrl: "",
assetUrl: "../../static/model/passflow/zhaji.FBX"
assetUrl: "../../static/model/passflow/zhajiin.FBX"
},
zhajiout: {
id: "5",
name: "闸机",
deviceType: "zhajiout",
type: "hrb",
picUrl: "",
assetUrl: "../../static/model/passflow/zhajiout.FBX"
},
monitor: {
id: "5",
id: "6",
name: "摄像机",
deviceType: "monitor",
type: "hrb",

View File

@ -17,7 +17,8 @@ var humans = [];
var checkdoor1 = [];
var checkdoor2 = [];
var station;
var zhaji;
var zhajiinmodel;
var zhajioutmodel;
var monitor;
let ids = 0;
var rungroup = new THREE.Group();
@ -30,6 +31,8 @@ let moveanimatelist = [];
let zhajiin = [];
let zhajiout = [];
let deviceaction = [];
for(let i=0;i<5;i++){
checkdoor1[i]={
id:"c1"+i,
@ -41,13 +44,22 @@ for(let i=0;i<5;i++){
for(let i=0;i<5;i++){
let zhaji = {
id:"in"+i,
id:"in0"+(i+1),
status:0,
waiting:0
}
zhajiin.push(zhaji);
}
for(let i=0;i<5;i++){
let zhaji = {
id:"out0"+(i+1),
status:0,
waiting:0
}
zhajiout.push(zhaji);
}
let stationleft = [];
let stationright = [];
@ -201,11 +213,10 @@ export function Jl3dpassflow(dom) {
this.modelmanager = new ModelManager();
this.modelmanager.loadpromise(Staticmodel, scope.mixers).then(function (data) {
// console.log(scope.modelmanager);
station = scope.modelmanager.station.mesh;
zhaji = scope.modelmanager.zhaji.mesh;
initstationanimation(scope.modelmanager.station.mesh);
initzhajiinaimation(scope.modelmanager.zhajiin.mesh);
initzhajioutanimation(scope.modelmanager.zhajiout.mesh);
monitor = scope.modelmanager.monitor.mesh;
scene.add(station);
scene.add(zhaji);
scene.add(monitor);
originhuman1 = scope.modelmanager.man1.mesh;
originhuman2 = scope.modelmanager.man2.mesh;
@ -239,20 +250,11 @@ export function Jl3dpassflow(dom) {
if(humans[i].status == 0){
if(humans[i].stage == 1){
for(let j =0;j<5;j++){
if(zhajiin[j].waiting == 0){
let points = [];
points.push(new THREE.Vector3(humans[i].mesh.position.x,humans[i].mesh.position.y,humans[i].mesh.position.z));
points.push(new THREE.Vector3(6.5-j*1.5,10,18.5));
points.push(new THREE.Vector3(6.5-j*1.5,10,13));
humans[i].doors = j;
zhajiin[j].waiting = 1;
moveanimateinit(humans[i],i,points,i);
j =5;
}
}
points.push(new THREE.Vector3(humans[i].mesh.position.x,humans[i].mesh.position.y,humans[i].mesh.position.z-5));
zhajicontrol("in",humans[i].doors);
moveanimateinit(humans[i],i,points,i,0.02);
}
if(humans[i].stage == 2){
let points = [];
@ -274,7 +276,7 @@ export function Jl3dpassflow(dom) {
humans[i].doors = j;
stationright[j].waiting = 1;
moveanimateinit(humans[i],i,points,i);
moveanimateinit(humans[i],i,points,i,0.002);
j =22;
}
}
@ -290,12 +292,12 @@ export function Jl3dpassflow(dom) {
points.push(new THREE.Vector3(51-j*5,1.7,2));
humans[i].doors = j;
stationright[j].waiting = 1;
moveanimateinit(humans[i],i,points,i);
moveanimateinit(humans[i],i,points,i,0.002);
j =22;
}
}
}
moveanimateinit(humans[i],i,points,i);
moveanimateinit(humans[i],i,points,i,0.002);
}
//出站
if(humans[i].stage == 3){
@ -322,22 +324,26 @@ export function Jl3dpassflow(dom) {
}
points.push(new THREE.Vector3(-5,10,4));
points.push(new THREE.Vector3(14,10,3));
moveanimateinit(humans[i],i,points,i);
var j = Math.floor(Math.random()*(4-1+1))+1;
points.push(new THREE.Vector3(19,10,-2+j*1.4));
humans[i].doors = j;
moveanimateinit(humans[i],i,points,i,0.002);
}
if(humans[i].stage == 4){
var j = Math.floor(Math.random()*(4-1+1))+1;
let points = [];
points.push(new THREE.Vector3(humans[i].mesh.position.x,humans[i].mesh.position.y,humans[i].mesh.position.z));
points.push(new THREE.Vector3(19,10,5-j*1.4));
points.push(new THREE.Vector3(23,10,5-j*1.4));
console.log();
points.push(new THREE.Vector3(humans[i].mesh.position.x+4,humans[i].mesh.position.y,humans[i].mesh.position.z));
if(humans[i].direct == 1){
points.push(new THREE.Vector3(33,10,25));
}else{
points.push(new THREE.Vector3(33.5,10,-5));
}
humans[i].doors = j;
moveanimateinit(humans[i],i,points,i);
zhajicontrol("out",humans[i].doors);
moveanimateinit(humans[i],i,points,i,0.002);
}
}
}
@ -382,7 +388,7 @@ export function Jl3dpassflow(dom) {
}
function moveanimateinit(model,name,points,index){
function moveanimateinit(model,name,points,index,speed){
let curve = new THREE.CatmullRomCurve3(points);
curve.curvrtype = "chordal";
@ -399,7 +405,7 @@ export function Jl3dpassflow(dom) {
directchange:false,
enable:true,
status:"start",
speed:0.002,
speed:speed,
};
humans[index].runrail = animate;
humans[index].status = 1;
@ -420,45 +426,46 @@ export function Jl3dpassflow(dom) {
if(humans[i].status == 1){
humans[i].runrail.enable = false;
humans[i].runrail.progress = 1;
humans[i].mixer.runplay = false;
humans[i].action.stop();
humans[i].status = 0;
humans[i].mixer.runplay = false;
humans[i].action.stop();
humans[i].status = 0;
if(humans[i].stage == 4){
if(humans[i].stage == 4){
rungroup.remove(humans[i].mesh);
// humans.splice(i,1);
rungroup.remove(humans[i].mesh);
// humans.splice(i,1);
}
if(humans[i].stage == 3){
if(humans[i].direct == 1){
stationleft[humans[i].doors].waiting = 0;
}else{
stationright[humans[i].doors].waiting = 0;
}
humans[i].stage = 4;
if(humans[i].stage == 3){
}
if(humans[i].direct == 1){
if(humans[i].stage == 2){
humans[i].stage = 3;
stationleft[humans[i].doors].waiting = 0;
}else{
}
stationright[humans[i].doors].waiting = 0;
}
humans[i].stage = 4;
if(humans[i].stage == 1){
}
if(humans[i].stage == 2){
humans[i].stage = 3;
humans[i].stage = 2;
}
}
if(humans[i].stage == 1){
zhajiin[humans[i].doors].waiting = 0;
humans[i].stage = 2;
}
if(humans[i].stage == 0){
humans[i].stage = 1;
}
if(humans[i].stage == 0){
console.log(humans[i].doors);
zhajiin[humans[i].doors].waiting = 0;
humans[i].stage = 1;
}
moveanimatelist.splice(i,1);
@ -467,22 +474,19 @@ export function Jl3dpassflow(dom) {
}else{
//根据动画进度获取动画轨迹上点
let point = humans[i].runrail.curve.getPointAt(humans[i].runrail.progress);
let point = humans[i].runrail.curve.getPointAt(humans[i].runrail.progress);
//更新模型坐标
humans[i].mesh.position.x = point.x;
humans[i].mesh.position.y = point.y;
humans[i].mesh.position.z = point.z;
if((humans[i].runrail.progress+0.001)<1){
let tangent = humans[i].runrail.curve.getPointAt(humans[i].runrail.progress+0.001);
humans[i].mesh.lookAt(new THREE.Vector3(tangent.x,humans[i].mesh.position.y,tangent.z));
}
// = ;
//更新模型坐标
humans[i].mesh.position.x = point.x;
humans[i].mesh.position.y = point.y;
humans[i].mesh.position.z = point.z;
if((humans[i].runrail.progress+0.001)<1){
let tangent = humans[i].runrail.curve.getPointAt(humans[i].runrail.progress+0.001);
humans[i].mesh.lookAt(new THREE.Vector3(tangent.x,humans[i].mesh.position.y,tangent.z));
}
//增加动画进度,释放点变量
humans[i].runrail.progress += humans[i].runrail.speed;
point = null;
humans[i].runrail.progress += humans[i].runrail.speed;
point = null;
}
@ -519,34 +523,298 @@ export function Jl3dpassflow(dom) {
points.push(new THREE.Vector3(18,10,18));
}
let j = Math.floor(Math.random()*(4-1+1))+1;
points.push(new THREE.Vector3(-0.5+j*1.4,10,18.5));
// zhajiin[j].waiting = 1;
let mixer = new THREE.AnimationMixer( newhuman );
mixer.runplay = false;
let action = mixer.clipAction( newhuman.animations[ 0 ] );
let mixer = new THREE.AnimationMixer( newhuman );
mixer.runplay = false;
let action = mixer.clipAction( newhuman.animations[ 0 ] );
var stationdirection = Math.floor(Math.random()*(2-1+1))+1;
var stationdirection = Math.floor(Math.random()*(2-1+1))+1;
let newone = {
id:humans.length,
mesh:newhuman,
status:1,
stage:0,
direct:stationdirection,
doorstatus:null,
doors:j,
action:action,
mixer:mixer,
runrail:null
};
let newone = {
id:humans.length,
mesh:newhuman,
status:1,
stage:0,
direct:stationdirection,
doorstatus:null,
doors:null,
action:action,
mixer:mixer,
runrail:null
};
humans.push(newone);
mixers.push(mixer);
rungroup.add(newhuman);
humans.push(newone);
mixers.push(mixer);
rungroup.add(newhuman);
moveanimateinit(newone,humans.length,points,newone.id);
moveanimateinit(newone,humans.length,points,newone.id,0.002);
// return newone;
}
function initstationanimation(object){
let mixer = new THREE.AnimationMixer( object );
let newclip = object.animations[ 0 ];
for(let j=0;j<object.children.length;j++){
if(object.children[j].name == "top"){
object.children[j].animations = [];
object.children[j].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( object.children[j] );
let action =mixer.clipAction( object.children[j].animations[0])
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
// action.play();
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[j].name] = device;
}
if(object.children[j].name == "down"){
object.children[j].animations = [];
object.children[j].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( object.children[j] );
let action =mixer.clipAction( object.children[j].animations[0])
// action.play();
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[j].name] = device;
}
}
station = object;
scene.add(object);
}
function initzhajiinaimation(object){
let mixer = new THREE.AnimationMixer( object );
let newclip = object.animations[ 0 ];
let newzhaji = object;
for(let i=0;i<newzhaji.children.length;i++){
if(newzhaji.children[i].name == "in01"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
if(newzhaji.children[i].name == "in02"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
if(newzhaji.children[i].name == "in03"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
if(newzhaji.children[i].name == "in04"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
if(newzhaji.children[i].name == "in05"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
}
zhajiinmodel = newzhaji;
scene.add(newzhaji);
}
function initzhajioutanimation(object){
let mixer = new THREE.AnimationMixer( object );
let newclip = object.animations[ 0 ];
let newzhaji = object;
for(let i=0;i<newzhaji.children.length;i++){
if(newzhaji.children[i].name == "out01"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
if(newzhaji.children[i].name == "out02"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
if(newzhaji.children[i].name == "out03"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
if(newzhaji.children[i].name == "out04"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
if(newzhaji.children[i].name == "out05"){
newzhaji.children[i].animations = [];
newzhaji.children[i].animations.push(newclip.clone());
let mixer = new THREE.AnimationMixer( newzhaji.children[i] );
let action =mixer.clipAction( newzhaji.children[i].animations[0]);
action.setLoop(THREE.LoopOnce);
action.clampWhenFinished = true;
mixer.runplay = true;
mixers.push(mixer);
let device = {
action:action,
mixer:mixer,
};
deviceaction[object.children[i].name] = device;
}
}
zhajioutmodel = newzhaji
scene.add(newzhaji);
}
function zhajicontrol(type,door){
console.log(door);
console.log(zhajiin);
let devicenum = door-1;
if(type == "in"){
deviceaction[zhajiin[devicenum].id].action.reset();
deviceaction[zhajiin[devicenum].id].action.time = 0;
deviceaction[zhajiin[devicenum].id].action.timeScale = 1;
deviceaction[zhajiin[devicenum].id].action.play();
}else if(type == "out"){
deviceaction[zhajiout[devicenum].id].action.reset();
deviceaction[zhajiout[devicenum].id].action.time = 0;
deviceaction[zhajiout[devicenum].id].action.timeScale = 1;
deviceaction[zhajiout[devicenum].id].action.play();
}
}
function monitorrender() {
// updateSize();

View File

@ -24,7 +24,13 @@ export function ModelManager(){
action:null
};
this.zhaji = {
this.zhajiin = {
code:null,
screenDoorOpenStatus:"01",
mesh:null,
action:null
};
this.zhajiout = {
code:null,
screenDoorOpenStatus:"01",
mesh:null,
@ -43,7 +49,8 @@ export function ModelManager(){
initlist.push(fbxpromise(data.man1,mixers,scope.man1));
initlist.push(fbxpromise(data.man2,mixers,scope.man2));
initlist.push(fbxpromise(data.station,mixers,scope.station));
initlist.push(fbxpromise(data.zhaji,mixers,scope.zhaji));
initlist.push(fbxpromise(data.zhajiin,mixers,scope.zhajiin));
initlist.push(fbxpromise(data.zhajiout,mixers,scope.zhajiout));
initlist.push(fbxpromise(data.monitor,mixers,scope.monitor));
return new Promise(function(resolve, reject){

Binary file not shown.

Binary file not shown.