I wrote this script in Python:
content = "ACESFilmicToneMapping, AddEquation, AddOperation, ..."
arr = content.split(", ")
f = open("result.txt", "w")
for v in arr:
parts = v.split(" ")
if len(parts) != 3:
f.write(f"exports.{v} = {v};" + "\n")
f.close()
I get exports:
exports.ACESFilmicToneMapping = ACESFilmicToneMapping;
exports.AddEquation = AddEquation;
exports.AddOperation = AddOperation;
exports.AdditiveAnimationBlendMode = AdditiveAnimationBlendMode;
exports.AdditiveBlending = AdditiveBlending;
...
Bundle was created. But I get this error:
three.module.js:49030 WARNING: Multiple instances of Three.js being imported.
main.js:37 Uncaught TypeError: THREE.OrbitControls is not a constructor
I tried with THREE:
controls = new THREE.OrbitControls(camera, renderer.domElement);
and without THREE:
controls = new OrbitControls(camera, renderer.domElement);
It the same.
const THREE = require("three");
const OrbitControls = require("three/examples/jsm/controls/OrbitControls.js");
let camera, scene, renderer;
let geometry, meterial, mesh;
let controls;
window.onload = () =>
{
init();
animate();
window.onresize = () => { onResize(); };
};
function init()
{
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 10);
camera.position.z = 1;
scene = new THREE.Scene();
geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh(geometry, meterial);
scene.add(mesh);
const canvas = document.getElementById("renderCanvas");
renderer = new THREE.WebGLRenderer({ antialias: true, canvas: canvas });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
controls = new THREE.OrbitControls(camera, renderer.domElement);
}
function animate()
{
requestAnimationFrame(animate);
// mesh.rotation.x += 0.01;
// mesh.rotation.y += 0.02;
controls.update();
renderer.render(scene, camera);
}
function onResize()
{
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
{
"name": "threejs-orbitcontrols-browserify-js",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clear": "del /f /q /s .\\public\\js\\*.*",
"del-bundle": "del /f /q /s .\\src\\bundle.js",
"bundle-debug": "browserify --debug src/main.js -o public/js/bundle.js",
"bundle-release": "browserify src/main.js -o src/bundle.js",
"uglify": "uglifyjs src/bundle.js -o public/js/bundle.min.js",
"debug": "npm run bundle-debug",
"release": "npm run clear && npm run bundle-release && npm run uglify && npm run del-bundle"
},
"keywords": [],
"author": "",
"license": "ISC"
}