Esempio n. 1
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;
        }
Esempio n. 2
0
        public static UnsafeRawList <byte> ReadToEnd(this Stream stream, out int length)
        {
            if (stream is null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            var buf = new UnsafeRawList <byte>(0);

            try {
                length = 0;
                while (true)
                {
                    var span    = buf.Extend(1024);
                    var readLen = stream.Read(span);
                    length += readLen;
                    if (readLen == 0)
                    {
                        break;
                    }
                }
                return(buf);
            }
            catch {
                buf.Dispose();
                throw;
            }
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
0
 public void Dispose()
 {
     _positions.Dispose();
     _normals.Dispose();
     _uvs.Dispose();
     _positionIndices.Dispose();
     _normalIndices.Dispose();
     _uvIndices.Dispose();
 }
Esempio n. 5
0
        public void Dispose()
        {
            _srcToDest?.Dispose();
            foreach (var l in _destLists.AsSpan())
            {
                l.Dispose();
            }
            _destLists.Dispose();

            _destToSrc?.Dispose();
            foreach (var l in _srcLists.AsSpan())
            {
                l.Dispose();
            }
            _srcLists.Dispose();
        }
Esempio n. 6
0
 private static UnsafeRawList <byte> ReadToBuffer(Stream stream, out int length)
 {
     if (stream.CanSeek)
     {
         var streamLen = stream.Length;
         if (streamLen <= int.MaxValue)
         {
             var buffer = new UnsafeRawList <byte>((int)streamLen);
             try {
                 length = stream.Read(buffer.Extend((int)streamLen, false));
                 return(buffer);
             }
             catch {
                 buffer.Dispose();
                 throw;
             }
         }
         else
         {
             throw new NotSupportedException();
         }
     }
     else
     {
         var buffer   = new UnsafeRawList <byte>();
         var totalLen = 0;
         while (true)
         {
             const int BlockSize = 1024;
             var       readLen   = stream.Read(buffer.Extend(BlockSize, false));
             totalLen += readLen;
             if (readLen < BlockSize)
             {
                 break;
             }
         }
         length = totalLen;
         return(buffer);
     }
 }