KhronosGroup / glTF-CSharp-Loader

C# Reference Loader for glTF
Other
213 stars 60 forks source link

Support for Khronos Extensions #19

Open christinejohnson opened 6 years ago

christinejohnson commented 6 years ago

Is there a plan for including the Khronos Extensions schemas (e.g. KHR_materials_pbrSpecularGlossiness.schema.json) or should these be handled like custom extensions?

bghgary commented 6 years ago

It would be great to add them. I'm not aware of any plans to add this at the moment. You can however generate them using the generator executable that is built by this project. In fact, we did exactly this in the glTF asset generator project.

https://github.com/bghgary/glTF-Asset-Generator/blob/master/Source/Schema/MaterialPbrSpecularGlossiness.cs

arne1895 commented 5 years ago

I was trying to include the KHR_techniques_webgl schema and the KHR_materials_pbrSpecularGlossiness schema to my loader as well. Unfortunately I'm always getting the "Attempting to overwrite non-Default schema." Exception. Is it not possible to create a loader which is supporting extensions with the Generator as you described before or what am I doing wrong?

bghgary commented 3 years ago

The way we did it is a hack.

Copy the extension's schema to the core schema location (e.g. copy glTF\extensions\2.0\Khronos\KHR_materials_pbrSpecularGlossiness\schema\glTF.KHR_materials_pbrSpecularGlossiness.schema.json to glTF\specification\2.0\schema).

Then change Program.cs to point to the copied extension schema.

static void Main(string[] args)
{
    var generator = new CodeGenerator(@"..\..\..\..\..\glTF\specification\2.0\schema\glTF.KHR_materials_pbrSpecularGlossiness.schema.json");
    generator.ParseSchemas();
    generator.ExpandSchemaReferences();
    generator.EvaluateInheritance();
    generator.PostProcessSchema();
    generator.CSharpCodeGen(Path.GetFullPath(@"..\..\..\..\glTFLoader\Schema\KHR_materials_pbrSpecularGlossiness"));
}

Ideally, we should change Program.cs to take some parameters and modify CodeGenerator and relevant code to accept a schema from a separate location from the core schema directory. Then we'll be able to run the generator on extension.

Contributions for this is very welcomed.