Beispiel #1
0
    public bool Initialize(string familyName, FluidInfo baseInfo, FluidRenderer renderer)
    {
        this.familyName = familyName;
        string result = null;

        BeginSimulatorProfilerSample();
        Profiler.BeginSample("Initialize");

        if (baseInfo == null)
        {
            result = "Attempting to initialize FluidSimulator without valid info";
        }
        fluidParameters     = baseInfo.fluidParameters;
        cellParameters      = baseInfo.cellParameters;
        operationParameters = baseInfo.operationParameters;
        operationFlags      = baseInfo.operationFlags;

        if (string.IsNullOrEmpty(result) && this.renderer != null)
        {
            result = "Attempting to re-initialize a FluidSimulator";
        }

        if (string.IsNullOrEmpty(result))
        {
            cellParameters.cellSize   = fluidParameters.physicalSize / fluidParameters.gridSize;
            fluidParameters.container = fluidParameters.container ?? transform;
            // TODO Renderer stuff should probably just be handled by the dispatcher ... if simulator and renderer can be complete ignorant of each other, that would be best. This may not be possible as the Collider depends on both the renderer and the simulator.
            this.renderer = renderer;
            this.renderer.transform.parent = fluidParameters.container;
            this.renderer.gameObject.name  = string.Format("{0} Renderer", familyName);
            result = this.renderer.Initialize(this, baseInfo);
        }

        Profiler.BeginSample("InitializeBuffers");
        result = initializeBuffers();
        if (!string.IsNullOrEmpty(result))
        {
            EndSimulatorProfilerSample();
            result = string.Format("Failed to initialize buffers: {0}", result);
        }

        Profiler.EndSample();
        EndSimulatorProfilerSample();

        if (!string.IsNullOrEmpty(result))
        {
            Debug.LogError(result);
            return(false);
        }

        return(true);
    }
    public string Initialize(FluidSimulator simulator, FluidInfo info)
    {
        string result = null;

        if (Simulator != null)
        {
            result = "Attempting to re-initialize FluidRenderer";
        }
        this.Simulator = simulator;

        fluidParameters    = info.fluidParameters;
        cellParameters     = info.cellParameters;
        visualizationFlags = info.visualizationFlags;

        if (string.IsNullOrEmpty(result))
        {
            Profiler.BeginSample("FluidRenderer.GenerateCells");
            result = generateCells();
            Profiler.EndSample();
        }

        Profiler.EndSample();
        return(result);
    }