Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    GLB extract textures

    General Talk
    5
    7
    4.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      JohnSmith
      last edited by JohnSmith

      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
      
      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by

        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 gltfio.com.gltf2_io.Image 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 gltfio.com.gltf2_io.Image has no such attribute.

        Cheers,
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • r_giganteR
          r_gigante
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • kbarK
            kbar
            last edited by kbar

            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 🙂

            https://www.gamelogicdesign.com
            https://www.plugins4d.com

            1 Reply Last reply Reply Quote 0
            • J
              JohnSmith
              last edited by JohnSmith

              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

              M 1 Reply Last reply Reply Quote 2
              • M
                Macsmiller @JohnSmith
                last edited by

                @JohnSmith Hey John, I would love to test you plugin - do you think you could upload it again?

                Thanks!
                Max

                J 1 Reply Last reply Reply Quote 0
                • J
                  JohnSmith @Macsmiller
                  last edited by

                  @Macsmiller I apologize for the late reply. Here is the plugin.
                  glTF Importer plugin

                  I managed to finish it and integrate it into Cinema 4D. You can follow the updates here:
                  glTF Importer topic

                  Maybe 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?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post