How to load three-orbitcontrols with import syntax?

前端 未结 5 1619
遇见更好的自我
遇见更好的自我 2021-01-17 14:59

Has anyone tried using the OrbitControls function with ReactJS? Here is the sample code I wrote:

import React, { Component } from \'react\';
import \'tachy         


        
5条回答
  •  粉色の甜心
    2021-01-17 15:26

    The problem is that when you import THREE, it is not globally scoped which is what the 'three-orbitcontrols' module relies on.

    You could use this module instead - 'three-orbit-controls' (https://www.npmjs.com/package/three-orbit-controls)

    and import it like so:

    const OrbitControls = require('three-orbit-controls')(THREE);

    Usage of orbital controls is the same as you have now but with this, an instance of THREE is being passed to the Orbit Controls module.


    EDIT - 2020

    Although the above answer was useful when the question was first asked, @Marquizzo rightly pointed out this is no longer the case.

    Orbit Controls is now packaged with three.js and there's no need to use require(), when you should use the import statement.

    Please refer to this answer now - https://stackoverflow.com/a/55929101/8837901

提交回复
热议问题