示例#1
0
        public void UpdateMesh(FlexContainer.ParticleData _particleData)
        {
            transform.rotation = Quaternion.identity;

            if (m_scene && m_scene.container && m_fluidMaterial)
            {
                int[] indices    = m_scene.container.fluidIndices;
                int   indexCount = m_scene.container.fluidIndexCount;

                if (indices.Length <= 0)
                {
                    return;
                }

                if (m_indexBuffer != null && indexCount != m_indexBuffer.count) // @@@
                {
                    m_indexBuffer.Release();
                    m_indexBuffer = null;
                }
                if (m_indexBuffer == null && indexCount > 0)
                {
                    m_indexBuffer = new ComputeBuffer(indexCount, sizeof(int));
                    m_mesh.SetIndices(new int[indexCount], MeshTopology.Points, 0);
                }
                if (m_indexBuffer != null)
                {
                    m_indexBuffer.SetData(indices);
                }
                Vector3 boundsMin = Vector3.one * 1e10f, boundsMax = Vector3.one * 1e10f;
                if (indexCount > 0)
                {
                    int maxParticles = m_scene.container.maxParticles;

                    Flex.GetParticles(m_scene.container.solver, m_positionBuffer0);
                    Flex.GetAnisotropy(m_scene.container.solver, m_anisotropy1Buffer0, m_anisotropy2Buffer0, m_anisotropy3Buffer0);

                    CopyBufferContent(m_positionBuffer0, m_positionBuffer);
                    CopyBufferContent(m_anisotropy1Buffer0, m_anisotropy1Buffer);
                    CopyBufferContent(m_anisotropy2Buffer0, m_anisotropy2Buffer);
                    CopyBufferContent(m_anisotropy3Buffer0, m_anisotropy3Buffer);

                    m_fluidMaterial.SetBuffer("_Points", m_positionBuffer);
                    m_fluidMaterial.SetBuffer("_Anisotropy1", m_anisotropy1Buffer);
                    m_fluidMaterial.SetBuffer("_Anisotropy2", m_anisotropy2Buffer);
                    m_fluidMaterial.SetBuffer("_Anisotropy3", m_anisotropy3Buffer);
                    m_fluidMaterial.SetBuffer("_Indices", m_indexBuffer);

                    FlexUtils.ComputeBounds(_particleData.particleData.particles, ref indices[0], indices.Length, ref boundsMin, ref boundsMax);
                }
                Vector3 center = (boundsMin + boundsMax) * 0.5f;
                Vector3 size   = boundsMax - boundsMin;
                m_bounds.center = Vector3.zero;
                m_bounds.size   = size;
                m_bounds.Expand(m_scene.container.radius);
                m_mesh.bounds      = m_bounds;
                transform.position = center;
            }
        }
        void UpdateBounds(FlexContainer.ParticleData _particleData)
        {
            Vector3 boundsMin = Vector3.one * float.MaxValue, boundsMax = Vector3.one * float.MaxValue;

            if (m_container != null && m_indices != null && m_indices.Length > 0)
            {
                FlexUtils.ComputeBounds(_particleData.particleData.particles, ref m_indices[0], m_indices.Length, ref boundsMin, ref boundsMax);
            }
            m_bounds.SetMinMax(boundsMin, boundsMax);
        }