Jump to content

Flipped axis on imported Sketchup OBJ


erixon
 Share

Recommended Posts

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
	}
}

 

Link to comment
Share on other sites

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 :D
I'm also not so sure if it should be a Tools function or directly a function of the Geometry class.

Link to comment
Share on other sites

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

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