rt-sim-training-client/src/jlmap3d/edit/neweditmodel/TrainListTest.js

176 lines
5.1 KiB
JavaScript
Raw Normal View History

import {TrainModel} from '@/jlmap3d/edit/editmodel/TrainModel.js';
export function TrainListTest() {
let scope = this;
this.type = "trainlist";
this.list = [];
this.group = [];
this.textlist = [];
this.initpromise = function(data,scene,assetloader){
return new Promise(function(resolve, reject){
//列车节数
let trainnum = 4;
//遍历列车数据
for(let i=0;i<data.length;i++){
// let group = new THREE.Group();
// //创建列车模型
// for(let j=0;j<trainnum;j++){
// let geometry = new THREE.BoxBufferGeometry( 10, 4, 5 );
// let material = new THREE.MeshBasicMaterial( {color: 0x3A5FCD} );
// let train = new THREE.Mesh( geometry, material );
// train.name = data[i].code;
// train.position.set(j*11,2,0);
// group.add(train);
// }
let newmesh;
for(let n=0;n<assetloader.modellist.length;n++){
if(assetloader.modellist[n].deviceType == "train"){
newmesh = assetloader.modellist[n].mesh.clone(true);
n = assetloader.modellist.length;
}
}
for(let j=0;j<newmesh.children.length;j++){
newmesh.children[j].name = data[i].code;
//newmesh.children[j].rotation.y = 0.05*j;
}
//创建列车字牌
let textgeometry = new THREE.PlaneBufferGeometry( 128, 64, 1 );
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map: new THREE.CanvasTexture(getTextCanvas(data[i])),transparent: true} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = data[i].code;
textplane.position.y = 30;
textplane.position.x = -30;
//textplane.rotation.x = Math.PI;
scope.textlist.push(textplane);
newmesh.add(textplane);
//group.add(textplane);
newmesh.first = false;
newmesh.name = data[i].code;
newmesh.groupNumber = data[i].groupNumber;
newmesh.position.set(20,2,-20*i);
//newmesh.rotation.y = Math.PI/2;
newmesh.movelist = [];
newmesh.rotelist = [];
newmesh.endpoint = null;
scope.list.push(newmesh);
//scene.add(newmesh);
}
resolve("loadedtrain");
});
}
this.init = function(data,scene,assetloader){
//列车节数
let trainnum = 4;
//遍历列车数据
for(let i=0;i<data.length;i++){
// let group = new THREE.Group();
// //创建列车模型
// for(let j=0;j<trainnum;j++){
// let geometry = new THREE.BoxBufferGeometry( 10, 4, 5 );
// let material = new THREE.MeshBasicMaterial( {color: 0x3A5FCD} );
// let train = new THREE.Mesh( geometry, material );
// train.name = data[i].code;
// train.position.set(j*11,2,0);
// group.add(train);
// }
let newmesh = assetloader.modellist[1].mesh.clone(true);
for(let j=0;j<newmesh.children.length;j++){
newmesh.children[j].name = data[i].code;
//newmesh.children[j].rotation.y = 0.05*j;
}
//创建列车字牌
let textgeometry = new THREE.PlaneBufferGeometry( 128, 64, 1 );
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map: new THREE.CanvasTexture(getTextCanvas(data[i])),transparent: true} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = data[i].code;
textplane.position.y = 30;
textplane.position.x = -30;
//textplane.rotation.x = Math.PI;
scope.textlist.push(textplane);
newmesh.add(textplane);
//group.add(textplane);
newmesh.first = false;
newmesh.name = data[i].code;
newmesh.groupNumber = data[i].groupNumber;
newmesh.position.set(20,2,-20*i);
//newmesh.rotation.y = Math.PI/2;
newmesh.movelist = [];
newmesh.rotelist = [];
newmesh.endpoint = null;
scope.list.push(newmesh);
scene.add(newmesh);
}
}
this.update = function(){
}
this.renderon = function(){
}
this.renderoff = function(){
}
this.dispose = function(){
}
}
let onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
let percentComplete = xhr.loaded / xhr.total * 100;
//console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
}
};
let onError = function () { };
//canvas文字贴图方法
//PS:待提炼 增强功能
function getTextCanvas(text){
var canvas = document.getElementById('canvastexture');
// let width = 128;
// let height = 64;
// canvas.style.width = width + "px";
// canvas.style.height = height + "px";
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(0, 0,128,64);
ctx.font = "500px";
ctx.fillStyle = '#000000';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.clearRect(0,0,128,64);
////console.log(text.groupNumber);
//ctx.fillText(text.trainNumber, width/2,height/4);
ctx.fillText("车组号:"+text.groupNumber, 128/2,64*2/4);
//ctx.fillText(text.trainModel.name, width/2,height*3/4);
let data = ctx.getImageData(0, 0,128,64);
return data;
}