-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
Material.fromMaterial #22179
Comments
I'm doing this in another project. Doesn't catch all the overlap between MeshStandardMaterial and others, but does a lot, and works similarly for switching between point and line materials as well. Material.prototype.copy.call(outputMaterial, inputMaterial);
outputMaterial.color.copy(inputMaterial.color);
outputMaterial.map = inputMaterial.map; An alternative to a new method might be to improve |
❤️ Since there's no significant backlash, I'll try to compose a PR next week for it (also taking into account the linked issues @gkjohnson 🙌 ) |
Related: #25004 |
Kind of an aside, but maybe related — I wish that we had a a.fromJSON(b.toJSON()); ... because I'd tend to assume most/all material properties are optional in JSON (can't we skip |
There is prior art on getting somewhat visually equivalent values for spec/gloss from a metal/roughness material, by the way (and vice versa). I did some research on this for the FBXLoader. I didn't apply it in the end so I'm not sure what the best choice of formula is, but if you research this you should find plenty of info. We should also ensure that of the available formulas for doing this we only use one throughout the repo. Is the conversion already done in any of the loaders? |
Is your feature request related to a problem? Please describe.
Having mobile / XR development in mind (ie. cases when hardware tends to not be the most powerful), it is sometimes useful to convert
MeshStandardMaterial
to something comparable, but a bit lighter (ex.MeshLambertMaterial
)Doing it this way:
may likely lead to 100k logs per second, since some properties of complex materials are not there in phong/lambert.
Describe the solution you'd like
On the
Material
prototype, we may consider adding aMaterial.fromMaterial(m)
helper (similar to Array.from) - that converts one material to another, taking into consideration props / optimisation / unnecessary texture disposal (ex. roughness maps when going from PBR materials.)Having it on the prototype as a static method would allow to easily create material alternatives:
Describe alternatives you've considered
Usually you'd just do it by hand (example) and hope the materials in three don't change over time and you didn't forget to dispose / remove something that should have been disposed / removed. Since materials and their props are strictly bound to three, it may be nice to have an util built-in three to convert between material types.
The text was updated successfully, but these errors were encountered: