资源
课程
Linux 下安装 bpy
从 Releases · TylerGubala/blenderpy (github.com) 下载静态安装包,然后:
pip install bpy-2.91a0-cp37-cp37m-manylinux2014_x86_64.whl && bpy_post_install
Create Curved Text In Blender | Bend Any Text | Part 1 in Text Effects | Two Easy Methods Explained
创建文本对象
- 创建一个
Text对象:
import bpy
bpy.ops.object.text_add()
text_obj = bpy.context.object- 将这个
Text对象的Rotation X和Z设为90°:
import numpy as np
text_obj.rotation_euler[0] = np.pi / 2
text_obj.rotation_euler[2] = np.pi / 2- 将文字设为居中对齐:
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"- 将这个
Text的Geometry的Extrude设为0.1m,使其具有厚度。
text_obj.data.extrude = 0.1- 切换到
Edit Mode,可以更改其文字内容。
text_obj.data.body = "Hello,\nWorld!"直接弯曲
- 给
Text对象添加一个Simple Deform的Modifier:
text_modifier = text_obj.modifiers.new(name="Bend", type="SIMPLE_DEFORM")- 设置其属性:
text_modifier.deform_method = "BEND"
text_modifier.deform_axis = "Z"
text_modifier.angle = np.pi / 4得到弯曲后的文本:
完整代码:
import bpy
import numpy as np
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.rotation_euler[0] = np.pi / 2
text_obj.rotation_euler[2] = np.pi / 2
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
text_obj.data.extrude = 0.1
text_obj.data.body = "Hello,\nWorld!"
text_modifier = text_obj.modifiers.new(name="Bend", type="SIMPLE_DEFORM")
text_modifier.deform_method = "BEND"
text_modifier.deform_axis = "Z"
text_modifier.angle = np.pi / 4沿 Bezier 曲线弯曲
- 新建一个
Circle对象,将其Rotation Z设为90°:
bpy.ops.curve.primitive_bezier_circle_add()
curve_obj = bpy.context.object
curve_obj.rotation_euler[2] = np.pi / 2- 给
Text对象添加一个Modifier,选择Curve,然后选择之前新建的BezierCircle对象:
curve_modifier = text_obj.modifiers.new(name="Curve", type="CURVE")
curve_modifier.object = curve_obj此时 Text 对象就会沿着 BezierCircle 曲线变形:
- 选中
BezierCircle对象,切换到Edit Mode,选择Segments→Switch Direction,便可切换文字方向:
bpy.ops.object.editmode_toggle()
bpy.ops.curve.switch_direction()
bpy.ops.object.editmode_toggle()- 修改
BezierCircle的Scale,Text对象也会随之变化:
curve_obj.delta_scale[0:3] = [2, 2, 2]完整代码:
import bpy
import numpy as np
# 新建一个 TextCurve 对象
bpy.ops.object.text_add()
text_obj = bpy.context.object
# 修改文本位置和旋转角度
text_obj.rotation_euler[0] = np.pi / 2
text_obj.rotation_euler[2] = np.pi / 2
# 修改文本对齐方式
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
# 挤出文本
text_obj.data.extrude = 0.1
# 设置文本内容
text_obj.data.body = "Hello,\nWorld!"
# 创建一个圆形对象
bpy.ops.curve.primitive_bezier_circle_add()
curve_obj = bpy.context.object
# 旋转该圆形对象
curve_obj.rotation_euler[2] = np.pi / 2
# 让文本沿着圆形变换
curve_modifier = text_obj.modifiers.new(name="Curve", type="CURVE")
curve_modifier.object = curve_obj
# 修改方向
bpy.ops.object.editmode_toggle()
bpy.ops.curve.switch_direction()
bpy.ops.object.editmode_toggle()
# 修改圆形大小
curve_obj.delta_scale[0:3] = [2, 2, 2]Add Text To Any Curved Surface In Blender | Part 2 in Text Effects | Blender Eevee & Cycles
- 新建一个茶壶:
import bpy
import numpy as np
bpy.ops.mesh.primitive_teapot_add()
teapot_obj = bpy.context.object- 新建一个文本对象,设置其对齐、位置(使其靠近茶壶表面)、旋转、挤出、文字内容、行间距等:
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
text_obj.location[1] = -2
text_obj.location[2] = 1.5
text_obj.rotation_euler[0] = np.pi / 2
text_obj.data.extrude = 0.1
text_obj.data.body = "Hello,\nWorld!"
text_obj.data.space_line = 0.75- 给文字对象添加一个红色的材质,此时转到渲染窗口,文字就会呈现红色:
text_material = bpy.data.materials.new(name="TextMaterial")
text_material.use_nodes = True
nodes = text_material.node_tree.nodes
principled_bsdf = nodes.get("Principled BSDF")
if principled_bsdf is not None:
principled_bsdf.inputs[0].default_value = (1, 0, 0, 1)
text_obj.data.materials.append(text_material)- 新建一个
Empty的Cube,设置其位置使其和Text相同,设置其旋转角,用于控制Text的旋转:
bpy.ops.object.empty_add(type="CUBE")
empty_obj = bpy.context.object
empty_obj.location[1] = -2
empty_obj.location[2] = 1.5
empty_obj.rotation_euler[0] = np.pi / 2
empty_obj.rotation_euler[2] = np.pi / 2- 给
Text对象添加 modifier:
Remesh:用于使字体集合与弯曲操作兼容,选择Sharp,Octree Depth设为8:
text_modifier_remesh = text_obj.modifiers.new(name="Remesh", type="REMESH")
text_modifier_remesh.mode = "SHARP"
text_modifier_remesh.octree_depth = 8
text_modifier_remesh.use_remove_disconnected = FalseSimpleDeform:用于字体弯曲,选择Bend,Origin选择Empty对象,Axis选择Y轴:
text_modifier_simple_deform = text_obj.modifiers.new(name="SimpleDeform", type="SIMPLE_DEFORM")
text_modifier_simple_deform.deform_method = "BEND"
text_modifier_simple_deform.origin = empty_obj
text_modifier_simple_deform.deform_axis = "Y"Shrinkwrap:使得文字映射到teapot上,Wrap Method选择Target Normal Project,Target选择Teapot对象,Offset选择0.1m:
text_modifier_shrink_wrap = text_obj.modifiers.new(name="Shrinkwrap", type="SHRINKWRAP")
text_modifier_shrink_wrap.wrap_method = "TARGET_PROJECT"
text_modifier_shrink_wrap.target = teapot_obj
text_modifier_shrink_wrap.offset = 0.1
完整代码:
import bpy
import numpy as np
# 新建 teapot 对象
bpy.ops.mesh.primitive_teapot_add()
teapot_obj = bpy.context.object
# 新建 text 对象
bpy.ops.object.text_add()
text_obj = bpy.context.object
# 居中对齐
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
# 设置位置
text_obj.location[1] = -2
text_obj.location[2] = 1.5
# 设置旋转角
text_obj.rotation_euler[0] = np.pi / 2
# 设置挤出举例
text_obj.data.extrude = 0.1
# 设置文本内容
text_obj.data.body = "Hello,\nWorld!"
# 设置行间距
text_obj.data.small_caps_scale = 0.75
# 新建材质
text_material = bpy.data.materials.new(name="TextMaterial")
text_material.use_nodes = True
nodes = text_material.node_tree.nodes
principled_bsdf = nodes.get("Principled BSDF")
if principled_bsdf is not None:
principled_bsdf.inputs[0].default_value = (1, 0, 0, 1)
# 给文本添加材质
text_obj.data.materials.append(text_material)
# 新建 empty 对象
bpy.ops.object.empty_add(type="CUBE")
empty_obj = bpy.context.object
# 设置 empty 位置
empty_obj.location[1] = -2
empty_obj.location[2] = 1.5
# 设置 empty 旋转角
empty_obj.rotation_euler[0] = np.pi / 2
empty_obj.rotation_euler[2] = np.pi / 2
# 新建 Remesh 的 modifier
text_modifier_remesh = text_obj.modifiers.new(name="Remesh", type="REMESH")
text_modifier_remesh.mode = "SHARP"
text_modifier_remesh.octree_depth = 8
text_modifier_remesh.use_remove_disconnected = False
# 新建 SimpleDeform 的 modifier
text_modifier_simple_deform = text_obj.modifiers.new(name="SimpleDeform", type="SIMPLE_DEFORM")
text_modifier_simple_deform.deform_method = "BEND"
text_modifier_simple_deform.origin = empty_obj
text_modifier_simple_deform.deform_axis = "Y"
# 新建 Shrinkwrap 的 modifier
text_modifier_shrink_wrap = text_obj.modifiers.new(name="Shrinkwrap", type="SHRINKWRAP")
text_modifier_shrink_wrap.wrap_method = "TARGET_PROJECT"
text_modifier_shrink_wrap.target = teapot_obj
text_modifier_shrink_wrap.offset = 0.1Engrave & Emboss Text Easily In Blender | Part 3 in Text Effects | Create 3D Text Logo In Blender
- 新建一个
Cube,并调整其Scale:
import bpy
import numpy as np
bpy.ops.mesh.primitive_cube_add()
cube_obj = bpy.context.object
cube_obj.scale[0] = 1.5
cube_obj.scale[1] = 2.5- 新建一个
Text,调整其Transform:
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.location[2] = 1.15
text_obj.rotation_euler[2] = np.pi / 2使其居中对齐:
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.location[2] = 1.15
text_obj.rotation_euler[2] = np.pi / 2设置文字内容:
text_obj.data.body = "Hello,\nWorld!"- 修改完文字内容后,将其转换成
Mesh,随后文字内容就不能再改变!
bpy.ops.object.convert(target="MESH")- 应用
Decimate以减少过多的顶点:
text_modifier_decimate = text_obj.modifiers.new(name="Decimate", type="DECIMATE")
text_modifier_decimate.decimate_type = "DISSOLVE"
bpy.ops.object.modifier_apply(modifier="Decimate")Edit Mode下,选择Text对象下的所有顶点,Mesh→Merge→By Distance:
在对话框中选择 0.01 m。
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.remove_doubles(threshold=0.01)Mesh→Delete→Limited Dissolve:
在对话框中选择 Max Angle:10°:
bpy.ops.mesh.dissolve_limited(angle_limit=np.pi / 18)
bpy.ops.object.editmode_toggle()- 给
Text添加一个Solidfy,使其具有高度:
text_modifier_solidify = text_obj.modifiers.new(name="Solidify", type="SOLIDIFY")
text_modifier_solidify.thickness = 0.2Object Mode下,给Text和Cude使用Shade Smooth:
bpy.ops.object.shade_smooth()
text_obj.data.use_auto_smooth = True
cube_obj.data.use_auto_smooth = True- 给
Cude添加Boolean,关闭Text的显示,形成雕刻效果:
cube_modifier_boolean = cube_obj.modifiers.new(name="Boolean", type="BOOLEAN")
cube_modifier_boolean.object = text_obj- 给
Cude添加Bevel,形成斜角效果:
cube_modifier_bevel = cube_obj.modifiers.new(name="Bevel", type="BEVEL")
cube_modifier_bevel.width = 0.005
cube_modifier_bevel.segments = 5
cube_modifier_bevel.use_clamp_overlap = False
cube_modifier_bevel.harden_normals = True- 将
Boolean改为Union,形成浮雕效果:
cube_modifier_boolean.operation = "UNION"emmmm 如果破了的话好像只能手动处理了。
完整代码:
import bpy
import numpy as np
bpy.ops.mesh.primitive_cube_add()
cube_obj = bpy.context.object
cube_obj.scale[0] = 1.5
cube_obj.scale[1] = 2.5
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.location[2] = 1.15
text_obj.rotation_euler[2] = np.pi / 2
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
text_obj.data.body = "Hello,\nWorld!"
bpy.ops.object.convert(target="MESH")
text_modifier_decimate = text_obj.modifiers.new(name="Decimate", type="DECIMATE")
text_modifier_decimate.decimate_type = "DISSOLVE"
bpy.ops.object.modifier_apply(modifier="Decimate")
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.remove_doubles(threshold=0.01)
bpy.ops.mesh.dissolve_limited(angle_limit=np.pi / 18)
bpy.ops.object.editmode_toggle()
text_modifier_solidify = text_obj.modifiers.new(name="Solidify", type="SOLIDIFY")
text_modifier_solidify.thickness = 0.2
bpy.ops.object.shade_smooth()
text_obj.data.use_auto_smooth = True
cube_obj.data.use_auto_smooth = True
cube_modifier_boolean = cube_obj.modifiers.new(name="Boolean", type="BOOLEAN")
cube_modifier_boolean.object = text_obj
text_obj.hide_viewport = True
text_obj.hide_render = True
cube_modifier_bevel = cube_obj.modifiers.new(name="Bevel", type="BEVEL")
cube_modifier_bevel.width = 0.005
cube_modifier_bevel.segments = 5
cube_modifier_bevel.use_clamp_overlap = False
cube_modifier_bevel.harden_normals = True
cube_modifier_boolean.operation = "UNION"Engrave or Carve Text On Curved Surface | Part 4 in Text Effects | Blender Eevee & Cycles
- 新建一个圆柱体:
import bpy
import numpy as np
bpy.ops.mesh.primitive_cylinder_add()
cylinder_obj = bpy.context.object
cylinder_obj.scale[0:3] = [1.2, 1.2, 1.2]
cylinder_modifier_edgesplit = cylinder_obj.modifiers.new(name="EdgeSplit", type="EDGE_SPLIT")
bpy.ops.object.modifier_apply(modifier="EdgeSplit")
cylinder_modifier_subsurf = cylinder_obj.modifiers.new(name="Subdivision", type="SUBSURF")
cylinder_modifier_subsurf.levels = 2
bpy.ops.object.modifier_apply(modifier="Subdivision")- 新建一个文本对象:
text_obj.location[0] = 1.22
text_obj.rotation_euler[0] = np.pi / 2
text_obj.rotation_euler[2] = np.pi / 2
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
text_obj.data.font = bpy.data.fonts.load("C:\\windows\\Fonts\\seguiemj.ttf")
text_obj.data.body = "I❤\nYOU"text_obj.data.size = 0.9
text_obj.data.space_line = 0.75
bpy.ops.object.convert(target="MESH")
text_modifier_decimate = text_obj.modifiers.new(name="Decimate", type="DECIMATE")
text_modifier_decimate.decimate_type = "DISSOLVE"
bpy.ops.object.modifier_apply(modifier="Decimate")
text_modifier_solidify = text_obj.modifiers.new(name="Solidify", type="SOLIDIFY")
text_modifier_solidify.thickness = 0.2
bpy.ops.object.shade_smooth()
text_obj.data.use_auto_smooth = True
bpy.ops.object.empty_add(type="CUBE")
empty_obj = bpy.context.object
empty_obj.location[0:3] = text_obj.location[0:3]
empty_obj.rotation_euler[0] = np.pi / 2
text_modifier_simple_deform = text_obj.modifiers.new(name="SimpleDeform", type="SIMPLE_DEFORM")
text_modifier_simple_deform.deform_method = "BEND"
text_modifier_simple_deform.origin = empty_obj
text_modifier_simple_deform.angle = - np.pi / 4
text_modifier_simple_deform.deform_axis = "Y"
cylinder_modifier_boolean = cylinder_obj.modifiers.new(name="Boolean", type="BOOLEAN")
cylinder_modifier_boolean.object = text_obj
text_obj.hide_viewport = True
text_obj.hide_render = True
cylinder_material = bpy.data.materials.new(name="Material")
cylinder_material.use_nodes = True
nodes = cylinder_material.node_tree.nodes
principled_bsdf = nodes.get("Principled BSDF")
if principled_bsdf is not None:
principled_bsdf.inputs[0].default_value = (1, 0.7, 0, 1)
cylinder_obj.data.materials.append(cylinder_material)完整代码:
import bpy
import numpy as np
bpy.ops.mesh.primitive_cylinder_add()
cylinder_obj = bpy.context.object
cylinder_obj.scale[0:3] = [1.2, 1.2, 1.2]
cylinder_modifier_edgesplit = cylinder_obj.modifiers.new(name="EdgeSplit", type="EDGE_SPLIT")
bpy.ops.object.modifier_apply(modifier="EdgeSplit")
cylinder_modifier_subsurf = cylinder_obj.modifiers.new(name="Subdivision", type="SUBSURF")
cylinder_modifier_subsurf.levels = 2
bpy.ops.object.modifier_apply(modifier="Subdivision")
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.location[0] = 1.22
text_obj.rotation_euler[0] = np.pi / 2
text_obj.rotation_euler[2] = np.pi / 2
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
text_obj.data.font = bpy.data.fonts.load("C:\\windows\\Fonts\\seguiemj.ttf")
text_obj.data.body = "I❤\nYOU"
text_obj.data.size = 0.9
text_obj.data.space_line = 0.75
bpy.ops.object.convert(target="MESH")
text_modifier_decimate = text_obj.modifiers.new(name="Decimate", type="DECIMATE")
text_modifier_decimate.decimate_type = "DISSOLVE"
bpy.ops.object.modifier_apply(modifier="Decimate")
text_modifier_solidify = text_obj.modifiers.new(name="Solidify", type="SOLIDIFY")
text_modifier_solidify.thickness = 0.2
bpy.ops.object.shade_smooth()
text_obj.data.use_auto_smooth = True
bpy.ops.object.empty_add(type="CUBE")
empty_obj = bpy.context.object
empty_obj.location[0:3] = text_obj.location[0:3]
empty_obj.rotation_euler[0] = np.pi / 2
text_modifier_simple_deform = text_obj.modifiers.new(name="SimpleDeform", type="SIMPLE_DEFORM")
text_modifier_simple_deform.deform_method = "BEND"
text_modifier_simple_deform.origin = empty_obj
text_modifier_simple_deform.angle = - np.pi / 4
text_modifier_simple_deform.deform_axis = "Y"
cylinder_modifier_boolean = cylinder_obj.modifiers.new(name="Boolean", type="BOOLEAN")
cylinder_modifier_boolean.object = text_obj
text_obj.hide_viewport = True
text_obj.hide_render = True
cylinder_material = bpy.data.materials.new(name="Material")
cylinder_material.use_nodes = True
nodes = cylinder_material.node_tree.nodes
principled_bsdf = nodes.get("Principled BSDF")
if principled_bsdf is not None:
principled_bsdf.inputs[0].default_value = (1, 0.7, 0, 1)
cylinder_obj.data.materials.append(cylinder_material)Emboss Any Text On Curved Surface | Bend Any Text | Part 5 in Text Effects | Blender Eevee & Cycles
- 新建一个圆柱体。
import bpy
import numpy as np
bpy.ops.mesh.primitive_cylinder_add()
cylinder_obj = bpy.context.object- 添加
Edgesplit,并应用,分离边:
cylinder_modifier_edgesplit = cylinder_obj.modifiers.new(name="EdgeSplit", type="EDGE_SPLIT")
bpy.ops.object.modifier_apply(modifier="EdgeSplit")- 添加
Subdivision,并应用,使得物体更平滑:
cylinder_modifier_subsurf = cylinder_obj.modifiers.new(name="Subdivision", type="SUBSURF")
cylinder_modifier_subsurf.levels = 2
bpy.ops.object.modifier_apply(modifier="Subdivision")- 新建一个
Text,调整其参数:
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.location[0] = 1.1
text_obj.rotation_euler[0] = np.pi / 2
text_obj.rotation_euler[2] = np.pi / 2设置文字内容:
text_obj.data.body = "Hello,\nWorld!"
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
text_obj.data.size = 0.5- 添加一个
Solidify修改器,挤出0.15m:
text_modifier_solidify = text_obj.modifiers.new(name="Solidify", type="SOLIDIFY")
text_modifier_solidify.thickness = 0.15- 将
Text转成Mesh:
bpy.ops.object.convert(target="MESH")Remesh处理:
text_modifier_remesh = text_obj.modifiers.new(name="Remesh", type="REMESH")
text_modifier_remesh.mode = "SHARP"
text_modifier_remesh.octree_depth = 8
text_modifier_remesh.use_remove_disconnected = FalseDecimate处理以减少边的数量:
text_modifier_decimate = text_obj.modifiers.new(name="Decimate", type="DECIMATE")
text_modifier_decimate.decimate_type = "DISSOLVE"
bpy.ops.object.modifier_apply(modifier="Decimate")- 平滑处理:
bpy.ops.object.shade_smooth()
text_obj.data.use_auto_smooth = True
cylinder_obj.data.use_auto_smooth = True- 新建一个
Empty,位置和Text相同,用于文本弯曲:
bpy.ops.object.empty_add(type="CUBE")
empty_obj = bpy.context.object
empty_obj.location[0:3] = text_obj.location[0:3]
empty_obj.rotation_euler[0] = np.pi / 2- 设置
SimpleDeform,使Text弯曲:
text_modifier_simple_deform = text_obj.modifiers.new(name="SimpleDeform", type="SIMPLE_DEFORM")
text_modifier_simple_deform.deform_method = "BEND"
text_modifier_simple_deform.origin = empty_obj
text_modifier_simple_deform.angle = - np.pi / 2
text_modifier_simple_deform.deform_axis = "Y"- 形成浮雕有一个简单的方法:
Object→Join:
- 如果不用
Join,改用Boolean运算:
cylinder_modifier_boolean = cylinder_obj.modifiers.new(name="Boolean", type="BOOLEAN")
cylinder_modifier_boolean.operation = "UNION"
cylinder_modifier_boolean.object = text_obj- 添加
Bevel使得斜角效果:
cylinder_modifier_bevel = cylinder_obj.modifiers.new(name="Bevel", type="BEVEL")
cylinder_modifier_bevel.width = 0.005
cylinder_modifier_bevel.segments = 5
cylinder_modifier_bevel.use_clamp_overlap = False
cylinder_modifier_bevel.harden_normals = Truetext_obj.hide_viewport = True
text_obj.hide_render = True- 如果有破,只能自己拿工具填边了:
完整代码:
import bpy
import numpy as np
bpy.ops.mesh.primitive_cylinder_add()
cylinder_obj = bpy.context.object
cylinder_modifier_edgesplit = cylinder_obj.modifiers.new(name="EdgeSplit", type="EDGE_SPLIT")
bpy.ops.object.modifier_apply(modifier="EdgeSplit")
cylinder_modifier_subsurf = cylinder_obj.modifiers.new(name="Subdivision", type="SUBSURF")
cylinder_modifier_subsurf.levels = 2
bpy.ops.object.modifier_apply(modifier="Subdivision")
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.location[0] = 1.1
text_obj.rotation_euler[0] = np.pi / 2
text_obj.rotation_euler[2] = np.pi / 2
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
text_obj.data.body = "Hello,\nWorld!"
text_obj.data.size = 0.5
text_modifier_solidify = text_obj.modifiers.new(name="Solidify", type="SOLIDIFY")
text_modifier_solidify.thickness = 0.15
bpy.ops.object.convert(target="MESH")
text_modifier_remesh = text_obj.modifiers.new(name="Remesh", type="REMESH")
text_modifier_remesh.mode = "SHARP"
text_modifier_remesh.octree_depth = 8
text_modifier_remesh.use_remove_disconnected = False
text_modifier_decimate = text_obj.modifiers.new(name="Decimate", type="DECIMATE")
text_modifier_decimate.decimate_type = "DISSOLVE"
bpy.ops.object.modifier_apply(modifier="Decimate")
bpy.ops.object.shade_smooth()
text_obj.data.use_auto_smooth = True
cylinder_obj.data.use_auto_smooth = True
bpy.ops.object.empty_add(type="CUBE")
empty_obj = bpy.context.object
empty_obj.location[0:3] = text_obj.location[0:3]
empty_obj.rotation_euler[0] = np.pi / 2
text_modifier_simple_deform = text_obj.modifiers.new(name="SimpleDeform", type="SIMPLE_DEFORM")
text_modifier_simple_deform.deform_method = "BEND"
text_modifier_simple_deform.origin = empty_obj
text_modifier_simple_deform.angle = - np.pi / 2
text_modifier_simple_deform.deform_axis = "Y"
cylinder_modifier_boolean = cylinder_obj.modifiers.new(name="Boolean", type="BOOLEAN")
cylinder_modifier_boolean.operation = "UNION"
cylinder_modifier_boolean.object = text_obj
cylinder_modifier_bevel = cylinder_obj.modifiers.new(name="Bevel", type="BEVEL")
cylinder_modifier_bevel.width = 0.005
cylinder_modifier_bevel.segments = 5
cylinder_modifier_bevel.use_clamp_overlap = False
cylinder_modifier_bevel.harden_normals = True
text_obj.hide_viewport = True
text_obj.hide_render = TrueNeon Light or Neon Sign In Blender | Easy & Realistic Method For Blender Eevee (All Versions)
- 新建一个
Text对象,调整其参数:
import bpy
import numpy as np
import os
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.rotation_euler[0] = np.pi / 2
text_obj.rotation_euler[2] = np.pi / 2
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
text_obj.data.space_line = 1.2- 修改文字:
text_obj.data.body = "BARBEQUE\nNATION"- 从 Neon Future Font | dafont.com 找一个适合霓虹灯的字体,应用之:
font_path = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(bpy.data.filepath))
, './fonts/Neon_Future.ttf'))
text_obj.data.font = bpy.data.fonts.load(font_path)- 设置
extrude:
text_obj.data.extrude = 0.02- 添加一个
emission的材质,设置参数:
text_material = bpy.data.materials.new(name="Emission")
text_material.use_nodes = True
nodes = text_material.node_tree.nodes
for node in nodes:
nodes.remove(node)
emission_node = nodes.new(type='ShaderNodeEmission')
emission_node.inputs[0].default_value = (0.25, 1, 0.325, 1)
emission_node.inputs[1].default_value = 4
output_node = nodes.new(type='ShaderNodeOutputMaterial')
links = text_material.node_tree.links
links.new(emission_node.outputs[0], output_node.inputs[0])
text_obj.data.materials.append(text_material)- 设置
scene里的Bloom:
bpy.context.scene.eevee.use_bloom = True
bpy.context.scene.eevee.bloom_radius = 3
bpy.context.scene.eevee.bloom_color = (0.25, 1, 0.325)
bpy.context.scene.eevee.bloom_intensity = 0.25- 新建一个
plane,用于接受霓虹灯的光线:
bpy.ops.mesh.primitive_plane_add()
plane_obj = bpy.context.object
plane_obj.rotation_euler[1] = np.pi / 2
plane_obj.scale[0] = 2.5
plane_obj.scale[1] = 3.5
plane_obj.location[0] = -0.25- 从网上找一张贴图,给这个
plane一个贴图的纹理:
plane_material = bpy.data.materials.new(name="Wall")
plane_material.use_nodes = True
nodes = plane_material.node_tree.nodes
image_texture_node = nodes.new(type='ShaderNodeTexImage')
image_texture_node.image = bpy.data.images.load(os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(bpy.data.filepath))
, './texture/Wall.jpg')))- 调整其 shader nodes,翻转贴图:
mapping_node = nodes.new(type='ShaderNodeMapping')
mapping_node.inputs[2].default_value[2] = np.pi / 2
texcoord_node = nodes.new(type="ShaderNodeTexCoord")
links = plane_material.node_tree.links
links.new(texcoord_node.outputs[0], mapping_node.inputs[0])
links.new(mapping_node.outputs[0], image_texture_node.inputs[0])
links.new(image_texture_node.outputs[0], nodes["Principled BSDF"].inputs[0])
plane_obj.data.materials.append(plane_material)- 添加环境光探针,大小包围平面和文字:
bpy.ops.object.lightprobe_add(type="GRID")- 将 Light Probe 的大小包围屏幕和文字:
lightprobe_obj = bpy.context.object
lightprobe_obj.scale[0:3] = [1, 3.5, 2]Bake Cubemap Only:
- 调低背景亮度,
Screen Space Reflections:
bpy.data.worlds["World"].node_tree.nodes["Background"].inputs[1].default_value = 0
bpy.context.scene.eevee.use_ssr = True- 添加点光源,补充亮度:
light_obj_list = []
for i in range(8):
bpy.ops.object.light_add(type="POINT")
light_obj_list.append(bpy.context.object)
light_obj_list[-1].data.color = (0.25, 1, 0.325)
if i < 5:
light_obj_list[-1].location[1] = -2 + i
light_obj_list[-1].location[2] = 0.5
else:
light_obj_list[-1].location[1] = -6 + i
light_obj_list[-1].location[2] = -0.5完整代码:
import bpy
import numpy as np
import os
bpy.ops.object.text_add()
text_obj = bpy.context.object
text_obj.rotation_euler[0] = np.pi / 2
text_obj.rotation_euler[2] = np.pi / 2
text_obj.data.align_x = "CENTER"
text_obj.data.align_y = "CENTER"
text_obj.data.space_line = 1.2
text_obj.data.extrude = 0.02
text_obj.data.body = "BARBEQUE\nNATION"
font_path = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(bpy.data.filepath))
, './fonts/Neon_Future.ttf'))
text_obj.data.font = bpy.data.fonts.load(font_path)
text_material = bpy.data.materials.new(name="Emission")
text_material.use_nodes = True
nodes = text_material.node_tree.nodes
for node in nodes:
nodes.remove(node)
emission_node = nodes.new(type='ShaderNodeEmission')
emission_node.inputs[0].default_value = (0.25, 1, 0.325, 1)
emission_node.inputs[1].default_value = 4
output_node = nodes.new(type='ShaderNodeOutputMaterial')
links = text_material.node_tree.links
links.new(emission_node.outputs[0], output_node.inputs[0])
text_obj.data.materials.append(text_material)
bpy.context.scene.eevee.use_bloom = True
bpy.context.scene.eevee.bloom_radius = 3
bpy.context.scene.eevee.bloom_color = (0.25, 1, 0.325)
bpy.context.scene.eevee.bloom_intensity = 0.25
bpy.ops.mesh.primitive_plane_add()
plane_obj = bpy.context.object
plane_obj.rotation_euler[1] = np.pi / 2
plane_obj.scale[0] = 2.5
plane_obj.scale[1] = 3.5
plane_obj.location[0] = -0.25
plane_material = bpy.data.materials.new(name="Wall")
plane_material.use_nodes = True
nodes = plane_material.node_tree.nodes
image_texture_node = nodes.new(type='ShaderNodeTexImage')
image_texture_node.image = bpy.data.images.load(os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(bpy.data.filepath))
, './texture/Wall.jpg')))
mapping_node = nodes.new(type='ShaderNodeMapping')
mapping_node.inputs[2].default_value[2] = np.pi / 2
texcoord_node = nodes.new(type="ShaderNodeTexCoord")
links = plane_material.node_tree.links
links.new(texcoord_node.outputs[0], mapping_node.inputs[0])
links.new(mapping_node.outputs[0], image_texture_node.inputs[0])
links.new(image_texture_node.outputs[0], nodes["Principled BSDF"].inputs[0])
plane_obj.data.materials.append(plane_material)
bpy.ops.object.lightprobe_add(type="GRID")
lightprobe_obj = bpy.context.object
lightprobe_obj.scale[0:3] = [1, 3.5, 2]
bpy.data.worlds["World"].node_tree.nodes["Background"].inputs[1].default_value = 0
bpy.context.scene.eevee.use_ssr = True
light_obj_list = []
for i in range(8):
bpy.ops.object.light_add(type="POINT")
light_obj_list.append(bpy.context.object)
light_obj_list[-1].data.color = (0.25, 1, 0.325)
if i < 5:
light_obj_list[-1].location[1] = -2 + i
light_obj_list[-1].location[2] = 0.5
else:
light_obj_list[-1].location[1] = -6 + i
light_obj_list[-1].location[2] = -0.5