Example #1
0
def main():
    
    path = storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES, title="Please Choose a 32 Bit Image:")
    #path = "C:\\Users\\tobi\\Desktop\\test.jpg"
    if not path: return

    # Create and initialize selected image
    orig = bitmaps.BaseBitmap()
    if orig.InitWith(path)[0] != c4d.IMAGERESULT_OK:
        gui.MessageDialog("Cannot load image \"" + path + "\".")
        return

    width, height = orig.GetSize()
    bits = orig.GetBt()
    pxColl = []
    
    for x in range (0,width):
        for y in range (0,height):
            pxColl.append( orig.GetPixel(x,y) )

    
    samples = 16
    seed = 500
    pxColl.sort()

        
     
            
    i = 0
    for x in range (0,width):
        for y in range (0,height):
            
            orig.SetPixel(x,y,int(pxColl[i][0]),int(pxColl[i][1]),int(pxColl[i][2]))
            
            i += 1  
            
    bitmaps.ShowBitmap(orig)
    
    
    copy = bitmaps.BaseBitmap() 
    copy.Init(samples, 1, bits)
    collPic = []
    for x in range(0,samples):
        
        #random.seed(x+seed)
        rgb =len(pxColl)/samples*x
        newcoll = pxColl[rgb][0],pxColl[rgb][1],pxColl[rgb][2]
        #print newcoll
        collPic.append( newcoll )

    collPic.sort(key=lambda rgb: colorsys.rgb_to_hsv(*rgb))

    i = 0
    #print collPic
    for item in collPic:
        copy.SetPixel(i,0,item[0],item[1],item[2])        
        
        i += 1
Example #2
0
def main():
    

    size = 64
    n = size*size
    
    s = (float(1)/float(n))
    
    px = []
    bmp = bitmaps.BaseBitmap()
    bmp.Init(size, size, depth=32)
    for i in xrange(0,n): px.append(i*s)
    
    x = 0
    y = -1
    i = 0
    shuffle(px)
    for p in px:
        
        if (x % size == 0):
            y+=1
            x =0
        bmp.SetPixel(x, y, p*255,p*255 ,p*255 )
        x +=1

    
    bitmaps.ShowBitmap(bmp)
Example #3
0
def main():
    path = storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES, title="Please Choose a 32-bit Image:")
    if not path: return
    
    # Create and initialize selected image
    orig = bitmaps.BaseBitmap()
    if orig.InitWith(path)[0] != c4d.IMAGERESULT_OK:
        gui.MessageDialog("Cannot load image \"" + path + "\".")
        return
    
    # Check if channel depth is really 32 bit
    if orig.GetBt()/3 != 32:
        gui.MessageDialog("The image \"" + path + "\" is not a 32 bit per-channel image.")
        return
    
    # Get selected image infos
    width, height = orig.GetSize()
    bits = orig.GetBt()
    
    # Create the copy and initialize it
    copy = bitmaps.BaseBitmap()
    copy.Init(width, height, bits)
    
    # Calculate the number of bytes per pixel
    inc = orig.GetBt()/8 # Each pixel has RGB bits, so we need an offset of 'inc' bytes per pixel
                         # the image has 32 bits per-channel : (32*3)/8 = 12 bytes per pixel (1 byte = 8 bits)
                         # the image has 3 channels per pixel (RGB) : 12/3 = 4 bytes per component = 1 float
    
    # Create a byte sequence buffer large enough to store the copied image pixels
    sq = storage.ByteSeq(None, width*height*inc)
    
    for row in xrange(height):
        offset = sq.GetOffset(row*(width*inc)) # Offset on bitmap row + offset bytes per pixel
        orig.GetPixelCnt(0, row, width, offset, inc, c4d.COLORMODE_RGBf, c4d.PIXELCNT_0) # Read pixels from the original bitmap into the buffer
    
    #Example: RGB value of first pixel (only for 32 bits)
    #import struct
    #r, g, b = struct.unpack("fff", sq[0:12])
    #print r, g, b
    
    for row in xrange(height):
        offset = sq.GetOffset(row*(width*inc)) # Offset on bitmap row + offset bytes per pixel
        copy.SetPixelCnt(0, row, width, offset, inc, c4d.COLORMODE_RGBf, c4d.PIXELCNT_0) # Set pixels in bitmap copy
    
    bitmaps.ShowBitmap(orig) # Show original
    bitmaps.ShowBitmap(copy) # Show copied image
Example #4
0
 def __init__(self, doc):
     self.dest_file = ''
     self.doc = doc.GetClone(c4d.COPYFLAGS_DOCUMENT)
     self.render_data = self.doc.GetActiveRenderData().GetData()
     self.bmp = bitmaps.BaseBitmap()
     self.bmp.Init(x=int(self.render_data[c4d.RDATA_XRES]),
                   y=int(self.render_data[c4d.RDATA_YRES]),
                   depth=24)
     self.status = False
Example #5
0
    def __init__(self, aDoc, typeOfRender, aFlags, continious=False):

        self.continious = continious
        self._doc = aDoc
        self.typeOfRender = typeOfRender
        self._flags = aFlags

        self.rd = self._doc.GetActiveRenderData()

        self.bmp = bitmaps.BaseBitmap()
        self.bmp.Init(int(round(self.rd[c4d.RDATA_XRES_VIRTUAL])),
                      int(round(self.rd[c4d.RDATA_YRES_VIRTUAL])),
                      depth=24)
Example #6
0
def main():
    rd = doc.GetActiveRenderData().GetData()
    xres = int(round(rd[c4d.RDATA_XRES]))
    yres = int(round(rd[c4d.RDATA_YRES]))

    bmp = bitmaps.BaseBitmap()
    bmp.Init(xres, yres, depth=32)

    res = documents.RenderDocument(doc, rd, bmp, c4d.RENDERFLAGS_EXTERNAL)
    if res == c4d.RENDERRESULT_OK:
        bitmaps.ShowBitmap(bmp)

    if __name__ == '__main__':
        main()
def getImageSize(mat):
    pathToFile = ''
    try:
        pathToFile = mat[c4d.MATERIAL_COLOR_SHADER][c4d.BITMAPSHADER_FILENAME]
    except:
        try:
            pathToFile = mat[c4d.MATERIAL_LUMINANCE_SHADER][
                c4d.BITMAPSHADER_FILENAME]
        except:
            return [400, 400]

    bmp = bitmaps.BaseBitmap(pathToFile)
    bmp.InitWith(pathToFile)
    w, h = bmp.GetSize()
    return [w, h]
Example #8
0
def main():
    path = storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES,
                              title="Please Choose an Image:")
    if not path: return

    # Create and initialize selected image
    img = bitmaps.BaseBitmap()
    if img.InitWith(path)[0] != c4d.IMAGERESULT_OK:
        gui.MessageDialog("Cannot load image \"" + path + "\".")
        return

    byteseq, size = WriteBitmap(
        img)  # Save image to hyper file in byte sequence
    bmp = ReadBitmap(byteseq)  # Read image from the byte sequence

    bitmaps.ShowBitmap(bmp)
Example #9
0
def main():

    size = 256

    bmp = bitmaps.BaseBitmap()
    bmp.Init(size, size, depth=32)
    bmp.SetData(c4d.BASEBITMAP_DATA_GAMMA, 2.2)

    for x in xrange(0, (size)):

        for y in xrange(0, (size)):

            bmp.SetPixel(x, y,
                         x * (float(1) / float(size)) * 255,
                         y * (float(1) / float(size)) * 255 * -1 + 255, 0)

    bitmaps.ShowBitmap(bmp)
Example #10
0
def importPalette(path):
    orig = bitmaps.BaseBitmap()
    if orig.InitWith(path)[0] != c4d.IMAGERESULT_OK:
        gui.MessageDialog("Cannot load image \"" + path + "\".")
        return

    width, height = orig.GetSize()

    if height != 1:
        gui.MessageDialog("This is not a MagicaVoxel .PNG Palette")
    else:
        for x in range(0, width):
            mat = doc.SearchMaterial(str(x + 1))
            if mat:
                color = orig.GetPixel(x, 0)
                mat[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(
                    float(color[0]) / 255,
                    float(color[1]) / 255,
                    float(color[2]) / 255)
Example #11
0
def ReadBitmap(byteseq):
    """
    Creates a bitmap from a buffer object.
    
    @return: The image if succeeded, otherwise False
    
    @byteseq: The buffer object.
    """

    bmp = bitmaps.BaseBitmap()
    hf = storage.HyperFile()
    mfs = storage.MemoryFileStruct()

    bmp = None
    mfs.SetMemoryReadMode(byteseq, len(byteseq))
    if hf.Open(0, mfs, c4d.FILEOPEN_READ, c4d.FILEDIALOG_NONE):
        bmp = hf.ReadImage()
        hf.Close()

    return bmp
Example #12
0
def main():
    
    docpath = doc.GetDocumentPath()
    picture = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES, flags=c4d.FILESELECT_LOAD, def_path=docpath)
    
    #create a standard material
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    
    doc.StartUndo()
    #insert the material in the document
    doc.InsertMaterial(mat)
    doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
    
    imgname = os.path.splitext(os.path.basename(picture))[0]
    
    mat[c4d.MATERIAL_USE_REFLECTION] = 0
    mat.SetName(imgname)

    #create a bitmap shader
    xch = c4d.BaseList2D(c4d.Xbitmap)

    #set the path of the image file to the bitmap shader
    xch[c4d.BITMAPSHADER_FILENAME] = picture


    #set the shader to the color channel
    mat[c4d.MATERIAL_COLOR_SHADER] = xch
    
    #set the shader to the luminanz channel
    #mat[c4d.MATERIAL_LUMINANCE_SHADER] = xch   
    #mat[c4d.MATERIAL_USE_LUMINANCE]=True
    #mat[c4d.MATERIAL_USE_COLOR]=False
    
    mat.InsertShader(xch)

    filename = xch[c4d.BITMAPSHADER_FILENAME]
    bm = bitmaps.BaseBitmap()
    bm.InitWith(filename)
    getsize = bm.GetSize()
    xpix = float(getsize[0])
    ypix = float(getsize[1])

    #internal update of the material
    mat.Message(c4d.MSG_UPDATE)

    #recalculate the thumbnails of the material
    mat.Update(True, True)
    
    # Normalize width to 200px
    
    ypixnorm = float(xpix/ypix)

    # Create plane
    plane = c4d.BaseObject(c4d.Oplane)
    plane[c4d.PRIM_PLANE_WIDTH] = 200
    plane[c4d.PRIM_PLANE_HEIGHT] = 200/ypixnorm
    plane[c4d.PRIM_AXIS] = 5
    plane[c4d.ID_BASELIST_NAME] = imgname
    plane[c4d.PRIM_PLANE_SUBW] = 1
    plane[c4d.PRIM_PLANE_SUBH] = 1
    
    doc.InsertObject(plane)
    doc.AddUndo(c4d.UNDOTYPE_NEW, plane)
    doc.EndUndo()
     
    # Create texture tag
    tag = plane.MakeTag(c4d.Ttexture) 
    tag[c4d.TEXTURETAG_MATERIAL] = mat
    tag[c4d.TEXTURETAG_PROJECTION] = 6
    
    # Create display tag
    disptag = plane.MakeTag(c4d.Tdisplay) 
    disptag[c4d.DISPLAYTAG_AFFECT_DISPLAYMODE]=True
    
    # Set texture resolution
    maxres = int(max(ypix, xpix))
    
    print maxres
    
    if maxres > 1024 and maxres < 2048:
        mat[c4d.MATERIAL_PREVIEWSIZE] = 11
        
    elif maxres > 2048 and maxres < 4096:
        mat[c4d.MATERIAL_PREVIEWSIZE] = 12
        
    elif maxres > 4096 and maxres < 8192:
        mat[c4d.MATERIAL_PREVIEWSIZE] = 13
        
    elif maxres > 8192:
        mat[c4d.MATERIAL_PREVIEWSIZE] = 14
        
    else:
        mat[c4d.MATERIAL_PREVIEWSIZE] = 10
    
    c4d.EventAdd()
Example #13
0
        if self.dialog is None:
            self.dialog = MakeAwesomeButtonDialog()
        return self.dialog.Open(c4d.DLG_TYPE_ASYNC,
                                pluginid=ID_MAKEAWESOMEBUTTON)

    def RestoreLayout(self, secref):
        # manage nonmodal dialog
        if self.dialog is None:
            self.dialog = MakeAwesomeButtonDialog()
        return self.dialog.Restore(pluginid=ID_MAKEAWESOMEBUTTON,
                                   secret=secref)


if __name__ == "__main__":
    thispath = os.path.dirname(os.path.abspath(__file__))
    icon = bitmaps.BaseBitmap()
    icon.InitWith(os.path.join(thispath, "res", "icon.png"))
    plugins.RegisterCommandPlugin(ID_MAKEAWESOMEBUTTON, PLUGIN_NAME, 0, icon,
                                  PLUGIN_HELP, MakeAwesomeButtonMain())
    print(u"%s v%s loaded. (C) %s ${FULLNAME}" %
          (PLUGIN_NAME, PLUGIN_VERSION, CR_YEAR))

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Example #14
0
import c4d
from c4d import gui
from c4d import bitmaps, documents
from random import shuffle

size = 64
n = size * size

s = (float(1) / float(n))

px = []
bmp = bitmaps.BaseBitmap()
bmp.Init(size, size, depth=32)
for i in xrange(0, n):
    px.append(i * s)

x = 0
y = -1
i = 0

shuffle(px)
r = list(px)
shuffle(px)
g = list(px)
shuffle(px)
b = list(px)

for i in range(len(px)):

    if (x % size == 0):
        y += 1
def main():
    # globale Variablen übernehmen
    global scaleart, orig, alpha, button, showo, shows, bitmapfile

    c4d.CallCommand(13957)  # Pythonkonsole leeren

    # Objekt ausgewählt? Sonst Fehlerausgabe und beenden
    if not op:
        gui.MessageDialog("Please select a object!")
        return False  # EXIT

    # Prüfen ob das Objekt ein Polygonobjekt ist
    if (op.GetType() == 5100):  # 5100 ist der Type für das Polygonobjekt
        print
    else:
        gui.MessageDialog("ERROR - Object is not a polygon object?")
        return False

    # Erstes UVTag auslesen
    uvtag = op.GetTag(c4d.Tuvw)
    # Kein UVW Tag? Sonst Fehlerausgabe und beenden
    if not uvtag:
        gui.MessageDialog("Please assign UVW to the object")
        return

    # Dialog aufrufen
    dlg = Dialog()
    dlg.Open(c4d.DLG_TYPE_MODAL)
    if (button == 0):
        return False  # Kein Button gedrückt (z.B. beim Fenster schließen über Fensterelement X)

    # Bitmap Variablen vorbereiten
    smallbitm = bitmaps.BaseBitmap()
    bitmap = bitmaps.BaseBitmap()
    bitmapPath = bitmapfile

    if (button == 1024):
        abspath = bitmapfile
        bitmapPath = bitmapfile
    else:
        #  Selektiertes Tag auslesen
        ttag = doc.GetActiveTag()
        if (
                not ttag or not ttag.CheckType(c4d.Ttexture)
        ):  # Falls kein Material Tag vorhanden oder/und ausgewählt - abbrechen
            gui.MessageDialog(
                "Please attach AND SELECT a Material to the object!")
            return False

        # Material der Variable mat zuweisen
        mat = ttag.GetMaterial()

        # Kein Material übernehmen können? Dann Fehlerausgabe und beenden
        if not mat:
            gui.MessageDialog(
                "Please attach a Material with simple bitmap in color Channel to the object!"
            )
            return False  # EXIT

        # Farbkanal auslesen falls Variable alpha = 0 (Button links gedrückt)
        if (alpha == 0):
            if (mat[c4d.MATERIAL_USE_COLOR] == True
                ):  # ist der Color kanal des Materials aktiv?
                shader = mat[c4d.MATERIAL_COLOR_SHADER]  # dann Shader auslesen
            else:
                gui.MessageDialog("Miss COLOR Channel!")
                return False  # Exit
        # Alphakanal auslesen falls Variable alpha = 1 (Button mitte gedrückt)
        if (alpha == 1):
            if (mat[c4d.MATERIAL_USE_ALPHA] == True
                ):  # ist der Alpha kanal des Materials aktiv?
                shader = mat[c4d.MATERIAL_ALPHA_SHADER]  # dann Shader auslesen
            else:
                gui.MessageDialog("Miss ALPHA Channel!")
                return False  # Exit

        # Farbkanal / Alphakanal konnte nicht gelesen werden?
        if shader is None:
            if (alpha == 0):
                gui.MessageDialog(
                    "Can't get the Shader!\nPlease check that the COLOR Channel is not empty!"
                )
            if (alpha == 1):
                gui.MessageDialog(
                    "Can't get the Shader!\nPlease check that the ALPHA Channel is not empty!"
                )
            return False  # EXIT

        # Shader vor dem auslesen erst abrufbar machen!!!
        bitmapPath = shader[c4d.BITMAPSHADER_FILENAME]
        # Shadertyp und Filename bei Bitmapshader auslesen
        name, path = shader.GetName(), shader[c4d.BITMAPSHADER_FILENAME]

        #if bitmapPath is´nt absolute
        if not os.path.dirname(bitmapPath):
            #the document has´nt been saved already ->picture in user library
            if not doc.GetDocumentPath():
                abspath = c4d.storage.GeGetStartupWritePath(
                ) + "/" + "tex" + "/" + bitmapPath
            #the picture should be inside the asset´s texture folder
            else:
                abspath = doc.GetDocumentPath() + "/" + bitmapPath
        else:
            abspath = bitmapPath

    #
    if op is not None:

        # Bitmap mit vollem Pfad und Dateinamen Initialisieren:
        result = bitmap.InitWith(abspath)

        if (button <> 1024): irs = render.InitRenderStruct()
        else: irs = True
        if (button <> 1024): shader.InitRender(irs)
        if irs:

            # Bitmapdateien in Shadern können absolut oder relativ gespeichert werden.
            # Also muss geprüft werden ob der komplette Pfad ausgelesen wurde!

            # Falls Bitmap ordnungsgemäß verarbeitet wurde:
            if result:

                # Die Variable bitmap wurde jetzt auf eine von 3 Arten befüllt:
                if bitmap is not None:  # hats geklappt? Dann weiter:
                    width, height = bitmap.GetSize(
                    )  # Pixel-Maße  der Bilddatei auslesen
                    bits = bitmap.GetBt()  # Bittiefe auslesen
                    pixelzahl = width * height  # Gesamtpixelanzahl ermitteln
                    punktezahl = uvtag.GetDataCount(
                    )  # Punkteanzahl der UVW-Map ermitteln

                    # Scalierung auf basis des Skalierungs-Sliders berechnen
                    # Aufgrund der Differenz der Auflösung der Bilddatei
                    # und der Auflösung des Polygonmesh (bzw. der UVW-Map)
                    # berechnet sich die Scalierung der Bilddatei.
                    # Die Bilddatei wird skaliert damit in einer hohen Bildauflösung
                    # ein einzelner ausgerissener Pixel den Punkt in einem niedrig aufgelösen Mesh                        # nicht so stark beeinflusst beeinflusst. nur weil der UV-Punkt genau auf diesem Pixel liegt.

                    differenz = pixelzahl - punktezahl  # Differenz ermitteln
                    if scaleart == 10:
                        diffadd = float(
                            differenz
                        ) / 1000  # Neue Bildgröße = Anzahl der Punkte der UV-Map + Differenz geteilt durch 1000
                    if scaleart == 9:
                        diffadd = float(
                            differenz
                        ) / 500  # Neue Bildgröße = Anzahl der Punkte der UV-Map + Differenz geteilt durch 500
                    if scaleart == 8:
                        diffadd = float(
                            differenz
                        ) / 100  # Neue Bildgröße = Anzahl der Punkte der UV-Map + Differenz geteilt durch 100
                    if scaleart == 7:
                        diffadd = float(
                            differenz
                        ) / 50  # Neue Bildgröße = Anzahl der Punkte der UV-Map + Differenz geteilt durch 50
                    if scaleart == 6:
                        diffadd = float(
                            differenz
                        ) / 20  # Neue Bildgröße = Anzahl der Punkte der UV-Map + Differenz geteilt durch 20
                    if scaleart == 5:
                        diffadd = float(
                            differenz
                        ) / 10  # Neue Bildgröße = Anzahl der Punkte der UV-Map + Differenz geteilt durh 10
                    if scaleart == 4:
                        diffadd = float(
                            differenz
                        ) / 5  # Neue Bildgröße = Anzahl der Punkte der UV-Map + Differenz geteilt durch 5
                    if scaleart == 3:
                        diffadd = float(
                            differenz
                        ) / 3  # Neue Bildgröße = Anzahl der Punkte der UV-Map + ein Drittel der Differenz
                    if scaleart == 1:
                        diffadd = float(
                            differenz
                        ) / 2  # Neue Bildgröße = Anzahl der Punkte der UV-Map + die Hälfte der Differenz
                    if scaleart == 2:
                        diffadd = float(
                            (differenz / 3)
                        ) * 2  # Neue Bildgröße = Anzahl der Punkte der UV-Map + Zwei Drittel der Differenz
                    if scaleart == 0:
                        diffadd = differenz  # Neue Bildgröße = Anzahl der Punkte der UV-Map + komplette Defferenz - Also volle Auflösung!

                    # Geladenes Bild bestimmt das Seitenverhältnis. Anhand der alten Menge an Pixel,
                    # der zur Verfügung stehenden Punkte im UV-Mesh und dem Grad der Skalierung (Slider)
                    # wird die neue Bildgröße berechnet. mit gleich bleibenden Seitenverhältnis.

                    # Scalierungsfaktor berechnen: Punkte+Pixelreduzierung geteilt durch Pixelanzahl
                    scalefaktor = float(punktezahl + diffadd) / (pixelzahl)
                    # Anhand des Skalierungsfaktors der Fläche die Seitenlängen berechnen
                    scale_width = int(width * math.sqrt(scalefaktor))
                    scale_height = int(height * math.sqrt(scalefaktor))

                    # Kleinere Version der Bitmap erstellen
                    smallbitm.Init(
                        scale_width, scale_height, bits
                    )  # Kleinere Maße, gleiche Bittiefe, gleiches Seitenverhältnis

                    # Copy&Scale Original Bitmap zu Kleine Bitmap
                    bitmap.ScaleBicubic(smallbitm, 0, 0, width - 1, height - 1,
                                        0, 0, scale_width - 1,
                                        scale_height - 1)

                    if (showo == True): bitmaps.ShowBitmap(bitmap)
                    if (shows == True): bitmaps.ShowBitmap(smallbitm)
                    bitmap = smallbitm

                else:
                    gui.MessageDialog("Bitmap-Error")
                    return False

                if (button <> 1024): shader.FreeRender()

                # Abbrechen falls Bitmap nicht übergeben werden konnte
                if bitmap is None:
                    gui.MessageDialog("Bitmap can't load")
                    return False

            else:
                # Im Kanal steckt keine einfache Bitmap-Datei. Wahrscheinlich ein prozeduraler Shader, oder Ebenen ect.
                gui.MessageDialog("In channel ist not a simple bitmap")
                return False  # EXIT

            # Es wird eine Vertexmap erstellt die gleichviele Punkte enthält wie das Polygonobjekt
            vtag = c4d.VariableTag(c4d.Tvertexmap, op.GetPointCount())
            bitmap_w = bitmap.GetBw()  # Breite der Bitmap auslesen
            bitmap_h = bitmap.GetBh()  # Höhe der Bitmap auslesen
            pixel = (bitmap_w * bitmap_h)  # Pixelanzahl des Skalierten Bildes
            points = uvtag.GetDataCount()  # Punktanzahl des UVW-Tags
            if (op.GetPointCount() >
                    0):  # Prüfen ob das Objekte Punkte zum auslesen hat
                vertexList = op.GetPointCount() * [
                    0
                ]  # Die Variable für die Vertagsmap-Befüllung mit der Anzahl an Punkten des selektierten Objektesvorbereiten
            else:
                gui.MessageDialog(
                    "Object have no read able points! Is it a polygon object?")
                return False

            # Schleife liest jedes UVW-tag Polygon aus. Ein Punkt eines UVW-Tags kann mehreren Polygonobjekt-Punkten zugewisen sein
            # Es wird der Reihe nach jedes UV-Polygon ausgelesen. Dann wird das zugehörige Polygon des Objektes ausgelesen und
            # dessen Punkte mit den Farbwerten der Bitmap gefüllt. Die Anzahl der Polygonpunkte müssen nämlich gleich sein mit der Anzahl der Vertexmap-Punkte

            # Laut Wiki: Grauwert = 0,299 × Rotanteil + 0,587 × Grünanteil + 0,114 × Blauanteil

            for i in xrange(uvtag.GetDataCount()
                            ):  # Schleife durchläuft Polygone des UVW-Tag
                uvwdict = uvtag.GetSlow(i)  # UVW-Polygon wird eingelesen
                objpolygon = op.GetPolygon(i)  # Objekt-Polygon wird eingelesen
                point_a = op.GetPoint(
                    objpolygon.a)  # Objekt Polygon-PunktA ID wird ausgelesen
                point_b = op.GetPoint(
                    objpolygon.b)  # Objekt Polygon-PunktB ID wird ausgelesen
                point_c = op.GetPoint(
                    objpolygon.c)  # Objekt Polygon-PunktC ID wird ausgelesen
                point_d = op.GetPoint(
                    objpolygon.d)  # Objekt Polygon-PunktD ID wird ausgelesen
                u = uvwdict[
                    "a"].x  # UVW-Koordinate des Punktes A wird ermittelt
                v = uvwdict[
                    "a"].y  # UVW-Koordinate des Punktes A wird ermittelt
                w = uvwdict["a"].z
                ux = bitmap_w * u  # UV-Koordinate liegt zwischen 0-1 und wird mit der Bildbreite multipliziert
                uy = bitmap_h * v  # UV-Koordinate liegt zwischen 0-1 und wird mit der Bildhöhe multipliziert
                color = bitmap.GetPixel(int(ux), int(uy))
                # "ubjektiver" Helligkeitswert aus RGB ermitteln
                weight_a = 0.299 * (float(color[0]) / 256) + 0.587 * (
                    float(color[1]) / 256) + 0.114 * (float(color[2]) / 256)

                u = uvwdict[
                    "b"].x  # UVW-Koordinate des Punktes B wird ermittelt
                v = uvwdict[
                    "b"].y  # UVW-Koordinate des Punktes B wird ermittelt
                w = uvwdict["b"].z
                ux = bitmap_w * u  # UV-Koordinate liegt zwischen 0-1 und wird mit der Bildbreite multipliziert
                uy = bitmap_h * v  # UV-Koordinate liegt zwischen 0-1 und wird mit der Bildhöhe multipliziert
                color = bitmap.GetPixel(int(ux), int(uy))
                # "ubjektiver" Helligkeitswert aus RGB ermitteln
                weight_b = 0.299 * (float(color[0]) / 256) + 0.587 * (
                    float(color[1]) / 256) + 0.114 * (float(color[2]) / 256)

                u = uvwdict[
                    "c"].x  # UVW-Koordinate des Punktes C wird ermittelt
                v = uvwdict[
                    "c"].y  # UVW-Koordinate des Punktes C wird ermittelt
                w = uvwdict["c"].z
                ux = bitmap_w * u  # UV-Koordinate liegt zwischen 0-1 und wird mit der Bildbreite multipliziert
                uy = bitmap_h * v  # UV-Koordinate liegt zwischen 0-1 und wird mit der Bildhöhe multipliziert
                color = bitmap.GetPixel(int(ux), int(uy))
                # "ubjektiver" Helligkeitswert aus RGB ermitteln
                weight_c = 0.299 * (float(color[0]) / 256) + 0.587 * (
                    float(color[1]) / 256) + 0.114 * (float(color[2]) / 256)

                u = uvwdict[
                    "d"].x  # UVW-Koordinate des Punktes D wird ermittelt
                v = uvwdict[
                    "d"].y  # UVW-Koordinate des Punktes D wird ermittelt
                w = uvwdict["d"].z
                ux = bitmap_w * u  # UV-Koordinate liegt zwischen 0-1 und wird mit der Bildbreite multipliziert
                uy = bitmap_h * v  # UV-Koordinate liegt zwischen 0-1 und wird mit der Bildhöhe multipliziert
                color = bitmap.GetPixel(int(ux), int(uy))
                # "ubjektiver" Helligkeitswert aus RGB ermitteln
                weight_d = 0.299 * (float(color[0]) / 256) + 0.587 * (
                    float(color[1]) / 256) + 0.114 * (float(color[2]) / 256)

                # Helligkeitswerte der Vertexmap Wert-Variable zuweisen
                vertexList[objpolygon.a] = weight_a
                vertexList[objpolygon.b] = weight_b
                vertexList[objpolygon.c] = weight_c
                vertexList[objpolygon.d] = weight_d

            if vtag:  # falls die Vertexmap auch wirlich erstellt wurde kann es weiter gehen:
                op.InsertTag(vtag)  # Vertexmap wird an dem objekt erstellt

                vtag.SetAllHighlevelData(
                    vertexList
                )  # erstellte Vertexmap wird mit den ermittelten Werten gefüllt

            c4d.EventAdd(
            )  # Veränderung in der Szene mitteilen, damit C4D aktualisiert.
        else:
            # Das Vorbereiten der Bitmapinitialisierung hat fehlgeschlagen:
            gui.MessageDialog("Can Not Init Shader")
            if irs == c4d.INITRENDERRESULT_OUTOFMEMORY:
                gui.MessageDialog("Out Of Memory")
            if irs == c4d.INITRENDERRESULT_ASSETMISSING:
                gui.MessageDialog("Texture Not Assigned")
            if irs == c4d.INITRENDERRESULT_UNKNOWNERROR:
                gui.MessageDialog("Unknown Error")
            if irs == c4d.INITRENDERRESULT_THREADEDLOCK:
                gui.MessageDialog("Threaded Lock")

        gui.MessageDialog(" - Finish - ")
import c4d
import os
from c4d import bitmaps, storage
from c4d import utils, gui
from c4d.gui import GeDialog
from c4d.modules import render
import math

chlist = []
scaleart = 0
button = 0
alpha = 0
orig = bitmaps.BaseBitmap()
objekttext = ""
showo = False
shows = False
bitmapfile = ""


# Dialog erstellen
class Dialog(GeDialog):
    global objekttext, showo, shows

    def __init__(self):
        pass

    # Layout definieren
    def CreateLayout(self):
        # Objektname in Beschreibungstext einfügen
        objekttext = "Selected object is: " + op.GetName()
        self.SetTitle("RenameTexture")  # Titel definieren