RequireJS and THREE.js Orbit Controls

2019-09-07 02:07发布

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条回答
贼婆χ
2楼-- · 2019-09-07 03:09

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.

查看更多
登录 后发表回答