Jump to content

Importing OBJ file


juanmajr93
 Share

Recommended Posts

Hi, i would like to import an OBJ file into my scene and I have got it. However, I don't get change the position and scale of the mesh. ¿How could I do it?

This is my code:

var loader = new BABYLON.AssetsManager(scene);
		var edificioB4 = loader.addMeshTask("A2", "", "http://localhost:8080/modelos/A2/", "A2.obj");
		BABYLON.OBJFileLoader.OPTIMIZE_WITH_UV = true;
		loader.load();

Thanks,

JuanMa J.R.

 

 

 

Link to comment
Share on other sites

I guess, you mean your FPS drops dramatically and everything is like lagging? Check your FPS and stuff with "scene.debugLayer.show();" and maybe your obj file is way too high poly or sth. like that. I encountered the same problem with high poly objects. Maybe you can share your obj / code so that we can try what's the issue.

Link to comment
Share on other sites

Well, i tried your OBJ and it has almost 1370 vertices and executes about 940 draw calls. But i have no laggs or jerky/sluggish moving with my camera if i change the resolution to HD (1280x720).

You are using a 1680x916 resolution. Try another resolution, I would suggest the most common FHD/HD (see https://en.wikipedia.org/wiki/Display_resolution).

To change resolution, just apply the height width style to your canvas like:

#renderCanvas{
	width:1280px;
	height:720px;
	touch_action: none;
}

 

Another option would be to change the obj to lower poly if possible?

 

Hope it helps you too.

Link to comment
Share on other sites

@juanmajr93 : Well I took a look at your .obj model in Blender - and it is the building I see on the map.

Exporting from Blender and viewing the .babylon file in the BJS Sandbox tells me it has 18 meshes and 17 of those are the letters that make up the name. And I get 35-40 fps, 29 Drawcalls and 13 Total Materials.

However, when I look at the image you posted above at the debug console it says that "Total Meshes = 1007",  "Drawcalls = 1004" and "Total Materials = 82". The question is what and where are these ~990 other meshes?

I don't think it is the .obj file (though it seems to have issues with the way some of the normals are facing.

cheers, gryff :)

Link to comment
Share on other sites

Thanks you very much gryff. This is the reason that there was a lot of lag in the scene. The exporting obj in SketchUp was bad because, the OBJ had many meshes. Although, I have resolved this problem i don't understand the follow:

I have the next images. The first is the result of import this model in BabylonJs and the second is the object in Blender. As you can see the building in BabylonJs is turned around and I am very surprised by this(mirror¿?). Other thing is that in the model of BabylonJS 's scene appear many triangles like the doors which must not show.

 

JuanMa J.R.

Captura1.PNG

Captura2.PNG

Link to comment
Share on other sites

@juanmajr93 : Juan, the model in Blender shows that there are all kinds of issues with the normals. See image below.

The long blue lines - normals pointing out (which is what you want),  the blue dots are normals pointing to the inside.(red rectangle -don't want)

Normals are strange all over the model - including the doors. Not sure about the mirror effect.

cheers, gryff :)

normals1.png

Link to comment
Share on other sites

Hi again gryff, good job! I agree with you and there is an important problem with theese normals of model. To solve it, I have recalculated normals in blender however, many of them go on pointing to inside. Do you know any way to solve it fastly?. The mirror effect, in BabylonJs, is very strange because in Blender like you could see the model is right.

Thank you very much.

JuanMa J.R.

Link to comment
Share on other sites

  • 1 year later...

It looks like Juanmarj93 was happy with the mirroring code that he wrote.  I was facing a similar problem, but I found another question in this forum (38580) that gives a better solution.  The default coordinate system used by Babylon is left handed.  This is easily verified by using the pg and adding spheres or cubes of different sizes with positions set to positive values for the x-, y-, or z-directions.  

The class scene has a method to switch to a right-handed coordinate system:

scene.useRightHandedSystem = true;

This will render objects 'as expected' to engineers like me.  

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...