Galaxy
import bpy
import random
import math
scene = bpy.context.scene
# =========================
# NEBULA (VOLUMETRIC CLOUD)
# =========================
bpy.ops.mesh.primitive_cube_add(size=40, location=(0, 0, 40))
nebula = bpy.context.object
nebula.name = "Nebula"
mat = bpy.data.materials.new("Nebula_Mat")
mat.use_nodes = True
nodes = mat.node_tree.nodes
links = mat.node_tree.links
nodes.clear()
output = nodes.new("ShaderNodeOutputMaterial")
volume = nodes.new("ShaderNodeVolumePrincipled")
noise = nodes.new("ShaderNodeTexNoise")
noise.inputs["Scale"].default_value = 2.5
volume.inputs["Density"].default_value = 0.05
volume.inputs["Color"].default_value = (0.8, 0.3, 0.4, 1)
links.new(noise.outputs["Fac"], volume.inputs["Density"])
links.new(volume.outputs["Volume"], output.inputs["Volume"])
nebula.data.materials.append(mat)
# =========================
# GALAXY (SPIRAL DISC)
# =========================
bpy.ops.mesh.primitive_circle_add(vertices=64, radius=25, location=(0,0,70))
galaxy = bpy.context.object
galaxy.name = "Galaxy"
galaxy.rotation_euler = (math.radians(75), 0, 0)
# Slow galaxy rotation
galaxy.keyframe_insert("rotation_euler", frame=7200)
galaxy.rotation_euler[2] += math.pi / 4
galaxy.keyframe_insert("rotation_euler", frame=9600)
# =========================
# METEOR PARTICLE SYSTEM
# =========================
bpy.ops.mesh.primitive_plane_add(size=200, location=(0,0,60))
meteor_emitter = bpy.context.object
meteor_emitter.name = "Meteor_Emitter"
ps = meteor_emitter.modifiers.new("Meteors", type='PARTICLE_SYSTEM')
psys = ps.particle_system.settings
psys.count = 300
psys.frame_start = 3000
psys.frame_end = 3600
psys.lifetime = 120
psys.emit_from = 'FACE'
psys.physics_type = 'NEWTON'
psys.normal_factor = -3
psys.gravity = 0.2
psys.render_type = 'HALO'
# =========================
# CAMERA SLOWING FOR AWE
# =========================
cam = scene.camera
cam.keyframe_insert("location", frame=8400)
cam.location.z += 0.2
cam.keyframe_insert("location", frame=9600)
# =========================
# FINAL FADE TO BLACK
# =========================
world = bpy.data.worlds["World"]
bg = world.node_tree.nodes["Background"]
bg.inputs[1].keyframe_insert("default_value", frame=9000)
bg.inputs[1].default_value = 0.02
bg.inputs[1].keyframe_insert("default_value", frame=9600)
print("Cosmic extension complete: nebula, galaxy, meteors, ending fade.")