コード例 #1
0
ファイル: StringToken.cs プロジェクト: UkooLabs/FBXSharpie
        internal override void WriteBinary(FbxVersion version, BinaryWriter binaryWriter)
        {
            const string asciiSeparator  = "::";
            const string binarySeparator = "\0\x1";

            binaryWriter.Write((byte)('S'));

            var str = Value;

            if (str.Contains(asciiSeparator))
            {
                var  tokens = str.Split(new[] { asciiSeparator }, StringSplitOptions.None);
                var  sb     = new StringBuilder();
                bool first  = true;
                for (int i = tokens.Length - 1; i >= 0; i--)
                {
                    if (!first)
                    {
                        sb.Append(binarySeparator);
                    }
                    sb.Append(tokens[i]);
                    first = false;
                }
                str = sb.ToString();
            }
            var bytes = Encoding.ASCII.GetBytes(str);

            binaryWriter.Write(bytes.Length);
            binaryWriter.Write(bytes);
        }
コード例 #2
0
            public FBXHeader(FbxVersion version)
            {
                this.Version = version;
                CreationTime = DateTime.Now;

                switch (Version)
                {
                case FbxVersion.v2000:
                case FbxVersion.v2001:
                case FbxVersion.v3000:
                case FbxVersion.v3001:
                case FbxVersion.v4000:
                case FbxVersion.v4001:
                case FbxVersion.v4050:
                case FbxVersion.v5000:
                case FbxVersion.v5800:
                case FbxVersion.v6000:
                case FbxVersion.v6100:
                case FbxVersion.v7000:
                case FbxVersion.v7100:
                case FbxVersion.v7200:
                case FbxVersion.v7300:
                case FbxVersion.v7400:
                case FbxVersion.v7500:
                case FbxVersion.v7600:
                case FbxVersion.v7700:
                    HeaderVersion = 1003;
                    break;

                default:
                    break;
                }
            }
コード例 #3
0
            public GlobalSettings(FbxVersion version)
            {
                switch (version)
                {
                case FbxVersion.v2000:
                case FbxVersion.v2001:
                case FbxVersion.v3000:
                case FbxVersion.v3001:
                case FbxVersion.v4000:
                case FbxVersion.v4001:
                case FbxVersion.v4050:
                case FbxVersion.v5000:
                case FbxVersion.v5800:
                case FbxVersion.v6000:
                case FbxVersion.v6100:
                case FbxVersion.v7000:
                case FbxVersion.v7100:
                case FbxVersion.v7200:
                case FbxVersion.v7300:
                case FbxVersion.v7400:
                case FbxVersion.v7500:
                case FbxVersion.v7600:
                case FbxVersion.v7700:
                    Version = 1000;
                    break;

                default:
                    break;
                }
            }
コード例 #4
0
ファイル: FbxBinaryWriter.cs プロジェクト: tankyx/actools
        void WriteProperty(FbxVersion version, Token obj)
        {
            if (obj == null)
            {
                return;
            }

            obj.WriteBinary(version, stream);
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FbxWriter"/> class for the specified file.
        /// </summary>
        /// <param name="path">The complete file path to write to.</param>
        /// <param name="version"></param>
        public FbxWriter(string path, FbxVersion version = FbxVersion.v7400)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            this._stream = new FileStream(path, FileMode.Create);
            this.Version = version;
        }
コード例 #6
0
        public static void WriteBinary(string path, Scene scene, FbxVersion version = FbxVersion.v7400)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            using (FbxWriter writer = new FbxWriter(path, version))
                writer.WriteBinary(scene);
        }
コード例 #7
0
        public GlobalSettings(FbxVersion version)
        {
            switch (version)
            {
            case FbxVersion.v2000:
            case FbxVersion.v2001:
            case FbxVersion.v3000:
            case FbxVersion.v3001:
            case FbxVersion.v4000:
            case FbxVersion.v4001:
            case FbxVersion.v4050:
            case FbxVersion.v5000:
            case FbxVersion.v5800:
            case FbxVersion.v6000:
            case FbxVersion.v6100:
            case FbxVersion.v7000:
            case FbxVersion.v7100:
            case FbxVersion.v7200:
            case FbxVersion.v7300:
            case FbxVersion.v7400:
            case FbxVersion.v7500:
            case FbxVersion.v7600:
            case FbxVersion.v7700:
                Version = 1000;
                break;

            default:
                break;
            }

            _properties.Add(new FbxProperty <int>("UpAxis", null, 1, "int", "Integer", PropertyFlags.None));
            _properties.Add(new FbxProperty <int>("UpAxisSign", null, 1, "int", "Integer", PropertyFlags.None));
            _properties.Add(new FbxProperty <int>("FrontAxis", null, 2, "int", "Integer", PropertyFlags.None));
            _properties.Add(new FbxProperty <int>("FrontAxisSign", null, 1, "int", "Integer", PropertyFlags.None));
            _properties.Add(new FbxProperty <int>("CoordAxis", null, 0, "int", "Integer", PropertyFlags.None));
            _properties.Add(new FbxProperty <int>("CoordAxisSign", null, 1, "int", "Integer", PropertyFlags.None));
            _properties.Add(new FbxProperty <int>("OriginalUpAxis", null, 2, "int", "Integer", PropertyFlags.None));
            _properties.Add(new FbxProperty <int>("OriginalUpAxisSign", null, 1, "int", "Integer", PropertyFlags.None));
            _properties.Add(new FbxProperty <double>("UnitScaleFactor", null, 100000, "double", "Number", PropertyFlags.None));
            _properties.Add(new FbxProperty <double>("OriginalUnitScaleFactor", null, 100, "double", "Number", PropertyFlags.None));
            _properties.Add(new FbxProperty <Color>("AmbientColor", null, new Color(), "ColorRGB", "Color", PropertyFlags.None));
            _properties.Add(new FbxProperty <string>("DefaultCamera", null, "Producer", "KString", "", PropertyFlags.None));
            //_properties.Add(new FbxProperty<>("TimeMode", null, "enum", "", "", 6));
            //_properties.Add(new FbxProperty<>("TimeProtocol", null, "enum", "", "", 2));
            //_properties.Add(new FbxProperty<>("SnapOnFrameMode", null, "enum", "", "", 0));
            //_properties.Add(new FbxProperty<>("TimeSpanStart", null, "KTime", "Time", "", 0));
            //_properties.Add(new FbxProperty<>("TimeSpanStop", null, "KTime", "Time", "", 153953860));
            _properties.Add(new FbxProperty <double>("CustomFrameRate", null, -1, "double", "Number", PropertyFlags.None));
            //_properties.Add(new FbxProperty<>("TimeMarker", null, "Compound", "", ""));
            _properties.Add(new FbxProperty <int>("CurrentTimeMarker", null, -1, "int", "Integer", PropertyFlags.None));
        }
コード例 #8
0
ファイル: FbxAsciiWriter.cs プロジェクト: tankyx/actools
        // Adds the given node text to the string
        void BuildString(FbxNode node, LineStringBuilder sb, FbxVersion version, int indentLevel = 0)
        {
            // Write identifier
            sb.Indent(indentLevel);

            node.Identifier.WriteAscii(version, sb, indentLevel);

            // Write properties
            var first = true;

            for (int j = 0; j < node.Properties.Count; j++)
            {
                var p = node.Properties[j];
                if (p == null)
                {
                    continue;
                }

                if (!first)
                {
                    sb.Append(",");
                }

                sb.Append(" ");

                p.WriteAscii(version, sb, indentLevel);

                first = false;
            }

            // Write child nodes
            if (node.Nodes.Count > 0)
            {
                sb.Append(" {\n");
                foreach (var n in node.Nodes)
                {
                    if (n == null)
                    {
                        continue;
                    }

                    BuildString(n, sb, version, indentLevel + 1);
                }

                sb.Indent(indentLevel);

                sb.Append("}");
            }
            sb.Append("\n");
        }
コード例 #9
0
ファイル: IdentifierToken.cs プロジェクト: tankyx/actools
        internal override void WriteBinary(FbxVersion version, BinaryWriter binaryWriter)
        {
            var bytes = Encoding.ASCII.GetBytes(Value ?? string.Empty);

            if (bytes.Length > byte.MaxValue)
            {
                throw new FbxException(binaryWriter.BaseStream.Position, "Identifier value is too long");
            }
            binaryWriter.Write((byte)bytes.Length);
            if (bytes.Length > 0)
            {
                binaryWriter.Write(bytes);
            }
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FbxWriter"/> class for the specified stream.
        /// </summary>
        /// <param name="stream">The stream to write to.</param>
        /// <param name="version"></param>
        public FbxWriter(Stream stream, FbxVersion version = FbxVersion.v7400)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanSeek)
            {
                throw new ArgumentException("The stream must support seeking. Try reading the data into a buffer first");
            }

            this._stream = stream;
            this.Version = version;
        }
コード例 #11
0
ファイル: ByteArrayToken.cs プロジェクト: tankyx/actools
        internal override void WriteAscii(FbxVersion version, LineStringBuilder lineStringBuilder, int indentLevel)
        {
            var arrayLength = Values.Length;

            WriteAsciiArray(version, lineStringBuilder, arrayLength, indentLevel, (itemWriter) => {
                for (var i = 0; i < Values.Length; i++)
                {
                    if (i > 0)
                    {
                        lineStringBuilder.Append(",");
                    }
                    lineStringBuilder.Append(Values[i].ToString());
                }
            });
        }
コード例 #12
0
ファイル: FbxBinary.cs プロジェクト: cmdr2/UnityFbxWriter
        /// <summary>
        /// Reads and checks the FBX footer extension (NB - not the unique footer code)
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="version"></param>
        /// <returns><c>true</c> if it's compliant</returns>
        protected bool CheckFooter(BinaryReader stream, FbxVersion version)
        {
            var buffer = new byte[Math.Max(footerZeroes1, footerZeroes2)];

            stream.Read(buffer, 0, footerZeroes1);
            bool correct     = AllZero(buffer);
            var  readVersion = stream.ReadInt32();

            correct &= (readVersion == (int)version);
            stream.Read(buffer, 0, footerZeroes2);
            correct &= AllZero(buffer);
            stream.Read(buffer, 0, extension.Length);
            correct &= CheckEqual(buffer, extension);
            return(correct);
        }
コード例 #13
0
        internal override void WriteBinary(FbxVersion version, BinaryWriter binaryWriter)
        {
            var count = Values.Length;

            binaryWriter.Write((byte)'i');
            binaryWriter.Write(count);
            var uncompressedSize = count * sizeof(int);

            WriteBinaryArray(binaryWriter, uncompressedSize, (itemWriter) => {
                foreach (var value in Values)
                {
                    itemWriter.Write(value);
                }
            });
        }
コード例 #14
0
ファイル: Token.cs プロジェクト: UkooLabs/FBXSharpie
        internal void WriteAsciiArray(FbxVersion version, LineStringBuilder lineStringBuilder, int arrayLength, int indentLevel, Action <LineStringBuilder> itemWriterAction)
        {
            if (version >= FbxVersion.v7_1)
            {
                lineStringBuilder.Append("*").Append(arrayLength.ToString()).Append(" {\n");
                lineStringBuilder.Indent(indentLevel + 1);
                lineStringBuilder.Append("a: ");
            }

            itemWriterAction.Invoke(lineStringBuilder);

            if (version >= FbxVersion.v7_1)
            {
                lineStringBuilder.Append("\n");
                lineStringBuilder.Indent(indentLevel);
                lineStringBuilder.Append("}");
            }
        }
コード例 #15
0
        public static IFbxConverter GetConverter(Scene scene, FbxVersion version)
        {
            IFbxConverter converter = null;

            switch (version)
            {
            case FbxVersion.v2000:
            case FbxVersion.v2001:
            case FbxVersion.v3000:
            case FbxVersion.v3001:
            case FbxVersion.v4000:
            case FbxVersion.v4001:
            case FbxVersion.v4050:
            case FbxVersion.v5000:
            case FbxVersion.v5800:
            case FbxVersion.v6000:
            case FbxVersion.v6100:
                throw new NotImplementedException($"Incompatible version {version}");

            case FbxVersion.v7000:
            case FbxVersion.v7100:
            case FbxVersion.v7200:
            case FbxVersion.v7300:
            case FbxVersion.v7400:
                converter = new FbxConverter7400(scene);
                break;

            case FbxVersion.v7500:
            case FbxVersion.v7600:
            case FbxVersion.v7700:
                converter = new FbxConverter7400(scene);
                break;

            default:
                throw new NotSupportedException($"Incompatible version {version}");
            }

            //TODO: check the versions differences to implement the missing converters

            return(converter);
        }
コード例 #16
0
ファイル: FbxBinary.cs プロジェクト: tankyx/actools
        /// <summary>
        /// Reads and checks the FBX footer extension (NB - not the unique footer code)
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="version"></param>
        /// <returns><c>true</c> if it's compliant</returns>
        protected bool CheckFooter(BinaryReader stream, FbxVersion version)
        {
            var position      = stream.BaseStream.Position;
            var paddingLength = (int)(16 - (position % 16));

            if (paddingLength == 0)
            {
                paddingLength = 16;
            }
            paddingLength += 4;
            var buffer = new byte[Math.Max(paddingLength, footerZeroes)];

            stream.Read(buffer, 0, paddingLength);
            bool correct     = AllZero(buffer);
            var  readVersion = stream.ReadInt32();

            correct &= (readVersion == (int)version);
            stream.Read(buffer, 0, footerZeroes);
            correct &= AllZero(buffer);
            stream.Read(buffer, 0, extension.Length);
            correct &= CheckEqual(buffer, extension);
            return(correct);
        }
コード例 #17
0
 public FbxWriterOptions(FbxVersion version)
 {
 }
コード例 #18
0
ファイル: ByteArrayToken.cs プロジェクト: tankyx/actools
 internal override void WriteBinary(FbxVersion version, BinaryWriter binaryWriter)
 {
     binaryWriter.Write((byte)'R');
     binaryWriter.Write(Values.Length);
     binaryWriter.Write(Values);
 }
コード例 #19
0
ファイル: IdentifierToken.cs プロジェクト: tankyx/actools
 internal override void WriteAscii(FbxVersion version, LineStringBuilder lineStringBuilder, int indentLevel)
 {
     lineStringBuilder.Append($"{Value}:");
 }
コード例 #20
0
ファイル: FbxRootNode.cs プロジェクト: DomCR/MeshIO
        /// <summary>
        /// Create a <see cref="FbxRootNode"/> from an <see cref="Scene"/>.
        /// </summary>
        /// <param name="scene">Scene from where the <see cref="FbxRootNode"/> will be created.</param>
        /// <param name="version"><see cref="FbxVersion"/> format for the <see cref="FbxRootNode"/></param>
        public static FbxRootNode CreateFromScene(Scene scene, FbxVersion version = FbxVersion.v7400)
        {
            IFbxConverter converter = FbxConverterBase.GetConverter(scene, version);

            return(converter.ToRootNode());
        }
コード例 #21
0
 internal override void WriteBinary(FbxVersion version, BinaryWriter binaryWriter)
 {
     binaryWriter.Write((byte)('Y'));
     binaryWriter.Write(Value);
 }
コード例 #22
0
ファイル: Token.cs プロジェクト: UkooLabs/FBXSharpie
 internal virtual void WriteAscii(FbxVersion version, LineStringBuilder lineStringBuilder, int indentLevel)
 {
     throw new NotImplementedException();
 }
コード例 #23
0
ファイル: Token.cs プロジェクト: UkooLabs/FBXSharpie
 internal virtual void WriteBinary(FbxVersion version, BinaryWriter binaryWriter)
 {
     throw new NotImplementedException();
 }
コード例 #24
0
ファイル: FbxBinary.cs プロジェクト: Hengle/FbxWriter
		/// <summary>
		/// Reads and checks the FBX footer extension (NB - not the unique footer code)
		/// </summary>
		/// <param name="stream"></param>
		/// <param name="version"></param>
		/// <returns><c>true</c> if it's compliant</returns>
		protected bool CheckFooter(BinaryReader stream, FbxVersion version)
		{
			var buffer = new byte[Math.Max(footerZeroes1, footerZeroes2)];
			stream.Read(buffer, 0, footerZeroes1);
			bool correct = AllZero(buffer);
			var readVersion = stream.ReadInt32();
			correct &= (readVersion == (int)version);
			stream.Read(buffer, 0, footerZeroes2);
			correct &= AllZero(buffer);
			stream.Read(buffer, 0, extension.Length);
			correct &= CheckEqual(buffer, extension);
			return correct;
		}
コード例 #25
0
 public static void WriteAscii(string path, Scene scene, FbxVersion version = FbxVersion.v7400)
 {
     using (FbxWriter writer = new FbxWriter(path, version))
         writer.WriteAscii(scene);
 }
コード例 #26
0
 public FbxConverterBase(Scene scene, FbxVersion version)
 {
     this._scene  = scene;
     this.Version = version;
 }