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); }
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; } }
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; } }
void WriteProperty(FbxVersion version, Token obj) { if (obj == null) { return; } obj.WriteBinary(version, stream); }
/// <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; }
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); }
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)); }
// 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"); }
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); } }
/// <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; }
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()); } }); }
/// <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); }
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); } }); }
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("}"); } }
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); }
/// <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); }
public FbxWriterOptions(FbxVersion version) { }
internal override void WriteBinary(FbxVersion version, BinaryWriter binaryWriter) { binaryWriter.Write((byte)'R'); binaryWriter.Write(Values.Length); binaryWriter.Write(Values); }
internal override void WriteAscii(FbxVersion version, LineStringBuilder lineStringBuilder, int indentLevel) { lineStringBuilder.Append($"{Value}:"); }
/// <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()); }
internal override void WriteBinary(FbxVersion version, BinaryWriter binaryWriter) { binaryWriter.Write((byte)('Y')); binaryWriter.Write(Value); }
internal virtual void WriteAscii(FbxVersion version, LineStringBuilder lineStringBuilder, int indentLevel) { throw new NotImplementedException(); }
internal virtual void WriteBinary(FbxVersion version, BinaryWriter binaryWriter) { throw new NotImplementedException(); }
/// <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; }
public static void WriteAscii(string path, Scene scene, FbxVersion version = FbxVersion.v7400) { using (FbxWriter writer = new FbxWriter(path, version)) writer.WriteAscii(scene); }
public FbxConverterBase(Scene scene, FbxVersion version) { this._scene = scene; this.Version = version; }