Hi, guys!
I have been playing with Babylon.js for the last week or so and having so much fun!!
Though, I am having a trouble looking for my object every time I load a different one.
This example on Babylon PlayGround is somehow at the origin (0, 0, 0) and its scale is beautifully appropriate.
However, when I loaded an object that I downloaded from “sketchfab.com,” it is located way up in the Y axis. Of course, I can manually type in values for camera and target position and drag and zoom in/out to find objects that I load every time, but it is just so frustrating.
Here is what I did:
var createScene = function () {
// This creates a basic Babylon Scene object (non-mesh)
const scene = new BABYLON.Scene(engine);
var camera = new BABYLON.ArcRotateCamera("camera", 2.372, 1, 0.5, BABYLON.Vector3.Zero(), scene);
camera.upperRadiusLimit = 0.5;
camera.lowerRadiusLimit = 0.25;
camera.minZ = 0.01;
// 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("light", new BABYLON.Vector3(0, 0, 0), scene);
// Default intensity is 1. Let's dim the light a small amount
light.intensity = 1;
light.range = 10;
var assetsManager = new BABYLON.AssetsManager(scene);
var meshTask = assetsManager.addMeshTask("shoe task", "", "https://assets.babylonjs.com/meshes/", "shoe_variants.glb");
// var meshTask = assetsManager.addMeshTask("shoe task", "", "./hoodie-v2/source/Hoodie/", "Hoodie.obj");
meshTask.onSuccess = function (task) {
task.loadedMeshes[0].position = BABYLON.Vector3.Zero();
}
assetsManager.onFinish = function (tasks) {
engine.runRenderLoop(function () {
scene.render();
});
};
assetsManager.load();
showAxis(900);
return scene;
};
I tried BABYLON.Vector3.Zero(); so that hopefully, it is centered when I load it, but it is not working. Also, sometimes, the object is way too big.
Is there a way for me to load objects with properly centered with adequately scaled so it is fit right in the canvas?
Thank you so much!! I hope you guys enjoy coding with Babylon!!
Have a wonderful day!!