import bpy
import json
import os
import math
from mathutils import Vector

class LogoAnimator:
    def __init__(self, project_dir):
        self.project_dir = project_dir
        self.logo_path = os.path.join(project_dir, "logo.png")
        self.config_path = os.path.join(project_dir, "config.json")
        
    def setup_scene(self):
        # Clear existing scene
        bpy.ops.object.select_all(action='SELECT')
        bpy.ops.object.delete()
        
        # Set up render settings
        bpy.context.scene.render.resolution_x = 1024
        bpy.context.scene.render.resolution_y = 1024
        bpy.context.scene.render.film_transparent = True
        bpy.context.scene.render.image_settings.file_format = 'PNG'
        bpy.context.scene.render.image_settings.color_mode = 'RGBA'
        
        # Set up animation settings
        bpy.context.scene.frame_start = 0
        bpy.context.scene.frame_end = 60  # Default 60 frames, can be override by config
        
    def create_logo_plane(self):
        # Create plane
        bpy.ops.mesh.primitive_plane_add(size=2)
        logo_plane = bpy.context.active_object
        
        # Add material with logo texture
        mat = bpy.data.materials.new(name="LogoMaterial")
        mat.use_nodes = True
        nodes = mat.node_tree.nodes
        
        # Clear default nodes
        nodes.clear()
        
        # Create nodes
        texture_coord = nodes.new('ShaderNodeTexCoord')
        mapping = nodes.new('ShaderNodeMapping')
        image_tex = nodes.new('ShaderNodeTexImage')
        transparent = nodes.new('ShaderNodeBsdfTransparent')
        mix = nodes.new('ShaderNodeMixShader')
        output = nodes.new('ShaderNodeOutputMaterial')
        
        # Load and assign image
        image_tex.image = bpy.data.images.load(self.logo_path)
        
        # Connect nodes
        links = mat.node_tree.links
        links.new(texture_coord.outputs['UV'], mapping.inputs['Vector'])
        links.new(mapping.outputs['Vector'], image_tex.inputs['Vector'])
        links.new(image_tex.outputs['Color'], mix.inputs[2])
        links.new(image_tex.outputs['Alpha'], mix.inputs['Fac'])
        links.new(transparent.outputs['BSDF'], mix.inputs[1])
        links.new(mix.outputs['Shader'], output.inputs['Surface'])
        
        # Assign material to plane
        logo_plane.data.materials.append(mat)
        
        return logo_plane
        
    def load_config(self):
        with open(self.config_path, 'r') as f:
            return json.load(f)
            
    def setup_output(self, output_path):
        # Set output path
        bpy.context.scene.render.filepath = output_path
        
    def render_animation(self):
        bpy.ops.render.render(animation=True)
        
    def apply_effect(self, logo_object, effect_config):
        # This will be expanded based on config.json structure
        # Example structure in config.json:
        # {
        #    "effect_type": "rotate",
        #    "duration_frames": 60,
        #    "parameters": {
        #        "rotation_axis": "Z",
        #        "rotation_amount": 360
        #    }
        # }
        
        effect_type = effect_config.get("effect_type", "none")
        if effect_type == "rotate":
            self.apply_rotation_effect(logo_object, effect_config["parameters"])
        # Add more effects as needed
        
    def apply_rotation_effect(self, obj, params):
        # Example rotation effect
        axis = params.get("rotation_axis", "Z")
        amount = params.get("rotation_amount", 360)
        duration = params.get("duration_frames", 60)
        
        # Set keyframes
        bpy.context.scene.frame_set(0)
        if axis == "Z":
            obj.rotation_euler.z = 0
            obj.keyframe_insert(data_path="rotation_euler", frame=0)
            
            bpy.context.scene.frame_set(duration)
            obj.rotation_euler.z = math.radians(amount)
            obj.keyframe_insert(data_path="rotation_euler", frame=duration)

def main():
    project_dir = r"/mnt/c/Users/Jeff/logo"
    animator = LogoAnimator(project_dir)
    
    # Setup scene
    animator.setup_scene()
    
    # Create logo plane
    logo_obj = animator.create_logo_plane()
    
    # Load and apply effects from config
    try:
        config = animator.load_config()
        animator.apply_effect(logo_obj, config)
    except FileNotFoundError:
        print("No config.json found. Creating basic setup only.")
    
    # Setup output
    animator.setup_output(os.path.join(project_dir, "output"))
    
    # Render
    animator.render_animation()

if __name__ == "__main__":
    main() what does this script do