コード例 #1
0
ファイル: AlembicMesh.cs プロジェクト: bachlis/Kinect2Viz
        public override void AbcSampleUpdated(AbcAPI.aiSample sample, bool topologyChanged)
        {
            AlembicMaterial abcMaterials = m_trans.GetComponent <AlembicMaterial>();

            if (abcMaterials != null)
            {
                if (abcMaterials.HasFacesetsChanged())
                {
                    AbcVerboseLog("AlembicMesh.AbcSampleUpdated: Facesets updated, force topology update");
                    topologyChanged = true;
                }

                hasFacesets = (abcMaterials.GetFacesetsCount() > 0);
            }
            else if (hasFacesets)
            {
                AbcVerboseLog("AlembicMesh.AbcSampleUpdated: Facesets cleared, force topology update");
                topologyChanged = true;
                hasFacesets     = false;
            }

            if (m_freshSetup)
            {
                topologyChanged = true;

                m_freshSetup = false;
            }

            AbcAPI.aiPolyMeshGetSampleSummary(sample, ref m_sampleSummary, topologyChanged);

            AbcAPI.aiPolyMeshData vertexData = default(AbcAPI.aiPolyMeshData);

            UpdateSplits(m_sampleSummary.splitCount);

            for (int s = 0; s < m_sampleSummary.splitCount; ++s)
            {
                Split split = m_splits[s];

                split.clear  = topologyChanged;
                split.active = true;

                int vertexCount = AbcAPI.aiPolyMeshGetVertexBufferLength(sample, s);

                Array.Resize(ref split.positionCache, vertexCount);
                vertexData.positions = GetArrayPtr(split.positionCache);

                if (m_sampleSummary.hasNormals)
                {
                    Array.Resize(ref split.normalCache, vertexCount);
                    vertexData.normals = GetArrayPtr(split.normalCache);
                }
                else
                {
                    Array.Resize(ref split.normalCache, 0);
                    vertexData.normals = IntPtr.Zero;
                }

                if (m_sampleSummary.hasUVs)
                {
                    Array.Resize(ref split.uvCache, vertexCount);
                    vertexData.uvs = GetArrayPtr(split.uvCache);
                }
                else
                {
                    Array.Resize(ref split.uvCache, 0);
                    vertexData.uvs = IntPtr.Zero;
                }

                if (m_sampleSummary.hasTangents)
                {
                    Array.Resize(ref split.tangentCache, vertexCount);
                    vertexData.tangents = GetArrayPtr(split.tangentCache);
                }
                else
                {
                    Array.Resize(ref split.tangentCache, 0);
                    vertexData.tangents = IntPtr.Zero;
                }

                AbcAPI.aiPolyMeshFillVertexBuffer(sample, s, ref vertexData);

                split.center = vertexData.center;
                split.size   = vertexData.size;
            }

            if (topologyChanged)
            {
                AbcAPI.aiFacesets       facesets       = default(AbcAPI.aiFacesets);
                AbcAPI.aiSubmeshSummary submeshSummary = default(AbcAPI.aiSubmeshSummary);
                AbcAPI.aiSubmeshData    submeshData    = default(AbcAPI.aiSubmeshData);

                if (abcMaterials != null)
                {
                    abcMaterials.GetFacesets(ref facesets);
                }

                int numSubmeshes = AbcAPI.aiPolyMeshPrepareSubmeshes(sample, ref facesets);

                if (m_submeshes.Count > numSubmeshes)
                {
                    m_submeshes.RemoveRange(numSubmeshes, m_submeshes.Count - numSubmeshes);
                }

                for (int s = 0; s < m_sampleSummary.splitCount; ++s)
                {
                    m_splits[s].submeshCount = AbcAPI.aiPolyMeshGetSplitSubmeshCount(sample, s);
                }

                while (AbcAPI.aiPolyMeshGetNextSubmesh(sample, ref submeshSummary))
                {
                    if (submeshSummary.splitIndex >= m_splits.Count)
                    {
                        Debug.Log("Invalid split index");
                        continue;
                    }

                    Submesh submesh = null;

                    if (submeshSummary.index < m_submeshes.Count)
                    {
                        submesh = m_submeshes[submeshSummary.index];
                    }
                    else
                    {
                        submesh = new Submesh
                        {
                            indexCache   = new int[0],
                            facesetIndex = -1,
                            splitIndex   = -1,
                            index        = -1,
                            update       = true
                        };

                        m_submeshes.Add(submesh);
                    }

                    submesh.facesetIndex = submeshSummary.facesetIndex;
                    submesh.splitIndex   = submeshSummary.splitIndex;
                    submesh.index        = submeshSummary.splitSubmeshIndex;
                    submesh.update       = true;

                    Array.Resize(ref submesh.indexCache, 3 * submeshSummary.triangleCount);

                    submeshData.indices = GetArrayPtr(submesh.indexCache);

                    AbcAPI.aiPolyMeshFillSubmeshIndices(sample, ref submeshSummary, ref submeshData);
                }

                if (abcMaterials != null)
                {
                    abcMaterials.AknowledgeFacesetsChanges();
                }
            }
            else
            {
                for (int i = 0; i < m_submeshes.Count; ++i)
                {
                    m_submeshes[i].update = false;
                }
            }

            AbcDirty();
        }
コード例 #2
0
 public void GetFacesets(ref AbcAPI.aiFacesets facesets)
 {
     facesets.count       = facesetsCache.faceCounts.Length;
     facesets.faceCounts  = Marshal.UnsafeAddrOfPinnedArrayElement(facesetsCache.faceCounts, 0);
     facesets.faceIndices = Marshal.UnsafeAddrOfPinnedArrayElement(facesetsCache.faceIndices, 0);
 }