How Can I load .obj Mesh By typescript

Recommended Posts


       I am new beginner of Babylonjs , I want to load a mesh(.obj) by typescript.    

     Here is my code (run in playground):

class Playground {
public static CreateScene(engine: BABYLON.Engine, canvas: HTMLCanvasElement): BABYLON.Scene {
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
// This creates and positions a free camera (non-mesh)
var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
// This targets the camera to scene origin
// This attaches the camera to the canvas
camera.attachControl(canvas, true);
// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
var 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 = 0.7;
// BABYLON.SceneLoader.ImportMesh("Rabbit", "scenes/","Rabbit.babylon", scene, function (newMeshes) {
BABYLON.SceneLoader.ImportMesh("Rabbit", "scenes/Box/","Box.obj", scene, function (newMeshes) {
var rabbit = newMeshes[0];
if(rabbit == null)
console.log("rabbit is null")
rabbit.scaling = new BABYLON.Vector3(0.1,0.1,0.1);
console.log("I can see the rabbit");
// scene.beginAnimation(skeletons[0], 0, 100, true, 0.8);
return scene;
When  I load Box.obj I got a log  "rabbit is null".   but  when i load a Rabbit.babylon file it work good.   

What happened when I loaded.Obj?

Who can help me load .obj Mesh By Typescript?


Thank you


Share this post

Link to post
Share on other sites
9 hours ago, Deltakosh said:

Hello and welcome!

You have to make sure that box.obj contains a mesh named "Rabbit" or use:

BABYLON.SceneLoader.ImportMesh("", "scenes/Box/","Box.obj", scene, function (newMeshes) 

Thank you for you reply.    I misunderstood the meaning of meshName......  

thank you anain

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.