コード例 #1
0
        void Update()
        {
            //get the data from the GPU
            PullParticlesFromGPU(m_solverPtr, m_cntr, Flex.Memory.eFlexMemoryHostAsync);

            if (m_diffuseParticles && m_diffuseParticles.m_maxDiffuseParticlesCount > 0)
            {
                m_diffuseParticles.m_diffuseParticlesCount = Flex.GetDiffuseParticles(m_solverPtr, m_diffuseParticles.m_diffuseParticlesHndl.AddrOfPinnedObject(), m_diffuseParticles.m_diffuseVelocitiesHndl.AddrOfPinnedObject(), m_diffuseParticles.m_sortedDepthHndl.AddrOfPinnedObject(), Flex.Memory.eFlexMemoryHostAsync);
            }

            //update solver parameters
            //TODO check impact on performance
            m_parameters.GetParams(ref m_params);
            Flex.SetParams(m_solverPtr, ref m_params);

            //ensure memory transfers have finished
            Flex.SetFence();
            Flex.WaitFence();


            //for (int i = 0; i < m_cntr.m_particlesCount; i++)
            //{
            //    print("index:" + i + "velocity:" + m_cntr.m_velocities[i]);
            //}


            if (Input.GetKeyDown(KeyCode.Space))
            {
                Debug.Log("uFlex Scene Reset");
                for (int i = 0; i < m_cntr.m_particlesCount; i++)
                {
                    m_cntr.m_particles[i] = m_cntr.m_restParticles[i];

                    m_cntr.m_velocities[i] = new Vector3();
                }
            }

            //copy data to instances
            UpdateGameObjects();

            //do the custom processing on flex gameobjects
            m_processors = FindObjectsOfType <FlexProcessor>();
            foreach (FlexProcessor fp in m_processors)
            {
                fp.PreContainerUpdate(this, m_cntr, m_parameters);
            }

            //update container
            if (m_dynamic)
            {
                m_cntr.UpdateContainer();
            }

            //do the custom processing on the container
            foreach (FlexProcessor fp in m_processors)
            {
                fp.PostContainerUpdate(this, m_cntr, m_parameters);
            }

            //copy the processed data back to the GPU
            PushParticlesToGPU(m_solverPtr, m_cntr, Flex.Memory.eFlexMemoryHostAsync);


            if (m_dynamic)
            {
                //Async transfers on unpinned arrays!?
                //PushConstraintsToGPU(m_solverPtr, m_cntr, Flex.Memory.eFlexMemoryHostAsync);
                //m_colliders.UpdateColliders(m_solverPtr, Flex.Memory.eFlexMemoryHostAsync);

                PushConstraintsToGPU(m_solverPtr, m_cntr, Flex.Memory.eFlexMemoryHost);
                m_colliders.UpdateColliders(m_solverPtr, Flex.Memory.eFlexMemoryHost);
            }

            //do not wait here for memory transfers to finish
            //Flex.SetFence();
            //Flex.WaitFence();


            //Debug.Log("Total Time: "+m_timers.mTotal);
        }