问题描述
这是我第一次尝试创建具有django背景的C / C ++ / Python电子应用程序,但我不太了解这段代码中发生了什么。是来自这个仓库。 https://github.com/justinctlam/BabylonJS-Electron/blob/master/src/renderer.ts
为什么要导出同一脚本文件中使用的类? 这是电子的必需条件吗?
import * as BABYLON from 'babylonjs';
export default class Renderer {
private _canvas: HTMLCanvasElement;
private _engine: BABYLON.Engine;
private _scene: BABYLON.Scene;
createScene(canvas: HTMLCanvasElement,engine: BABYLON.Engine) {
this._canvas = canvas;
this._engine = engine;
// This creates a basic Babylon Scene object (non-mesh)
const scene = new BABYLON.Scene(engine);
this._scene = scene;
// This creates and positions a free camera (non-mesh)
const camera = new BABYLON.FreeCamera("camera1",new BABYLON.Vector3(0,5,-10),scene);
// This targets the camera to scene origin
camera.setTarget(BABYLON.Vector3.Zero());
// This attaches the camera to the canvas
camera.attachControl(canvas,true);
// This creates a light,aiming 0,1,0 - to the sky (non-mesh)
const light = new BABYLON.HemisphericLight("light1",0),scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 0.7;
// Our built-in 'sphere' shape. Params: name,subdivs,size,scene
const sphere = BABYLON.Mesh.CreateSphere("sphere1",16,2,scene);
// Move the sphere upward 1/2 its height
sphere.position.y = 1;
// Our built-in 'ground' shape. Params: name,width,depth,scene
const ground = BABYLON.Mesh.CreateGround("ground1",6,scene);
}
initialize(canvas: HTMLCanvasElement) {
const engine = new BABYLON.Engine(canvas,true);
this.createScene(canvas,engine);
engine.runRenderLoop(() => {
this._scene.render();
});
window.addEventListener('resize',function () {
engine.resize();
});
}
}
const renderer = new Renderer();
renderer.initialize(document.getElementById('render-canvas') as HTMLCanvasElement);