新数据三维区段模型自动生成修改,哈尔滨背景模型修改

This commit is contained in:
sunzhenyu 2020-04-10 18:55:06 +08:00
parent 8c3dd94cc1
commit 2b0ee65a67
11 changed files with 224 additions and 178 deletions

View File

@ -147,6 +147,7 @@ export function Jlmap3dSubscribeNew(jlmap3d,routegroup,jsonwebwork) {
function trainrun(data){
let code = data.code;
if(trainlisttest.list[code].dispose == "0"){
if(trainlisttest.list[code].curve == null){
if (data.right == '1') { // 向右
@ -181,6 +182,8 @@ export function Jlmap3dSubscribeNew(jlmap3d,routegroup,jsonwebwork) {
if(rails.sectionrail[data.section].standTrack){
trainlisttest.list[code].statsstop = 0;
}
console.log(rails.sectionrail[data.section].lineright);
console.log(trainlisttest.list[code].progress);
let point = rails.sectionrail[data.section].lineright.getPointAt(trainlisttest.list[code].progress);
trainlisttest.list[code].rotation.y = Math.PI;
@ -204,6 +207,7 @@ export function Jlmap3dSubscribeNew(jlmap3d,routegroup,jsonwebwork) {
}else{
//后端数据驱动车的位置更新与代码驱动车的移动相结合
if(data.code != trainlisttest.list[code].code){
if (data.right == '1') { // 向右
trainlisttest.list[code].right = '1';

View File

@ -85,7 +85,7 @@ export function DriverLoadNew(data,scope,netdata,mapdata,sectionlist,signallist,
})
.then(function(data){
//console.log(data);
return sectionlist.loadpromise(mapdata.sectionList,sectiondata.section,scene,assetloader);
return sectionlist.loadpromise(mapdata.sectionList,sectiondata.section,rails,scene,assetloader);
})
.then(function(data){
//console.log(data);
@ -99,14 +99,14 @@ export function DriverLoadNew(data,scope,netdata,mapdata,sectionlist,signallist,
//console.log(assetloader);
return trainlisttest.drivertrain(mapdata.trainList,sceneload,assetloader,mixers,actions,"01");
})
.then(function(data){
return new Promise(function(resolve, reject){
let stopoffset = 64;
rails.init(sectiondata.section,sectiondata,switchdata,sceneload);
resolve("loadrail");
});
})
// .then(function(data){
// return new Promise(function(resolve, reject){
// let stopoffset = 64;
// rails.init(sectiondata.section,sectiondata,switchdata,sceneload);
// resolve("loadrail");
//
// });
// })
.then(function(data){
return new Promise(function(resolve, reject){

View File

@ -83,7 +83,7 @@ export function SimulationLoadNew(data,scope,netdata,mapdata,camera,controls,sce
})
.then(function(data){
//console.log(data);
return sectionlist.loadpromise(mapdata.sectionList,sectiondata.section,scene,assetloader);
return sectionlist.loadpromise(mapdata.sectionList,sectiondata.section,rails,scene,assetloader);
})
.then(function(data){
//console.log(data);
@ -97,14 +97,13 @@ export function SimulationLoadNew(data,scope,netdata,mapdata,camera,controls,sce
//console.log(assetloader);
return trainlisttest.initpromise(mapdata.trainList,sceneload,assetloader,mixers,actions,"02");
})
.then(function(data){
return new Promise(function(resolve, reject){
let stopoffset = 64;
rails.init(sectiondata.section,sectiondata,switchdata,sceneload);
resolve("loadrail");
});
})
// .then(function(data){
// return new Promise(function(resolve, reject){
// rails.init(sectiondata.section,sectiondata,switchdata,sceneload);
// resolve("loadrail");
//
// });
// })
.then(function(data){
return new Promise(function(resolve, reject){

View File

@ -180,7 +180,7 @@ export function RailListN(){
scope.sectionrail[section[i].code].standTrack = false;
}
//
//
// for(let n=0,nm=scope.sectionrail[section[i].code].lineleft.points.length;n<nm;n++){
// var geometry = new THREE.CircleGeometry( 0.05, 16 );
// var material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
@ -216,5 +216,60 @@ export function RailListN(){
}
}
this.setrails = function(sectioncode,points,standtrack,lengthfact,scene){
scope.sectionrail[sectioncode] = {
lengthfact:lengthfact,
lineleft:null,
lineright:null,
standTrack:standtrack,
};
let leftpoints = [];
let rightpoints = [];
for(let i=0;i<points.length;i++){
leftpoints.push(points[i]);
rightpoints.push(points[points.length-i-1]);
}
scope.sectionrail[sectioncode].lineleft = new THREE.CatmullRomCurve3(leftpoints);
scope.sectionrail[sectioncode].lineleft.curveType = "centripetal";
scope.sectionrail[sectioncode].lineleft.name = sectioncode;
scope.sectionrail[sectioncode].lineright = new THREE.CatmullRomCurve3(rightpoints);
scope.sectionrail[sectioncode].lineright.curveType = "centripetal";
scope.sectionrail[sectioncode].lineright.name = sectioncode;
// //
// for(let n=0,nm=scope.sectionrail[sectioncode].lineleft.points.length;n<nm;n++){
// var geometry = new THREE.CircleGeometry( 0.05, 16 );
// var material = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
// var circle = new THREE.Mesh( geometry, material );
// // console.log(n);
// // console.log(scope.sectionrail[section[i].code].lineleft.points[n]);
// circle.position.x = scope.sectionrail[sectioncode].lineleft.points[n].x;
// circle.position.y = scope.sectionrail[sectioncode].lineleft.points[n].y;
// circle.position.z = scope.sectionrail[sectioncode].lineleft.points[n].z;
// circle.rotation.x = -Math.PI/2;
// scene.add( circle );
// }
// // scope.sectionrail[section[i].code].lineright.tension = 0.11;
// var points = scope.sectionrail[sectioncode].lineleft.getPoints( 50 );
// var geometry = new THREE.BufferGeometry().setFromPoints( points );
// var material;
// if(scope.sectionrail[sectioncode].type == "a"){
// material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
// }
// if(scope.sectionrail[sectioncode].type == "b"){
// material = new THREE.LineBasicMaterial( { color : 0x00ff00 } );
// }
// if(scope.sectionrail[sectioncode].type == "c"){
// material = new THREE.LineBasicMaterial( { color : 0x0000ff } );
// }
//
//
// // Create the final object to add to the scene
// var curveObject = new THREE.Line( geometry, material );
//
// curveObject.position.y = Math.random();
// scene.add(curveObject);
}
}

View File

@ -17,32 +17,32 @@ export function SectionListN() {
this.stopsection = [];
this.standtrack = [];
var autorail;
this.loadpromise = function(sectionList,sectiondata,scene,assetloader){
this.loadpromise = function(sectionList,sectiondata,rails,scene,assetloader){
// console.log(sectiondata);
var texture = new THREE.TextureLoader().load( '../../static/test/z0251.png' );
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set( 1,1);
var selectmaterial = new THREE.MeshPhongMaterial( { map: texture,transparent:true } );
var selectmaterial = new THREE.MeshPhongMaterial( { map: texture,transparent:true,alphaTest:0.1 } );
for(let i=0;i<assetloader.modellist.length;i++){
if(assetloader.modellist[i].deviceType == "autorail"){
autorail = assetloader.modellist[i].mesh.children[0];
}
}
let count = autorail.geometry.attributes.position.count;
let rightlist = [];
let leftlist = [];
for(let i=0;i<count;i++){
if(autorail.geometry.attributes.position.array[i*3] >0.49){
rightlist.push(i);
}
if(autorail.geometry.attributes.position.array[i*3] <-0.49){
leftlist.push(i);
}
}
autorail.rightlist = rightlist;
autorail.leftlist = leftlist;
// for(let i=0;i<assetloader.modellist.length;i++){
// if(assetloader.modellist[i].deviceType == "autorail"){
// autorail = assetloader.modellist[i].mesh.children[0];
// }
// }
// let count = autorail.geometry.attributes.position.count;
// let rightlist = [];
// let leftlist = [];
// for(let i=0;i<count;i++){
// if(autorail.geometry.attributes.position.array[i*3] >0.49){
// rightlist.push(i);
// }
// if(autorail.geometry.attributes.position.array[i*3] <-0.49){
// leftlist.push(i);
// }
// }
// autorail.rightlist = rightlist;
// autorail.leftlist = leftlist;
scene.add(scope.sectiongroup);
return new Promise(function(resolve, reject){
// console.log(sectiondata);
@ -73,148 +73,137 @@ this.loadpromise = function(sectionList,sectiondata,scene,assetloader){
};
let len = newsection.lengthFact;
let testmesh2 = autorail.clone(true);
for(let i=0;i<autorail.rightlist.length;i++){
testmesh2.geometry.attributes.position.array[autorail.rightlist[i]*3] = len;
testmesh2.geometry.attributes.uv.array[autorail.rightlist[i]*2] = testmesh2.geometry.attributes.position.array[0]-testmesh2.geometry.attributes.position.array[3];
}
let newrail = new THREE.BufferGeometry();
newrail.copy(testmesh2.geometry);
testmesh2.geometry = newrail;
testmesh2.geometry.attributes.position.needsUpdate = true;
testmesh2.geometry.attributes.uv.needsUpdate = true;
testmesh2.geometry.computeBoundingSphere();
testmesh2.geometry.center();
testmesh2.position.set(sectiondata[i].position.x,sectiondata[i].position.y,sectiondata[i].position.z);
testmesh2.rotation.set(sectiondata[i].rotation._x,sectiondata[i].rotation._y,sectiondata[i].rotation._z);
testmesh2.matrixAutoUpdate = false;
scope.sections.datalist[newsection.code] = newsection;
testmesh2.updateMatrix();
mergegeometry.merge(new THREE.Geometry().fromBufferGeometry(testmesh2.geometry),testmesh2.matrix);
testmesh2.geometry.dispose();
for(let j in testmesh2.material){
testmesh2.material[j].map.dispose();
testmesh2.material[j].dispose();
}
testmesh2 = null;
// if(newsection.rp.z != newsection.lp.z){
// // console.log(newsection);
// let height = Math.random()/1000;
// var closedSpline = new THREE.CatmullRomCurve3( [
// new THREE.Vector3(newsection.lp.x, height, newsection.lp.z),
// new THREE.Vector3(newsection.lp.x+2, height,newsection.lp.z),
// new THREE.Vector3((newsection.lp.x+newsection.rp.x)/2, height,(newsection.lp.z+newsection.rp.z)/2),
// new THREE.Vector3(newsection.rp.x-2, height,newsection.rp.z),
// new THREE.Vector3(newsection.rp.x, height, newsection.rp.z)
// ] );
//
// closedSpline.type = 'catmullrom';
// closedSpline.closed = false;
// // Set up settings for later extrusion
// var extrudeSettings = {
// steps : 12,
// curveSegments : 1,
// bevelSegments : 1,
// bevelEnabled : false,
// extrudePath : closedSpline,
// };
// var shape = new THREE.Shape();
// shape.moveTo( 0,-2 );
// shape.lineTo( 0, 2 );
// // Extrude the triangle along the CatmullRom curve
// var geometry = new THREE.ExtrudeBufferGeometry( shape, extrudeSettings );
// var material = new THREE.MeshLambertMaterial( { color: 0xb00000, wireframe: true } );
// // newnormal = new Float32Array(newnormal);
// // console.log(newnormal);
// // geometry.attributes.normal = new THREE.BufferAttribute(newnormal, 3);
// // geometry.attributes.needsUpdate = true;
// // Create mesh with the resulting geometry
// var mesh = new THREE.Mesh( geometry, selectmaterial );
// let count = mesh.geometry.attributes.position.count/3;
//
// for(let i=0;i<count;i++){
// let ui=i*6;
// if(i%2 != 0){
// mesh.geometry.attributes.uv.array[ui] = 0;
// mesh.geometry.attributes.uv.array[ui+1] = 1;
// mesh.geometry.attributes.uv.array[ui+2] = len/10;
// mesh.geometry.attributes.uv.array[ui+3] = 1;
// mesh.geometry.attributes.uv.array[ui+4] = len/10;
// mesh.geometry.attributes.uv.array[ui+5] = 0;
// }else{
// mesh.geometry.attributes.uv.array[ui] = 0;
// mesh.geometry.attributes.uv.array[ui+1] = 0;
// mesh.geometry.attributes.uv.array[ui+2] = 0;
// mesh.geometry.attributes.uv.array[ui+3] = 1;
// mesh.geometry.attributes.uv.array[ui+4] = len/10;
// mesh.geometry.attributes.uv.array[ui+5] = 0;
// }
// }
// mergegeometry.merge(new THREE.Geometry().fromBufferGeometry(mesh.geometry),mesh.matrix);
// // mergegeometry.merge(new THREE.Geometry().fromBufferGeometry(mesh.geometry),mesh.matrix);
// console.log(mesh);
// // scene.add(mesh);
// }else{
// let height = Math.random()/1000;
// var closedSpline = new THREE.CatmullRomCurve3( [
// new THREE.Vector3(newsection.lp.x, height, newsection.lp.z),
// new THREE.Vector3(newsection.rp.x, height, newsection.rp.z)
// ] );
//
// closedSpline.type = 'catmullrom';
// closedSpline.closed = false;
// // Set up settings for later extrusion
// var extrudeSettings = {
// steps : 1,
// curveSegments : 1,
// bevelSegments : 1,
// bevelEnabled : false,
// extrudePath : closedSpline,
// };
// var shape = new THREE.Shape();
// shape.moveTo( -2,0 );
// shape.lineTo( 2,0 );
// // Extrude the triangle along the CatmullRom curve
// var geometry = new THREE.ExtrudeBufferGeometry( shape, extrudeSettings );
// var material = new THREE.MeshLambertMaterial( { color: 0xb00000, wireframe: true } );
// // newnormal = new Float32Array(newnormal);
// // console.log(newnormal);
// // geometry.attributes.normal = new THREE.BufferAttribute(newnormal, 3);
// // geometry.attributes.needsUpdate = true;
// // Create mesh with the resulting geometry
// var mesh = new THREE.Mesh( geometry, selectmaterial );
// let count = mesh.geometry.attributes.position.count/3;
//
// for(let i=0;i<count;i++){
// let ui=i*6;
// if(i%2 != 0){
// mesh.geometry.attributes.uv.array[ui] = 0;
// mesh.geometry.attributes.uv.array[ui+1] = 1;
// mesh.geometry.attributes.uv.array[ui+2] = len;
// mesh.geometry.attributes.uv.array[ui+3] = 1;
// mesh.geometry.attributes.uv.array[ui+4] = len;
// mesh.geometry.attributes.uv.array[ui+5] = 0;
// }else{
// mesh.geometry.attributes.uv.array[ui] = 0;
// mesh.geometry.attributes.uv.array[ui+1] = 0;
// mesh.geometry.attributes.uv.array[ui+2] = 0;
// mesh.geometry.attributes.uv.array[ui+3] = 1;
// mesh.geometry.attributes.uv.array[ui+4] = len;
// mesh.geometry.attributes.uv.array[ui+5] = 0;
// }
// }
//
// mergegeometry.merge(new THREE.Geometry().fromBufferGeometry(mesh.geometry),mesh.matrix);
// // console.log(mesh);
// // scene.add(mesh);
//
// let testmesh2 = autorail.clone(true);
// for(let i=0;i<autorail.rightlist.length;i++){
// testmesh2.geometry.attributes.position.array[autorail.rightlist[i]*3] = len;
// testmesh2.geometry.attributes.uv.array[autorail.rightlist[i]*2] = testmesh2.geometry.attributes.position.array[0]-testmesh2.geometry.attributes.position.array[3];
// }
}
let mergemesh = new THREE.Mesh( mergegeometry, autorail.material );
// let mergemesh = new THREE.Mesh( mergegeometry, selectmaterial );
// let newrail = new THREE.BufferGeometry();
// newrail.copy(testmesh2.geometry);
// testmesh2.geometry = newrail;
// testmesh2.geometry.attributes.position.needsUpdate = true;
// testmesh2.geometry.attributes.uv.needsUpdate = true;
// testmesh2.geometry.computeBoundingSphere();
// testmesh2.geometry.center();
// testmesh2.position.set(sectiondata[i].position.x,sectiondata[i].position.y,sectiondata[i].position.z);
// testmesh2.rotation.set(sectiondata[i].rotation._x,sectiondata[i].rotation._y,sectiondata[i].rotation._z);
// testmesh2.matrixAutoUpdate = false;
// scope.sections.datalist[newsection.code] = newsection;
// testmesh2.updateMatrix();
// mergegeometry.merge(new THREE.Geometry().fromBufferGeometry(testmesh2.geometry),testmesh2.matrix);
// testmesh2.geometry.dispose();
// for(let j in testmesh2.material){
// testmesh2.material[j].map.dispose();
// testmesh2.material[j].dispose();
// }
// testmesh2 = null;
if(newsection.rp.z != newsection.lp.z){
// console.log(newsection);
let height = Math.random()/1000;
var closedSpline = new THREE.CatmullRomCurve3( [
new THREE.Vector3(newsection.lp.x, height, newsection.lp.z),
new THREE.Vector3(newsection.lp.x+2, height,newsection.lp.z),
new THREE.Vector3((newsection.lp.x+newsection.rp.x)/2, height,(newsection.lp.z+newsection.rp.z)/2),
new THREE.Vector3(newsection.rp.x-2, height,newsection.rp.z),
new THREE.Vector3(newsection.rp.x, height, newsection.rp.z)
] );
closedSpline.type = 'catmullrom';
closedSpline.closed = false;
var extrudeSettings = {
steps : 5,
curveSegments : 1,
bevelSegments : 1,
bevelEnabled : false,
extrudePath : closedSpline,
};
var shape = new THREE.Shape();
shape.moveTo( 0,-2 );
shape.lineTo( 0, 2 );
var geometry = new THREE.ExtrudeBufferGeometry( shape, extrudeSettings );
var mesh = new THREE.Mesh( geometry, selectmaterial );
let count = mesh.geometry.attributes.position.count/3;
for(let i=0;i<count;i++){
let ui=i*6;
if(i%2 != 0){
mesh.geometry.attributes.uv.array[ui] = 0;
mesh.geometry.attributes.uv.array[ui+1] = 1;
mesh.geometry.attributes.uv.array[ui+2] = len/5;
mesh.geometry.attributes.uv.array[ui+3] = 1;
mesh.geometry.attributes.uv.array[ui+4] = len/5;
mesh.geometry.attributes.uv.array[ui+5] = 0;
}else{
mesh.geometry.attributes.uv.array[ui] = 0;
mesh.geometry.attributes.uv.array[ui+1] = 0;
mesh.geometry.attributes.uv.array[ui+2] = 0;
mesh.geometry.attributes.uv.array[ui+3] = 1;
mesh.geometry.attributes.uv.array[ui+4] = len/5;
mesh.geometry.attributes.uv.array[ui+5] = 0;
}
}
mergegeometry.merge(new THREE.Geometry().fromBufferGeometry(mesh.geometry),mesh.matrix);
mesh.geometry.dispose();
mesh.material.map.dispose();
mesh.material.dispose();
rails.setrails(sectiondata[i].code,closedSpline.points,sectiondata[i].standTrack,len,scene);
}else{
let height = Math.random()/1000;
var closedSpline = new THREE.CatmullRomCurve3( [
new THREE.Vector3(newsection.lp.x, height, newsection.lp.z),
new THREE.Vector3(newsection.rp.x, height, newsection.rp.z)
] );
closedSpline.type = 'catmullrom';
closedSpline.closed = false;
// Set up settings for later extrusion
var extrudeSettings = {
steps : 1,
curveSegments : 1,
bevelSegments : 1,
bevelEnabled : false,
extrudePath : closedSpline,
};
var shape = new THREE.Shape();
shape.moveTo( -2,0 );
shape.lineTo( 2,0 );
// Extrude the triangle along the CatmullRom curve
var geometry = new THREE.ExtrudeBufferGeometry( shape, extrudeSettings );
var mesh = new THREE.Mesh( geometry, selectmaterial );
let count = mesh.geometry.attributes.position.count/3;
for(let i=0;i<count;i++){
let ui=i*6;
if(i%2 != 0){
mesh.geometry.attributes.uv.array[ui] = 0;
mesh.geometry.attributes.uv.array[ui+1] = 1;
mesh.geometry.attributes.uv.array[ui+2] = len;
mesh.geometry.attributes.uv.array[ui+3] = 1;
mesh.geometry.attributes.uv.array[ui+4] = len;
mesh.geometry.attributes.uv.array[ui+5] = 0;
}else{
mesh.geometry.attributes.uv.array[ui] = 0;
mesh.geometry.attributes.uv.array[ui+1] = 0;
mesh.geometry.attributes.uv.array[ui+2] = 0;
mesh.geometry.attributes.uv.array[ui+3] = 1;
mesh.geometry.attributes.uv.array[ui+4] = len;
mesh.geometry.attributes.uv.array[ui+5] = 0;
}
}
mergegeometry.merge(new THREE.Geometry().fromBufferGeometry(mesh.geometry),mesh.matrix);
mesh.geometry.dispose();
mesh.material.map.dispose();
mesh.material.dispose();
rails.setrails(sectiondata[i].code,closedSpline.points,sectiondata[i].standTrack,len,scene);
}
}
// let mergemesh = new THREE.Mesh( mergegeometry, autorail.material );
let mergemesh = new THREE.Mesh( mergegeometry, selectmaterial );
console.log(rails.sectionrail);
mergemesh.matrixAutoUpdate = false;
scope.sectiongroup.add(mergemesh);
resolve("loadersection");
});

View File

@ -202,7 +202,6 @@ export default {
},
updatetrainstatus(newdata){
//
this.updatespeed(newdata.v);
this.updateatpspeed(newdata.pv);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.8 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

BIN
static/test/z02512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB