Jump to content

How Can I load .obj Mesh By typescript


MibuWolf
 Share

Recommended Posts

Hi 

       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
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)
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")
}
else
{
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

 

Link to comment
Share on other sites

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) 

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...