I am trying to use the THREE TransformControls class in a JSBin project that I am creating. Unfortunately, I cannot share my entire code. However, my JS code is within <script type="text/javascript"></script>
HTML tags. All my imports are handled by <script src=""> </script>
HTML tags. I have tried various source URLs for the TransformControls class to no avail.
I have imported the module using: <script src="https://threejs.org/examples/js/controls/TransformControls.js"></script>
but I keep getting a "Script error. (line 0)" as soon as I create a new TransformControls object.
Here is my TransformControls code:
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 );
What am I doing wrong?
Disclaimer: I am very new to JavaScript and to THREE
Add crossorigin in your script tag
Code(Will work in 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>
Other helpful articles:
Just for knowledge:
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.
Use
https://threejs.org/examples/jsm/controls/TransformControls.js