The 3D Web Coder

Flipping OBJ Axes and OBJ Texture for Forge

The Forge DevCon finished, and I spent a nice weekend walking around San Francisco.

Saturday, I crossed the Golden Gate bridge and the Marin headlands to Sausalito:

Golden Gate Sausalito Walk

Sunday, I participated in the ecstatic dance event (FB) in their great new location and enjoyed the views from the Buena Vista and Presidio parks:

Buena Vista and Presidio

At the Forge DevCon, I had a full body 3D scan created in the Shapify Booth.

The resulting OBJ model can be downloaded for $10 from

It includes the material and texture files. The material is initially set to very shiny, to match the plastic figurine that you can have printed out.

Unfortunately, the initial model is lying down, not standing up:

Jeremy lying down

Lying down, it is kind of hard to manipulate in a meaningful fashion.

I uploaded that initial model to both the Dotty trial and A360 platforms for you to test the rotation behaviour in that orientation.

Flipping the OBJ Axes using sed

Happily, it is easy to change the axis definitions in the OBJ file using a simple sed operation.

I case you are not familiar with it, sed is the age-old stream editor Unix text processing utility, developed at Bell labs in 1973-1974.

It is available for just about any operating system, and already built in to every Unix, Linux or Mac OS shell.

You can easily install sed on other operating systems, including Windows.

Now, how can sed help us flip the figure to stand up?

To flip the figure from lying to standing, we need to modify two of the three cardinal axes:

By the way, the negation is required to conserve the 'handedness' of the surface triangles.

The rendering system assumes them to be oriented in a specified direction, based on a right-handed coordinate system.

Not flipping the sign would convert the right-handed system to a left-handed one, invert the triangle orientation, and corrupt the rendering.

In the OBJ file, each vertex is defined in a line of text like these:

v -87.852317810058594 -89.117828369140625 25.285612106323242
v 166.26298522949219 197.78297424316406 1084.01806640625
v -29.722711563110352 307.6329345703125 1215.2177734375

The transformation required is achieved by the following sed script:

s/^v \([0-9\.\-]*\) \([0-9\.\-]*\) \([0-9\.\-]*\)/v \1 \3 -\2/

In clear text, it says the following:

Since the original Y value may be negative, and the replacement expression prepends another minus character to it, we may end up with two minus characters in front of the Z value.

Another simple substitution statement clears that up:

s/ --/ /

Meaning, 'replace space-minus-minus by just a space'.

I stored these two lines in a file obj_flip_axes.sed:

s/^v \([0-9\.\-]*\) \([0-9\.\-]*\) \([0-9\.\-]*\)/v \1 \3 -\2/
s/ --/ /g

The original OBJ file can be transformed to create a new one with flipped axes by running sed from the command line like this:

$ sed -f obj_flip_axes.sed model__0.obj

The result is printed to the command line.

The output can be directed to a new OBJ file like this:

$ sed -f obj_flip_axes.sed model__0.obj > model_flipped.obj

In my case, the OBJ file size exceeds 57 MB, and this operation takes less than a second, so it is pretty efficient.

The resulting model is correctly oriented:

Jeremy standing up

The interactive behaviour now is much better.

You can try this out for yourself as well.

Here it is again in the Dotty trial and on A360 including the option to embed it:

Uploading OBJ with Material and Textures to Forge

This more or less answers the question on how to upload OBJ with MTL and textures to bucket:

Question: As the title suggests, how do I upload the obj model's material file and textures, as they are hard coded in the obj file?

Can I upload the zipped dir structure or multiple files that are in correct relation (because of the hard coded nature of obj)?

Answer: A ZIP file should work for Autodesk Model Derivative as long as the same works locally (meaning all references are working).

For the sample above, I simply uploaded a single zip file containing OBJ, MTL and PNG to the Dotty trial site.

The upload to A360 was performed by uploading the parent folder and specifying the OBJ file as the main model.