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