Skip to content

Commit

Permalink
properties
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Jan 23, 2024
1 parent 95cda35 commit 7d5b214
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 33 deletions.
11 changes: 0 additions & 11 deletions src/MeshIO.FBX.Tests/FbxReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ static FbxReaderTest()

public FbxReaderTest(ITestOutputHelper output) : base(output) { }

[Theory(Skip = "skipy skip")]
[MemberData(nameof(AsciiFiles))]
[MemberData(nameof(BinaryFiles))]
public void GetVersion(string path)
{
using (FbxReader reader = new FbxReader(path))
{
var version = reader.GetVersion();
}
}

[Theory]
[MemberData(nameof(AsciiFiles))]
public void ReadAsciiTest(string test)
Expand Down
19 changes: 11 additions & 8 deletions src/MeshIO.FBX/FbxPropertyOld.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CSMath;
using System;
using System.Xml.Linq;
using System.Collections.Generic;

namespace MeshIO.FBX
{
Expand Down Expand Up @@ -87,8 +87,12 @@ public Property ToProperty()
{
Property property = null;

object value = property.Value;
object[] arr = value as object[];
object value = this.Value;
List<object> arr = null;
if (value is IEnumerable<object> en)
{
arr = new List<object>(en);
}

switch ((string)this.FbxType)
{
Expand All @@ -104,12 +108,12 @@ public Property ToProperty()
g = (byte)(Convert.ToDouble(arr[1]) * 255);
b = (byte)(Convert.ToDouble(arr[2]) * 255);
byte a = (byte)(Convert.ToDouble(arr[3]) * 255);
property = new Property<Color>(this .Name, Flags, new Color(r, g, b, a));
property = new Property<Color>(this.Name, Flags, new Color(r, g, b, a));
break;
case "Visibility":
case "Bool":
case "bool":
property = new Property<bool>(this.Name, Flags, Convert.ToInt32(arr[4]) != 0);
property = new Property<bool>(this.Name, Flags, Convert.ToInt32(value) != 0);
break;
case "Vector":
case "Vector3":
Expand Down Expand Up @@ -146,10 +150,9 @@ public Property ToProperty()
break;
case "Reference":
case "Compound":
property = new Property(this.Name, Flags, null);
break;
case "object":
default:
System.Diagnostics.Debug.Fail($"{arr[1]}");
property = new Property(this.Name, Flags, value);
break;
}

Expand Down
9 changes: 0 additions & 9 deletions src/MeshIO.FBX/FbxReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ public FbxReader(Stream stream)
this._stream = stream;
}

/// <summary>
/// Get the fbx version of the file
/// </summary>
/// <returns></returns>
public FbxVersion GetVersion()
{
throw new NotImplementedException();
}

/// <summary>
/// Read the FBX file
/// </summary>
Expand Down
16 changes: 12 additions & 4 deletions src/MeshIO.FBX/Readers/FbxFileBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,22 @@ protected FbxProperty readFbxProperty(FbxNode node)
string type1 = node.GetProperty<string>(1);
string label = node.GetProperty<string>(2);
PropertyFlags flags = FbxProperty.ParseFlags(node.GetProperty<string>(3));
List<object> arr = new();
object value = null;

for (int i = 4; i < node.Properties.Count; i++)
if (node.Properties.Count == 5)
{
arr.Add(node.Properties[i]);
value = node.Properties[4];
}
else
{
value = new List<object>();
for (int i = 4; i < node.Properties.Count; i++)
{
(value as List<object>).Add(node.Properties[i]);
}
}

return new FbxProperty(name, type1, label, flags, arr);
return new FbxProperty(name, type1, label, flags, value);
}

protected void buildScene()
Expand Down
15 changes: 14 additions & 1 deletion src/MeshIO.FBX/Readers/Templates/FbxNodeTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using MeshIO.Entities;
using CSMath;
using CSUtilities.Extensions;
using MeshIO.Entities;
using MeshIO.FBX.Connections;
using MeshIO.Shaders;
using System.Collections.Generic;

namespace MeshIO.FBX.Readers.Templates
{
Expand All @@ -23,6 +26,16 @@ public override void Build(FbxFileBuilderBase builder)
this.processChildren(builder);
}

protected override void addProperties(Dictionary<string, FbxProperty> properties)
{
if(properties.Remove("Lcl Translation", out FbxProperty value))
{
this.Element.Transform.Translation = (XYZ)value.ToProperty().Value;
}

base.addProperties(properties);
}

protected void processChildren(FbxFileBuilderBase builder)
{
foreach (FbxConnection c in builder.GetChildren(this.TemplateId))
Expand Down
2 changes: 2 additions & 0 deletions src/MeshIO.FBX/Readers/Templates/FbxObjectTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public virtual void Build(FbxFileBuilderBase builder)

nodeProp.Add(t.Key, t.Value);
}

this.addProperties(nodeProp);
}

protected string removePrefix(string fullname)
Expand Down

0 comments on commit 7d5b214

Please sign in to comment.