Esempio n. 1
0
        unsafe private void UpdateMeshPart(MVGraphAPI.MeshData meshData)
        {
            if (!m_meshPart)
            {
                m_meshPart = CreateNewMeshPart();
            }

            UInt32 collectionsCapacity = GetMinimalMeshCollectionsCapacity(meshData);

            MvxUtils.EnsureCollectionMinimalCapacity <Vector3>(ref m_meshPartVertices, collectionsCapacity);

            fixed(Vector3 *verticesPtr = m_meshPartVertices)
            meshData.CopyVerticesRaw((IntPtr)verticesPtr);

            if (!IgnoreNormals())
            {
                MvxUtils.EnsureCollectionMinimalCapacity <Vector3>(ref m_meshPartNormals, collectionsCapacity);

                fixed(Vector3 *normalsPtr = m_meshPartNormals)
                meshData.CopyNormalsRaw((IntPtr)normalsPtr);
            }

            if (!IgnoreColors())
            {
                MvxUtils.EnsureCollectionMinimalCapacity <Color32>(ref m_meshPartColors, collectionsCapacity);

                fixed(Color32 *colorsPtr = m_meshPartColors)
                meshData.CopyColorsRGBARaw((IntPtr)colorsPtr);
            }

            if (!IgnoreUVs())
            {
                MvxUtils.EnsureCollectionMinimalCapacity <Vector2>(ref m_meshPartUVs, collectionsCapacity);

                fixed(Vector2 *uvsPtr = m_meshPartUVs)
                meshData.CopyUVsRaw((IntPtr)uvsPtr);
            }

            UInt32 meshIndicesCount = GetFrameMeshIndicesCount(meshData);

            if (meshIndicesCount == 0)
            {
                m_meshPart.gameObject.SetActive(false);
                return;
            }
            MvxUtils.EnsureCollectionMinimalCapacity <Int32>(ref m_meshPartIndices, meshIndicesCount);
            CopyMeshIndicesToCollection(meshData, m_meshPartIndices);
            MVGraphAPI.MeshIndicesMode meshIndicesMode = GetFrameIndicesMode(meshData);

            // fill the unused trailing of the indices collection with the last used index
            Int32 unusedIndicesValue = m_meshPartIndices[(Int32)meshIndicesCount - 1];

            for (UInt32 unusedIndex = meshIndicesCount; unusedIndex < m_meshPartIndices.Length; unusedIndex++)
            {
                m_meshPartIndices[unusedIndex] = unusedIndicesValue;
            }

            m_meshPart.UpdateMesh(m_meshPartVertices, m_meshPartNormals, m_meshPartColors, m_meshPartUVs, m_meshPartIndices, IndicesModeToMeshTopology(meshIndicesMode));
            m_meshPart.gameObject.SetActive(true);
        }
Esempio n. 2
0
 public void Reset(float[] newData, UInt32 newChannelsCount, UInt32 newSampleRate)
 {
     MvxUtils.EnsureCollectionMinimalCapacity(ref m_data, (UInt32)newData.Length);
     Array.Copy(newData, m_data, newData.Length);
     m_dataSize      = newData.Length;
     m_channelsCount = newChannelsCount;
     m_sampleRate    = newSampleRate;
 }
Esempio n. 3
0
        private static int ConvertUnsignedByteDataToFloats(byte[] byteData, ref float[] floatData)
        {
            MvxUtils.EnsureCollectionMinimalCapacity(ref floatData, (UInt32)byteData.Length);

            for (int index = 0; index < byteData.Length; index++)
            {
                floatData[index] = (float)byteData[index] / (float)byte.MaxValue;
                // transform range from <0, 1> to <-1, 1> (see PCM format standard)
                floatData[index] = floatData[index] * 2f - 1f;
            }

            return(byteData.Length);
        }
Esempio n. 4
0
        private static int ConvertSignedFloatDataToFloats(byte[] byteData, ref float[] floatData)
        {
            if (byteData.Length % 4 != 0)
            {
                throw new System.ArgumentException("Bytes array does not contain valid count of bytes");
            }

            int floatDataLength = byteData.Length / 4;

            MvxUtils.EnsureCollectionMinimalCapacity(ref floatData, (UInt32)floatDataLength);

            for (int floatDataIndex = 0; floatDataIndex < floatDataLength; floatDataIndex++)
            {
                int byteDataIndex = floatDataIndex * 4;
                Buffer.BlockCopy(byteData, byteDataIndex, floatAuxValue, 0, 4);
                // value is supposed to be in range <-1, 1> already  (see PCM format standard)
                floatData[floatDataIndex] = floatAuxValue[0];
            }

            return(floatDataLength);
        }
Esempio n. 5
0
        private static int ConvertSignedShortDataToFloats(byte[] byteData, ref float[] floatData)
        {
            if (byteData.Length % 2 != 0)
            {
                throw new System.ArgumentException("Bytes array does not contain valid count of bytes");
            }

            int floatDataLength = byteData.Length / 2;

            MvxUtils.EnsureCollectionMinimalCapacity(ref floatData, (UInt32)floatDataLength);

            for (int floatDataIndex = 0; floatDataIndex < floatDataLength; floatDataIndex++)
            {
                int byteDataIndex = floatDataIndex * 2;
                Buffer.BlockCopy(byteData, byteDataIndex, shortAuxValue, 0, 2);
                short shortValue = shortAuxValue[0];
                floatData[floatDataIndex] = (float)shortValue / (float)short.MaxValue;
            }

            return(floatDataLength);
        }