Skip to content

Commit

Permalink
Removed OBJ and MTL Loader and added gltf loader [refs #3]
Browse files Browse the repository at this point in the history
  • Loading branch information
KiWiGiW committed Dec 21, 2020
1 parent 22415bc commit e009a81
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions src/threedigitaltwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { KMZLoader } from 'three/examples/jsm/loaders/KMZLoader.js';
import { ColladaLoader } from 'three/examples/jsm/loaders/ColladaLoader.js';
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader.js';
import { OBJLoader2 } from 'three/examples/jsm/loaders/OBJLoader2.js';
import { MTLLoader } from 'three/examples/jsm/loaders/MTLLoader.js';
//import { extrudeGeoJSON } from 'geometry-extrude';
import { reproject } from 'reproject';
import proj4 from 'proj4';
Expand Down Expand Up @@ -341,7 +339,7 @@ export default class ThreeDigitalTwin {
var geo = this.convertGeoJsonToWorldUnits(geojson);
var shape = null;
var model = null;
var modelAndMTL = null;
var modelGLTF = null;
var values;
var feature;

Expand Down Expand Up @@ -384,7 +382,6 @@ export default class ThreeDigitalTwin {

break;
case "MODEL":

for (feature of geo.features) {
feature.layerCode = layerCode;
feature.properties = Object.assign({}, properties, feature.properties);
Expand All @@ -410,23 +407,22 @@ export default class ThreeDigitalTwin {
this.dispatch('layerloaded', layerCode);

break;
case "OBJ":

case "GLTF":
for (feature of geo.features) {
feature.layerCode = layerCode;
feature.properties = Object.assign({}, properties, feature.properties);

modelAndMTL = await this.createModelAndMTL(feature);
modelGLTF = await this.createModelGLTF(feature);

if (modelAndMTL) {
this.scene.add(modelAndMTL);
if (modelGLTF) {
this.scene.add(modelGLTF);

if (layerCode) {
values = [];
if (this.layers.get(layerCode)) {
values = this.layers.get(layerCode);
}
values.push(modelAndMTL);
values.push(modelGLTF);
this.layers.set(layerCode, values);
}
}
Expand Down Expand Up @@ -681,7 +677,8 @@ export default class ThreeDigitalTwin {
return mesh;
}

async createModelAndMTL(feature) {

async createModelGLTF(feature) {
var coordX;
var coordY;
if (feature.geometry.type != "Point") {
Expand All @@ -694,7 +691,7 @@ export default class ThreeDigitalTwin {
}

var mesh;
await this.loadOBJAndMTL(feature.properties.model, feature.properties.modelMTL).then((object) => {
await this.loadGLTF(feature.properties.model).then((object) => {

object.position.set(coordX - this.centerWorldInMeters[0], feature.properties.altitude, -(coordY - this.centerWorldInMeters[1]));

Expand Down Expand Up @@ -753,18 +750,6 @@ export default class ThreeDigitalTwin {
mesh.material[1].map.repeat.set(repeatValX, repeatValY);
}

loadOBJAndMTL(objPath, mtlPath) {
return new Promise((resolve) => {
var mtlL = new MTLLoader();
mtlL.load(mtlPath, (materials) => {
materials.preload();
new OBJLoader().setMaterials(materials).load(objPath, (root) => {
resolve(root);
});
});
});
}

loadGeometry(objectPath) {
return new Promise((resolve) => {
new THREE.BufferGeometryLoader().load(
Expand Down Expand Up @@ -794,7 +779,7 @@ export default class ThreeDigitalTwin {
element.material.metalness = 0;
}
});
resolve(gltf);
resolve(gltf.scene);
},
(error) => {
console.error(error);
Expand Down

0 comments on commit e009a81

Please sign in to comment.