juanmajr93 Posted November 30, 2016 Share Posted November 30, 2016 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 30, 2016 Share Posted November 30, 2016 Hello You should add a onsuccess callback on your task to get the mesh and then just call mesh.position.x = ... (http://doc.babylonjs.com/tutorials/How_to_use_AssetsManager) Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 1, 2016 Author Share Posted December 1, 2016 Okey, thanks you very much, I got it. However i have another problem. After load the obj file, the movement in the scene is so slow, it seem that the fps are lower (under 60fps/sec) How can i get a better scene without this problem? Thanks, JuanMa J.R. Quote Link to comment Share on other sites More sharing options...
dbawel Posted December 1, 2016 Share Posted December 1, 2016 Playground Scene? I expect there is an issue with your model or code. DB Quote Link to comment Share on other sites More sharing options...
Ice-T Posted December 1, 2016 Share Posted December 1, 2016 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. Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 1, 2016 Author Share Posted December 1, 2016 Hi, thanks by all your answers. I cant show the scene becasue, i am making this job in server that disable the port 80. Although, I can share you my file obj and the results of debug. I think that the problem can be this model but I am not sure... Thank you very much. JuanMa J.R C6.rar Quote Link to comment Share on other sites More sharing options...
Ice-T Posted December 1, 2016 Share Posted December 1, 2016 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. Quote Link to comment Share on other sites More sharing options...
gryff Posted December 1, 2016 Share Posted December 1, 2016 @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 Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 9, 2016 Author Share Posted December 9, 2016 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. Quote Link to comment Share on other sites More sharing options...
gryff Posted December 9, 2016 Share Posted December 9, 2016 @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 Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 10, 2016 Author Share Posted December 10, 2016 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. Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 11, 2016 Author Share Posted December 11, 2016 Yeah!!!, I got correct all normals in my model @gryff .The result now is pretty!!! However, could somebody explain me why the model is represented in the world as inverse or mirror???? Theese are the images: Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 12, 2016 Author Share Posted December 12, 2016 I solved it by this code: var vertex_data = BABYLON.VertexData.ExtractFromMesh(b); for (var i = 0; i < vertex_data.normals.length; i+=3) { vertex_data.positions[i] *= -1; } vertex_data.applyToMesh(b); Bye. Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted December 12, 2016 Share Posted December 12, 2016 @juanmajr93 after that compute normal again Quote Link to comment Share on other sites More sharing options...
juanmajr93 Posted December 13, 2016 Author Share Posted December 13, 2016 Okey, I will. This problem is resolved! Quote Link to comment Share on other sites More sharing options...
ChadK Posted July 16, 2018 Share Posted July 16, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.