Ejemplo 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);
        }
Ejemplo n.º 2
0
        private MvxMeshPart CreateNewMeshPart()
        {
            GameObject partGameObject = new GameObject("MeshPart");

            partGameObject.hideFlags = partGameObject.hideFlags | HideFlags.DontSave;
            partGameObject.transform.SetParent(m_transformFixGO.transform);
            partGameObject.transform.localPosition = Vector3.zero;
            partGameObject.transform.localRotation = Quaternion.identity;
            partGameObject.transform.localScale    = Vector3.one;

            MvxMeshPart newMeshPart = partGameObject.AddComponent <MvxMeshPart>();

            newMeshPart.SetMaterials(m_materialInstances);
            return(newMeshPart);
        }
Ejemplo n.º 3
0
        private void DestroyMeshPart()
        {
            if (!m_meshPart)
            {
                return;
            }

            m_meshPart.ClearMesh();
            m_meshPart.gameObject.SetActive(false);
            if (Application.isPlaying)
            {
                Destroy(m_meshPart.gameObject);
            }
            else
            {
                DestroyImmediate(m_meshPart.gameObject);
            }
            m_meshPart = null;
        }