-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannon ES Debugger. WARNING: Multiple instances of Three.js being imported #39
Comments
But it works without the warning when I import from unpkg: <!-- Since import maps are not yet supported by all browsers, it is
necessary to add the polyfill es-module-shims.js -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/[email protected]/build/three.module.min.js",
"collada-loader": "https://unpkg.com/[email protected]/examples/jsm/loaders/ColladaLoader.js",
"orbit-controls": "https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls.js",
"cannon-es": "https://unpkg.com/[email protected]/dist/cannon-es.js",
"cannon-es-debugger": "https://unpkg.com/[email protected]/dist/cannon-es-debugger.js"
}
}
</script>
<script type="module" src="./js/index.js"></script> |
It works as expected with unpkg:
index.html <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example</title>
<!-- <link rel="stylesheet" type="text/css" href="css/style.css"> -->
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<!-- Since import maps are not yet supported by all browsers, it is
necessary to add the polyfill es-module-shims.js -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/[email protected]/build/three.module.min.js",
"collada-loader": "https://unpkg.com/[email protected]/examples/jsm/loaders/ColladaLoader.js",
"orbit-controls": "https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls.js",
"cannon-es": "https://unpkg.com/[email protected]/dist/cannon-es.js",
"cannon-es-debugger": "https://unpkg.com/[email protected]/dist/cannon-es-debugger.js"
}
}
</script>
<script type="module" src="./js/index.js"></script>
</body>
</html> index.js import * as THREE from "three";
import { ColladaLoader } from "collada-loader";
import { OrbitControls } from "orbit-controls";
import * as CANNON from "cannon-es";
import CannonDebugger from "cannon-es-debugger";
async function init() {
const modelLoader = new ColladaLoader();
const textureLoader = new THREE.TextureLoader();
const scene = new THREE.Scene();
const ground = await modelLoader.loadAsync("./models/ground.dae");
const groundTexture = await textureLoader.loadAsync("./models/ground.png");
ground.scene.children[0].material.map = groundTexture;
scene.add(ground.scene);
const camera = new THREE.PerspectiveCamera(50,
window.innerWidth / window.innerHeight, 0.1, 500);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setClearColor(0x079bb0, 1);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
camera.position.y = 2;
camera.position.z = 5;
const orbitControls = new OrbitControls(camera, renderer.domElement);
orbitControls.target = new THREE.Vector3(0, 0, 0);
const ambientLight = new THREE.AmbientLight(0xffffff, 0.7);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
scene.add(directionalLight);
const world = new CANNON.World({ gravity: new CANNON.Vec3(0, 0, 0) });
const cannonDebugger = new CannonDebugger(scene, world);
const groundShape = new CANNON.Box(new CANNON.Vec3(1, 1, 1));
const groundBody = new CANNON.Body({ mass: 0 });
groundBody.addShape(groundShape);
world.addBody(groundBody);
let dt;
const clock = new THREE.Clock();
window.onresize = () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
};
function render() {
requestAnimationFrame(render);
orbitControls.update();
dt = clock.getDelta();
world.step(dt);
cannonDebugger.update();
renderer.render(scene, camera);
}
render();
}
init(); |
do you know how to enable cannon-es-debugger because ive gui, when its true cannon debugger will active, if its not, its not active this.gui = new GUI();
const controls = {
isColliderDebugger: this.isColliderDebugger
};
this.gui.add(controls, 'isColliderDebugger').name('Collider Debugger').onChange((value) => {
this.isColliderDebugger = value;
if (this.isColliderDebugger) {
this.enableColliderDebugger();
} else {
this.disableColliderDebugger();
}
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This warning appears when I add cannon-es-debugger:
index.html
index.js
The text was updated successfully, but these errors were encountered: