GLB extract textures
-
Hello everyone! I created a plugin for importing glb/gltf (using the gltfio library), however I am having trouble extracting textures from glb. At the moment, the task is to save the texture to a folder with the name described below (material-name_channel.jpg / png). Please tell me how to solve this problem?
def GLB_textures(self, glb): # C:\Users\%USERNAME%\Desktop\123.glb folder , glb_name = os.path.split(glb) tex_folder = os.path.join(folder, glb_name + '_tex') try : os.mkdir(tex_folder ) except : print('Error create folder %s' % tex_folder) if glb.data.textures is None: return for texture in glb.data.textures: image = glb.data.images[texture.source] # gltfio.com.gltf2_io.Image instance full_path = os.path.join(tex_folder, image.name+'.jpg') # 'tex_folder' + 00000_basecolor.jpg try : image.Save(full_path, c4d.FILTER_JPG, None, c4d.SAVEBIT_0) except : print 'Error saving image %s' % full_path
-
Hi,
you left out the crucial part of what is not working, which makes any possible help rather difficult, especially since you utilise a third party library.
But what strikes me as odd, is that you try to invoke
Save
on the objectimage
. As you state yourself in your code, that object is angltfio.com.gltf2_io.Image
object. But from the looks of the signature ofimage.Save
it seems that you are trying to treat it like aBaseBitmap
and invoke its methodSave
. Which probably will raise an attribute error, telling you thatgltfio.com.gltf2_io.Image
has no such attribute.Cheers,
zipit -
Hi @JohnSmith , thanks for reaching out us and welcome to PluginCafé.
With regard to your issue, we leave the discussion to our very-supportive Community (kudos @zipit) because we can't provide support for third-party APIs.
Best, R
-
If your goal is to write your own python plugin for fun then great. But if you just want to be able to actually load in gltf and glb files then I think the sketchfab plugins should do the trick.
https://github.com/sketchfab/c4d-plugin/releases/tag/1.3.1
Its also worth mentioning that they also use the gltf2_io library, the same as you. So even if they haven't actually registered their plugins as actual scene loaders you could still learn how they used it to extract textures.
Note that I haven't used it myself.
I have my own plugins for loading in GLTF and GLB files, since it is still fun to write your own
-
Thanks everyone for the help, I figured it out. I tried the plugin on several dozen different models - no errors were found. I hope it will be useful to someone.
Download glb_import plugin -
@JohnSmith Hey John, I would love to test you plugin - do you think you could upload it again?
Thanks!
Max -
@Macsmiller I apologize for the late reply. Here is the plugin.
glTF Importer pluginI managed to finish it and integrate it into Cinema 4D. You can follow the updates here:
glTF Importer topicMaybe I am asking a question in the wrong topic - where can I find some sample code that can be used to create various import settings and write them to default presets.lib4d?