Procedural 3D Model Generation in Dust3D

In this article, I will try to introduce you the Procedural Generation feature in Dust3D using JavaScript.

About Dust3D

Dust3D is a free and open-source software for quick making 3D model with texture and rig automatically generated. It supports Linux, MacOS, and Windows.

In case you never use this software before, Here is a short demo on how to make a model in this software in none procedural mode.

The progress of modeling is to put nodes on canvas. By modifying the radius and position of the nodes, and other settings, you control the shape of the generated model.

Procedural Generation using JavaScript

In recent beta release, there is a new feature which allows you to generate nodes from JavaScript. It’s similar as web browser parse JavaScript to create HTML document. For example, the following JavaScript code will generate a paragraph in web browser,

var paragraph = document.createElement("p");
var node = document.createTextNode("This is text node under paragraph element.");
paragraph.appendChild(node);
document.body.appendChild(paragraph);

In Dust3D, you can create a node in a similar way,

var component = document.createComponent();
var part = document.createPart(component);
var node = document.createNode(part);
document.setAttribute(node, "x", 0.5);
document.setAttribute(node, "y", 0.5);
document.setAttribute(node, "z", 1.0);
document.setAttribute(node, "radius", 0.2);

Copy and paste the code to the script editor of Dust3D to run it

This will generate a node on canvas, and then the node been further generated into a cube mesh.

There are two circles on the canvas, orange circle represent the front view, green circle represent the side view. And the small triangle is the model center anchor.

Dust3D Document Structure

From the code, you may noticed that there are component, part, node, and attributes. Let’s explain a little bit here, for details you may need to check the Dust3D Script Reference.

1. Document 2. Canvas 3. Nodes and Edges 4. Part 5. Component

A document shows as a window in Dust3D, you draw nodes and connect nodes with edges on the canvas, all the connected nodes and edges grouped as parts. One document can have multiple parts. Each part belongs to a component.

Now let’s make a more complex example to understand these concepts.

More Complex JavaScript Example

function createNode(part, origin, radius)
{
    var node = document.createNode(part);
    document.setAttribute(node, "x", origin.getComponent(0));
    document.setAttribute(node, "y", origin.getComponent(1));
    document.setAttribute(node, "z", origin.getComponent(2));
    document.setAttribute(node, "radius", radius);
    return node;
}

function createLine(fromPosition, fromRadius, toPosition, toRadius, segments)
{
    var component = document.createComponent();
    var part = document.createPart(component);
    var previousNode = undefined;
    for (var i = 0; i <= segments; ++i) {
        var alpha = (i + 0.0) / segments;
        var origin = fromPosition.clone().lerp(toPosition, alpha);
        var radius = fromRadius * (1.0 - alpha) + toRadius * alpha;
        var node = createNode(part, origin, radius);
        if (undefined != previousNode)
            document.connect(previousNode, node);
        previousNode = node;
    }
    return part;
}

var fromPosition = new THREE.Vector3(0.5, 0.8, 1.0);
var fromRadius = 0.3;

var toPosition = new THREE.Vector3(0.5, 0.2, 1.0);
var toRadius = 0.1;

var segments = document.createIntInput("Segments", 3, 2, 10);
console.log("Hey, we accept parameter from the UI input control! The segments is " + segments);

var linePart = createLine(fromPosition, fromRadius, toPosition, toRadius, segments);
document.setAttribute(linePart, "subdived", "true");

The above JavaScript code generates a cylinder, from the down right corner, you can see a Segments slider control, adjust the slider, the generated result will change according to the segments value you modified. You may need toggle the settings in view menu to see the wireframe, the actual generated segments may greater than the value you configured because of intermediate nodes generation.

Also, there is a text box above the slider, shows

Hey, we accept parameter from the UI input control! The segments is 3

This is the console output. Yes, you can use console.log just as you use it in web browser.

Where to Go From Here?

If you have successfully tried the example code, now it’s time to dive deeper by checking the Dust3D Script Reference, to see a full API and attributes list. You can also check the Procedural Tree example from the Open Example menu which requires 1.0.0-beta.22 and above versions.

Dust3D is very young, any contributions are welcome, if you have any suggestions or want contribute a new feature please don’t hesitate to raise a issue here or make a pull request.

Last, I use my Procedural Tree v3.0 to end this article, please enjoy your procedural generation and welcome to share your script and screenshot to our forum.

Dust3D awarded Epic MegaGrants

I am very excited to share that Dust3D has been awarded Epic MegaGrants.

Dust3D is a 3D modeling software for quick making game assets with texture and rig automatically generated, it supports Linux, MacOS, and Windows. And it’s fully opensourced since the first day, https://github.com/huxingyi/dust3d

Epic MegaGrants is a funding provided by Epic Games,

to support game developers, enterprise professionals, media and entertainment creators, students, educators, and tool developers doing amazing things with Unreal Engine or enhancing open-source capabilities for the 3D graphics community. https://www.unrealengine.com/en-US/megagrants

Thank you Epic Games and all the contributors,

Siaržuk Piatroŭski  
PowPingDone
anderejd  
Alistair Miles  
hdu  
Ian Diaz  
Skullfurious  
Gamefromscratch  
RSDuck  
xtvjxk123456  
Zireael07  
glasyalabolas  
David Patrick  
Abraão Filho  
probonopd  
John Tsiombikas  
Jared Deckard  
Brandon Vandegrift  
iKlsR  
Jimmy Gunawan  
mikeruddy  
Helspank  
Demorde  
vanous  
justStand  
Ruben Niculcea  
boynet  
fornclake  
bvanevery  
Toshio Araki  
Evan Gruda  
KeepFenDou  
Kubilay Yalçın  
Satish Goda  
Sawm Fawk  
Erlend Sogge Heggen  
Michael Nowak  

* Ordered by first contribution

there are many others who also give invaluable supports not listed, thank you all, the grant will enable more possibilities for this tiny software.

Please stay tuned by join our mailing list and twitter hash tag #10minuteseveryday!

Dust3D on Raspberry Pi 3 Model B+

My friend Kevin Liang, who helped me 3D printed many cool Dust3D models, bought a Raspberry Pi 3 Model B+, the first thing to do when he received this tiny size computer is to run Dust3D, the same tiny size 3D modeling software.

Unfortunately, the Travis CI generated AppImage file can not run on Pi’s ARM CPU. But we can always build from source.

Most of the needed dev tools are out of the box on the default system, such as gcc, make. The Dust3D build instructions which written for Ubuntu, works like a charm on Pi. However, it always failed on the same file nodemesh/combiner.cpp, this file used CGAL library heavily. Every time, the machine dies on compiling this file, all system lose response. After power off, try, die, power off again, try, die again, several times, we found, out of memory is the root cause.

Googling keywords, “gcc low memory”, the first answer by Colin lan King shows how to create large swap memory for linux. So we created 4G swap for Pi to replace the default 100M swap.

Finally, more than one hours building, we succeed running Dust3D on Raspberry Pi.

The following are the full commands to build Dust3D on a Raspberry Pi 3 Model B+ with default system.

; Prepare 4G virtual memory for building, the default 1G memory and 100M swap are not enough to build.
; (The following swap image creating script comes from Colin lan King)

$ dd if=/dev/zero of=swap.img bs=1M count=4096
$ mkswap swap.img
$ chmod 0600 swap.img
$ sudo chown root:root swap.img
$ swapon swap.img



; Install dependencies

$ sudo apt-get install qtbase5-dev
$ sudo apt-get install qttools5-dev-tools
$ sudo apt-get install libcgal-dev
$ sudo apt install cmake
$ wget https://github.com/CGAL/cgal/releases/download/releases/CGAL-4.13/CGAL-4.13.zip
$ unzip CGAL-4.13.zip
$ cd CGAL-4.13
$ mkdir build
$ cd build
$ cmake ../
$ make
$ sudo make install



; Build Dust3D

$ git clone https://github.com/huxingyi/dust3d.git
$ cd dust3d
$ qmake -qt=5 -makefile
$ make



; Run Dust3D

$ ./dust3d

Dust3D 1.0 Beta 17 Is Now Available

Dust3D 1.0.0-beta.17 is now available, here are the changes,

  • Remote IO Protocol
  • Uncombined Mode
  • User Defined Cut Face
  • Base Plane Constrain
  • Color Solubility
  • Crash Fix

Download:
http://docs.dust3d.org/en/latest/install.html

Remote IO Protocol:

This is an experiment with Evan from University of Florida, to enable third party software/hardware to control the modeling process of Dust3D. This feature remains in experiment stage and may not exist in the final 1.0 stable version. See the protocol here: http://docs.dust3d.org/en/latest/remote_io_protocol.html

Uncombined Mode:

There are Normal and Inverse modes there before this release for component, normal represents the normal mesh union, inverse represents the mesh subtraction. This release introduce Uncombined mode, which represents the component would not take part in the mesh boolean algorithms. Be noticed that, model with uncombined mode component exists, would not be generate as a watertight mesh.

User Defined Cut Face:

Cut face is the extruding shape, with this release, the cut face could be configured as Quad, Pentagon, Hexagon, Triangle, and User Defined. User defined cut face could be selected from other parts with the target set to Cut Face. See demo here: https://twitter.com/jeremyhu2016/status/1132026219522772993

Base Plane Constrain:

Mesh layout and thickness adjustment are depend on base plane calculation. This release introduce the constrain settings: Dynamic, Side Plane, Front Plane, and Top Plane. It’s useful to limit the directions of mesh been generated. See demo here: https://twitter.com/jeremyhu2016/status/1130586879454109696

Color Solubility:

If one part configured color solubility, the generated color texture seam between the neighbor parts will be gradient filled using this part’s color with the specified solubility. See demo here: https://twitter.com/jeremyhu2016/status/1132159910815227904

P.S. Please note that, there is a #10minuteseveryday activity on going, where there are some fresh daily models been added.

First time ever! Dust3D model get 3D printed

I’ve always wanted to try 3D printing, today I finally get my hands on it! Cos my day job company has bought a MakerBot. :)

It took the printer 30min to print this frog, from nothing to real thing! I was super stoked.

(Lowpoly frog, 3D Printing in MakerBot, model generated by Dust3D)

Though it’s not my intention, it’s not a coincidence that models made in Dust3D is perfectly suitable for 3D print, the reason being so is that Dust3D models are watertight and no self intersection.

I remember the first ever model made in Dust3D by myself was an ant. I showed it to my day job manager, after that he refers my software as “Jeremy’s Bug Application”, is ant a bug? LOL. I kind of like the name. The feeling of knowing the software which I wrote from scratch can actually work and generate 3D models properly, was ever so sweet.

Today this feeling had come back to me.