"""IntelliGrowth learning universe — editable Blender scene.
Open Blender 4+, switch to Scripting, open this file, and Run Script.
Saves intelligrowth-world.blend next to this script (or in Blender's temp folder).
The scene contains six named skill nodes, three orbits, a faceted center,
lights, camera, and a 240-frame looping animation. It does not replace the
current file's objects: all generated objects live in a separate collection.
"""
import bpy
import math
import os
from mathutils import Vector

collection = bpy.data.collections.new('IntelliGrowth Learning Universe')
bpy.context.scene.collection.children.link(collection)

def organize(obj, name):
    obj.name = name
    for parent in list(obj.users_collection):
        parent.objects.unlink(obj)
    collection.objects.link(obj)
    return obj

def material(name, color, metallic=.2, roughness=.3):
    mat=bpy.data.materials.new(name)
    mat.diffuse_color=(*color,1)
    mat.use_nodes=True
    shader=mat.node_tree.nodes.get('Principled BSDF')
    shader.inputs['Base Color'].default_value=(*color,1)
    shader.inputs['Metallic'].default_value=metallic
    shader.inputs['Roughness'].default_value=roughness
    return mat

sage=material('Intelligence crystal',(.40,.67,.24),.38,.19)
ring_material=material('Orbit silver green',(.43,.57,.39),.55,.27)
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=3,radius=1.32)
core=organize(bpy.context.object,'HumanOS x IntelligenceOS — Core')
core.data.materials.append(sage)
core.rotation_euler[2]=0
core.keyframe_insert(data_path='rotation_euler',frame=1)
core.rotation_euler[2]=math.tau
core.keyframe_insert(data_path='rotation_euler',frame=241)
for i in range(3):
    bpy.ops.mesh.primitive_torus_add(major_radius=2.25+i*.47,minor_radius=.012,major_segments=180,minor_segments=8)
    obj=organize(bpy.context.object,f'Knowledge orbit {i+1}')
    obj.rotation_euler=(.4*(i-1),i*.45,0)
    obj.data.materials.append(ring_material)

worlds=[('HumanOS',(.65,.90,.35)),('Engineering foundations',(.57,.42,.85)),('Shape the build',(.90,.53,.35)),('Your agent crew',(.36,.67,.91)),('AI application studio',(.88,.68,.30)),('Launch and evolve',(.29,.75,.57))]
for i,(name,color) in enumerate(worlds):
    angle=i*math.tau/6+.35
    bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=3,radius=.29,location=(math.cos(angle)*2.8,math.sin(angle)*2.8,math.sin(angle*2)*.45))
    obj=organize(bpy.context.object,name)
    obj.data.materials.append(material(name+' material',color))
    obj['learning_path']=name
    for frame,scale in [(1,1),(121,1.12),(241,1)]:
        obj.scale=(scale,)*3
        obj.keyframe_insert(data_path='scale',frame=frame)

for name,loc,power,size in [('Key softbox',(-4,-4,7),950,5),('Rim softbox',(4,1,5),750,4),('Fill softbox',(-2,4,2),500,3)]:
    data=bpy.data.lights.new(name,'AREA');data.energy=power;data.shape='DISK';data.size=size
    obj=bpy.data.objects.new(name,data);collection.objects.link(obj);obj.location=loc
    obj.rotation_euler=(Vector((0,0,0))-obj.location).to_track_quat('-Z','Y').to_euler()
camdata=bpy.data.cameras.new('Universe camera');camera=bpy.data.objects.new('Universe camera',camdata);collection.objects.link(camera)
camera.location=(0,-10.5,5.2);camera.rotation_euler=(-camera.location).to_track_quat('-Z','Y').to_euler();camdata.lens=42
scene=bpy.context.scene;scene.camera=camera
scene.render.engine='BLENDER_EEVEE_NEXT';scene.render.resolution_x=1920;scene.render.resolution_y=1440;scene.render.resolution_percentage=100
scene.render.film_transparent=True;scene.render.fps=30;scene.frame_start=1;scene.frame_end=240
scene.frame_set(1)
root=os.path.dirname(os.path.abspath(__file__)) if '__file__' in globals() else bpy.app.tempdir
path=os.path.join(root,'intelligrowth-world.blend')
bpy.ops.wm.save_as_mainfile(filepath=path)
print('Saved editable IntelliGrowth scene:',path)
