"""
流体动力学插件测试示例
此文件演示如何使用流体动力学插件
"""

def create_fluid_demo(world):
    """
    创建流体动力学演示场景
    
    Args:
        world: 主世界对象
    """
    try:
        # 检查插件是否已加载
        if not hasattr(world, 'plugin_manager') or not world.plugin_manager:
            print("插件管理器未初始化")
            return
            
        # 加载流体动力学插件
        fluid_plugin = world.plugin_manager.load_plugin("fluid_dynamics")
        if not fluid_plugin:
            print("流体动力学插件加载失败")
            return
            
        # 启用插件
        if not world.plugin_manager.enable_plugin("fluid_dynamics"):
            print("流体动力学插件启用失败")
            return
            
        # 获取流体世界实例
        fluid_world = fluid_plugin.fluid_world
        if not fluid_world:
            print("流体世界实例获取失败")
            return
            
        # 创建流体域
        from .components.fluid_domain import FluidDomain
        domain = FluidDomain(
            Point3(-10, -10, 0),
            Point3(10, 10, 20)
        )
        fluid_world.add_fluid_domain(domain)
        
        # 创建流体发射器
        from .components.fluid_emitter import FluidEmitter
        emitter = FluidEmitter(
            Point3(0, 0, 10),
            fluid_world
        )
        emitter.set_emit_rate(50)  # 每秒发射50个粒子
        emitter.set_emit_velocity(Vec3(0, 0, 2))  # 向上发射
        fluid_world.add_fluid_emitter(emitter)
        
        # 创建障碍物
        from .components.fluid_obstacle import FluidObstacle
        obstacle = FluidObstacle(
            Point3(0, 0, 5),
            Vec3(2, 2, 2),
            "box"
        )
        fluid_world.add_fluid_obstacle(obstacle)
        
        # 设置求解器
        from .core.fluid_solver import FluidSolver
        solver = FluidSolver(fluid_world)
        fluid_world.solver = solver
        
        # 设置可视化器
        from .core.fluid_visualizer import FluidVisualizer
        visualizer = FluidVisualizer(fluid_world, world)
        
        # 创建粒子系统用于可视化
        particle_system = visualizer.create_particle_system("fluid_particles", 2000)
        
        print("流体动力学演示场景创建完成")
        print("使用方法：")
        print("1. 调整发射器参数：emitter.set_emit_rate(粒子数)")
        print("2. 暂停/恢复模拟：fluid_world.pause(True/False)")
        print("3. 调整时间缩放：fluid_world.set_time_scale(缩放因子)")
        
    except Exception as e:
        print(f"创建流体动力学演示场景时出错: {e}")
        import traceback
        traceback.print_exc()