使用 THREE.js 转换控件

Using THREE.js TransformControls

我正在尝试在我正在创建的 JSBin 项目中使用三个 TransformControls class。不幸的是,我无法分享我的全部代码。但是,我的 JS 代码在 <script type="text/javascript"></script> HTML 标签内。我所有的导入都由 <script src=""> </script> HTML 标签处理。我尝试了 TransformControls class 的各种源 URL 都无济于事。

我已经使用以下方法导入了模块:<script src="https://threejs.org/examples/js/controls/TransformControls.js"></script> 但是我在创建一个新的 TransformControls 对象时总是收到“脚本错误。(第 0 行)”。

这是我的 TransformControls 代码:

var tC= new THREE.TransformControls(camera, renderer.domElement); // this line causes the error
var cC = new THREE.OrbitControls(camera, renderer.domElement); // camera controls works
tC.addEventListener( 'mousemove', render );

我做错了什么?

免责声明:我是 非常 JavaScript 和三个

新手

在脚本标签中添加 crossorigin

代码(将在 jsbin 中工作):

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r121/three.min.js" crossorigin="anonymous"></script> //<----here

  <script type="text/javascript" src="https://threejs.org/examples/js/controls/TransformControls.js" crossorigin></script> //<----here

</head>
<body>
    <canvas id="myCanvas"></canvas>
  <script>
    //import {TransformControls} from "https://threejs.org/examples/jsm/controls/TransformControls.js";
    var tC= new THREE.TransformControls(); //<-- not a complete code just for understanding
  </script>
</body>
</html>

其他有用的文章:

仅供参考:

runner-4.1.8.min.js:1 THREE.TransformControls: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation.

使用

https://threejs.org/examples/jsm/controls/TransformControls.js