Its’ my first time trying to create an electron app coming from a C/C++/Python with some django background and I am not quite understanding whats happening in this code. It’s from this repo here. BabylonJS-Electron/renderer.ts at master · justinctlam/BabylonJS-Electron · GitHub
I am trying to load a obj file knight.obj and display it on the screen. However it’s not working.
Nothing seems wrong, and I do not see any obviously glaring errors in the code, or the console output from Electron.
I know its not the Obj file because I am able to load it using an html example found in the playground (Can’t find original link) and the Knight loads up fine.
Does anyone have a working example? What am I doing wrong?
import * as BABYLON from 'babylonjs';
import 'babylonjs-loaders';
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", new BABYLON.Vector3(0, 1, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 1;
// 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;
var loader = new BABYLON.AssetsManager(scene);
var head = loader.addMeshTask("head", "", "http://192.168.1.54:8080/", "knight.obj");
var meshThin;
var meshFat;
head.onSuccess = function() {
meshThin = head.loadedMeshes[1];
meshFat = head.loadedMeshes[0];
console.log("No. of vertices for thin: "+meshThin.getTotalVertices());
console.log("No. of vertices for fat: "+meshFat.getTotalVertices());
}
// Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
const ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, 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();