-
Notifications
You must be signed in to change notification settings - Fork 16
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
It should be possible to reuse mesh with different materials #89
Comments
Something that might tie into this: I've been thinking about bringing in the concept of As to how the loader can help resolve this issue... If I envision |
I wrote a loader model to do something like this in my app. It manages a globally accessible directory of mesh data (and various relevant meta data), loading everything from IndexedDB on launch and fetching data via XHR as required (and caching it in indexedDB after download). Of course my implementation is very specific to the peculiar structure of mesh data in my app. It'd be great if something similar were baked into Jax.Mesh. However I imagine the design challenge would be making it both usable without fuss in the simplest cases such as where users have a set of obj files they want to load n instances of into the scene, but still workable without too much hacking for cases such as mine in which the actual meshes loaded into the scene are the result of combining a number of meshes managed by the loader according to meta data also managed by the loader. |
Thanks for the input. Hypothetically, I imagine in your use case you'd want to create a secondary loader, either inheriting from or just making use of the basic OBJ loader. Once all required meshes have been loaded, the custom loader would handle the merging. It may or may not be interested in clearing the caches for the individual meshes once finished (read: the loader needs a public API for doing so), and then it'd just emit the merged data. This concept seems straightforward to me, unless I've missed something important that might throw a wrench into the works. It also raises some important points for consideration, such as: we need to be careful not to abuse the fact that the loading is done in a Worker. An example would be the calculation of normals, tangents and bitangents -- each of which is an expensive operation. Today, these are performed lazily -- only when accessed. Although the loader would offload the calculations to a worker, it should also continue doing so lazily. Your use case shows us that eagerly calculating such data would be a waste of cycles, because the merged mesh is just going to invalidate all of it anyway. Also, falling into the "let's just eager load data we might never actually use" trap would be bad news for mobile, where memory is much more finite. (The second 2 paragraphs were as much to remind myself, as for anyone else... because I was seriously considering eager calculating that data, earlier.) |
Here's an example of adding 2 models to the world using the current API, both sharing the same mesh data:
In the above example, it is not currently possible within the Jax API to render each of the two models with different materials.
Basically, if you want to render the same mesh twice -- for example, with each mesh using a different diffuse color -- you have to instantiate the mesh itself twice.
I think it's acceptable (even expected) to instantiate multiple models and multiple materials when representing different variations on the same mesh, but the models should be able to share the same mesh data especially when that data is identical between them.
Mesh data is usually going to occupy the single biggest chunk of memory, and it should be easy to be memory-efficient in Jax relative to this data. Currently it is not.
I am not clear on the best way to resolve this issue. My current thought is that the API should look like:
This is a little more verbose and much less intuitive IMHO, but it does get the job done. It decouples Material from Mesh, and it should be straightforward to stay backward compatible with the current API, to easily accommodate the "happy path" of always using the same material with a given mesh.
I'm open to suggestions and refinements, but will probably implement this as written if I don't get any negative feedback toward the idea.
The text was updated successfully, but these errors were encountered: