Saturday, August 3, 2013

Sculptris to Shapeways with texture

I got into Sculptris a while back, and it's a great (free) program to sculpt organic objects. Only recently did I start painting the objects that I sculpted, using Sculptris' built in painter. It works wonderfully... right up until you want to export anything. The issue that everyone runs into is that the texture that you just painstakingly made is not attached to the .obj that you export!

Many sites advise the following:

"Export the texture map, and apply it in another program"

This is almost the most incredibly useless advice I have ever seen on the internet, for a couple of reasons.
  1. If an explanation that is this vague helps you, then you must already be familiar with mapping textures to 3D models. If you are just starting with 3D modelling and texturing, then you're out of luck.
  2. Sculptris does not, by default, show the option to export the texture map, which can be a bit confusing at first.
  3. When you export the texture map and .obj, Sculptris does not create an essential file for the mapping process!
Number 3 on that list is the real killer. You can understand how Sculptris works, and you can understand how your mapping program works, but unless you delve into the intricacies of the .obj filetype, you're never going to get the texture to map.

How to Export Textured .obj Files from Sculptris: The COMPLETE Guide

I am going to outline every step that I take when creating a textured model from Sculptris. A lot of this may seem obvious, but I want this tutorial to be accessible to anyone, even if you've never exported from Sculptris before.

Here we go!


Once you're done painting, select "Show Advanced Tools"

From the buttons that appear, press "SAVE TEXMAP"
(TEXMAP stands for "Texture Map")

Save your file. It's best to create a new folder, since we will have quite a few files by the end.
(You should choose a simple name; you will be typing it often from now on)

Next export your .obj by selecting the "Export" button.

Save the .obj in the same folder as the TEXMAP.
Use the same name as your TEXMAP.

CHECKPOINT: We now have two files (.png and .obj), both named "catbug_tex", saved in the same folder.

Open the .obj in a text editor

I'm going to take a quick break here to discuss the .obj file type. It is a very common format, but it's not without its faults. An .obj does contain the information for its texture within the file. Instead, it relies on a ".mtl" file to describe how the texture is mapped to the mesh.

If you check back in your folder, you'll notice that you don't have a .mtl file! Sculptris does not automatically generate one for you. We're going to have to create it ourselves.

But we're getting just a bit ahead of ourselves. Let's go back to the .obj, opened in a text editor.

Notice the highlighted line: "usemtl (null)". Null is nothing, zilch, nada. In terms of computing,
it means that it is "pointing" at nothing.

This isn't good! We want the material used to be something, not nothing! We'll make two changes
to the file to fix this.

Here are the two changes made.
A quick break again to explain the changes.
  1. Delete "(null)" on the line that says "usemtl (null)".
  2. Add "material_0" after "usemtl"
  3. Add "mtllib catbug_tex.mtl" to a new line, above "usemtl material_0"
Please take care to notice the spelling. If you misspell anything, your texture will not apply.
Another note: "catbug_tex.mtl" is the name of my .obj and TEXMAP. Change this to match yours. 

The new code should read:
mtllib catbug_tex.mtl
usemtl material_0 

Click save, and exit the text editor. There should be no apparent change in your file folder.
Next, create a new document in the text editor of your choice.
Add the following code to your new text document.
The code should read:
newmtl material_0
map_Kd catbug_tex.png
Please note: replace "catbug_tex.png" with the name of your texture!

This will be the entirety of our .mtl file. A brief explanation:

On the first line we are creating a new material, named "material_0". This material is the one that is referenced as "usemtl" in our .obj file. The spelling of these references must be the same, or your texture will not be applied.

On the second line, we are telling the file what image will be mapped to this material. This image is the texture exported from Sculptris. The spelling of these references must be the same, or your texture will not be applied.



*****Check and double check that you are writing these lines correctly! I got stuck for a very long time because the website I was following did not display underscores, and used spaces instead. You don't get an error or a warning, just a model without a texture.*****


Now that we've written our .mtl, save it in the same folder as the model and TEXMAP.
Select "All files" next to "Save as Type:"
Name the file: "Your_Model_Name.mtl"

Checkpoint: An .obj, a .png, and a .mtl, all named the same!

Now open up Blender. You should see this scene.

Right click on the cube to select it, then press delete.

Now that we have a blank scene, we can import our model.
Go File->Import->Wavefront | .obj

Navigate to and select your obj.

And in comes your model! Now is the time to orient and scale your model, because you can't later.

Now simply export your file!
Shapeways accepts .x3d files, so that's what we'll choose.
Go File->Export->X3D Extensible 3D | .x3d

Save your .x3d in the same folder as your original .obj, with the same name!

Checkpoint: We have 4 files: an .obj, a .png, a .mtl, and a .x3d, all named the same.

Just to double check, let's view our textured model in Meshlab. Open Meshlab and select "Import Mesh".

Navigate to and select your .x3d,

SUCCESS! A colorful Catbug!

Close Meshlab (Don't save), and go back to the folder with your .x3d file.
Select both the .x3d (The model) and the .png (The texture).
Right click and select "Add to Archive". (If you don't use WinRAR, zip these in your preferred program)

Save the files in "Your_Model_Name.zip"
Be sure to use .zip, not .rar, or .7z, or something.

Checkpoint: All 4 files, plus the zipped files. Upload that .zip to Shapeways, and get your full color goodness on!

Conclusion:

I hope this helps people using Sculptris bring their designs to life. It's a fantastic (and free) software, but being unable to export automatically textured .obj files is a huge pain.

Taking these steps has given me a textured model every time. Some people suggest applying the texture in blender, either through UV mapping or through its painter, but Blender's UI can be a bit daunting, especially to a new user. With this method, all that is required of Blender is "Import the .obj, then export the .x3d".

Let me know if this helps you out, or if you have problems. I'll do my best to clear up any murky areas!


Thanks,
Brandon Pomeroy


7 comments:

  1. I was really glad I found this post! I tried the entire process a couple of times, double checked everything, but unfortunately, my model appears in meshlab and shapeways without color. I have no idea how to fix it. :(

    ReplyDelete
    Replies
    1. Unfortunately, I can't really help diagnose your problem without seeing your files... If you're comfortable with uploading them, I'd be happy to take a look!

      There's also the possibility that some software updates have come out since this post... Hopefully this method still works!

      Delete
  2. I have the same problem! I checked everything but my model is still not showing any colors in meshlab or shapeways (I am able to order it in colored sandstone though, which is normally not possible if there are no colors).
    Can you please help?

    ReplyDelete
    Replies
    1. Unfortunately, I can't really help diagnose your problem without seeing your files... If you're comfortable with uploading them, I'd be happy to take a look!

      There's also the possibility that some software updates have come out since this post... Hopefully this method still works!

      Delete
  3. I finally managed to make a color model for Shapeways. This is the tutorial I've been looking for. Thank you!

    ReplyDelete
  4. Thank you.
    Thank you.
    THANK YOU.
    I was struggling all morning with this and no one could give me a straight answer. Pixologic definitely needs to make MTL files part of the export package.
    The rest is all fine-tuning; sketchfab tells me my geometries invert some of the lighting, but I'm not really worried about that right now. It looks on Sketchfab like it did in Sculptris, and that's all I need for now.

    ReplyDelete
  5. YO I just wanna say that model is fucking beautiful

    ReplyDelete