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

    Cinema4D Get Texture Atlas/Get Image At Coordinate

    Cinema 4D SDK
    python
    2
    4
    975
    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.
    • C
      ccgould
      last edited by ccgould

      Hello there I am wondering how I can use a texture atlas in cinema4D to use for my icons instead of loading seperate icons for example like what I see they are doing in XPaticles

      unknown (1).png

      1 Reply Last reply Reply Quote 1
      • ferdinandF
        ferdinand
        last edited by

        Hi,

        it is a bit unclear to me, what your actual question is. The bitmap type of Cinema is BaseBitmap. It has a method called CopyPartTo with which you can copy a part of a BaseBitmap (your atlas) into another BaseBitmap (an icon). There is no texture atlas type in the Python API for Cinema, which would handle the parsing of an atlas and its metadata into a set of bitmaps for you. So you will have to do that yourself.

        Cheers,
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 1
        • C
          ccgould
          last edited by ccgould

          @zipit said in Cinema4D read texture atlas:

          e

          Seems like you might have answered the question I wanted to know how to get the icon I wanted from that image and use it as an icon in C4D seems like GetClonePart returns the bitmap CopyPartTo returns bool is CopyPartTo still the anwser?

          1 Reply Last reply Reply Quote 1
          • C
            ccgould
            last edited by ccgould

            Did GetClonePart and it works 🙂

            Cinema4D Preview Icon
            unknown.png demoIcons.png

            [CODE HERE]

            #  // Imports  //
            import os
            import sys
            #  // Imports for Cinema 4D //
            import c4d
            from c4d import plugins, gui, bitmaps, documents, storage, utils
            
            # Icons Image Paths
            OneImageIcons = os.path.join(os.path.dirname(__file__), 'icons', "demoIcons.png")
            
            
            # ---------------------------------------------------------------------
            #       Creating GUI Instance Functions UI Elements Operations
            #                          Hepler Methods.
            # ---------------------------------------------------------------------
            
            # Get Icon from Icons one image.
            def GetCustomIcon(size, locCordX, locCordY):
                """ Get Texture Atlas Image """
                bmp = c4d.bitmaps.BaseBitmap()
                bmp.InitWith(OneImageIcons)
                w = size
                h = size
                x = locCordX
                y = locCordY
                selectIcon = bmp.GetClonePart(x, y, w, h)
                return selectIcon
            
            # Create a Bitmap Button Custom GUI.
            def CustomImageButton_GUI(ui_ins, btn_id, toolname, tooltip, image):
                ui_ins.GroupBegin(0, c4d.BFH_MASK, 1, 0, "")
                bc = c4d.BaseContainer()                                  # Create a new container to store the button image
                bc.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_NONE)      # Sets the border flag to look like a button look. eg.( c4d.BORDER_NONE or c4d.BORDER_THIN_OUT or c4d.BORDER_OUT )
                bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True)                 # Clickable button / Does not seem to to work in R13?
                bc.SetBool(c4d.BITMAPBUTTON_TOGGLE, True)                 # Toggle button, like a checkbox.
                bc.SetString(c4d.BITMAPBUTTON_TOOLTIP, "<b>"+ toolname + "</b><br>" + tooltip)
                ui_ins.myBitButton = ui_ins.AddCustomGui(btn_id, c4d.CUSTOMGUI_BITMAPBUTTON, "Bitmap Button", c4d.BFH_MASK, 10, 10, bc)
                ui_ins.myBitButton.SetImage(image)
                ui_ins.GroupEnd()
                return True
            
            
            
            
            # ----------------------------------------
            #  // UI Main Window //
            # ----------------------------------------
            class Tool_WindowDialog(c4d.gui.GeDialog):
            
                # GUI Ids
                IDS_VER = 999
                IDS_OverallGrp = 1000
                IDS_StaticText = 1001
                IDS_BTN_01 = 1002
                IDS_BTN_02 = 1003
                IDS_BTN_03 = 1004
                IDS_BTN_04 = 1005
            
                # // Main GeDialog Overrides //
            
                """
                The __init__ is an Constuctor and help get
                and passes data on from the another class.
                """
                def __init__(self):
                    super(Tool_WindowDialog, self).__init__()
            
                # UI Layout
                def CreateLayout(self):
            
                    # Dialog Title
                    self.SetTitle("Tool Ui")
            
                    # Adding the GUI Buttons and inside a empty group with 4 rows.
                    self.GroupBegin(0, c4d.BFH_SCALEFIT, 4, 0, "")
                    self.GroupBorderSpace(5, 5, 5, 5)
                    
                    CustomImageButton_GUI(ui_ins=self,
                                          btn_id=self.IDS_BTN_01,
                                          toolname="Go UP",
                                          tooltip="HelloWorld",
                                          image=GetCustomIcon(size=32, locCordX=0, locCordY=37))
            
                    CustomImageButton_GUI(ui_ins=self,
                                          btn_id=self.IDS_BTN_02,
                                          toolname="Go Right",
                                          tooltip="HelloWorld",
                                          image=GetCustomIcon(size=32, locCordX=0, locCordY=0))
            
                    self.GroupEnd()
            
                    self.GroupEnd() # End of the overall group.
                    return True
            
                # Called when the dialog is initialized by the GUI / GUI's with startup values basically.
                def InitValues(self):
                    print("Yang Ultimate Tools Dialog is open.")
                    return True
            
                # Adding Excuting Commands Functions for UI Elements.
                def Command(self, id, msg):
                    if id == id:
                        print(str(id))
                    return True
            
                # Override this function if you want to react to Cinema 4D core messages.
                # The original message is stored in msg
                def CoreMessage(self, id, msg):
                    if id == c4d.EVMSG_CHANGE:
                        #self.add_images()
                        pass
                    return True
            
                """
                DestroyWindow Override this method - this function is
                called when the dialog is about to be closed temporarily,
                for example for layout switching.
                """
                def DestroyWindow(self):
                    print("Tools Dialog Close.")
            
            
            if __name__=='__main__':
                class_dialog = Tool_WindowDialog()
                class_dialog.Open(c4d.DLG_TYPE_ASYNC, defaultw=200, defaulth=10)
            
            
            1 Reply Last reply Reply Quote 2
            • First post
              Last post