This is related to this question here and this one here but neither of those fit my needs.
I'm migrating an Angular2 app over to the angular-cli
structure and I'm trying to include the .OBJLoader
& .MTLLoader
for the threejs
library in my migrated project.
I've included the scripts from the threejs
node folder in my .angular-cli.json
file like this:
"styles": [
"styles.css"
],
"scripts": [
"../node_modules/three/examples/js/loaders/OBJLoader.js",
"../node_modules/three/examples/js/loaders/MTLLoader.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Because the .OBJLoader
& .MTLLoader
don't have typings I thought that I'd have to create them myself in the typings.d.ts
file:
/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
id: string;
}
// OBJLoader
declare var objloader: OBJLoader;
interface OBJLoader {
}
// MTLLoader
declare var mtlloader: MTLLoader;
interface MTLLoader {
}
I then tried to import the modules into the service I required them in like this:
import { Injectable } from '@angular/core';
import * as THREE from 'three';
import * as OBJLoader from 'OBJLoader';
import * as MTLLoader from 'MTLLoader';
@Injectable()
export class LoaderService {
constructor() {}
setupMTLLoader(appPath) {
var mtlLoader = new MTLLoader();
return mtlLoader;
}
setupObjLoader(materials, appPath) {
var objLoader = new OBJLoader();
return objLoader;
}
}
but angular-cli
complains that:
Module not found: Error: Can't resolve 'OBJLoader' in '/my-path/src/app/shared/services'
@ ./src/app/shared/services/loader.service.ts 12:0-39
Several questions here:
- What do I need to change to get this to work?
- Does the typings folder examine the
@types
folder in thenode_nodules
for declared types? - How do scripts get loaded in and made available in typescript?
I'm confused as to what to do here.