[Blender x Python] How to use modifiers

table of contents

0.Subdivision Surface 1.Array 2.Bevel 3.Boolean 4.Build 5.Decimate 6.Mirror 7.Screw 8.Skin 9.Solidify 10.ShrinkWrap (11.Shape Key)

0.Subdivision Surface

ssss.png

import bpy

def subSurf(level = 3):
    bpy.ops.object.modifier_add(type='SUBSURF')
    bpy.context.object.modifiers["Subdivision"].levels = level

bpy.ops.mesh.primitive_monkey_add()
subSurf()

1.Array aaaa.png

import bpy

def array(num = 5,o_x = 2,o_y = 0,o_z = 0):
    bpy.ops.object.modifier_add(type='ARRAY')
    
    array = bpy.context.object.modifiers["Array"]
    array.count = num
    
    array.relative_offset_displace[0] = o_x
    array.relative_offset_displace[1] = o_y
    array.relative_offset_displace[2] = o_z


bpy.ops.mesh.primitive_cube_add()
array(o_x = 5,o_y = 5,o_z = 5)

2.Bevel

tttttt.png

import bpy

def bevel(_amount = 0.3,_segments = 1):
    bpy.ops.object.modifier_add(type='BEVEL')

    bevel = bpy.context.object.modifiers["Bevel"]
    bevel.width = _amount
    bevel.segments = _segments

bpy.ops.mesh.primitive_ico_sphere_add()
bevel()

2-1.Bevel_animation

ezgif.com-gif-maker (30).gif

import bpy

frame_num = 0
bpy.context.scene.frame_set(frame_num)
bpy.context.scene.frame_end = 50

bpy.ops.mesh.primitive_cube_add()

bpy.ops.object.modifier_add(type='BEVEL')
bevel = bpy.context.object.modifiers["Bevel"]

for i in range(0,2):
    bevel.width = i
    bevel.keyframe_insert(data_path = "width",frame = frame_num)
    frame_num += 50

3.Boolean eee.png

import bpy

def boolean(obj):
    bpy.ops.object.modifier_add(type='BOOLEAN')
    
    boolean = bpy.context.object.modifiers["Boolean"]
    boolean.operation = 'DIFFERENCE'
    boolean.object = bpy.data.objects[obj]
    bpy.ops.object.modifier_apply(modifier="Boolean")
    

bpy.ops.mesh.primitive_cube_add()
bpy.ops.mesh.primitive_cube_add(location = (1,1,1))
boolean("Cube")

4.Build

import bpy

def build(f):
    bpy.ops.object.modifier_add(type='BUILD')
    
    build = bpy.context.object.modifiers["Build"]
    build.frame_start = f
    build.use_random_order = False
    build.seed = 0
    

bpy.ops.mesh.primitive_monkey_add()
build(f = 0)

4-1.Build_animation ezgif.com-gif-maker (27).gif

import bpy

frame_num = 0
bpy.context.scene.frame_set(frame_num)
bpy.context.scene.frame_end = 120

bpy.ops.mesh.primitive_monkey_add()

bpy.ops.object.modifier_add(type='BUILD')
build = bpy.context.object.modifiers["Build"]

for i in range(0,2):
    build.frame_start = 12 -i * 110
    build.keyframe_insert(data_path = "frame_start",frame = frame_num)
    frame_num -= 110

5.Decimate wwwww.png

import bpy

def decimate(limit_num):
    bpy.ops.object.modifier_add(type='DECIMATE')
    
    decim = bpy.context.object.modifiers["Decimate"]
    decim.decimate_type = 'DISSOLVE'
    decim.delimit = {'NORMAL'}
    decim.angle_limit = limit_num
    

bpy.ops.mesh.primitive_monkey_add()
decimate(limit_num = 0.8)

6.Mirror

import bpy

def mirror(obj):
    bpy.ops.object.modifier_add(type='MIRROR')
    
    mir = bpy.context.object.modifiers["Mirror"]
    mir.use_axis[0] = True
    mir.mirror_object = bpy.data.objects[obj]

    

bpy.ops.mesh.primitive_monkey_add()
bpy.ops.mesh.primitive_cube_add(location = (3,0,0))
bpy.context.view_layer.objects.active = bpy.data.objects["Suzanne"]
mirror("Cube")

7.Screw

import bpy

def subSurf(level = 3):
    bpy.ops.object.modifier_add(type='SUBSURF')
    bpy.context.object.modifiers["Subdivision"].levels = level

def screw(angle = 6.28,screw = 10,itr = 1,ax = 'Z'):
    bpy.ops.object.modifier_add(type='SCREW')
    
    scr = bpy.context.object.modifiers["Screw"]
    scr.angle = angle
    scr.screw_offset = screw
    scr.iterations = 2
    scr.axis = ax

bpy.ops.mesh.primitive_grid_add()
screw(itr = 2)
subSurf()

7-1.Screw_animation

ezgif.com-gif-maker (29).gif

import bpy

frame_num = 0
bpy.context.scene.frame_set(frame_num)
bpy.context.scene.frame_end = 120

bpy.ops.mesh.primitive_grid_add()


bpy.ops.object.modifier_add(type='SCREW')
scr = bpy.context.object.modifiers["Screw"]

_angle = 0
_screw_offset = 10


for i in range(0,2):
    scr.angle = _angle
    scr.screw_offset = _screw_offset
    #scr.iterations = i + 1
    scr.keyframe_insert(data_path = "angle",frame = frame_num)
    scr.keyframe_insert(data_path = "screw_offset",frame = frame_num)
    scr.keyframe_insert(data_path = "iterations",frame = frame_num)
    frame_num  += 110
    _angle += 15
    _screw_offset += 15

8.Skin

ssssss.png

import bpy

bpy.ops.mesh.primitive_uv_sphere_add()
bpy.ops.object.mode_set(mode='EDIT')

bpy.ops.mesh.delete(type='EDGE_FACE')
bpy.ops.mesh.select_all(action='SELECT')

bpy.ops.object.modifier_add(type='SKIN')
bpy.ops.transform.skin_resize(value=(0.1, 0.1, 0.1))

bpy.ops.object.mode_set(mode='OBJECT')

9.Solidify

import bpy

def solid(thick = -0.15,ofs = -1):
    bpy.ops.object.modifier_add(type='SOLIDIFY')
    solid = bpy.context.object.modifiers["Solidify"]
    solid.thickness = thick
    solid.offset = ofs

bpy.ops.mesh.primitive_monkey_add()
solid()

10.ShrinkWrap

ezgif.com-gif-maker (24).gif

import bpy

def subSurf(level = 3):
    bpy.ops.object.modifier_add(type='SUBSURF')
    bpy.context.object.modifiers["Subdivision"].levels = level

def shrinkWrapAnim(obj):
    bpy.ops.object.modifier_add(type='SHRINKWRAP')
    bpy.context.object.modifiers["Shrinkwrap"].target = bpy.data.objects[obj]
    bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=False, modifier="Shrinkwrap")
    
def shapeKeyInsert(frame_num = 10,shape_value = 1):
    obj = bpy.context.object
    obj.active_shape_key_index = 1
    
    for i in range(0,2):
        obj.active_shape_key.value = shape_value
        obj.active_shape_key.keyframe_insert(data_path = "value",frame = frame_num)
        
        frame_num += 50
        shape_value -= 1

s = 0.3
bpy.context.scene.frame_set(0)
bpy.context.scene.frame_end = 50

bpy.ops.mesh.primitive_cube_add(scale = (s,s,s))
bpy.ops.mesh.primitive_monkey_add()
subSurf()
shrinkWrapAnim("Cube")
shapeKeyInsert()

11.Shape Key

ezgif.com-gif-maker (25).gif

import bpy

bpy.ops.mesh.primitive_cube_add()
bpy.ops.object.shape_key_add(from_mix=False)

obj = bpy.context.object
deform_num = 2

for i in range(0,deform_num):
    obj.active_shape_key_index = i + 1

    obj.data.vertices[i * 2].co.z  += 5
    bpy.ops.object.shape_key_add(from_mix=False)
    
    frame_num = 0
    for f in range(0,deform_num + 1):
        
        if(f == i + 1):
            val = 1
        else:
            val = 0
            
        obj.active_shape_key.value = val
        obj.active_shape_key.keyframe_insert(data_path = "value",frame = frame_num)
        frame_num += 50

Recommended Posts

[Blender x Python] How to use modifiers
python3: How to use bottle (2)
[Python] How to use list 1
How to use Python argparse
Python: How to use pydub
[Python] How to use checkio
[Algorithm x Python] How to use the list
[Blender x Python] How to make an animation
[Blender x Python] How to make vertex animation
[Python] How to use input ()
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
[Blender x Python] How to create an original object
Python: How to use async with
[Python] How to use Pandas Series
How to use Requests (Python Library)
How to use SQLite in Python
[Python] How to use list 3 Added
How to use Mysql in python
How to use OpenPose's Python API
How to use ChemSpider in Python
How to use FTP with Python
Python: How to use pydub (playback)
How to use PubChem in Python
How to use python zip function
[Python] How to use Typetalk API
[Python] Summary of how to use pandas
[Introduction to Python] How to use class in Python?
How to install and use pandas_datareader [Python]
[python] How to use __command__, function explanation
[Python] How to use import sys sys.argv
How to erase Python 2.x on Mac.
[Python] Organizing how to use for statements
Memorandum on how to use gremlin python
[Python2.7] Summary of how to use unittest
python: How to use locals () and globals ()
How to use __slots__ in Python class
How to use "deque" for Python data
How to use Python zip and enumerate
[Python] Understand how to use recursive functions
How to use regular expressions in Python
[Python2.7] Summary of how to use subprocess
How to use is and == in Python
[Question] How to use plot_surface of python
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
How to use Seaboan
How to use image-match
How to use shogun
How to install Python
How to use Pandas 2
How to use numpy.vectorize
How to use pytest_report_header
How to install python
How to use partial
How to use Bio.Phylo