Exemplo n.º 1
0
        void OnEnable()
        {
            //    Debug.Log("ENABLED: " + Application.isPlaying);
            if (m_flexDiffuseParticles == null)
            {
                m_flexDiffuseParticles = GetComponent <FlexDiffuseParticles>();
            }

            m_posBuffer   = new ComputeBuffer(m_flexDiffuseParticles.m_maxDiffuseParticlesCount, 16);
            m_colorBuffer = new ComputeBuffer(m_flexDiffuseParticles.m_maxDiffuseParticlesCount, 16);

            m_posBuffer.SetData(m_flexDiffuseParticles.m_diffuseParticles);
            m_colorBuffer.SetData(m_flexDiffuseParticles.m_diffuseVelocities);

            m_quadVerticesBuffer = new ComputeBuffer(6, 16);
            m_quadVerticesBuffer.SetData(new[]
            {
                new Vector4(-0.5f, 0.5f),
                new Vector4(0.5f, 0.5f),
                new Vector4(0.5f, -0.5f),
                new Vector4(0.5f, -0.5f),
                new Vector4(-0.5f, -0.5f),
                new Vector4(-0.5f, 0.5f),
            });

            //    hideFlags = HideFlags.DontSave;

            m_material = new Material(Shader.Find("uFlex/DiffuseParticlesShader"));

            m_material.hideFlags = HideFlags.DontSave;

            m_material.SetBuffer("buf_Positions", m_posBuffer);
            m_material.SetBuffer("buf_Colors", m_colorBuffer);
            m_material.SetBuffer("buf_Vertices", m_quadVerticesBuffer);
        }
Exemplo n.º 2
0
        void Start()
        {
            if (m_cntr == null)
            {
                m_cntr = GetComponent <FlexContainer>();
            }

            if (m_diffuseParticles == null)
            {
                m_diffuseParticles = GetComponent <FlexDiffuseParticles>();
            }

            if (m_parameters == null)
            {
                m_parameters = GetComponent <FlexParameters>();
            }

            if (m_colliders == null)
            {
                m_colliders = GetComponent <FlexColliders>();
            }

            m_errorCallback = new Flex.ErrorCallback(this.ErrorCallback);

            m_timers = new Flex.Timers();

            Flex.Error flexErr = Flex.Init(100, m_errorCallback, -1);

            Debug.Log("NVidia FleX v" + Flex.GetVersion());
            if (flexErr != Flex.Error.eFlexErrorNone)
            {
                Debug.LogError("FlexInit: " + flexErr);
            }

            if (m_diffuseParticles)
            {
                m_solverPtr = Flex.CreateSolver(m_cntr.m_maxParticlesCount, m_diffuseParticles.m_maxDiffuseParticlesCount, m_maxNeighboursCount);
            }
            else
            {
                m_solverPtr = Flex.CreateSolver(m_cntr.m_maxParticlesCount, 0, m_maxNeighboursCount);
            }

            m_parameters.GetParams(ref m_params);
            Flex.SetParams(m_solverPtr, ref m_params);

            m_cntr.UpdateContainer();

            m_processors = FindObjectsOfType <FlexProcessor>();
            foreach (FlexProcessor fp in m_processors)
            {
                fp.FlexStart(this, m_cntr, m_parameters);
            }

            PushParticlesToGPU(m_solverPtr, m_cntr, Flex.Memory.eFlexMemoryHost);

            PushConstraintsToGPU(m_solverPtr, m_cntr, Flex.Memory.eFlexMemoryHost);

            if (m_colliders)
            {
                m_colliders.ProcessColliders(m_solverPtr, Flex.Memory.eFlexMemoryHost);
            }

            //Flex.SetShapes(m_solverPtr, m_cnt.shapeGeometry, shapeGeometry.Length, shapeAabbMin, shapeAabbMax, shapeStarts, shapePositions, shapeRotations,
            //          shapePrevPositions, shapePrevRotations, shapeFlags, shapeStarts.Length, Flex.Memory.eFlexMemoryHost);
        }