-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Allow GltfLoader
to load user defined materials.
#13564
base: main
Are you sure you want to change the base?
Conversation
The generated |
@MalekiRe you wanted this as well, correct? |
I'm not sure this solves my issue. As described, the PR swaps out every material in a GLTF, and they must all be the same type. That doesn't describe my use case at all:
Here's an example: Say I have a fireplace created in Blender. The fireplace has a special "flames" material that uses an animated texture. In Blender, I create a custom property "flames: true" an add it to the material. However, the rest of the fireplace - the bricks and so on - use normal materials. When I load the model (in my previous non-Bevy engine), I examine the GLTF extras field and decide what type of material to substitute based on the custom properties. For most meshes I leave the material as-is - the standard material is good enough. However, for the flames material, I replace the standard material with the special animated shader material. There are more complex scenarios. In my blender files, I also have a custom property called "outline", which creates a cartoon outline around the object. This requires two materials (because the outline is a separate pass). There are two ways to accomplish this:
As you can see, simply globally replacing the standard material with a different type isn't useful to me at all. |
I've made the PR use dynamic typing and untyped handles (still stuck on a few thing so not ready yet.) |
Yes It's useful for mobile when I wanna change the material so it has less performance impact |
The new version should fit your use case better. |
GltfLoader
to swap out StandardMaterial
.GltfLoader
load user defined materials.
GltfLoader
load user defined materials.GltfLoader
to load user defined materials.
Objective
Allow
GltfLoader
to load materials other thanStandardMaterial
. This allows theGltfLoader
to load user defined materials, for example a toon shader.Solution
AllowGltfPlugin
,GltfLoader
to specify a generic parameterMaterial
, by defaultStandardMaterial
.Added
FromStandardMaterial
that constructs a new material from aStandardMaterial
andgltf_extras
.Notable types that implement this are
StandardMaterial
andExtendedMaterial<StandardMaterial, impl FromStandardMaterial>
, which can serve to extend theStandardMaterial
's functionalities.Added
with_default_material
onGltfLoaderSettings
to change the default material used byGltfLoader
. Addedwith_standard_material
onGltfPlugin
to do it globally.Allow user to register named
FromStandardMaterial
materials ontoGltfPlugin
. We will seach for"material": "name"
ingltf_extras
, if the corresponding name is found, the corresponding material will be used instead of the default one.Notable Footguns Introduced
Assets are always cached by path. Meaning loading a different standard material with a previous handle alive will instead obtain the previously loaded handle. This is hard to avoid given the current implementation of
bevy_assets
.Testing
Added an example showcasing these features.
Changelog
Added
FromStandardMaterial
trait that constructs a new material from aStandardMaterial
andgltf_extras
json string.Added a setting to
GltfPlugin
for swapping outStandardMaterial
globally.Added the ability to register material deserializers onto
GltfPlugin
.Added a setting to
GltfLoaderSettings
to use a different default material.GltfLoader
now readsgltf_extras
attributematerial
to determine which material to use.Gltf
now contains untyped handles. Added method for retrieving typed handles.NEED REVIEW
MetaTransform
now copies to parentHandle
s (i.e
Handle<Gltf>
) from loading child assets.Migration Guide
Gltf
now contains untyped handles. Added method for retrieving typed handles fromGltf
.