How to load three-orbitcontrols with import syntax?

前端 未结 5 1614
遇见更好的自我
遇见更好的自我 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

    There is also an option to import OrbitControls directly from "three" package like this:

    import React, { Component } from "react";
    import ReactDOM from "react-dom";
    import * as THREE from 'three';
    import {OrbitControls} from "three/examples/jsm/controls/OrbitControls";
    

    and use it in the app without any issues:

    this.controls = new OrbitControls(camera, domElement);
    

    domElement has to be passed as second argument in latest builds of Three.js. React ref can be used for it.

    Here is a live demo with latest React and Three.js https://codesandbox.io/s/github/supromikali/react-three-demo

提交回复
热议问题