erixon Posted May 22, 2016 Share Posted May 22, 2016 Hello! One axis is flipped when I imported an object from Sketchup/OBJ into Babylonjs. What is the easiest solution to solve this? kind regards Tomas Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 23, 2016 Share Posted May 23, 2016 hey! If only one axis is inverted you can edit the mesh data (mesh.getVerticesData) and invert Y value. But I'm afraid this could be more a right handed vs. left handed question. In this case you should export your model with the right axis (check "Good things to know here:https://github.com/BabylonJS/Babylon.js/tree/master/loaders/OBJ) Quote Link to comment Share on other sites More sharing options...
erixon Posted May 25, 2016 Author Share Posted May 25, 2016 Sketchup export options are few. One little bit odd solution is to flip in sketchup/work mirrored. Another is to make a script for the obj-file. I guess if I edit the data and like update normals also, it sounds unnecessary heavy clientside. Thanks anyways, unfortunately this kind of development with many softwares seldom is 'it just works'. But I'm happy that I can import, some year ago I had trouble with the converter not working. kind regards Tomas Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 25, 2016 Share Posted May 25, 2016 An option could be to use Blender to import the obj and then export .babylon from blender Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 25, 2016 Share Posted May 25, 2016 Here a typescript function i wrote some time ago to convert a geometry to left handed. I also used it in combination with th OBJ loader. public static geometryToLeftHanded(pGeom: BABYLON.Geometry): void { if (pGeom == null) return; //flip faces let tIndices = pGeom.getIndices(false); if (tIndices != null && tIndices.length > 0) { for (let i = 0; i < tIndices.length; i += 3) { let tTemp = tIndices[i + 0]; tIndices[i + 0] = tIndices[i + 2]; tIndices[i + 2] = tTemp; } pGeom.setIndices(tIndices); } //negate position.z let tPositions = pGeom.getVerticesData(BABYLON.VertexBuffer.PositionKind, false); if (tPositions != null && tPositions.length > 0) { for (let i = 0; i < tPositions.length; i += 3) { tPositions[i + 2] = -tPositions[i + 2]; } pGeom.setVerticesData(BABYLON.VertexBuffer.PositionKind, tPositions, false); } //negate normal.z let tNormals = pGeom.getVerticesData(BABYLON.VertexBuffer.NormalKind, false); if (tNormals != null && tNormals.length > 0) { for (let i = 0; i < tNormals.length; i += 3) { tNormals[i + 2] = -tNormals[i + 2]; } pGeom.setVerticesData(BABYLON.VertexBuffer.NormalKind, tNormals, false); } } Wingnut 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 25, 2016 Share Posted May 25, 2016 Hey Kesshi! this is worth a PR to me Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 26, 2016 Share Posted May 26, 2016 7 hours ago, Deltakosh said: Hey Kesshi! this is worth a PR to me I will put it on my todo list ... a bit busy at the moment Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 26, 2016 Share Posted May 26, 2016 I can do it for you if you want Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 26, 2016 Share Posted May 26, 2016 Yes you can do it if you have the time. Lot of things to do at work at the moment and at home my 1 year old daughter keeps me busy I'm also not so sure if it should be a Tools function or directly a function of the Geometry class. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 26, 2016 Share Posted May 26, 2016 Done Quote Link to comment Share on other sites More sharing options...
Kesshi Posted May 27, 2016 Share Posted May 27, 2016 nice, one more function i can remove from my code base :-) GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
erixon Posted June 2, 2016 Author Share Posted June 2, 2016 Thanks for the replies. I initially choosed obj because it looked like a nice compact format supported by Sketchup. Though struggling hours in Blender with small errors in my baked textures and the flipped problem, I started to use the babylon-format and it solved more or less all my problems. I really hate blender ui but it helps me with the baking. But Babylonjs is wonderful :-) kind regards Tomas Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 2, 2016 Share Posted June 2, 2016 Lol thanks! 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.