Using Threejs + OrbitContols in TypeScript

前端 未结 14 1205
清歌不尽
清歌不尽 2021-02-07 11:59

I\'m not able to get this example of using the aforementioned combo going in TypeScript.

I have and <

14条回答
  •  醉梦人生
    2021-02-07 12:28

    After adding the three-orbitcontrols typings and three-orbit-controls npm package (why aren't these named the same?), I was still having issues getting it to work in Typescript. This ended up working for me in case it's helpful for anyone else who doesn't want to use the workaround:

    import * as three from 'three';
    three.OrbitControls = require('three-orbit-controls')(three);
    
    let camera = new three.PerspectiveCamera(75, aspectRatio, 1, 1000);
    let renderer = new three.WebGLRenderer();
    let controls = new three.OrbitControls(camera, renderer.domElement);
    

    As of today, it seems that the OrbitControls npm package is using an old style of exports that requires an old-style require statement that passes in the Three library.

提交回复
热议问题