3DCoatScripting  4.8.31β
You can manage 3DСoat features with help of scripting
🌀 Boolean operations for meshes

3DCoat can combine meshes, creating mesh that you need. 3DCoat supports three types of boolean operations:

  1. Add
  2. Subtract
  3. Intersect

Lets see how we can do this with scripts.

Lets create two spheres and see what 3DCoat can do with it. There will be an example code in each section that you may simply copy it and run.

Take a note that in the end you get a complete mesh with accurate structure. You may press 'W' key to toggle wireframe mode.

(Add)

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// create two spheres that
// overlap
Builder builder;
Mesh a = builder.sphere()
.radius( 70 )
.details( 0.1 )
.build();
Mesh b = builder.sphere()
.radius( 40 )
.position( Vec3( 30, 40, 50 ) )
.details( 0.5 )
.build();
// join meshes
Mesh result = a | b;
// put resulting mesh into scene
room += result;
}

(Subtract)

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// create two spheres of different sizes
// that overlap
Builder builder;
Mesh a = builder.sphere()
.radius( 70 )
.details( 0.1 )
.build();
Mesh b = builder.sphere()
.radius( 40 )
.position( Vec3( 30, 40, 50 ) )
.details( 0.5 )
.build();
// subtract meshes
Mesh result = a - b;
// put resulting mesh into scene
room += result;
}

(Intersect)

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// create two spheres of different sizes
// that overlap
Builder builder;
Mesh a = builder.sphere()
.radius( 70 )
.details( 0.1 )
.build();
Mesh b = builder.sphere()
.radius( 40 )
.position( Vec3( 30, 40, 50 ) )
.details( 0.5 )
.build();
// intersect meshes
Mesh result = a & b;
// put resulting mesh into scene
room += result;
}

- Combination

As you would probably like to make something more complex than a single mesh in the scene, lets combine all examples of boolean operations used previously, and put all created objects in the scene.

You’ll need to know about transform methods.

void main() {
// prepare scene
SculptRoom room;
room.clear().toSurface();
// create two spheres of different sizes
// that overlap
Builder builder;
Mesh a = builder.sphere()
.radius( 70 )
.details( 0.1 )
.build();
Mesh b = builder.sphere()
.radius( 40 )
.position( Vec3( 30, 40, 50 ) )
.details( 0.5 )
.build();
// perform boolean operations on spheres
// put resulting mesh into scene
const Vec3 floorShift( 0, 200, 0 );
Mesh add = a | b;
Vec3 floor = Vec3( 0 );
add.tools().transform().position( floor ).run();
room += add;
Mesh subtract = a - b;
floor += floorShift;
subtract.tools().transform().position( floor ).run();
room += subtract;
Mesh intersect = a & b;
floor += floorShift;
intersect.tools().transform().position( floor ).run();
room += intersect;
}

As a result you must get a “pyramid” made with spheres after they’ve been added, subtracted and intersected.

More complex code might require for debugging. There is such an option in 3DCoat scripting

See Also
🌀 How to make a script
🌀 Making meshes out of primitives
🌀 Mesh Transform
🌀 Script debugging