Esempio n. 1
0
 void InitializeSimulation()
 {
     if (SystemInfo.supportsComputeShaders)
     {
         m_cb_params     = new ComputeBuffer(1, CSParams.size);
         m_cb_particles  = new ComputeBuffer(m_particle_count, peParticle.size);
         m_cb_positions  = new ComputeBuffer(m_particle_count, 12);
         m_cb_velocities = new ComputeBuffer(m_particle_count, 12);
         m_buf_positions.ResizeDiscard(m_particle_count);
         m_buf_velocities.ResizeDiscard(m_particle_count);
         m_csparams = new CSParams[1];
     }
     {
         UnityEngine.Random.InitState(0);
         var tmp = new peParticle[m_particle_count];
         for (int i = 0; i < tmp.Length; ++i)
         {
             tmp[i].position = new Vector3(
                 UnityEngine.Random.Range(-5.0f, 5.0f),
                 UnityEngine.Random.Range(-5.0f, 5.0f) + 5.0f,
                 UnityEngine.Random.Range(-5.0f, 5.0f));
         }
         m_cb_particles.SetData(tmp);
     }
 }
Esempio n. 2
0
        public override void AbcSyncDataBegin()
        {
            if (!m_abcSchema.schema.isDataUpdated)
            {
                return;
            }

            var sample = m_abcSchema.sample;

            sample.GetSummary(ref m_sampleSummary);
            int splitCount   = m_sampleSummary.splitCount;
            int submeshCount = m_sampleSummary.submeshCount;

            m_splitSummaries.ResizeDiscard(splitCount);
            m_splitData.ResizeDiscard(splitCount);
            m_submeshSummaries.ResizeDiscard(submeshCount);
            m_submeshData.ResizeDiscard(submeshCount);

            sample.GetSplitSummaries(m_splitSummaries);
            sample.GetSubmeshSummaries(m_submeshSummaries);

            UpdateSplits(splitCount);

            bool topologyChanged = m_sampleSummary.topologyChanged;

            // setup buffers
            var vertexData = default(aiPolyMeshData);

            for (int spi = 0; spi < splitCount; ++spi)
            {
                var split = m_splits[spi];
                split.active = true;

                int vertexCount = m_splitSummaries[spi].vertexCount;

                if (!m_summary.constantPoints || topologyChanged)
                {
                    split.points.ResizeDiscard(vertexCount);
                }
                else
                {
                    split.points.ResizeDiscard(0);
                }
                vertexData.positions = split.points;

                if (m_summary.hasVelocities && (!m_summary.constantVelocities || topologyChanged))
                {
                    split.velocities.ResizeDiscard(vertexCount);
                }
                else
                {
                    split.velocities.ResizeDiscard(0);
                }
                vertexData.velocities = split.velocities;

                if (m_summary.hasNormals && (!m_summary.constantNormals || topologyChanged))
                {
                    split.normals.ResizeDiscard(vertexCount);
                }
                else
                {
                    split.normals.ResizeDiscard(0);
                }
                vertexData.normals = split.normals;

                if (m_summary.hasTangents && (!m_summary.constantTangents || topologyChanged))
                {
                    split.tangents.ResizeDiscard(vertexCount);
                }
                else
                {
                    split.tangents.ResizeDiscard(0);
                }
                vertexData.tangents = split.tangents;

                if (m_summary.hasUV0 && (!m_summary.constantUV0 || topologyChanged))
                {
                    split.uv0.ResizeDiscard(vertexCount);
                }
                else
                {
                    split.uv0.ResizeDiscard(0);
                }
                vertexData.uv0 = split.uv0;

                if (m_summary.hasUV1 && (!m_summary.constantUV1 || topologyChanged))
                {
                    split.uv1.ResizeDiscard(vertexCount);
                }
                else
                {
                    split.uv1.ResizeDiscard(0);
                }
                vertexData.uv1 = split.uv1;

                if (m_summary.hasColors && (!m_summary.constantColors || topologyChanged))
                {
                    split.colors.ResizeDiscard(vertexCount);
                }
                else
                {
                    split.colors.ResizeDiscard(0);
                }
                vertexData.colors = split.colors;

                m_splitData[spi] = vertexData;
            }

            {
                if (m_submeshes.Count > submeshCount)
                {
                    m_submeshes.RemoveRange(submeshCount, m_submeshes.Count - submeshCount);
                }
                while (m_submeshes.Count < submeshCount)
                {
                    m_submeshes.Add(new Submesh());
                }

                var submeshData = default(aiSubmeshData);
                for (int smi = 0; smi < submeshCount; ++smi)
                {
                    var submesh = m_submeshes[smi];
                    m_submeshes[smi].update = true;
                    submesh.indices.ResizeDiscard(m_submeshSummaries[smi].indexCount);
                    submeshData.indices = submesh.indices;
                    m_submeshData[smi]  = submeshData;
                }
            }

            // kick async copy
            sample.FillVertexBuffer(m_splitData, m_submeshData);
        }