Skip to content

Automatic 3D Optimization

Bake my scan

This tutorial presents a small program we have developed thanks to Loic Norgeot's awesome and opensource plugin for Blender, called "Bake my scan". It is a plugin that allows you to quickly process your 3D scans or highly complex objects for them to be imported in real-time applications.

We have developed a version of this plugin which allows you to simply drag and drop an object on a script, and it will automatically process it and export five different versions of the decimated object, from very low poly (1 500 triangles) to relatively high (120 000 triangles).

You can download the script on this GitHub repository.

When NOT to use the script

The script is not magic, and there are a few cases in which you will certainly encounter problems.

  • This script is made to process very large models such as models issued from photogrammetry or 3D scanning. That is to say, it targets models which are over 100 or 200 000 triangles. If your object is 50 000 triangles and that you don't want any other object in your scene (or if it is accompanied by very low poly objects), you should not use this script, because you will lose quality. Use this script only if you have no other choice for it to be imported in Minsar Studio.

  • Check that the diffuse texture of the object is no greater than 2048 x 2048: if your device is not powerful enough, Minsar Studio will crash.

  • If your object contains parts of the geometry which overlap over parts (for instance cushions on a sofa, or an arm which goes over the stomach for a statue), you might get some baking artefacts.

  • The script does not work yet for animated objects, but we are working on it.

How to use the script

Install the script and prepare your object

1.1. Go to Github and download the script on your computer, by clicking "Clone or download" and then choosing "Download ZIP".

1.2. Unzip the script wherever you want on your computer. The folder name should be "Automatic_BakemyScan-master", if you don't change anything.

Beware of the path

Make sure that your "Automatic_BakemyScan-master" folder is put somewhere on your computer where it doesn't create a weird path. The path should look something like C:\Users\YourName\Downloads\Automatic_BakemyScan-master, with no accents or spaces in the whole path.

1.3. In the "Input" folder of Automatic_Bakemyscan-master, create a new folder named after the object you want to optimize. For example, let's say "Cat".

1.4. In this folder, first you have to put your high-poly mesh, named exactly like the folder (in our case, "Cat"). In the end, your object should look like something like "Cat.obj" or "Cat.fbx".

1.5. In the same folder, you now have to put your diffuse texture, that is to say the color map of your object. There again, it should be named exactly like the folder, but you should add "_color" to the name of your texture. You now should have something like "Cat_color.jpg" or "Cat_color.png".

Multiple textures

If your object has several color textures, you must create a "Color" folder and put the textures in there. Each texture should be named "name_color0", "name_color1", etc.

Objects from Sketchfab

If you want to use the script to process an object coming from Sketchfab, there are a couple of things you should be aware of.

  • When you download from Sketchfab, first you will have to unzip your download. Then, you will have to get the model into the "Source" folder (sometimes you will have to unzip its contents as well), and the diffuse texture into "Textures".

  • Do not use the auto conversion in ".glTF" when you download an object from Sketchfab. Until further update, it creates elements that cannot be processed by the script. We are working on it :)

  • If the Sketchfab object is in ".glTF" anyway, then after you have unzipped its contents, you have to respect the original hierarchy. Copy the contents exactly how they are (for instance the folder "Source" and the folder "Textures"). In the script "Input" folder, create a new folder with the name you want for your object (for example "Cat"), and paste the contents in there.

  • Then, only change the name of your "object.glTF", but don't touch the other files (textures and .bin). For instance, if in your folder "Sources" you have "cat-150.gltf" and "cat-150.bin", only rename "cat-150.glTF" with the exact same name of the "Cat" folder. You now should have "Cat.glTF", and "cat-150.bin". This is fine, don't touch anything else :)

Process your object

2.1. Get out of the folder you have just created (in our case "Cat"). You can see a script named Automatic_Bake.bat. You have to select your "Cat" folder, and drag and drop it on that script.

2.2. A Windows console is going to appear. Just let it run until it says "Process done, you can close the console!"

Weird messages

In the console, there will be a moment where you will see a succession of "Invalid clnors in this fan!" messages. Even if it seems to have crashed because you can't see anything but these messages for a while, this is completely normal. Just be patient!

Get your exported model

2.3. Close the console.

2.4. Get out of the "Input" folder, and navigate to the "Output" folder.

2.5. There, you will find a folder with the name of your object. If you open it, you will see seven folders. Six of them are named "verylow", "low", "medium", "high", "veryhigh" and "ultrahigh". These contain the data of the five decimated versions that the script has exported. It contains the baked textures, and gives you information about their resolution.

2.6. The most important folder is the "Glb" one. It is the folder which contains the final exports. You will find five versions of your object: one with 1500 triangles, one with 3000, one with 6000, one with 10 000 triangles, one with 50 000 and one with 120 000. This way, you can compare which version you feel corresponds better to your needs! Don't worry, the textures are packed inside the ".glb."

If you want only one version

Alongside the "Automatic_Bake.bat" script, you can see other scripts named "1500.bat", "3000.bat", "6000.bat", etc. As you might think, these are scripts which are dedicated to creating only one decimated version of your model, not the five: "1500.bat" will decimate to 1500 triangles, "3000.bat" to "3000", etc. If you have a precise idea of the level of decimation you want prior to its processing, just drag and drop your folder on one of those scripts, and go find the result in the "Output" folder :)

There you are, your model is optimized for Minsar Studio. Now you just have to drag and drop your final object in the provider of your choice, and access it through Minsar Studio. If you want to know more about this awesome script by Loic Norgeot, we strongly invite you to go see his page and use his work!

If you want to learn how to do this yourself

Loic Norgeot's script is awesome because it gives non-technical people access to the complex process of optimizing a 3D object for real-time applications. However, if you are curious and want to do this by yourself, you are welcome to have a look at this tutorial that explains every step of the process.