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 is None:
        for texture in
            image =[texture.source]         # instance
            full_path = os.path.join(tex_folder,'.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 object image. As you state yourself in your code, that object is an object. But from the looks of the signature of image.Save it seems that you are trying to treat it like a BaseBitmap and invoke its method Save. Which probably will raise an attribute error, telling you that has no such attribute.


  • 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.

    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