You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feature request: api support for loading textures from obj/mtl file #27
We're making pretty heavy use of meshcat in class again this term. I'm working on getting it into drake proper so the in-tree examples can use it, too: RobotLocomotion/drake#9833
But the current implementation that we have uses MeshLambertMaterial for all of the objects -- including the ones loaded from obj files. It looks like Meshcat does support texture maps. But if I leave the materials field = None for that call to SetObject, then I still don't see e.g. the kuka's textures.
Currently, I don't try to do something clever like parse the .mtl file to load the texture, but I suspect that would be possible, perhaps with a Mesh.from_file() constructor.
This would be nice for getting textures drawn on e.g. Drake's flashy new Skydio quadcopter model, which has relatively complex material setup on its different parts. Would this be easy to do using _meshfile_object parsing that looks like has come into existence on the javascript side over the last year?
(I'm happy to take a crack at it some time, just don't have a birds-eye view if that's the right strategy.)
The hardest part of this actually getting the texture file into the right format. I'm using the native object loader in Three.js, which expects that the texture files will be at some URL that it can access. Since that's annoying, I'm instead relying on the fact that you can create a data URI which includes the actual contents of the image file as base-64 encoded data. That means that texture loading just works, as long as you're willing to jump through some hoops to encode the data. The example linked above does that. In case it's helpful, the relevant Julia code that parses an obj file for its associated .mtl and then parses that .mtl for its necessary image textures is here: https://github.com/rdeits/MeshCat.jl/blob/8fbf7286a1bd721d80d990f5ea744911fb1adc2f/src/mesh_files.jl#L77-L101
Activity
gizatt commentedon Apr 16, 2020
This would be nice for getting textures drawn on e.g. Drake's flashy new Skydio quadcopter model, which has relatively complex material setup on its different parts. Would this be easy to do using
_meshfile_objectparsing that looks like has come into existence on the javascript side over the last year?(I'm happy to take a crack at it some time, just don't have a birds-eye view if that's the right strategy.)
rdeits commentedon Apr 22, 2020
Yeah, that's the right thing to do. I'm happy to help out with the details!
There's an example of
_meshfile_objectusage from javascript here: https://github.com/rdeits/meshcat/blob/master/test/meshfile_object_obj.html . Adding support in python would just mean creating aMeshFileObjecttype ingeometry.pywhich lowers to the same data format as that examplejsondata.The hardest part of this actually getting the texture file into the right format. I'm using the native object loader in Three.js, which expects that the texture files will be at some URL that it can access. Since that's annoying, I'm instead relying on the fact that you can create a data URI which includes the actual contents of the image file as base-64 encoded data. That means that texture loading just works, as long as you're willing to jump through some hoops to encode the data. The example linked above does that. In case it's helpful, the relevant Julia code that parses an
objfile for its associated.mtland then parses that.mtlfor its necessary image textures is here: https://github.com/rdeits/MeshCat.jl/blob/8fbf7286a1bd721d80d990f5ea744911fb1adc2f/src/mesh_files.jl#L77-L101