Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
MeshBuilder,
PhysicsImpostor,
CannonJSPlugin,
Texture,
StandardMaterial,
ShadowGenerator,
DirectionalLight,
Color4,
CSG,
} from 'babylonjs';
import CANNON from 'cannon';
window.CANNON = CANNON;
const canvas = document.getElementById("stage");
const engine = new Engine(canvas);
const scene = new Scene(engine);
const light = new HemisphericLight("light", new Vector3(0, 1, 0), scene);
light.intensity = 0.5;
const pointLight = new DirectionalLight("dir01", new Vector3(0, -2, -3), scene);
const shadowGenerator = new ShadowGenerator(1024, pointLight);
// const camera = new FreeCamera("FreeCamera",new Vector3(0, 2, 10), scene);
// camera.setTarget(new Vector3(0, 5, -10));
const camera = new ArcRotateCamera("ArcRotateCamera", Math.PI/2, Math.PI/2, 10, new Vector3(0, 4, 0), scene);
camera.attachControl(canvas, false);
camera.setTarget(Vector3.Zero());
camera.applyGravity = true;
const ground = Mesh.CreateGround("ground1", 10, 30, 2, scene);
const sphere = Mesh.CreateSphere("sphere1", 16, 1, scene);
const bin = MeshBuilder.CreateCylinder("bin", {
diameterTop: 2,
diameterBottom: 1,
constructor(canvas, { onScore, onInit, onFinish }) {
window.CANNON = CANNON;
this._engine = new Engine(canvas, true);
this._scene = new Scene(this._engine);
this._canvas = canvas;
this._onScore = onScore;
this._onInit = onInit;
this._onFinish = onFinish;
this._scene.clearColor = new Color3(255, 255, 255);
this._sounds = {};
this.addPhysics();
this.addLights();
this.addCamera();
this.addBall();
this.addLoadingTasks();
this.addPlatforms();
this.addTouchListeners();
//this.loadSounds();
// allow moderate degradation
module.exports = function HexBoard(canvas, window, backgroundColor) {
//Protect the constructor from being called as a normal method
if (!(this instanceof HexBoard)) {
return new HexBoard(canvas, window, backgroundColor);
}
//A reference to the board for functions
var board = this;
//Setup babylonjs
this.engine = new babylon.Engine(canvas, true);
//Run the engines render loop
this.engine.runRenderLoop(function() {
if (board.scene) {
board.scene.render();
}
});
board.scene = new babylon.Scene(board.engine);
// Change the scene background color
var rgb = hexToRgb(backgroundColor);
board.scene.clearColor =new babylon.Color3(
rgb.r / 256,
rgb.g / 256,
rgb.b / 256
setScene() {
this.engine = new Engine(this.$refs.scene, true);
this.scene = new Scene(this.engine);
// https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen
this.vrHelper = this.scene.createDefaultVRExperience({
createFallbackVRDeviceOrientationFreeCamera: false,
});
this.resolveScene(this.scene);
this.resolveEngine(this.engine);
this.engine.runRenderLoop(() => this.scene.render());
// HACK: investigate sqaush effect on initial load
this.scene.executeWhenReady(this.resize);
// TODO: Add ability to toggle debugLayer on keystroke
// this.scene.debugLayer.show();
},
},
componentDidMount() {
if (this.state.support) {
this.engine = new BABYLON.Engine(this.canvas, true, {
preserveDrawingBuffer: true,
stencil: true
});
this.scene = new BABYLON.Scene(this.engine);
if (typeof this.props.onSceneMount === "function") {
this.props.onSceneMount({
scene: this.scene,
engine: this.engine,
canvas: this.canvas
});
} else {
console.error("onSceneMount function not available");
}
componentDidMount() {
if (this.state.support) {
this.engine = new BABYLON.Engine(this.canvas, true, {
preserveDrawingBuffer: true,
stencil: true
});
this.scene = new BABYLON.Scene(this.engine);
if (typeof this.props.onSceneMount === "function") {
this.props.onSceneMount({
scene: this.scene,
engine: this.engine,
canvas: this.canvas
});
} else {
console.error("onSceneMount function not available");
}
Texture,
StandardMaterial,
ShadowGenerator,
DirectionalLight,
Color4,
CSG,
Animation,
AnimationEvent,
Sound,
} from 'babylonjs';
import CANNON from 'cannon';
window.CANNON = CANNON;
const canvas = document.getElementById("stage");
const engine = new Engine(canvas, true);
const scene = new Scene(engine);
const light = new HemisphericLight("light", new Vector3(0, 3, 0), scene);
let started = false;
let renderScene = true;
let shift = 0;
light.intensity = 2.5;
const camera = new FreeCamera("FreeCamera",new Vector3(0, 4, -22), scene);
camera.setTarget(new Vector3(0, 1, 0));
const sphere = MeshBuilder.CreateSphere("ball", {
diameter: 0.6
}, scene);
sphere.position.z = -17;
sphere.position.y = 0.7;
const boxes=[];
let sceneAnimations = [];
private createEngine() {
this.engine = new Engine(this.canvas, true);
}
initBabylon(){
document.querySelectorAll('input').forEach(el =>
el.checked =debugger3d.options[el.getAttribute("data-target")]);
let canvas3d= document.getElementById("babylon");
canvas3d.classList.add(debugger3d.cssclass);
debugger3d.engine = new BABYLON.Engine(canvas3d, true);
debugger3d.scene = new BABYLON.Scene(debugger3d.engine);
debugger3d.createScene(debugger3d.engine,canvas3d);
debugger3d.createMesh();
debugger3d.engine.runRenderLoop(function() {
debugger3d.scene.render();
debugger3d.updateMesh();
});
},
private createEngine() {
this.engine = new Engine(this.canvas, true);
}