def main():
    # Checks if selected object is valid
    if op is None:
        raise ValueError("op is none, please select one object.")

    # Retrieves the Vertex Color Tag
    tag = op.GetTag(c4d.Tvertexcolor)
    if tag is None:
        raise TypeError("Failed to retrieve the vertex tag color.")

    # Checks in Point mode
    if not tag.IsPerPointColor():
        # If not changes to Point mode
        tag.SetPerPointMode(True)

    # Obtains vertex colors data R/W addresses
    addrR = tag.GetDataAddressR()
    addrW = tag.GetDataAddressW()

    # Initializes black and red colors
    black = c4d.Vector4d(0, 0, 0, 1)
    red = c4d.Vector4d(1, 0, 0, 1)

    # By default the Vertex Color Tag is in Point mode
    # So GetDataCount() returns the number of points
    count = tag.GetDataCount()
    for idx in range(count):
        # If point color is black then changes it to red
        point = c4d.VertexColorTag.GetPoint(addrR, None, None, idx)
        if point == black:
            c4d.VertexColorTag.SetPoint(addrW, None, None, idx, red)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
Ejemplo n.º 2
0
def main():
    # Checks if there is an active object
    if op is None: return

    # Retrieves the Vertex Color Tag
    tag = op.GetTag(c4d.Tvertexcolor)
    if tag is None: return

    # Checks in Point mode
    if not tag.IsPerPointColor():
        # If not changes to Point mode
        tag.SetPerPointMode(True)

    # Obtains vertex colors data R/W addresses
    addrR = tag.GetDataAddressR()
    addrW = tag.GetDataAddressW()

    # Initializes black and red colors
    black = c4d.Vector4d(0, 0, 0, 0)
    red = c4d.Vector4d(1, 0, 0, 0)

    # By default the Vertex Color Tag is in Point mode
    # So GetDataCount() returns the number of points
    count = tag.GetDataCount()
    for idx in xrange(count):
        # If point color is black then changes it to red
        point = VertexColorTag.GetPoint(addrR, None, None, idx)
        if point == black:
            VertexColorTag.SetPoint(addrW, None, None, idx, red)

    c4d.EventAdd()
def main():
    # Checks if there is an active object
    if op is None: return

    # Retrieves Vertex Color Tag
    tag = op.GetTag(c4d.Tvertexcolor)
    if tag is None: return

    # Checks in Point mode
    if tag.IsPerPointColor():
        # If not changes to Polygon mode
        tag.SetPerPointMode(False)

    # Obtains Vertex Colors data address
    addr = tag.GetDataAddressW()

    # Initializes red color and Vertex Colors polygon
    red = c4d.Vector4d(1, 0, 0, 0)
    poly = {}
    poly['a'] = red
    poly['b'] = red
    poly['c'] = red
    poly['d'] = red

    # GetDataCount() returns the number of polygons in Polygon mode
    count = tag.GetDataCount()
    for idx in xrange(count):
        # Sets Vertex Colors red
        VertexColorTag.SetPolygon(addr, idx, poly)

    c4d.EventAdd()
Ejemplo n.º 4
0
        def parse_vertex_colors(index, c4d_mesh):
            colors = []
            color_key = 'COLOR_{}'.format(index)
            colortag = None
            if color_key in prim.attributes:
                colors = BinaryData.get_data_from_accessor(
                    gltf, prim.attributes[color_key])
                if colors:
                    nb_verts = len(verts)
                    colortag = c4d.VertexColorTag(nb_verts)
                    colortag.SetPerPointMode(True)
                    colortag.SetName(color_key)
                    vtx_color_data = colortag.GetDataAddressW()

                    has_alpha = len(colors[0]) > 3
                    for i in range(nb_verts):
                        c4d.VertexColorTag.SetPoint(
                            vtx_color_data, None, None, i,
                            c4d.Vector4d(colors[i][0], colors[i][1],
                                         colors[i][2],
                                         colors[i][3] if has_alpha else 1.0))

                c4d_mesh.InsertTag(colortag)

                self.has_vertex_colors = True

            return colortag
def main():
    # Checks if selected object is valid
    if op is None:
        raise ValueError("op is none, please select one object.")

    # Retrieves the Vertex Color Tag
    tag = op.GetTag(c4d.Tvertexcolor)
    if tag is None:
        raise TypeError("Failed to retrieve the vertex tag color.")

    # Checks in Point mode
    if tag.IsPerPointColor():
        # If not changes to Polygon mode
        tag.SetPerPointMode(False)

    # Obtains Vertex Colors data address
    addr = tag.GetDataAddressW()

    # Initializes red color and Vertex Colors polygon
    red = c4d.Vector4d(1, 0, 0, 1)
    poly = dict()
    poly['a'] = red
    poly['b'] = red
    poly['c'] = red
    poly['d'] = red

    # GetDataCount() returns the number of polygons in Polygon mode
    count = tag.GetDataCount()
    for idx in range(count):
        # Sets Vertex Colors red
        c4d.VertexColorTag.SetPolygon(addr, idx, poly)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
Ejemplo n.º 6
0
def main():
    # Opens a Dialog to choose a picture file
    bitmapPath = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES, title="Please Choose an Image:")
    if not bitmapPath:
        return

    # Loads the picture as a BaseBitmap
    bmp = c4d.bitmaps.BaseBitmap()
    if bmp.InitWith(bitmapPath)[0] != c4d.IMAGERESULT_OK:
        raise RuntimeError("Failed to load the Picture")

    # Retrieves a GeClipMap multiplied with a color. Value are from 0 to 255 for red, blue, green, alpha
    geClip = FillBitmapWithColor(bmp, c4d.Vector4d(100.0, 0.0, 0, 100.0))

    # Displays the Bitmap stored in the GeClipMap into the Picture Viewer
    c4d.bitmaps.ShowBitmap(geClip.GetBitmap())