-
Notifications
You must be signed in to change notification settings - Fork 985
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
Do we have any examples of rendering a .drc model with materials using THREE.js? #364
Comments
Thanks for the link, @zwcloud, however, none of these examples ( |
I've got the following to work where I reference a particular const mesh = new THREE.Mesh(
geometry,
material.materials['material0000'] // the name of the first material of the set of 4
); So, then, I applied the array of materials with the following: const mesh = new THREE.Mesh(
geometry,
_.map(material.materials, m => m)
); The result is the same. The texture is applied but the mapping is incorrect as it's duplicated and incorrectly referenced throughout the model position. |
if the issue is that you have multiple materials, you would have to split the geometry first (as far as I know, three.js allow only one material per geometry). You can see for example this issue for a discussion how to do that. In future we may add a function to the javascript API that would do this automatically, but for now the splitting has to be done manually. |
Thanks for the quick response, @ondys. THREE.js does provide a way for a Mesh to have multiple materials by providing an array of materials as the argument. That said, it's complicated to split up a model as it's generated by our users (via photogrammetry), so I'm not sure if there's a programatic way for doing this. I'm really hoping we are able to leverage Looking forward to your response. |
@FarhadG I'm not sure if I understand the problem completely. If THREE.js supports more materials per single object, you should be able to avoid the splitting altogether. Draco encodes material ids that would have to be somehow translated into material ids of THREE.js. I'm not familiar how THREE.js handles mapping between materials and faces but if they support it you should be able to modify DRACOLoader.js to fill whatever array the three js geometry needs to perform this mapping. |
Thanks for the response, @ondys. THREE does, indeed, support multiple textures. For example, if you visit this photogrammetry service where you get a large I tried this in a variety of ways but could not get it to render the textures correctly. Hence, why I've started looking into partitioning the OBJ to the number of textures provided. Let me know if anything's unclear, @ondys. Thank you! |
Since three.js supports multiple materials per object, you just need to map them to the correct faces. As I said, I'm not familiar with the proper way to handle the setup in three.js so I would suggest asking at their forums instead. To get the material ids for faces you can use following code (in case the .obj was encoded with
then in the DRACOLoader.js code where the faces, you can update it to store material ids as:
|
@ondys does By the way, when I'm encoding Am I missing some data using |
Since I've received a few emails on whether I've resolved this, here's some good news for individuals with a similar use case as I've mentioned above. I opted to leverage the Here's the discussion for reference: https://discourse.threejs.org/t/mapping-multiple-materials-to-an-obj-model-in-three-js/2577/14 |
@JohnnyPosi Can you post model.obj and model.ply? If the models are the same the compression should not be different. |
I've looked and haven't found a working example of rendering a .drc model with materials with THREE.js. Ive used the the
mtl-loader
anddrc-loader
to load my model, however, associating the material with the model has been a challenge. For example:When I receive the
model
(i.e.BufferGeometry
) andmaterial
(i.e. THREE.MTLLoader.MaterialCreator) which comprises4
materials, I am not able to render the model with the following:The text was updated successfully, but these errors were encountered: