public FbxConnectionResolver(FbxNode connectionsNode) { var count = connectionsNode.Children.Count; var destLists = new UnsafeRawList <UnsafeRawList <long> >(count); var srcToDest = new BufferPooledDictionary <long, int>(count); var destToSrc = new BufferPooledDictionary <long, int>(count); var srcLists = new UnsafeRawList <UnsafeRawList <long> >(count); try { foreach (var c in connectionsNode.Children) { var props = c.Properties; var conn = new Connection(props[0].AsString().ToConnectionType(), props[1].AsInt64(), props[2].AsInt64()); // Create source-to-dest dictionary { UnsafeRawList <long> dests; if (srcToDest.TryAdd(conn.SourceID, destLists.Count)) { dests = new UnsafeRawList <long>(); destLists.Add(dests); } else { dests = destLists[srcToDest[conn.SourceID]]; } Debug.Assert(dests.IsNull == false); dests.Add(conn.DestID); } // Create dest-to-source dictionary { UnsafeRawList <long> sources; if (destToSrc.TryAdd(conn.DestID, srcLists.Count)) { sources = new UnsafeRawList <long>(); srcLists.Add(sources); } else { sources = srcLists[destToSrc[conn.DestID]]; } Debug.Assert(sources.IsNull == false); sources.Add(conn.SourceID); } } } catch { destLists.Dispose(); srcToDest.Dispose(); destToSrc.Dispose(); srcLists.Dispose(); throw; } _destLists = destLists; _srcToDest = srcToDest; _destToSrc = destToSrc; _srcLists = srcLists; }
public void BasicTest() { using var dic = new BufferPooledDictionary <int, long>(); const int count = 1000; for (int i = 0; i < count; i++) { dic.Add(i, i); } Assert.Equal(count, dic.Count); foreach (var key in dic.Keys) { Assert.Equal((long)key, dic[key]); Assert.True(dic.TryGetValue(key, out var value) && value == (long)key); Assert.True(dic.ContainsKey(key)); Assert.True(dic.ContainsValue(dic[key])); } foreach (var value in dic.Values) { Assert.True(dic.ContainsValue(value)); } foreach (var(key, value) in dic) { Assert.Equal((long)key, value); Assert.Equal(dic[key], value); Assert.True(dic.TryGetValue(key, out var v) && v == value); Assert.True(dic.ContainsKey(key)); Assert.True(dic.ContainsValue(dic[key])); } Assert.True(dic.Values.Count == dic.Count); Assert.True(dic.Keys.Count == dic.Count); Assert.False(dic.TryAdd(10, 10)); Assert.False(dic.TryAdd(0, 0)); Assert.False(dic.TryAdd(999, 999)); Assert.True(dic.TryAdd(10000, 10000)); dic.Clear(); Assert.True(dic.Count == 0); foreach (var _ in dic) { throw new Exception(); } foreach (var _ in dic.Keys) { throw new Exception(); } foreach (var _ in dic.Values) { throw new Exception(); } }
public DeformerList(FbxNode objectsNode) { using var buf = new UnsafeRawArray <int>(objectsNode.Children.Count, false); var count = objectsNode.FindChildIndexAll(FbxConstStrings.Deformer(), buf.AsSpan()); _dic = new BufferPooledDictionary <long, FbxNode>(count); foreach (var index in buf.AsSpan(0, count)) { var deformer = objectsNode.Children[index]; var id = deformer.Properties[0].AsInt64(); _dic.Add(id, deformer); } }
public ModelList(FbxNode objectsNode) { var meshDic = new BufferPooledDictionary <long, MeshModel>(); var limbDic = new BufferPooledDictionary <long, LimbNode>(); var nullDic = new BufferPooledDictionary <long, NullModel>(); try { using var indexBuf = new ValueTypeRentMemory <int>(objectsNode.Children.Count, false); var modelCount = objectsNode.FindChildIndexAll(FbxConstStrings.Model(), indexBuf.AsSpan()); foreach (var i in indexBuf.AsSpan(0, modelCount)) { var modelNode = objectsNode.Children[i]; var modelType = modelNode.Properties[2].AsString().ToModelType(); switch (modelType) { case ModelType.LimbNode: { var limb = new LimbNode(modelNode); limbDic.Add(limb.ID, limb); break; } case ModelType.Mesh: { var meshModel = new MeshModel(modelNode); meshDic.Add(meshModel.ID, meshModel); break; } case ModelType.Null: { var nullModel = new NullModel(modelNode); nullDic.Add(nullModel.ID, nullModel); break; } case ModelType.Unknown: default: break; } } _meshDic = meshDic; _limbDic = limbDic; _nullDic = nullDic; } catch { meshDic.Dispose(); limbDic.Dispose(); nullDic.Dispose(); throw; } }
public static InterleavedMesh <Vertex> CreateInterleavedVertices( ReadOnlySpan <Vector3> positions, ReadOnlySpan <int> positionIndices, ReadOnlySpan <Vector3> normals, ReadOnlySpan <int> normalIndices, ReadOnlySpan <Vector2> uvs, ReadOnlySpan <int> uvIndices, IBufferWriter <Vertex> verticesWriter, IBufferWriter <int> indicesWriter) { var isValid = (positionIndices.Length == normalIndices.Length) && (positionIndices.Length == uvIndices.Length); if (isValid == false) { throw new ArgumentException(); } var len = positionIndices.Length; using var dic = new BufferPooledDictionary <Key_PNT, int>(len); var vertices = verticesWriter.GetSpan(len); var indices = indicesWriter.GetSpan(len); var verticesCount = 0; var indicesCount = 0; for (int i = 0; i < len; i++) { var key = new Key_PNT(positionIndices.At(i), normalIndices.At(i), uvIndices.At(i)); if (dic.TryGetValue(key, out var index)) { indices[indicesCount++] = index; } else { index = dic.Count; indices[indicesCount++] = index; dic.Add(key, index); vertices[verticesCount++] = new Vertex(positions[key.P], normals[key.N], uvs[key.T]); } } verticesWriter.Advance(verticesCount); indicesWriter.Advance(indicesCount); return(new(vertices.Slice(0, verticesCount), indices.Slice(0, indicesCount))); }