User Tools

Site Tools


blender:main-blender-csg-union-shapes

Back to Blender Help Design

The example shows how to build a gate by combining 3 cylinders : two vertical and one horizontal.

The combination is computed with CSG (Constructive Solid Geometry). The CSG has 3 basic operations : union, intersection and difference. Here we will use the union to get a mesh that corresponds to the union of the 3 meshes.

First we create 3 simple cylinders (see here for details. Then we select only the third cylinder cyl3 on which we add a modifier called csg2 to make the union with cyl2. After we do the same with cyl1 using csg1 modifier. The result is renamed Gate and is stored in gate Python variable . To clean the scene, the objects cyl1 and cyl2 are deleted as we do not need them any more. Finally we can apply some transformations. Here we apply 2 operations : rotation and scaling.

def create_gate():
    cyl1 = define_cylinder ("Gate1", 0.5, 3.0 ,-5.0, 0.0, 1.5, 0.0, 0.0 , 0.0)
    cyl2 = define_cylinder ("Gate2", 0.5, 3.0 , 5.0, 0.0, 1.5, 0.0, 0.0 , 0.0)
    cyl3 = define_cylinder ("Gate3", 0.5, 9.5 , 0.0, 0.0, 2.75, 0.0, 90.0 , 0.0)
    cyl1.select_set(False)
    cyl2.select_set(False)
    cyl3.select_set(True)
    csg2 = cyl3.modifiers.new(name="csg2", type="BOOLEAN")
    csg2.operation = "UNION"
    csg2.object=cyl2
    ops.object.modifier_apply(apply_as='DATA', modifier='csg2')
    csg1 = cyl3.modifiers.new(name="csg1", type="BOOLEAN")
    csg1.operation = "UNION"
    csg1.object=cyl1
    ops.object.modifier_apply(apply_as='DATA', modifier='csg1')
    gate = context.active_object
    gate.select_set(False)
    cyl1.select_set(True)
    cyl2.select_set(True)
    ops.object.delete()
    gate.select_set(True)
    gate.name = "Gate"
    gate.rotation_euler = (90.0*deg2rad, 90.0*deg2rad, 0.0*deg2rad)
    ops.transform.resize(value=(10.0, 10.0, 10.0))
    return gate

Back to top.

blender/main-blender-csg-union-shapes.txt · Last modified: 2020/04/13 18:38 by admin