Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Only material file #205

Closed
AN3Orik opened this issue Nov 27, 2023 · 2 comments
Closed

[Feature Request] Only material file #205

AN3Orik opened this issue Nov 27, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@AN3Orik
Copy link

AN3Orik commented Nov 27, 2023

Hello.
Is it possible to create "material-only" GLTF file like a mentioned in this Issue KhronosGroup/glTF#1420 via SharpGLTF API?

{
	"asset": {
		"version": "2.0",
	},
	"material": 0,
	"images": [
		{
			"uri": "base.jpg"
		}
	],
	"samplers": [
		{
			"magFilter": 9729,
			"minFilter": 9985,
			"wrapS": 10497,
			"wrapT": 10497
		}
	],
	"textures": [
		{
			"sampler": 0,
			"source": 0
		}
	],
	"materials": [
		{
			"pbrMetallicRoughness": {
				"baseColorTexture" : {
					"index" : 0,
					"texCoord" : 0
				},
				"baseColorFactor": [1, 1, 1, 1],
				"metallicFactor": 1,
				"roughnessFactor": 1
			},
			"doubleSided": false,
			"name": "MyMaterial"
		}
	]
}
@AN3Orik AN3Orik added the bug Something isn't working label Nov 27, 2023
@vpenades
Copy link
Owner

vpenades commented Nov 27, 2023

Theoretically it should be possible.

From a strict point of view, I think glTF specification discourages it because they consider glTF as the "jpg of 3D", so you could say that in a materials library only glTF. "there's nothing to view". But I don't think importers and exporters would complains much. At best you would simply have warnings when exporting/importing an empty scene.

Regarding KhronosGroup/glTF#1420 , glTF spec does not support referencing external components, but it's something I would not dislike to have, not only for materials, but also for meshes and animations too.

But, right now, there's only two ways of doing it:

  • As they suggested, with extensions (which also means you would have to fork and tweak importers and exporters to suit your needs, not for the faint of heart)
  • hack you engine, so when loading a glTF, replace the materials by name from another glTF.

From the point of view of SharpGLTF, it would be not too difficult to import a scene, convert the materials to MaterialBuilders, and export them individually, but it could be even easier if you simply load the Json DOM and simply remove every node except Textures, Images, Materials and so on.

@AN3Orik
Copy link
Author

AN3Orik commented Nov 27, 2023

Thanks for answer!
I'm using currently SharpGLTF for creating from scratch some old materials from old game (UE2) to PBR-materials for importing to UE5, so variant with loading existing scene is not for me, unfortunately. Now I’m just deleting extra-nodes with JSON parser.

My proposal it's s let users adding MaterialBuilder to scene without creating meshes: something like a scene.AddMaterial(MaterialBuilder)

Btw gltf-validator successfully validating GLTF even with only one material node. And even more: Unreal engine 4/5 also importing this material to assets without problem.
Ty for your time and have a good day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants