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); }
public override void AbcSampleUpdated(AbcAPI.aiSample sample, bool topologyChanged) { var abcMaterials = AlembicTreeNode.linkedGameObj.GetComponent <AlembicMaterial>(); if (abcMaterials != null) { if (abcMaterials.HasFacesetsChanged()) { topologyChanged = true; } hasFacesets = (abcMaterials.GetFacesetsCount() > 0); } else if (hasFacesets) { topologyChanged = true; hasFacesets = false; } if (m_FreshSetup) { topologyChanged = true; m_FreshSetup = false; } AbcAPI.aiPolyMeshGetSampleSummary(sample, ref sampleSummary, topologyChanged); AbcAPI.aiPolyMeshData vertexData = default(AbcAPI.aiPolyMeshData); UpdateSplits(sampleSummary.splitCount); for (int s = 0; s < sampleSummary.splitCount; ++s) { Split split = 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 (sampleSummary.hasVelocities) { Array.Resize(ref split.velocitiesCache, vertexCount); vertexData.velocities = GetArrayPtr(split.velocitiesCache); Array.Resize(ref split.velocitiesXYCache, vertexCount); vertexData.interpolatedVelocitiesXY = GetArrayPtr(split.velocitiesXYCache); Array.Resize(ref split.velocitiesZCache, vertexCount); vertexData.interpolatedVelocitiesZ = GetArrayPtr(split.velocitiesZCache); } if (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 (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 (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 (submeshes.Count > numSubmeshes) { submeshes.RemoveRange(numSubmeshes, submeshes.Count - numSubmeshes); } for (int s = 0; s < sampleSummary.splitCount; ++s) { splits[s].submeshCount = AbcAPI.aiPolyMeshGetSplitSubmeshCount(sample, s); } while (AbcAPI.aiPolyMeshGetNextSubmesh(sample, ref submeshSummary)) { if (submeshSummary.splitIndex >= splits.Count) { Debug.Log("Invalid split index"); continue; } Submesh submesh = null; if (submeshSummary.index < submeshes.Count) { submesh = submeshes[submeshSummary.index]; } else { submesh = new Submesh { indexCache = new int[0], facesetIndex = -1, splitIndex = -1, index = -1, update = true }; 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 < submeshes.Count; ++i) { submeshes[i].update = false; } } AbcDirty(); }