Code Monkey home page Code Monkey logo

Comments (6)

eoineoineoin avatar eoineoineoin commented on June 3, 2024 1

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.

pfcDorn avatar pfcDorn commented on June 3, 2024

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.

marwie avatar marwie commented on June 3, 2024

@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.

eoineoineoin avatar eoineoineoin commented on June 3, 2024

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.

pfcDorn avatar pfcDorn commented on June 3, 2024

Can i close this issue? :)

from unitygltf.

hybridherbst avatar hybridherbst commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.