Ejemplo n.º 1
0
        public static unsafe FbxObject Parse(Stream stream)
        {
            if (stream is null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            var reader = new Reader(stream);

            ParseHeader(reader, out var version);
            UnsafeRawList <FbxNode_> nodes = default;

            try {
                while (true)
                {
                    if (!ParseNodeRecord(reader, version, out var node))
                    {
                        break;
                    }
                    nodes.Add(node);
                }
                return(new FbxObject(nodes));
            }
            catch {
                nodes.Dispose();
                throw;
            }
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        public void Add()
        {
            using (var list = new UnsafeRawList <int>()) {
                const int Count = 10;
                for (int i = 0; i < Count; i++)
                {
                    list.Add(i);
                }
                for (int i = 0; i < list.Count; i++)
                {
                    Assert.Equal(i, list[i]);
                }
            }

            ReadOnlySpan <int> source = Enumerable.Range(0, 100).ToArray();

            using (var list = new UnsafeRawList <int>(source)) {
                list.AddRange(source);
                Assert.True(list.AsSpan(0, source.Length).SequenceEqual(source));
                Assert.True(list.AsSpan(source.Length, source.Length).SequenceEqual(source));
            }
        }