freestyle线框改为场景线条画

This commit is contained in:
libtxixi 2025-07-18 20:47:36 +08:00
parent eb97bc5817
commit 3c381c2a21
3 changed files with 2197 additions and 2131 deletions

View File

@ -786,23 +786,23 @@ def setup_render_settings():
print("已设置渲染引擎为: BLENDER_EEVEE_NEXT")
# 启用Freestyle线条渲染
scene.render.use_freestyle = True
print("已启用Freestyle线条渲染")
# scene.render.use_freestyle = True # False True
# #print("已启用Freestyle线条渲染")
# 配置Freestyle线条设置
if hasattr(scene, 'view_layers'):
view_layer = scene.view_layers[0] # 获取第一个视图层
view_layer.use_freestyle = True
# # 配置Freestyle线条设置
# if hasattr(scene, 'view_layers'):
# view_layer = scene.view_layers[0] # 获取第一个视图层
# view_layer.use_freestyle = True
# 获取Freestyle线条设置
freestyle = view_layer.freestyle_settings
# # 获取Freestyle线条设置
# freestyle = view_layer.freestyle_settings
# 启用线条渲染
freestyle.use_smoothness = True
freestyle.use_culling = True
# 设置线条宽度 - 使用正确的API 没有生效
# # 启用线条渲染
# freestyle.use_smoothness = True
# freestyle.use_culling = True
# 设置线条宽度 - 使用正确的API
#bpy.data.scenes["Scene"].render.line_thickness = 1.5
# 设置世界环境
if hasattr(scene, 'world') and scene.world:
@ -919,6 +919,60 @@ def setup_camera_and_lighting():
print("摄像机设置完成")
print(f"相机位置: ({{camera.location.x}}, {{camera.location.y}}, {{camera.location.z}})")
# 设置蜡笔-场景线条画
print("设置蜡笔-场景线条画...")
try:
# 启用蜡笔渲染 - 在Blender 4.2中使用不同的属性
if hasattr(bpy.context.scene.render, 'use_grease_pencil'):
bpy.context.scene.render.use_grease_pencil = True
print("已启用蜡笔渲染")
else:
# 在Blender 4.2中,蜡笔渲染可能默认启用
print("蜡笔渲染已默认启用")
# 创建蜡笔对象(如果不存在)- 使用LINEART_SCENE类型
grease_pencil_name = "Grease_pencil"
grease_pencil_obj = None
# 检查是否已存在蜡笔对象
for obj in bpy.data.objects:
if obj.name == grease_pencil_name and obj.type == 'GPENCIL':
grease_pencil_obj = obj
print(f"找到现有蜡笔对象: {{grease_pencil_name}}")
break
if grease_pencil_obj is None:
# 创建新的蜡笔对象
bpy.ops.object.gpencil_add(type='LINEART_SCENE')
grease_pencil_obj = bpy.context.active_object
grease_pencil_obj.name = grease_pencil_name
# 等待一帧以确保数据创建完成
bpy.context.view_layer.update()
print(f"已创建蜡笔场景线条画对象: {{grease_pencil_name}}")
# 设置笔画厚度缩放为0.4
if grease_pencil_obj and grease_pencil_obj.data:
grease_pencil_data = grease_pencil_obj.data
grease_pencil_data.pixel_factor = 0.4
print(f"已设置蜡笔笔画厚度缩放: {{grease_pencil_data.pixel_factor}}")
else:
print("警告: 未找到蜡笔数据")
# 确保蜡笔对象在渲染时可见
if grease_pencil_obj:
grease_pencil_obj.hide_render = False
grease_pencil_obj.hide_viewport = False
print("蜡笔对象已设置为可见")
print("蜡笔-场景线条画设置完成")
except Exception as e:
print(f"设置蜡笔时出现错误: {{e}}")
print("继续执行其他设置...")
# 隐藏ISO Emission灯光如果存在
light_objects = ["ISO Emission Left", "ISO Emission Right"]
for obj_name in light_objects:
@ -929,40 +983,8 @@ def setup_camera_and_lighting():
light_obj.hide_viewport = True
print(f"已隐藏 {{obj_name}}")
# # 创建第一个160W点光源房间中心
# try:
# # 计算点光源位置(房间中心上方)
# room_length = {adjusted_length} # Y轴
# room_width = {adjusted_width} # X轴
# # 第一个点光源位置:房间中心上方
# light_x = 0 # X轴中心
# light_y = 0 # Y轴中心
# light_z = light_height
# # 创建第一个点光源
# bpy.ops.object.light_add(
# type='POINT', location=(light_x, light_y, light_z))
# point_light1 = bpy.context.active_object
# point_light1.name = "Main Point Light"
# point_light1.data.energy = 160 # 160W
# # 设置软衰减(简化设置)
# point_light1.data.shadow_soft_size = 0.5 # 0.5米半径,产生柔和阴影
# point_light1.data.use_shadow = True # 启用阴影
# print(f"已创建第一个点光源160W")
# print(f"点光源位置: x={{light_x}}, y={{light_y}}, z={{light_z}}")
# except Exception as e:
# print(f"创建第一个点光源时出错: {{e}}")
print("照明设置完成")
#print("灯光类型: 点光源 + 日光")
print(f"阴影设置: 启用,柔和阴影")
#print(f"主灯光高度: {{light_height}}米 (房间高度减一米)")
def render_scene():
"""渲染场景"""

View File

@ -110,7 +110,7 @@ def test_basic_render():
"length": 7.0,
"width": 4.0,
"height": 3.0,
"prop_type": 0 # 0=无, 1=落地窗, 2=拱门, 3=门"
"prop_type": 0 # 0=无, 1=落地窗, 2=拱门, 3=门
},
"camera": {
"height": 1.3,

View File

@ -578,20 +578,20 @@ def setup_render_settings():
print("已设置渲染引擎为EEVEE")
# 启用Freestyle线条渲染
scene.render.use_freestyle = True
print("已启用Freestyle线条渲染")
# scene.render.use_freestyle = True
# print("已启用Freestyle线条渲染")
# 配置Freestyle线条设置
if hasattr(scene, 'view_layers'):
view_layer = scene.view_layers[0] # 获取第一个视图层
view_layer.use_freestyle = True
# # 配置Freestyle线条设置
# if hasattr(scene, 'view_layers'):
# view_layer = scene.view_layers[0] # 获取第一个视图层
# view_layer.use_freestyle = True
# 获取Freestyle线条设置
freestyle = view_layer.freestyle_settings
# # 获取Freestyle线条设置
# freestyle = view_layer.freestyle_settings
# 启用线条渲染
freestyle.use_smoothness = True
freestyle.use_culling = True
# # 启用线条渲染
# freestyle.use_smoothness = True
# freestyle.use_culling = True
# 设置线条宽度 - 使用正确的API 没有生效
@ -715,15 +715,59 @@ def setup_camera_and_lighting():
print("摄像机设置完成")
print(f"相机位置: ({camera.location.x}, {camera.location.y}, {camera.location.z})")
# 隐藏ISO Emission灯光如果存在
light_objects = ["ISO Emission Left", "ISO Emission Right"]
for obj_name in light_objects:
if obj_name in bpy.data.objects:
light_obj = bpy.data.objects[obj_name]
# 隐藏发光对象
light_obj.hide_render = True
light_obj.hide_viewport = True
print(f"已隐藏 {obj_name}")
# 设置蜡笔-场景线条画
print("设置蜡笔-场景线条画...")
try:
# 启用蜡笔渲染 - 在Blender 4.2中使用不同的属性
if hasattr(bpy.context.scene.render, 'use_grease_pencil'):
bpy.context.scene.render.use_grease_pencil = True
print("已启用蜡笔渲染")
else:
# 在Blender 4.2中,蜡笔渲染可能默认启用
print("蜡笔渲染已默认启用")
# 创建蜡笔对象(如果不存在)- 使用LINEART SCENE类型
grease_pencil_name = "Grease_pencil"
grease_pencil_obj = None
# 检查是否已存在蜡笔对象
for obj in bpy.data.objects:
if obj.name == grease_pencil_name and obj.type == 'GPENCIL':
grease_pencil_obj = obj
print(f"找到现有蜡笔对象: {grease_pencil_name}")
break
if grease_pencil_obj is None:
# 创建新的蜡笔对象
bpy.ops.object.gpencil_add(type='LINEART_SCENE')
grease_pencil_obj = bpy.context.active_object
grease_pencil_obj.name = grease_pencil_name
# 等待一帧以确保数据创建完成
bpy.context.view_layer.update()
print(f"已创建蜡笔场景线条画对象: {grease_pencil_name}")
# 设置笔画厚度缩放为0.38
if grease_pencil_obj and grease_pencil_obj.data:
grease_pencil_data = grease_pencil_obj.data
grease_pencil_data.pixel_factor = 0.38
print(f"已设置蜡笔笔画厚度缩放: {grease_pencil_data.pixel_factor}")
else:
print("警告: 未找到蜡笔数据")
# 确保蜡笔对象在渲染时可见
if grease_pencil_obj:
grease_pencil_obj.hide_render = False
grease_pencil_obj.hide_viewport = False
print("蜡笔对象已设置为可见")
print("蜡笔-场景线条画设置完成")
except Exception as e:
print(f"设置蜡笔时出现错误: {e}")
print("继续执行其他设置...")
# 创建第一个160W点光源房间中心
# try: