108 lines
2.7 KiB
JavaScript
108 lines
2.7 KiB
JavaScript
import {TrainModel} from '@/jlmap3d/edit/editmodel/TrainModel.js';
|
|
|
|
export function TrainList() {
|
|
|
|
let scope = this;
|
|
|
|
this.type = "trainlist";
|
|
|
|
this.list = [];
|
|
|
|
this.group = [];
|
|
|
|
this.textlist = [];
|
|
|
|
this.init = function(data,scene){
|
|
scope.group = new THREE.Group();
|
|
scope.group.name = "train";
|
|
scene.add(scope.group);
|
|
// model
|
|
THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() ) ;
|
|
for(let i=0;i<data.length;i++){
|
|
new THREE.MTLLoader().setPath( '../../static/model/train/' ).load( 'train.mtl', function ( materials ) {
|
|
materials.preload();
|
|
|
|
new THREE.OBJLoader().setMaterials( materials ).setPath( '../../static/model/train/' ).load( 'train.obj', function ( object ) {
|
|
|
|
object.name = data[i].code;
|
|
|
|
object.position.z = 30000;
|
|
object.position.y = 2;
|
|
|
|
let textgeometry = new THREE.PlaneBufferGeometry( 64, 32, 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.rotation.x = Math.PI/2;
|
|
scope.textlist.push(textplane);
|
|
object.add(textplane);
|
|
|
|
let newtrain = {};
|
|
newtrain.mesh = object;
|
|
newtrain.mesh.scale.set(0.5,0.5,0.5);
|
|
newtrain.mesh.first = false;
|
|
|
|
scope.list.push(newtrain);
|
|
scope.group.add(newtrain.mesh);
|
|
}, onProgress, onError );
|
|
|
|
} );
|
|
}
|
|
|
|
}
|
|
|
|
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 () { };
|
|
|
|
|
|
function getTextCanvas(text){
|
|
var width=128, height=64;
|
|
var canvas = document.createElement('canvas');
|
|
canvas.width = width;
|
|
canvas.height = height;
|
|
canvas.style.width = width + "px";
|
|
canvas.style.height = height + "px";
|
|
|
|
var ctx = canvas.getContext('2d');
|
|
ctx.fillStyle = '#FFFFFF';
|
|
ctx.fillRect(0, 0, width, height);
|
|
ctx.font = 1+'px';
|
|
ctx.fillStyle = '#000000';
|
|
ctx.textAlign = 'center';
|
|
ctx.textBaseline = 'middle';
|
|
ctx.clearRect(0,0,width,height);
|
|
//ctx.fillText(text.trainNumber, width/2,height/4);
|
|
ctx.fillText("车组号:"+text.trainNumber, width/2,height*2/4);
|
|
//ctx.fillText(text.trainModel.name, width/2,height*3/4);
|
|
return canvas;
|
|
}
|