I just bootstrapped a project using Parcel which makes it so simple to get started.
I came across that issue as well but found how to make it work and even though the topic is quite old, I’ll share exactly what I did from the start:
-
yarn init
(fill up everything you want to on the interactive prompt but can just press enter all the way as well)
yarn add --dev -E parcel parcel-reporter-static-files-copy
yarn add -E @babylonjs/core @babylonjs/loaders
- Create
./tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true
}
}
{
"extends": ["@parcel/config-default"],
"reporters": ["...", "parcel-reporter-static-files-copy"]
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script src="main.ts" type="module"></script>
<title>BabylonJS app</title>
<style>
html,
body {
overflow: hidden;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#renderCanvas {
width: 100%;
height: 100%;
touch-action: none;
}
</style>
</head>
<body>
<canvas id="renderCanvas" touch-action="none"></canvas>
</body>
</html>
import {
ArcRotateCamera,
Engine,
HemisphericLight,
Scene,
SceneLoader,
Vector3,
} from '@babylonjs/core';
import '@babylonjs/core/Meshes/meshBuilder';
import '@babylonjs/loaders/OBJ';
const canvas = document.getElementById('renderCanvas') as HTMLCanvasElement;
const engine = new Engine(canvas, true);
var createScene = function () {
var scene = new Scene(engine);
SceneLoader.ImportMeshAsync(
'',
// DON'T FORGET TO UPDATE THE PATH HERE
new URL('../static/your-obj.obj', import.meta.url).toString()
);
const camera = new ArcRotateCamera(
'camera',
-Math.PI / 2,
Math.PI / 2.5,
15,
new Vector3(0, 0, 0),
scene
);
camera.attachControl(canvas, true);
const light = new HemisphericLight('light', new Vector3(1, 1, 0), scene);
return scene;
};
const scene = createScene();
engine.runRenderLoop(function () {
scene.render();
});
window.addEventListener('resize', function () {
engine.resize();
});
- Create
./static
folder where you’ll put your OBJ file (don’t forget in main.ts to put the correct path!)
- Finally, start the app:
yarn parcel src/index.html
Everything should be running fairly smoothly from there when you access localhost:1234 by default