RequireJS and THREE.js Orbit Controls

我只是一个虾纸丫 提交于 2020-01-07 02:35:29

问题


I am using THREEjs r83 in a requirejs build. No matter what I do, the OrbitControl is loading & running before THREEjs initiates so I get the persistant error:

Uncaught ReferenceError: THREE is not defined

Here is the initial part of my file where you can see THREE is required as a shim for the OrbitControl. I've gone over the code repeatedly & cannot work out a solution. Can anyone help me out?

requirejs.config({
    paths: {
        three: 'lib/three'
    },
    shim: {
        'three': ["lib/FloatFix"],
        'lib/OrbitControls': ["three"]
    }
});
require(
    [
        'jquery',
        'three',
        'lib/OrbitControls'
    ],
    ...

回答1:


I had this issue ( was using trackball instead of orbit) a while back. Try this:

paths: {
    three: 'lib/three'
    orbit: 'lib/OrbitControls'
},
shim: {
    'three': {
        exports: 'THREE'
    },
    'orbit': {
        deps: ['three']
    }
}

Let me know if this works for you.



来源:https://stackoverflow.com/questions/41306959/requirejs-and-three-js-orbit-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!