Skip to content

Commit 931e6f6

Browse files
authored
Merge pull request #2 from vpenades/master
Update to latest
2 parents 3a8bc54 + 7c4de4f commit 931e6f6

File tree

208 files changed

+10299
-4867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+10299
-4867
lines changed

SharpGLTF.sln

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.329
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29709.97
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{29566B60-311D-42A0-9E8D-C48DECDD587F}"
77
ProjectSection(SolutionItems) = preProject
8+
.editorconfig = .editorconfig
89
Analyzers.targets = Analyzers.targets
910
README.md = README.md
1011
SharpGLTF.ruleset = SharpGLTF.ruleset
@@ -18,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.CodeGen", "build\
1819
EndProject
1920
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Core", "src\SharpGLTF.Core\SharpGLTF.Core.csproj", "{B1DA4F42-AB6A-4021-9989-674B1394E8A2}"
2021
EndProject
21-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Tests", "tests\SharpGLTF.Tests\SharpGLTF.Tests.csproj", "{4FCBB910-67D4-4628-9B2B-F5F2C8D92257}"
22-
EndProject
2322
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{D7D51F42-D08C-4DDA-88DA-AF008F10B644}"
2423
EndProject
2524
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Toolkit", "src\SharpGLTF.Toolkit\SharpGLTF.Toolkit.csproj", "{41690879-1F91-4555-A40A-F67B01868D7E}"
@@ -36,7 +35,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Runtime.MonoGame"
3635
EndProject
3736
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoGameScene", "examples\MonoGameScene\MonoGameScene.csproj", "{894781CA-F508-43AE-8526-6AA6B6EDF613}"
3837
EndProject
39-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpGLTF.DownloadTestFiles", "tests\SharpGLTF.DownloadTestFiles\SharpGLTF.DownloadTestFiles.csproj", "{7CC20DF6-14B5-4C1C-B4FC-151E97AED4F4}"
38+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.DownloadTestFiles", "tests\SharpGLTF.DownloadTestFiles\SharpGLTF.DownloadTestFiles.csproj", "{7CC20DF6-14B5-4C1C-B4FC-151E97AED4F4}"
39+
EndProject
40+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.NUnit", "tests\SharpGLTF.NUnit\SharpGLTF.NUnit.csproj", "{7A5EAF7E-D6A6-4861-9488-F98E4AA00A3A}"
41+
EndProject
42+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Core.Tests", "tests\SharpGLTF.Tests\SharpGLTF.Core.Tests.csproj", "{56FE769E-6B09-462B-9947-A9B64161CD80}"
43+
EndProject
44+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Toolkit.Tests", "tests\SharpGLTF.Toolkit.Tests\SharpGLTF.Toolkit.Tests.csproj", "{7FEFC259-51D6-4409-8724-8DE0EA8D5CD9}"
45+
EndProject
46+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpGLTF.Plotly", "examples\SharpGLTF.Plotly\SharpGLTF.Plotly.csproj", "{A63C2A2D-950F-4C76-9299-2B2D325A8653}"
4047
EndProject
4148
Global
4249
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -52,10 +59,6 @@ Global
5259
{B1DA4F42-AB6A-4021-9989-674B1394E8A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
5360
{B1DA4F42-AB6A-4021-9989-674B1394E8A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
5461
{B1DA4F42-AB6A-4021-9989-674B1394E8A2}.Release|Any CPU.Build.0 = Release|Any CPU
55-
{4FCBB910-67D4-4628-9B2B-F5F2C8D92257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56-
{4FCBB910-67D4-4628-9B2B-F5F2C8D92257}.Debug|Any CPU.Build.0 = Debug|Any CPU
57-
{4FCBB910-67D4-4628-9B2B-F5F2C8D92257}.Release|Any CPU.ActiveCfg = Release|Any CPU
58-
{4FCBB910-67D4-4628-9B2B-F5F2C8D92257}.Release|Any CPU.Build.0 = Release|Any CPU
5962
{41690879-1F91-4555-A40A-F67B01868D7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6063
{41690879-1F91-4555-A40A-F67B01868D7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
6164
{41690879-1F91-4555-A40A-F67B01868D7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -84,21 +87,40 @@ Global
8487
{7CC20DF6-14B5-4C1C-B4FC-151E97AED4F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
8588
{7CC20DF6-14B5-4C1C-B4FC-151E97AED4F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
8689
{7CC20DF6-14B5-4C1C-B4FC-151E97AED4F4}.Release|Any CPU.Build.0 = Release|Any CPU
90+
{7A5EAF7E-D6A6-4861-9488-F98E4AA00A3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
91+
{7A5EAF7E-D6A6-4861-9488-F98E4AA00A3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
92+
{7A5EAF7E-D6A6-4861-9488-F98E4AA00A3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
93+
{7A5EAF7E-D6A6-4861-9488-F98E4AA00A3A}.Release|Any CPU.Build.0 = Release|Any CPU
94+
{56FE769E-6B09-462B-9947-A9B64161CD80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
95+
{56FE769E-6B09-462B-9947-A9B64161CD80}.Debug|Any CPU.Build.0 = Debug|Any CPU
96+
{56FE769E-6B09-462B-9947-A9B64161CD80}.Release|Any CPU.ActiveCfg = Release|Any CPU
97+
{56FE769E-6B09-462B-9947-A9B64161CD80}.Release|Any CPU.Build.0 = Release|Any CPU
98+
{7FEFC259-51D6-4409-8724-8DE0EA8D5CD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
99+
{7FEFC259-51D6-4409-8724-8DE0EA8D5CD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
100+
{7FEFC259-51D6-4409-8724-8DE0EA8D5CD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
101+
{7FEFC259-51D6-4409-8724-8DE0EA8D5CD9}.Release|Any CPU.Build.0 = Release|Any CPU
102+
{A63C2A2D-950F-4C76-9299-2B2D325A8653}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
103+
{A63C2A2D-950F-4C76-9299-2B2D325A8653}.Debug|Any CPU.Build.0 = Debug|Any CPU
104+
{A63C2A2D-950F-4C76-9299-2B2D325A8653}.Release|Any CPU.ActiveCfg = Release|Any CPU
105+
{A63C2A2D-950F-4C76-9299-2B2D325A8653}.Release|Any CPU.Build.0 = Release|Any CPU
87106
EndGlobalSection
88107
GlobalSection(SolutionProperties) = preSolution
89108
HideSolutionNode = FALSE
90109
EndGlobalSection
91110
GlobalSection(NestedProjects) = preSolution
92111
{E15F8DCC-987D-4FA8-B7B0-1F0614DC93DD} = {D7D51F42-D08C-4DDA-88DA-AF008F10B644}
93112
{B1DA4F42-AB6A-4021-9989-674B1394E8A2} = {072B725F-773F-4751-9616-E9778897C1D2}
94-
{4FCBB910-67D4-4628-9B2B-F5F2C8D92257} = {0CBF510D-D836-40BA-95EC-E93FDBB90632}
95113
{41690879-1F91-4555-A40A-F67B01868D7E} = {072B725F-773F-4751-9616-E9778897C1D2}
96114
{68662AA0-8523-4B9E-9230-DE79F2B07EAB} = {83E7E49D-8A28-45E8-9DBD-1F3AEDEF3E42}
97115
{53B7933A-DD1B-4E75-90EC-94E46101C6CC} = {83E7E49D-8A28-45E8-9DBD-1F3AEDEF3E42}
98116
{F64C6CC1-BD12-47B8-B6EA-D5609AC738DF} = {83E7E49D-8A28-45E8-9DBD-1F3AEDEF3E42}
99117
{6C7B3CD8-21D0-447E-9034-8F72057F2ED7} = {83E7E49D-8A28-45E8-9DBD-1F3AEDEF3E42}
100118
{894781CA-F508-43AE-8526-6AA6B6EDF613} = {83E7E49D-8A28-45E8-9DBD-1F3AEDEF3E42}
101119
{7CC20DF6-14B5-4C1C-B4FC-151E97AED4F4} = {0CBF510D-D836-40BA-95EC-E93FDBB90632}
120+
{7A5EAF7E-D6A6-4861-9488-F98E4AA00A3A} = {0CBF510D-D836-40BA-95EC-E93FDBB90632}
121+
{56FE769E-6B09-462B-9947-A9B64161CD80} = {0CBF510D-D836-40BA-95EC-E93FDBB90632}
122+
{7FEFC259-51D6-4409-8724-8DE0EA8D5CD9} = {0CBF510D-D836-40BA-95EC-E93FDBB90632}
123+
{A63C2A2D-950F-4C76-9299-2B2D325A8653} = {83E7E49D-8A28-45E8-9DBD-1F3AEDEF3E42}
102124
EndGlobalSection
103125
GlobalSection(ExtensibilityGlobals) = postSolution
104126
SolutionGuid = {1D7BBAD9-834C-4981-AC96-0AA5226FC43F}

build/SharpGLTF.CodeGen/CodeGen/EmitCSharp.cs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
// #define USENEWTONSOFT
2+
3+
using System;
24
using System.Collections.Generic;
35
using System.Linq;
46
using System.Reflection;
@@ -306,6 +308,9 @@ public string EmitContext(SchemaType.Context context)
306308
{
307309
var sb = new StringBuilder();
308310

311+
sb.AppendLine("// <auto-generated/>");
312+
sb.AppendLine();
313+
309314
sb.AppendLine("//------------------------------------------------------------------------------------------------");
310315
sb.AppendLine("// This file has been programatically generated; DON´T EDIT!");
311316
sb.AppendLine("//------------------------------------------------------------------------------------------------");
@@ -331,7 +336,12 @@ public string EmitContext(SchemaType.Context context)
331336
sb.AppendLine("using System.Linq;");
332337
sb.AppendLine("using System.Text;");
333338
sb.AppendLine("using System.Numerics;");
339+
340+
#if USENEWTONSOFT
334341
sb.AppendLine("using Newtonsoft.Json;");
342+
#else
343+
sb.AppendLine("using System.Text.Json;");
344+
#endif
335345
sb.AppendLine();
336346

337347
sb.AppendLine($"namespace {Constants.OutputNamespace}");
@@ -471,7 +481,7 @@ internal IEnumerable<string> _GetClassField(FieldInfo f)
471481
yield return string.Empty;
472482
}
473483

474-
#endregion
484+
#endregion
475485
}
476486

477487
/// <summary>
@@ -503,6 +513,8 @@ public CSharpClassEmitter(CSharpEmitter emitter)
503513

504514
public bool HasBaseClass { get; set; }
505515

516+
private const string _READERMODIFIER = "ref ";
517+
506518
#endregion
507519

508520
#region API
@@ -526,7 +538,7 @@ public void AddFields(ClassType type)
526538
this.AddFieldSerializerCase(smethod);
527539

528540
// emit deserializer
529-
this.AddFieldDeserializerCase(f.PersistentName, $"{frname} = DeserializePropertyValue<{_Emitter._GetRuntimeName(etype)}>(reader);");
541+
this.AddFieldDeserializerCase(f.PersistentName, $"{frname} = DeserializePropertyValue<{_Emitter._GetRuntimeName(etype)}>({_READERMODIFIER}reader);");
530542

531543
continue;
532544
}
@@ -565,15 +577,15 @@ private string _GetJSonDeserializerMethod(FieldInfo f)
565577
if (f.FieldType is ArrayType atype)
566578
{
567579
var titem = _Emitter._GetRuntimeName(atype.ItemType);
568-
return $"DeserializePropertyList<{titem}>(reader, {fname});";
580+
return $"DeserializePropertyList<{titem}>({_READERMODIFIER}reader, {fname});";
569581
}
570582
else if (f.FieldType is DictionaryType dtype)
571583
{
572584
var titem = _Emitter._GetRuntimeName(dtype.ValueType);
573-
return $"DeserializePropertyDictionary<{titem}>(reader, {fname});";
585+
return $"DeserializePropertyDictionary<{titem}>({_READERMODIFIER}reader, {fname});";
574586
}
575587

576-
return $"{fname} = DeserializePropertyValue<{_Emitter._GetRuntimeName(f.FieldType)}>(reader);";
588+
return $"{fname} = DeserializePropertyValue<{_Emitter._GetRuntimeName(f.FieldType)}>({_READERMODIFIER}reader);";
577589
}
578590

579591
public void AddFieldSerializerCase(string line) { _SerializerBody.Add(line); }
@@ -585,6 +597,15 @@ public void AddFieldDeserializerCase(string persistentName, string line)
585597

586598
public IEnumerable<string> EmitCode()
587599
{
600+
#if USENEWTONSOFT
601+
var readerType = "JsonReader";
602+
var writerType = "JsonWriter";
603+
#else
604+
var readerType = "ref Utf8JsonReader";
605+
var writerType = "Utf8JsonWriter";
606+
#endif
607+
608+
588609
foreach (var l in ClassSummary.EmitSummary(0)) yield return l;
589610

590611
yield return ClassDeclaration;
@@ -597,7 +618,7 @@ public IEnumerable<string> EmitCode()
597618
yield return string.Empty;
598619

599620
// yield return "/// <inheritdoc />".Indent(1);
600-
yield return "protected override void SerializeProperties(JsonWriter writer)".Indent(1);
621+
yield return $"protected override void SerializeProperties({writerType} writer)".Indent(1);
601622
yield return "{".Indent(1);
602623
if (HasBaseClass) yield return "base.SerializeProperties(writer);".Indent(2);
603624
foreach (var l in _SerializerBody.Indent(2)) yield return l;
@@ -606,13 +627,13 @@ public IEnumerable<string> EmitCode()
606627
yield return string.Empty;
607628

608629
// yield return "/// <inheritdoc />".Indent(1);
609-
yield return "protected override void DeserializeProperty(string jsonPropertyName, JsonReader reader)".Indent(1);
630+
yield return $"protected override void DeserializeProperty(string jsonPropertyName, {readerType} reader)".Indent(1);
610631
yield return "{".Indent(1);
611632
yield return "switch (jsonPropertyName)".Indent(2);
612633
yield return "{".Indent(2);
613634

614635
foreach (var l in _DeserializerSwitchBody.Indent(3)) yield return l;
615-
if (HasBaseClass) yield return "default: base.DeserializeProperty(jsonPropertyName, reader); break;".Indent(3);
636+
if (HasBaseClass) yield return $"default: base.DeserializeProperty(jsonPropertyName,{_READERMODIFIER}reader); break;".Indent(3);
616637
else yield return "default: throw new NotImplementedException();".Indent(3);
617638

618639
yield return "}".Indent(2);
@@ -623,6 +644,6 @@ public IEnumerable<string> EmitCode()
623644
yield return "}";
624645
}
625646

626-
#endregion
647+
#endregion
627648
}
628649
}

build/SharpGLTF.CodeGen/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ static class Constants
2929

3030
public static string KhronosDracoSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_draco_mesh_compression", "schema");
3131
public static string KhronosPbrSpecGlossSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_materials_pbrSpecularGlossiness", "schema", "glTF.KHR_materials_pbrSpecularGlossiness.schema.json");
32+
33+
public static string KhronosPbrClearCoatSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_materials_clearcoat", "schema", "glTF.KHR_materials_clearcoat.schema.json");
3234
public static string KhronosUnlitSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_materials_unlit", "schema", "glTF.KHR_materials_unlit.schema.json");
3335
public static string KhronosModelLightsPunctualSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_lights_punctual", "schema", "glTF.KHR_lights_punctual.schema.json");
3436
public static string KhronosNodeLightsPunctualSchemaFile => System.IO.Path.Combine(KhronosSchemaDir, "KHR_lights_punctual", "schema", "node.KHR_lights_punctual.schema.json");

build/SharpGLTF.CodeGen/Program.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ static void Main(string[] args)
2424

2525
_ProcessMainSchema();
2626

27-
_ProcessKhronosPBRExtension();
27+
_ProcessKhronosSpecularGlossinessExtension();
2828
_ProcessKhronosUnlitExtension();
29+
_ProcessKhronosClearCoatExtension();
2930
_ProcessKhronosModelLightsPunctualExtension();
3031
_ProcessKhronosNodeLightsPunctualExtension();
3132
_ProcessKhronosTextureTransformExtension();
@@ -91,7 +92,7 @@ private static void _ProcessMainSchema()
9192

9293
#region Extensions code generation
9394

94-
private static void _ProcessKhronosPBRExtension()
95+
private static void _ProcessKhronosSpecularGlossinessExtension()
9596
{
9697
var ctx = LoadSchemaContext(Constants.KhronosPbrSpecGlossSchemaFile);
9798
ctx.IgnoredByCodeEmitter("glTF Property");
@@ -122,6 +123,30 @@ private static void _ProcessKhronosUnlitExtension()
122123
ProcessSchema("ext.Unlit.g", ctx);
123124
}
124125

126+
private static void _ProcessKhronosClearCoatExtension()
127+
{
128+
var ctx = LoadSchemaContext(Constants.KhronosPbrClearCoatSchemaFile);
129+
ctx.IgnoredByCodeEmitter("glTF Property");
130+
ctx.IgnoredByCodeEmitter("glTF Child of Root Property");
131+
ctx.IgnoredByCodeEmitter("Texture Info");
132+
ctx.IgnoredByCodeEmitter("Material Normal Texture Info");
133+
134+
/*
135+
ctx.FindClass("KHR_materials_pbrSpecularGlossiness glTF extension")
136+
.GetField("diffuseFactor")
137+
.SetDataType(typeof(System.Numerics.Vector4), true)
138+
.SetDefaultValue("Vector4.One")
139+
.SetItemsRange(0);
140+
141+
ctx.FindClass("KHR_materials_pbrSpecularGlossiness glTF extension")
142+
.GetField("specularFactor")
143+
.SetDataType(typeof(System.Numerics.Vector3), true)
144+
.SetDefaultValue("Vector3.One")
145+
.SetItemsRange(0);*/
146+
147+
ProcessSchema("ext.ClearCoat.g", ctx);
148+
}
149+
125150
private static void _ProcessKhronosModelLightsPunctualExtension()
126151
{
127152
var ctx = LoadSchemaContext(Constants.KhronosModelLightsPunctualSchemaFile);
@@ -231,8 +256,9 @@ private static void ProcessSchema(string dstFile, SchemaType.Context ctx)
231256

232257
newEmitter.SetRuntimeName("KHR_materials_pbrSpecularGlossiness glTF extension", "MaterialPBRSpecularGlossiness");
233258
newEmitter.SetRuntimeName("KHR_materials_unlit glTF extension", "MaterialUnlit");
259+
newEmitter.SetRuntimeName("KHR_materials_clearcoat glTF extension", "MaterialClearCoat");
260+
234261

235-
236262

237263
newEmitter.SetRuntimeName("light", "PunctualLight");
238264
newEmitter.SetRuntimeName("light/spot", "PunctualLightSpot");

build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="LibGit2Sharp" Version="0.26.1" />
11-
<PackageReference Include="NJsonSchema.CodeGeneration" Version="10.0.27" />
12-
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.0.27" />
10+
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
11+
<PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.1.23" />
1312
</ItemGroup>
1413

1514
</Project>

examples/Example1/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void Main(string[] args)
4545

4646
// save the model in different formats
4747

48-
var model = scene.ToSchema2();
48+
var model = scene.ToGltf2();
4949
model.SaveAsWavefront("mesh.obj");
5050
model.SaveGLB("mesh.glb");
5151
model.SaveGLTF("mesh.gltf");

examples/MonoGameScene/MonoGameScene.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.7.1.189" />
11+
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1375-develop" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)