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

How to change glb model material color at runtime? #292

Open
sabuhiteymurov opened this issue Jan 21, 2025 · 4 comments
Open

How to change glb model material color at runtime? #292

sabuhiteymurov opened this issue Jan 21, 2025 · 4 comments

Comments

@sabuhiteymurov
Copy link

sabuhiteymurov commented Jan 21, 2025

Hi, I'm trying to change the color of a glb model's material at runtime using react-native-filament, but I'm having trouble figuring out how to do it. There is setDefaultFloat4Parameter method of Material interface in the docs. I just can’t figure out how to access Material.

@hannojg
Copy link
Member

hannojg commented Jan 22, 2025

I think you could look at this (to get a general idea)

and also peak into the implementation of EntitySelector:

The main idea is to select the correct entity, get the material and change its attributes (I think you also need to reapply the material then, let me double check on that …)

@hannojg
Copy link
Member

hannojg commented Jan 22, 2025

See this for reference, you can also get the entity from an asset:

const { renderableManager } = useFilamentContext()

const entity = asset.getFirstEntityByName("yourEntitysNameSeeDocLinkIShared")
// There is probably just one material, otherwise check which index to select
renderableManager.getMaterialInstanceAt(entity, 0).setFloat4Parameter('baseColorFactor', [1, 1, 1, 1]) // in sRGB

@hannojg
Copy link
Member

hannojg commented Jan 22, 2025

Ideally we would like to expose a declarative react API for this, probably in EntitySelector. Would def appreciate a PR for this (should be javacsript/typescript changes only!)

@sabuhiteymurov
Copy link
Author

Ideally we would like to expose a declarative react API for this, probably in EntitySelector. Would def appreciate a PR for this (should be javacsript/typescript changes only!)

Thank you, appreciated. I'll try to create a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants