Comments (6)
Thanks for bringing this to my attention. Following the "Extensibility" section in the Readme.md, I was able to get an implementation of my extension easily enough. The extension support is looking really good now.
One thing that I didn't see in the documentation was that in order to read data, a user needs an implementation of a GLTF.Schema.ExtensionFactory and that impl needs to be registered in GLTF.Schema.GLTFProperty._extensionRegistry. I just put that registration in my GLTFImportPlugin.CreateInstance() - not sure if there's a better place to do that?
Another piece which was maybe a little strange was the user's ExtensionFactory.Deserialize() method is called for both the root glTF document, as well as the nodes which have the extension, so inside Deserialize(), I needed a heuristic to determine what to parse. Is there a more robust way to determine the what is being deserialized at that point?
Otherwise, it all looks great and I've been able to get the results I wanted. I reckon it's worthwhile adding a sample which shows the full process of extending the loader with some sort of trivial extension. Happy to help out here.
from unitygltf.
There is a new plugin system in the current version. Please take a look :) (Documentation stills lags a bit behind, but more samples are planned)
When you still missing some explicit usecases what do you want to archive, please post it here
from unitygltf.
@eoineoineoin by "to read data" you mean on import to read e.g. extensions on nodes in the GLTF json?
If yes then I don't think you need to register anything to this ExtensionFactory. Here's a snippet from the Needle Engine import plugin to read component data in case it helps:
public override void OnAfterImportNode(Node node, int nodeIndex, GameObject nodeObject)
{
needleImportContext.Register("/nodes/" + nodeIndex, nodeObject);
if (node.Extensions != null)
{
foreach (var kvp in node.Extensions)
{
if (kvp.Value is DefaultExtension defaultExtension)
{
var data = defaultExtension.ExtensionData;
switch (kvp.Key)
{
case UnityGltf_NEEDLE_components_Extension.EXTENSION_NAME:
var ext = data.Children().First() as JObject;
NeedleComponentsImporter.OnImport(needleImportContext, nodeObject, nodeIndex, ext);
break;
}
}
}
}
}
from unitygltf.
Interesting; I am reading extensions on nodes in the JSON. I didn't realise that there was a DefaultExtension
which enabled access to the data like that. The reason I ended up with that opinion was from my reading of the Readme.md:
If your plugin reads/writes custom extension data, you need to also implement GLTF.Schema.IExtension for serialization and deserialization.
So I followed the breadcrumbs from there and made my own IExtension; then, the class responsible for instantiating my IExtension was the ExtensionFactory, and in order to get that to run, I needed to register it with the extension registry.
from unitygltf.
Can i close this issue? :)
from unitygltf.
I think a follow-up task here is to update the Readme and provide more complete examples for "how to make your own import and export extensions". If you make a follow-up issue for that and reference this issue here, this issue here can be closed.
from unitygltf.
Related Issues (20)
- Unity android after building the texture is black/dark HOT 1
- Generate Lightmap UVs affects removes geometry
- Import: Scale factor doesn't effect bounding boxes correctly HOT 1
- Missing Reference after building dlls HOT 1
- Import error, "Cannot perform upm operation: Unable to add package", Unity 2021.3 HOT 3
- Android package can't load streaming model, however project can running on the computer. How to setting or changing, about this problem? HOT 2
- Question - GLTF Recorder & animation clips HOT 2
- AfterNodeExport but no BeforeNodeExport? HOT 5
- UnityGLTF as project package HOT 7
- Build fails only for GLTFSerializationUWPTests HOT 4
- README supported extensions out of date? HOT 1
- HumanoidSetup needs to check "isHuman" HOT 1
- UnityMeshData.MorphTargetNormals[i] may need to check null on Import HOT 6
- [One line of code fix] Unnecessary color space correction is applied when swapping from Unity's metallic-smoothness textures HOT 6
- Incorrect import result for quantized model by gltfpack HOT 5
- 'Texture2D' does not contain a definition for 'isDataSRGB' HOT 10
- Encounter object export errors when using package HOT 5
- Timeline for implementing KHR_interactivity? HOT 1
- Creating animation on runtime, from scratch HOT 10
- ShaderGraph dependency problem for OpenUPM install HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unitygltf.