fork(3) download
  1. # 深圳中学3D模型 - 完整生成脚本
  2. # Blender 3.4+ Python Script
  3.  
  4.  
  5. # 清理场景
  6. def clear_scene():
  7. bpy.ops.object.select_all(action='SELECT')
  8. bpy.ops.object.delete(use_global=False)
  9.  
  10. # 创建主教学楼
  11. def create_main_building():
  12. # 主体结构
  13. bpy.ops.mesh.primitive_cube_add(location=(0, 0, 12))
  14. building = bpy.context.object
  15. building.scale = (60, 20, 12) # 120m x 40m x 24m
  16. building.name = "Main_Building"
  17.  
  18. # 添加玻璃幕墙材质
  19. material = bpy.data.materials.new("Glass_Facade")
  20. material.use_nodes = True
  21. nodes = material.node_tree.nodes
  22. nodes.clear()
  23.  
  24. # 创建材质节点
  25. bsdf = nodes.new(type='ShaderNodeBsdfPrincipled')
  26. output = nodes.new(type='ShaderNodeOutputMaterial')
  27.  
  28. # 设置玻璃材质
  29. bsdf.inputs['Base Color'].default_value = (0.8, 0.9, 1.0, 1.0)
  30. bsdf.inputs['Transmission'].default_value = 0.9
  31. bsdf.inputs['Roughness'].default_value = 0.1
  32. bsdf.inputs['IOR'].default_value = 1.45
  33.  
  34. # 连接节点
  35. material.node_tree.links.new(bsdf.outputs['BSDF'], output.inputs['Surface'])
  36. building.data.materials.append(material)
  37.  
  38. return building
  39.  
  40. # 创建科技中心穹顶
  41. def create_tech_dome():
  42. # 主体球体
  43. bpy.ops.mesh.primitive_uv_sphere_add(location=(80, 0, 7.5), radius=25)
  44. dome = bpy.context.object
  45. dome.scale = (1, 1, 0.3) # 扁平化
  46. dome.name = "Tech_Dome"
  47.  
  48. # 金属材质
  49. material = bpy.data.materials.new("Metal_Dome")
  50. material.use_nodes = True
  51. nodes = material.node_tree.nodes
  52. nodes.clear()
  53.  
  54. bsdf = nodes.new(type='ShaderNodeBsdfPrincipled')
  55. output = nodes.new(type='ShaderNodeOutputMaterial')
  56.  
  57. bsdf.inputs['Base Color'].default_value = (0.3, 0.3, 0.4, 1.0)
  58. bsdf.inputs['Metallic'].default_value = 0.8
  59. bsdf.inputs['Roughness'].default_value = 0.2
  60.  
  61. material.node_tree.links.new(bsdf.outputs['BSDF'], output.inputs['Surface'])
  62. dome.data.materials.append(material)
  63.  
  64. return dome
  65.  
  66. # 创建围墙系统
  67. def create_security_fence():
  68. # 创建围墙基础
  69. bpy.ops.mesh.primitive_cube_add(location=(0, 80, 1.5))
  70. fence_north = bpy.context.object
  71. fence_north.scale = (80, 1.5, 1.5)
  72. fence_north.name = "Fence_North"
  73.  
  74. bpy.ops.mesh.primitive_cube_add(location=(0, -80, 1.5))
  75. fence_south = bpy.context.object
  76. fence_south.scale = (80, 1.5, 1.5)
  77. fence_south.name = "Fence_South"
  78.  
  79. bpy.ops.mesh.primitive_cube_add(location=(80, 0, 1.5))
  80. fence_east = bpy.context.object
  81. fence_east.scale = (1.5, 80, 1.5)
  82. fence_east.name = "Fence_East"
  83.  
  84. bpy.ops.mesh.primitive_cube_add(location=(-80, 0, 1.5))
  85. fence_west = bpy.context.object
  86. fence_west.scale = (1.5, 80, 1.5)
  87. fence_west.name = "Fence_West"
  88.  
  89. # 创建观察塔
  90. for i, pos in enumerate([(80, 80), (80, -80), (-80, 80), (-80, -80)]):
  91. bpy.ops.mesh.primitive_cylinder_add(location=(pos[0], pos[1], 4), radius=2, depth=8)
  92. tower = bpy.context.object
  93. tower.name = f"WatchTower_{i+1}"
  94.  
  95. return [fence_north, fence_south, fence_east, fence_west]
  96.  
  97. # 创建地下设施入口
  98. def create_underground_entrance():
  99. bpy.ops.mesh.primitive_cube_add(location=(60, -60, 1))
  100. entrance = bpy.context.object
  101. entrance.scale = (8, 4, 1)
  102. entrance.name = "Underground_Entrance"
  103.  
  104. # 斜坡
  105. bpy.ops.mesh.primitive_cube_add(location=(60, -68, 0.5))
  106. ramp = bpy.context.object
  107. ramp.scale = (8, 4, 0.5)
  108. ramp.rotation_euler = (math.radians(30), 0, 0)
  109. ramp.name = "Entrance_Ramp"
  110.  
  111. return entrance, ramp
  112.  
  113. # 创建绿化环境
  114. def create_environment():
  115. # 创建地面
  116. bpy.ops.mesh.primitive_plane_add(location=(0, 0, 0), size=200)
  117. ground = bpy.context.object
  118. ground.name = "Ground"
  119.  
  120. # 地面材质
  121. material = bpy.data.materials.new("Ground_Material")
  122. material.use_nodes = True
  123. nodes = material.node_tree.nodes
  124. nodes.clear()
  125.  
  126. bsdf = nodes.new(type='ShaderNodeBsdfPrincipled')
  127. output = nodes.new(type='ShaderNodeOutputMaterial')
  128.  
  129. bsdf.inputs['Base Color'].default_value = (0.2, 0.6, 0.3, 1.0) # 绿色
  130. bsdf.inputs['Roughness'].default_value = 0.9
  131.  
  132. material.node_tree.links.new(bsdf.outputs['BSDF'], output.inputs['Surface'])
  133. ground.data.materials.append(material)
  134.  
  135. # 添加一些树木(简化表示)
  136. for i in range(20):
  137. x = (i % 5) * 30 - 60
  138. y = (i // 5) * 30 - 60
  139. if abs(x) < 70 and abs(y) < 70: # 避开建筑区域
  140. continue
  141.  
  142. bpy.ops.mesh.primitive_cone_add(location=(x, y, 2), radius1=1.5, depth=4)
  143. tree = bpy.context.object
  144. tree.name = f"Tree_{i+1}"
  145.  
  146. return ground
  147.  
  148. # 设置相机和灯光
  149. def setup_scene():
  150. # 设置相机
  151. bpy.ops.object.camera_add(location=(150, -150, 80))
  152. camera = bpy.context.object
  153. camera.rotation_euler = (math.radians(60), 0, math.radians(45))
  154. bpy.context.scene.camera = camera
  155.  
  156. # 设置灯光
  157. bpy.ops.object.light_add(type='SUN', location=(50, -50, 50))
  158. sun = bpy.context.object
  159. sun.data.energy = 5
  160.  
  161. bpy.ops.object.light_add(type='AREA', location=(0, 0, 30))
  162. area_light = bpy.context.object
  163. area_light.data.energy = 100
  164. area_light.scale = (20, 20, 1)
  165.  
  166. # 主执行函数
  167. def main():
  168. print("开始创建深圳中学3D模型...")
  169.  
  170. # 清理场景
  171. clear_scene()
  172.  
  173. # 创建各个组件
  174. main_building = create_main_building()
  175. tech_dome = create_tech_dome()
  176. fences = create_security_fence()
  177. entrance, ramp = create_underground_entrance()
  178. ground = create_environment()
  179.  
  180. # 设置场景
  181. setup_scene()
  182.  
  183. print("深圳中学3D模型创建完成!")
  184. print("模型包含:")
  185. print("- 主教学楼 (120m x 40m x 24m)")
  186. print("- 科技中心穹顶 (直径50m)")
  187. print("- 围墙系统 (800m周长)")
  188. print("- 地下设施入口")
  189. print("- 绿化环境")
  190.  
  191. # 运行脚本
  192. if __name__ == "__main__":
  193. main()
Success #stdin #stdout #stderr 0.01s 5300KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 6: near "def": syntax error