经过几个小时的搜索和测试.我终于放弃了.我正在使用Angular2和webpack,我尝试在angular2应用程序中使用three.js.我已经安装了npm包@type/three
sudo npm install @types/three --save
Run Code Online (Sandbox Code Playgroud)
我已经以多种方式编辑了我的tsconfig.json.我甚至尝试在我的polyfills.browser.ts中添加导入"三/三".但我一直在努力解决模块错误.也许我的tsconfig.json有问题如下
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "dist",
"rootDir": ".",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"typeRoots": [
"./node_modules/@types"
],
"types": [
"core-js",
"node",
"three"
]
},
"exclude": [
"node_modules"
],
"awesomeTypescriptLoaderOptions": {
"useWebpackText": true
},
"compileOnSave": false,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
Run Code Online (Sandbox Code Playgroud)
我在我的Component中至少尝试了以下语法
import {THREE} from "@types/three";
import {THREE} from "three";
import "@types/three";
import "three";
import * as _ from "@types/three";
import * as _ from …Run Code Online (Sandbox Code Playgroud) 我已经在我的angular2应用程序中通过npm安装应用了three.js @ types/three @ 0.0.27和three@0.82.1并在我的服务中导入它们.
import * as THREE from "three";
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用CSS3DRenderer时
this.renderer = new THREE.CSS3DRenderer();
Run Code Online (Sandbox Code Playgroud)
我收到了错误
core.umd.js:3004 EXCEPTION:THREE.CSS3DRenderer不是构造函数.似乎css3drenderer不在three.js包中.
我也做了npm install css3drenderer.现在我在node_modules/css3drenderer /中有CSS3DRenderer.js,在node_modules/@ types/three /中有三个css3drenderer.d.ts
那我怎么能在angular2中使用新的THREE.CSS3DRenderer()?顺便说一下,我有webpack的angular2@2.1.2.任何建议将不胜感激,谢谢!