在TypeScript中使用Threejs + OrbitContols [英] Using Threejs + OrbitContols in TypeScript
问题描述
我无法获得这个使用TypeScript中前面提到的组合的例子。
I'm not able to get this example of using the aforementioned combo going in TypeScript.
我有< script src =lib / three.min.js>< / script>
和<在我的html < head>
< script src =lib / OrbitControls.js>< / script> >和< body>
中的typescript文件:
I have <script src="lib/three.min.js"></script>
and <script src="lib/OrbitControls.js"></script>
in my html <head>
and the typescript file in <body>
:
/// <reference path="lib\three.d.ts" />
...
this.controls = new THREE.OrbitControls(this.camera); //there's the error
this.controls.addEventListener('change', this.render);
...
和
this.controls.update();
定期调用 render()
函数。对于我所知道的,设置与expample相同,但是在编译OrbitControls构造函数行时给我一个巨大的错误(缩写):
in periodically called render()
function. For all I know, the setup is identical to the expample, but gives me a huge error (abbreviated) on compilation of the OrbitControls constructor line:
The property 'OrbitControls' does not exist on value of type '{REVISION:string;
CullFace: {[x: number ...
我猜那里有整个Threejs错误,因为Visual Studio崩溃的时候我点击它:)。感谢您的帮助。
I guess there's whole Threejs in that error, since Visual Studio crashes the moment I click on it :). Thanks for your help.
推荐答案
感觉有点傻,因为解决方案(或解决方法至少)结果非常简单。 ..
Feeling kind of silly since the solution (or workaround at least) turns out to be quite simple...
只需声明 OrbitControls
变量:
declare var THREE.OrbitControls: any; // even "declare var THREE.OrbitControls;" will do the trick
仍然有一些编译错误,但它的工作。
There are still some compilation errors but it works.
这篇关于在TypeScript中使用Threejs + OrbitContols的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!