Closed windowslucker1121 closed 8 months ago
So far, there is no official way of writing an extension, as everything is still in the works, and to be clear, there's some stuff I am trying to figure out which is the right approach.
Having said that, the whole process of adding a custom extension is almost done, so to clarify some of the questions:
The CodeGen tool is just that, a tool that is used to generate the serialization code. It is an internal tool and it's not published anywhere, so it's fine to copy it and modify it to add your own extension. It's true that this approach is not ideal, the right approach would be to have a general tool that you can point to a schema and then it generates the code without modifications... but the glTF schema is ugly enough to require some manual tweaks that can only be done by code modifications.
if you've been able to do that, and you've been able to generate your own class library containing your extensions code, then, you can register your extensions into SharpGLTF like this:
Notice that you have to pass every extension type object, AND the parent object to which it is attached.
So if your extension called "NodeCustomDataExtension" is attached to nodes, then you registed it as <Node,NodeCustomDataExtension>
and finally you pass a lambda that's used to construct the object, receiving the parent object as the only parameter. This is required to prevent issues in AOT scenarios.
So if you want to use Agi extensions, you call AgiExtensions.RegisterExtensions at the beginning of your application. Afterwards, the library will recognize the extension.
So to double check my assumption: The CodeGen Tool only produces files to De-/Serialize my schema files - it is on me to write and maintain code (eg. creating classes which are mapping onto my schema) that i can "work" with them in combination with sharpGLTF in my IDE (eg. code completion)?
Because currently the CodeGen Tool generates only these "schema2/Generated/ext.xxxx.g.cs" files and i can see in other extension classes there are more .cs files in their respective schema2 root directory.
Thanks for your detailed and fast answer, awesome!
Well, strictly speaking, the CodeGen tool is only needed if you have your extension defined as json schema files (which is usually the case)
If you're not writing your own schema json files, and you're going to write your extension directly in C#, then you can forget avout the CodeGen tool, and write the de-/serialization code by hand
Thanks again for your fast answer!
I am indeed defining my schema in a json schema file - but to give an example:
You wrote that i can register my extension here:
and now looking in your code -
your are creating a new instance of new AgiRootArticulations(p) which referenced class is NOT(?) generated by the CodeGen Tool (because the class/file is not in the generated folder?)
Currently my generated files are looking like this:
Now to ease out the question, do i need to do either:
Edit: i just want my schema defined values (strings, integers, enums) to be exposed in the IDE that i can easily work with them.
Not exactly: notice the classes are decorated with PARTIAL modifier
A partial class can have its body distributed across multiple files.
So the generated files contain the serialization code
And the files written by you contain the constructor, properties and functions you may require for your public API
In other words:
// SomeExt.g.cs <- generated by CodeGen
partial class SomeExt
{
// fields and serialization code
}
// SomeExt.cs <- manually written by you
partial class SomeExt
{
// constructor, properties and methods
}
That was the answer i was looking for, thanks for your fast and handy response!
Hey folks, i cant seem to get my generated files working with SharpGLTF and i am taking the last straw now and searching help here... :-)
What i have done so far:
i tried registering it in the CodeExtensionFactory like in this file https://github.com/vpenades/SharpGLTF/blob/5a33d5452528d827ac55727f302d8a91a75c4186/src/SharpGLTF.Ext.Agi/Schema2/AgiExtensions.cs#L19 but then i need to call the function explicitly at startup in my other program(?) (so i cant use it in my IDE) - furthermore i dont want to mess with the base sharpGLTF repo to add it to the "base ExtensionsFactory".
and i tried using it directly, like
gltfRoot.UseExtension<vmde_machine>()
but the generated files are internal/private so i cant use them in another project.Do i need to write seperate classes to access the gernerated files and handle all the information, so whats the sense of the CodeGen project then? (no offense, just curious!) And what is the ExtensionFactory explicitly used for? Whats its purpose?
How do i proceed here? How i can "register" it to SharpGLTF to be able to use for example code completion for this schema and use it for gltf models that have this extension in their file as "extensionsUsed"?
Maybe a lightweight documentation on what files do and how to use them would be helpful for the following ones - because im already messing around with this a lot of time (just to find out how to use it :-P )
I would appreciate any guidance on how to go on in my specific case and thanks in advance! :-)