export function UpdateTrain(camera,traindata,control){ 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<1){ let movecurve = trainmodel.curve; if(trainmodel.status == "03"){ if(movecurve.points.length>1){ let point = movecurve.getPointAt(traindata.group.children[j].progress); if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.1){ 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); let rotas = { posr:point, rota:trainmodel.children[0].rotation.y } 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; } trainmodel.position.x = point.x; trainmodel.position.y = 0; 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;xh1){ let point = movecurve.getPointAt(trainmodel.progress); if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.1){ 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); let rotas = { posr:point, rota:trainmodel.children[0].rotation.y } 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; } trainmodel.position.x = point.x; trainmodel.position.y = 0; 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[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.y = 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); } trainmodel.progress += trainmodel.speeds; } } } }else if(trainmodel.speeds < 0 && trainmodel.speeds){ let speed = null; if(traindata.group.children[j].progress<1){ let movecurve = trainmodel.curve; if(trainmodel.status == "03" && trainmodel.progress>0){ if(movecurve.points.length>1){ let point = movecurve.getPointAt(traindata.group.children[j].progress); if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.1){ 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); let rotas = { posr:point, rota:trainmodel.children[0].rotation.y } 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; } trainmodel.position.x = point.x; trainmodel.position.y = 0; 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.speeds)){ trainmodel.progress += trainmodel.speeds; } } } if(trainmodel.status == "02"){ if(movecurve.points.length>1 && trainmodel.progress>0){ let point = movecurve.getPointAt(trainmodel.progress); if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.1){ 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); let rotas = { posr:point, rota:trainmodel.children[0].rotation.y } 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; } trainmodel.position.x = point.x; trainmodel.position.y = 0; 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[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.y = 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.progress > -(trainmodel.speeds)){ trainmodel.progress += trainmodel.speeds; } } } } } } } } } }