Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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");
}
// Resize the babylon engine when the window is resized
window.addEventListener("resize", this.onResizeWindow);
} else {
swal(
'Browser not supported',
function createScene(): Scene {
// Create scene
var scene: Scene = new Scene(engine);
var sphereLight = new DirectionalLight("dir02", new Vector3(0.2, -1, 0), scene);
sphereLight.position = new Vector3(0, 80, 0);
var gravityVector = new BABYLON.Vector3(0, -1, 0);
scene.enablePhysics(gravityVector, new CannonJSPlugin);
scene.clearColor = BABYLON.Color4.FromColor3(BABYLON.Color3.Black());
var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, -10), scene);
//var camera = new BABYLON.UniversalCamera("UniversalCamera", new BABYLON.Vector3(0, 0, -10), scene);
camera.checkCollisions = true;
camera.applyGravity = true;
// Targets the camera to a particular position. In this case the scene origin
camera.setTarget(BABYLON.Vector3.Zero());
// Attach the camera to the canvas
camera.attachControl(canvas, true);
initScene(){
this.scene = new BABYLON.Scene(this.engine);
this.scene.clearColor = new BABYLON.Color3(0.5, 0.8, 0.5);
const camera = this.setCamera();
const sphere = BABYLON.MeshBuilder.CreateSphere('', { diameter: .0001 }, this.scene);
BABYLON.SceneLoader.ImportMesh("", "/dist/Scenes/Dude/", "Dude.babylon", this.scene, (newMeshes, particleSystems, skeletons) => {
const mesh = newMeshes[0];
const skeleton = skeletons[0];
mesh.scaling = new BABYLON.Vector3(0.1, 0.1, 0.1);
mesh.position = new BABYLON.Vector3(0, 0, 0);
const head_bone = skeleton.bones[7];
const right_shoulder_bone = skeleton.bones[13];
const right_arm_bone = skeleton.bones[14];
const left_shoulder_bone = skeleton.bones[32];
const left_arm_bone = skeleton.bones[33];
const lookAtCtl = new BABYLON.BoneLookController(mesh, head_bone, sphere.position, { adjustYaw: Math.PI * .5, adjustRoll: Math.PI * .5 });
private createScene() {
this.scene = new Scene(this.engine);
this.scene.clearColor = new Color4(0, 0, 0, 0);
}
private createScene() {
this.scene = new Scene(this.engine);
this.scene.clearColor = new Color4(0, 0, 0, 0);
}
setScene(state, actions, sceneID, canvas) {
const canvasID = `canvas-${sceneID}`;
const engineID = `engine-${sceneID}`;
const engine = new Babylon.Engine(canvas, true);
const scene = new Babylon.Scene(engine);
const newState = state()
.setIn(["entities", canvasID], Immutable.Map({
id: canvasID,
entity: canvas,
type: "canvas"
}))
.setIn(["entities", engineID], Immutable.Map({
id: engineID,
entity: engine,
type: "engine"
}))
.setIn(["entities", sceneID], Immutable.Map({
id: sceneID,
entity: scene,
type: "scene"
reset() {
this.scene.dispose();
this.scene = new BABYLON.Scene(this.engine);
this.initScene();
}