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

    # Creates a default Cinema 4D Material, the created material only exist in the memory
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    if mat is None:
        raise RuntimeError("Failed to create a new BaseMaterial.")

    # Inserts the material in the active document
    doc.InsertMaterial(mat)

    # Checks if there is already a texture tag on the active object, if not creates it
    textureTag = op.GetTag(c4d.Ttexture)
    if not textureTag:
        textureTag = op.MakeTag(c4d.Ttexture)

    # If the texture tag is not available at this point, something went wrong
    if textureTag is None:
        raise RuntimeError("Failed to retrieve the texture tag.")

    # Links the newly created material from the textureTag Material link parameter
    textureTag[c4d.TEXTURETAG_MATERIAL] = mat

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
def create_standard_environment(doc, name, filepath):
    doc.StartUndo()
    # Create our Material for Sky Object
    mat = c4d.BaseMaterial(c4d.Mmaterial)

    mat.SetName(name)

    mat[c4d.MATERIAL_USE_COLOR] = False
    mat[c4d.MATERIAL_USE_LUMINANCE] = True
    mat[c4d.MATERIAL_USE_REFLECTION] = False
    mat[c4d.MATERIAL_PREVIEWSIZE] = c4d.MATERIAL_PREVIEWSIZE_1024

    _bmp_shader(doc, filepath, c4d.MATERIAL_LUMINANCE_SHADER, mat)

    doc.InsertMaterial(mat)
    doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
    # mat.Message(c4d.MSG_UPDATE)
    # mat.Update(True, True)

    # Create Sky Object
    sky = c4d.BaseObject(c4d.Osky)
    sky.SetName(name)
    doc.InsertObject(sky)
    doc.AddUndo(c4d.UNDOTYPE_NEW, sky)

    # Create Texture Tag and set our Material
    tag = c4d.BaseTag(c4d.Ttexture)
    sky.InsertTag(tag)
    tag.SetMaterial(mat)
    doc.AddUndo(c4d.UNDOTYPE_NEW, tag)

    doc.EndUndo()
    c4d.EventAdd()
Example #3
0
def main():
    doc.StartUndo()
    folder = s.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, 'Select image folder',
                          c4d.FILESELECT_DIRECTORY, '')
    if not folder: return
    files = os.listdir(folder)

    for f in files:
        mat = c4d.BaseMaterial(c4d.Mmaterial)
        mat[c4d.MATERIAL_USE_REFLECTION] = 0
        mat[c4d.MATERIAL_USE_ALPHA] = 1
        shd = c4d.BaseShader(c4d.Xbitmap)
        shd[c4d.BITMAPSHADER_FILENAME] = folder + "\\" + f
        alpha = c4d.BaseShader(c4d.Xbitmap)
        alpha[c4d.BITMAPSHADER_FILENAME] = folder + "\\" + f
        mat[c4d.MATERIAL_COLOR_SHADER] = shd
        mat[c4d.MATERIAL_ALPHA_SHADER] = alpha
        mat.InsertShader(shd)
        mat.InsertShader(alpha)
        mat.Message(c4d.MSG_UPDATE)
        mat.Update(True, True)
        doc.InsertMaterial(mat)
        doc.AddUndo(c4d.UNDOTYPE_NEW, mat)

        c4d.EventAdd()
        doc.EndUndo()
Example #4
0
def CreateMaterials(rootShaders, displacements, links):
    # {ArnoldNode: GvNode}
    shaderMap = {}

    for i, rootShader in enumerate(rootShaders):
        if not rootShader or not rootShader.IsValid(): continue
        rootShaderType = rootShader.GetNodeEntryName()
        rootShaderName = rootShader.GetName()
        PrintInfo("Create material for %s (%s)" %
                  (rootShaderName, rootShaderType))

        # create material
        mat = c4d.BaseMaterial(ARNOLD_SHADER_NETWORK)
        if mat is None:
            PrintError("Failed to create material")
            continue
        mat.SetName("ASN_%02d" % (i + 1))
        doc.InsertMaterial(mat)

        # create root shader
        rootShaderNode = shaderMap.get(rootShader)
        if rootShaderNode is None:
            rootShaderNode = CreateShader(mat, rootShader, BEAUTY_ROOT_POSX,
                                          BEAUTY_ROOT_POSY)
            if rootShaderNode is None:
                PrintError("Failed to create shader %s (%s)" %
                           (rootShaderName, rootShaderType))
                continue
            shaderMap[rootShader] = rootShaderNode

        SetRootShader(mat, rootShaderNode, ARNOLD_BEAUTY_PORT_ID)

        # create links
        CreateLinks(mat, rootShader, links, shaderMap, BEAUTY_ROOT_POSX,
                    BEAUTY_ROOT_POSY, True)

        # displacement root
        dispRootShader = displacements.get(rootShader)
        if dispRootShader and dispRootShader.IsValid():
            dispRootShaderType = dispRootShader.GetNodeEntryName()
            dispRootShaderName = dispRootShader.GetName()
            PrintInfo("Add displacement")

            dispRootShaderNode = shaderMap.get(dispRootShader)
            if dispRootShaderNode is None:
                dispRootShaderNode = CreateShader(mat, dispRootShader,
                                                  DISPLACEMENT_ROOT_POSX,
                                                  DISPLACEMENT_ROOT_POSY)
                if dispRootShaderNode is None:
                    PrintError(
                        "Failed to create displacement shader %s (%s)" %
                        dispRootShaderName, dispRootShaderType)
                    continue
                shaderMap[dispRootShader] = dispRootShaderNode

            SetRootShader(mat, dispRootShaderNode, ARNOLD_DISPLACEMENT_PORT_ID)

            # displacement links
            CreateLinks(mat, dispRootShader, links, shaderMap,
                        DISPLACEMENT_ROOT_POSX, DISPLACEMENT_ROOT_POSY, False)
Example #5
0
def SetMatProperty(matName, value, targetId, targetDoc):
    DebugPrint('  -> Inserting "' + str(value) + '" as "' +
               MTL_KEYWORDS_NAMES[targetId] + '" of material "' + matName +
               '".')
    mat = targetDoc.SearchMaterial(matName)

    # If material not found, create it
    if mat == None:
        mat = c4d.BaseMaterial(c4d.Mmaterial)
        mat.SetName(matName)
        targetDoc.InsertMaterial(mat)

    # Cancel if material could not be found or created
    if mat == None:
        DebugPrint(
            '     ERROR: COULD NEITHER FIND NOR ALLOCATE TARGET MATERIAL!')
        return

    # Add undo
    targetDoc.AddUndo(c4d.UNDOTYPE_CHANGE, mat)

    # Set property
    mat[targetId] = value * MTL_KEYWORDS_MUL[targetId]

    # Activate channel
    mat[MTL_KEYWORDS_USE[targetId]] = True
    if targetId == c4d.MATERIAL_SPECULAR_WIDTH:
        if value == 0.0:
            mat[MTL_KEYWORDS_USE[targetId]] = False
            DebugPrint('Turning Spec off cuz 0 width')

    # Update material
    mat.Update(True, True)
def CreateMaterialForNodeSpace(nodespaceId):
    # Create a baseMaterial first
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    if mat is None:
        raise ValueError("Cannot create a BaseMaterial.")

    # Retrieve the reference of the material as a node material.
    nodeMaterial = mat.GetNodeMaterialReference()
    if nodeMaterial is None:
        raise ValueError("Cannot retrieve nodeMaterial reference.")

    # Add a graph for the space Id
    addedGraph = nodeMaterial.AddGraph(nodespaceId)
    if addedGraph is None:
        raise ValueError("Cannot add a GraphNode for this NodeSpace.")

    # Retrieve the Nimbus reference for a specific NodeSpace
    nimbusRef = mat.GetNimbusRef(nodespaceId)
    if nimbusRef is None:
        raise ValueError(
            "Cannot retrieve the nimbus reference for that NodeSpace.")

    # Retrieve the graph corresponding to that NodeSpace.
    graph = nimbusRef.GetGraph()
    if graph is None:
        raise ValueError("Cannot retrieve the graph of this nimbus NodeSpace.")

    # Retrieve the root of the graph
    root = graph.GetRoot()

    # Insert the material in the document
    doc.InsertMaterial(mat)
    return root
    def CreateC4DMaterial(self):
        # create a standard C4D material
        newMaterial = c4d.BaseMaterial(c4d.Mmaterial)

        newMaterial.SetName(self.materialName)

        return newMaterial
    def CreateVRayMaterial(self):
        # create a VRay material
        newMaterial = c4d.BaseMaterial(VrayAdvancedMaterial)

        newMaterial.SetName(self.materialName)

        if self.diffuseEnabled:
            pass

        if self.specularEnabled:
            pass

        if self.refractionEnabled:
            pass

        if self.opacityEnabled:
            pass

        if self.emissionEnabled:
            pass

        if self.bumpEnabled:
            pass

        return newMaterial
    def CreateOctaneMaterial(self):
        # create an octane material
        newMaterial = c4d.BaseMaterial(ID_OCTANE_DIFFUSE_MATERIAL)
        newMaterial[OCT_MATERIAL_TYPE] = 2516  # universal material
        newMaterial.SetName(self.materialName)

        return newMaterial
Example #10
0
def main():
    # Retrieves active material
    mat = doc.GetActiveMaterial()
    if mat is None:
        return

    # Checks active material is a standard material
    if not mat.IsInstanceOf(c4d.Mmaterial):
        return

    # The active material's color
    color = mat.GetParameter(c4d.MATERIAL_COLOR_COLOR, c4d.DESCFLAGS_GET_0)
    if color is None:
        return

    # Calculates the complementary color
    res = cc.ColorHarmonyGetComplementary(color, False)
    # Retrieves the complementary color
    complementaryColor = res[1]

    # Creates a new material with complementary color
    complementaryMat = c4d.BaseMaterial(c4d.Mmaterial)
    if complementaryMat is None:
        return

    # Sets the complementary color as material's color
    complementaryMat.SetParameter(c4d.MATERIAL_COLOR_COLOR, complementaryColor,
                                  c4d.DESCFLAGS_SET_0)
    #Inserts the material with complementary color into the active document
    doc.InsertMaterial(complementaryMat)

    c4d.EventAdd()
Example #11
0
def importVox(path):
    #parse file
    with open(path, 'rb') as f:

        #check filetype
        bytes = f.read(4)
        file_id = struct.unpack(">4s", bytes)
        if file_id[0] == 'VOX ':

            #init material list
            matlist = []
            BaseCube = c4d.BaseObject(c4d.Ocube)
            BaseCube[c4d.PRIM_CUBE_DOFILLET] = True
            BaseCube[c4d.PRIM_CUBE_FRAD] = 8
            BaseCube[c4d.PRIM_CUBE_SUBF] = 1
            doc.InsertObject(BaseCube)

            #skip header
            f.seek(56)

            #read number of voxels, stuct.unpack parses binary data to variables
            bytes = f.read(4)
            numvoxels = struct.unpack('<I', bytes)

            #iterate through voxels
            for x in range(0, numvoxels[0]):

                #read voxels, ( each voxel : 1 byte x 4 : x, y, z, colorIndex ) x numVoxels
                bytes = f.read(4)
                voxel = struct.unpack('<bbbB', bytes)

                #generate Cube and set position, change to 'Oinstance' for instances
                MyCube = c4d.BaseObject(c4d.Oinstance)
                MyCube[c4d.INSTANCEOBJECT_RENDERINSTANCE] = True
                MyCube[c4d.INSTANCEOBJECT_LINK] = BaseCube
                MyCube.SetAbsPos(
                    c4d.Vector(-voxel[1] * 200, voxel[2] * 200,
                               voxel[0] * 200))

                #update material list, generate new material only if it isn't in the list yet
                matid = voxel[3]
                if matid not in matlist:
                    matlist.append(matid)
                    myMat = c4d.BaseMaterial(c4d.Mmaterial)
                    myMat.SetName(str(matid))
                    myMat[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(
                        random.random(), random.random(), random.random())
                    doc.InsertMaterial(myMat)

                #assign material to voxel and insert everything into the scene
                mat = doc.SearchMaterial(str(matid))
                textag = c4d.TextureTag()
                textag.SetMaterial(mat)
                MyCube.InsertTag(textag)
                doc.InsertObject(MyCube)

        else:
            gui.MessageDialog('Not a .VOX file')
Example #12
0
    def convertMat(self, sourceMat, matType="Std"):

        self.matType = matType

        print("----- Converting : " + sourceMat.GetName() + " -----")

        matName = sourceMat.GetName()
        mat = None

        if matType == "Std":
            mat = c4d.BaseMaterial(5703)
            self.MatNameAdd = "_STD"
        elif matType == "Vray":
            mat = c4d.BaseMaterial(1038954)
            self.MatNameAdd = "_VR"
        elif matType == "Redshift":
            mat = RedshiftMaterial()
            self.MatNameAdd = "_RS"
        elif matType == "Octane":
            mat = c4d.BaseMaterial(1029501)
            self.MatNameAdd = "_OCT"
        elif matType == "Corona":
            mat = c4d.BaseMaterial(1032100)
            self.MatNameAdd = "_CRNA"

        mat.SetName(matName + self.MatNameAdd)
        self.NewMatList.append([sourceMat, mat])

        self.convertShader(sourceMat, mat)

        if mat == None:
            return False

        mat.Message(c4d.MSG_UPDATE)
        mat.Update(True, True)

        doc = c4d.documents.GetActiveDocument()
        doc.InsertMaterial(mat)
        c4d.EventAdd()

        print("----- Converted : " + matName + " : " + mat.GetName() +
              " -----")
        bc = c4d.BaseContainer()
        c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_CHANNEL, bc)
        return True
def matbasecontainercopy():
    mat = doc.GetActiveMaterial()
    bc = mat.GetData()

    newmat = c4d.BaseMaterial(ARNOLD_SHADER_NETWORK)
    newmat.SetData(bc, add=False)

    doc.InsertMaterial(newmat)
    c4d.EventAdd()
Example #14
0
    def _byplay_plane_material(self):
        name = u"Byplay Plane"
        for mat in self.doc.GetMaterials():
            if mat.GetName() == name:
                return mat

        mat = c4d.BaseMaterial(c4d.Mshadowcatcher)
        mat.SetName(name)
        self.doc.InsertMaterial(mat)
        return mat
def main():
    # Defines the initials state of the scene (the state that will be restored if the user do an "Undo")
    doc.StartUndo()

    # Creates few objects, tag, material to be inserted into the document later
    null = c4d.BaseObject(c4d.Onull)
    cube = c4d.BaseObject(c4d.Ocube)
    textureTag = c4d.BaseTag(c4d.Ttexture)
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    if null is None or cube is None or textureTag is None or mat is None:
        raise RuntimeError(
            "Failed to create null or cube or textureTag or mat")

    # Inserts a Material into the active document
    doc.InsertMaterial(mat)
    doc.AddUndo(c4d.UNDOTYPE_NEW, mat)

    # Inserts both objects
    doc.InsertObject(null)
    doc.AddUndo(c4d.UNDOTYPE_NEW, null)

    # Inserts both objects
    doc.InsertObject(cube)
    doc.AddUndo(c4d.UNDOTYPE_NEW, cube)

    # Inserts the Texture Tag to the cube object
    cube.InsertTag(textureTag)
    doc.AddUndo(c4d.UNDOTYPE_NEW, textureTag)

    # Defines the material used in the Texture Tag to our material
    doc.AddUndo(c4d.UNDOTYPE_CHANGE, textureTag)
    textureTag[c4d.TEXTURETAG_MATERIAL] = mat

    # Ends the first Undo step, so when the user will press Undo 1 time the document will be restored to this scene state.
    doc.EndUndo()

    # Defines another Undo step (so if the user want to go to the initial state he have to press Undo twice)
    doc.StartUndo()

    # Moves the cube object under the Null Object
    doc.AddUndo(c4d.UNDOTYPE_HIERARCHY_PSR, cube)
    cube.Remove()
    cube.InsertUnderLast(null)

    # Delete the Texture Tag
    doc.AddUndo(c4d.UNDOTYPE_DELETE, textureTag)
    textureTag.Remove()

    # Defines the final state of the scene
    doc.EndUndo()

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
Example #16
0
def main():
    eazymat = doc.GetActiveMaterial()
    if not eazymat:
        newmat = c4d.BaseMaterial(5703)
        doc.InsertMaterial(newmat)
        doc.AddUndo(c4d.UNDOTYPE_NEW, newmat)
        c4d.EventAdd()
        newmat[c4d.MATERIAL_COLOR_COLOR] = randomColor()
        newmat.SetBit(c4d.BIT_ACTIVE)

    if eazymat:
        eazymat[c4d.MATERIAL_COLOR_COLOR] = randomColor()
    def CreateArnoldMaterial(self):
        # create an Arnold Shader Network
        newMaterial = c4d.BaseMaterial(ARNOLD_SHADER_NETWORK)

        newMaterial.SetName(self.materialName)

        # crete and attach Arnold Standard Shader
        rootShader = CreateArnoldShader(self.newMaterial,
                                        C4DAIN_STANDARD_SURFACE, 0, 50)
        SetRootShader(newMaterial, rootShader, ARNOLD_BEAUTY_PORT_ID)

        return newMaterial
Example #18
0
def InsertTexture(fBase, fName, matName, targetId, targetDoc , flipNormalY):
    DebugPrint('  -> Inserting "' + fName + '" into channel "' + MTL_KEYWORDS_NAMES[targetId] + '" of material "' + matName + '".')
    mat = targetDoc.SearchMaterial(matName)
   
    # If material not found, create it
    if mat == None:
        mat = c4d.BaseMaterial(c4d.Mmaterial)
        mat.SetName(matName)
        targetDoc.AddUndo(c4d.UNDOTYPE_NEW, mat)
        targetDoc.InsertMaterial(mat)

    # Cancel if material could not be found or created
    if mat == None:
        DebugPrint('     ERROR: COULD NEITHER FIND NOR ALLOCATE TARGET MATERIAL!')
        return

    # Create a new bitmap shader, insert texture
    tShader = c4d.BaseShader(c4d.Xbitmap)
    if tShader == None:
        DebugPrint('     ERROR: COULD NOT ALLOCATE BITMAP SHADER!')
        return

    fSlash = '/'
    fPath = str(fBase) + str(fSlash) + str(fName)

    tShader[c4d.BITMAPSHADER_FILENAME] = fPath #

    # Add undo
    targetDoc.AddUndo(c4d.UNDOTYPE_CHANGE, mat)

    # Activate channel
    mat[MTL_KEYWORDS_USE[targetId]] = True

    # Insert texture into channel
    mat[targetId] = tShader

    # Insert shader into node tree
    mat.InsertShader(tShader)

    # Special cases
    if targetId == c4d.MATERIAL_ALPHA_SHADER:
        # If we set an alpha map and the format is PNG of TIFF, it's likely to have an alpha channel, so we switch off "Image Alpha"
        if fName.endswith(('.tif','.tiff','.png','.tga')):
            mat[c4d.MATERIAL_ALPHA_IMAGEALPHA] = False

    #flip normals if needed
    if flipNormalY == 1:
        mat[c4d.MATERIAL_NORMAL_REVERSEY] = True
       

    # Update material
    mat.Update(True, True)
Example #19
0
 def _create_bg(self):
     bg_obj = create_object(self.doc,
                            u"Background {}".format(self.recording_id),
                            c4d.Obackground)
     bg_mat = c4d.BaseMaterial(c4d.Mmaterial)
     assign_shader_color(
         bg_mat,
         make_color_shader(
             self.recording_storage.first_frame_path(self.recording_id), 1,
             self.frame_count, self.fps))
     assign_material_frontal(self.doc, bg_obj, bg_mat)
     bg_mat.SetName(bg_obj.GetName())
     return bg_mat
Example #20
0
 def _create_sky(self, path):
     sky_obj = create_object(self.doc, u"Sky {}".format(self.recording_id),
                             c4d.Osky)
     sky_mat = c4d.BaseMaterial(c4d.Mmaterial)
     assign_shader_luminance(sky_mat, make_color_shader(path))
     assign_material_spherical(self.doc, sky_obj, sky_mat)
     sky_mat.SetName(sky_obj.GetName())
     sky_mat.SetChannelState(c4d.CHANNEL_COLOR, False)
     sky_mat.SetChannelState(c4d.CHANNEL_LUMINANCE, True)
     sky_obj[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = c4d.OBJECT_OFF
     comp_tag = self._add_compositing(sky_obj)
     comp_tag[c4d.COMPOSITINGTAG_SEENBYCAMERA] = False
     return sky_obj
Example #21
0
def createMaterial(name=None, color=None):
    ''' Create a new material. '''
    doc = c4d.documents.GetActiveDocument()
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    doc.StartUndo()
    doc.InsertMaterial(mat)
    if (name):
        mat.SetName(name)
    if (color):
        changeColor(mat, color)
    doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
    c4d.EventAdd()
    doc.EndUndo()
    return mat
def main():
    fn = s.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Select reference file",
                      c4d.FILESELECT_LOAD)
    if fn == None: return None
    res = g.InputDialog("Resolution", "1280x720")
    width = float(res.split("x")[0])
    height = float(res.split("x")[1])
    ren = doc.GetActiveRenderData()
    zpos = ren[c4d.RDATA_XRES_VIRTUAL]
    c4d.CallCommand(12544)  # Create new viewport
    bd = doc.GetActiveBaseDraw()
    cam = c4d.BaseObject(c4d.Ocamera)
    cam.SetName("REFERENCE_CAMERA")
    cam[c4d.CAMERAOBJECT_TARGETDISTANCE] = width
    cam[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2
    doc.InsertObject(cam)
    plane = c4d.BaseObject(c4d.Oplane)
    plane[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2
    plane.SetName("REFERENCE_PLANE")
    plane[c4d.PRIM_AXIS] = 5
    plane[c4d.PRIM_PLANE_SUBW] = 1
    plane[c4d.PRIM_PLANE_SUBH] = 1
    plane[c4d.PRIM_PLANE_WIDTH] = width
    plane[c4d.PRIM_PLANE_HEIGHT] = height
    plane[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Z] = zpos
    plane.InsertUnder(cam)
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    mat.SetName("REFERENCE_MATERIAL")
    mat[c4d.MATERIAL_USE_REFLECTION] = 0
    mat[c4d.MATERIAL_ANIMATEPREVIEW] = 1
    color = c4d.BaseShader(c4d.Xbitmap)
    color[c4d.BITMAPSHADER_FILENAME] = fn
    doc.ExecutePasses(None, 0, 1, 1, 0)
    c4d.CallButton(color, c4d.BITMAPSHADER_CALCULATE)
    mat[c4d.MATERIAL_COLOR_SHADER] = color
    mat.InsertShader(color)
    mat.Message(c4d.MSG_UPDATE)
    mat.Update(True, True)
    doc.InsertMaterial(mat)
    t = c4d.BaseTag(5616)
    plane.InsertTag(t)
    tag = plane.GetFirstTag()
    tag[c4d.TEXTURETAG_MATERIAL] = mat
    tag[c4d.TEXTURETAG_PROJECTION] = 6
    bd[c4d.BASEDRAW_DATA_TINTBORDER_OPACITY] = 1
    bd[c4d.BASEDRAW_DATA_CAMERA] = cam
    bd[c4d.BASEDRAW_TITLE] = "REFERENCE_VIEWPORT"
    cam[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X] = 5000000
    c4d.EventAdd()
Example #23
0
def Material(img,coloverride):
    #create material
    mat = c4d.BaseMaterial(5703)  
    if coloverride == True:
          mat[c4d.MATERIAL_USE_COLOR] = True
          mat[c4d.MATERIAL_USE_LUMINANCE] = False
    else:
        mat[c4d.MATERIAL_USE_COLOR] = False
        mat[c4d.MATERIAL_USE_LUMINANCE] = True
    mat[c4d.MATERIAL_USE_ALPHA] = True
    mat[c4d.MATERIAL_USE_REFLECTION] = False
    mat[c4d.MATERIAL_PREVIEWSIZE] = + 12
    mat[c4d.MATERIAL_ANIMATEPREVIEW] = True
    doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
    doc.InsertMaterial(mat)
    return mat 
Example #24
0
def main():

    # Create a baseMaterial first
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    if mat is None:
        raise ValueError("Cannot create a BaseMaterial")

    # Retrieve the reference of the material as a node Material
    nodeMaterial = mat.GetNodeMaterialReference()
    if nodeMaterial is None:
        raise ValueError("Cannot retrieve nodeMaterial reference")

    # Retrieve the current node space Id
    nodespaceId = c4d.GetActiveNodeSpaceId()

    # Add a graph for the space Id
    addedGraph = nodeMaterial.AddGraph(nodespaceId)
    if addedGraph is None:
        raise ValueError("Cannot add a graphnode for this nodespace")

    # Retrieve the Nimbus reference for a specific node space
    nimbusRef = mat.GetNimbusRef(nodespaceId)
    if nimbusRef is None:
        raise ValueError("Cannot retrieve the nimbus ref for that node space")

    # Retrieve the graph corresponding to that node space
    graph = nimbusRef.GetGraph()
    if graph is None:
        raise ValueError("Cannot retrieve the graph of this nimbus ref")

    # Retrieve the end node of this graph
    endNodePath = nimbusRef.GetPath(
        maxon.frameworks.nodespace.NIMBUS_PATH.MATERIALENDNODE)

    # Solo the end node
    nimbusRef.SetPath(maxon.frameworks.nodespace.NIMBUS_PATH.SOLO, endNodePath)

    # Retrieve the solo node of this graph
    soloNodePath = nodeMaterial.GetSoloNodePath(nodespaceId)

    print(endNodePath == soloNodePath)

    # Insert the material In the document
    doc.InsertMaterial(mat)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
Example #25
0
def create_octane_specular_material(material):
    mat = c4d.BaseMaterial(constants.ID_OCTANE_DIFFUSE_MATERIAL)
    mat[c4d.OCT_MATERIAL_TYPE] = constants.ID_OCTANE_SPECULAR_TYPE
    projection = create_octane_projection()
    for material_type, texture_path in material.get_paths().items():
      is_float = material_parser.PARSER_DATA[material_type].is_float()
      shader = None
      if material_type is constants.DISPLACEMENT:
        shader = create_octane_displacement(texture_path, projection)
      else:
        shader = create_octane_image_texture(texture_path, is_float, material_type == constants.GLOSS, projection)
      mat[material_parser.PARSER_DATA[material_type].get_material_id()] = shader
      mat.InsertShader(shader)

    mat.SetName(material.get_name())

    return mat
Example #26
0
def main():
    doc.StartUndo()
    folder = s.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, 'Select image folder',
                          c4d.FILESELECT_DIRECTORY, '')
    if not folder: return
    files = os.listdir(folder)

    for f in files:
        mat = c4d.BaseMaterial(c4d.Mmaterial)
        path = folder + "\\" + f

        # enable or disable channels
        mat[c4d.MATERIAL_USE_REFLECTION] = 0
        mat[c4d.MATERIAL_USE_LUMINANCE] = 1
        mat[c4d.MATERIAL_USE_ALPHA] = 1

        # color channel
        color = c4d.BaseShader(c4d.Xbitmap)
        color[c4d.BITMAPSHADER_FILENAME] = path
        mat[c4d.MATERIAL_COLOR_SHADER] = color

        # luminance channel
        luminance = c4d.BaseShader(c4d.Xbitmap)
        luminance[c4d.BITMAPSHADER_FILENAME] = path
        mat[c4d.MATERIAL_LUMINANCE_SHADER] = luminance

        # alpha channel
        alpha = c4d.BaseShader(c4d.Xbitmap)
        alpha[c4d.BITMAPSHADER_FILENAME] = path
        mat[c4d.MATERIAL_ALPHA_SHADER] = alpha

        # assign shaders to material
        mat.InsertShader(color)
        mat.InsertShader(luminance)
        mat.InsertShader(alpha)

        # other stuff
        mat.Message(c4d.MSG_UPDATE)
        mat.Update(True, True)
        matname = f.split(".")[0]
        mat.SetName(matname)
        doc.InsertMaterial(mat)
        doc.AddUndo(c4d.UNDOTYPE_NEW, mat)

        c4d.EventAdd()
        doc.EndUndo()
Example #27
0
def main():
    doc = c4d.documents.GetActiveDocument()  # Get active Cinema 4D document
    doc.StartUndo()  # Start recording undos
    folder = s.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, 'Select image folder',
                          c4d.FILESELECT_DIRECTORY, '')
    if not folder: return
    try:  # Try to execute following script
        files = os.listdir(folder)
        for f in files:  # Loop through files
            mat = c4d.BaseMaterial(c4d.Mmaterial)
            path = folder + "\\" + f
            mat[c4d.MATERIAL_USE_REFLECTION] = 0  # Disable reflection channel

            # Color channel
            color = c4d.BaseShader(c4d.Xbitmap)
            color[c4d.BITMAPSHADER_FILENAME] = path
            mat[c4d.MATERIAL_COLOR_SHADER] = color

            # Luminance channel
            luminance = c4d.BaseShader(c4d.Xbitmap)
            luminance[c4d.BITMAPSHADER_FILENAME] = path
            mat[c4d.MATERIAL_LUMINANCE_SHADER] = luminance

            # Alpha channel
            alpha = c4d.BaseShader(c4d.Xbitmap)
            alpha[c4d.BITMAPSHADER_FILENAME] = path
            mat[c4d.MATERIAL_ALPHA_SHADER] = alpha

            # Assign shaders to material
            mat.InsertShader(color)  # Insert shader to color channel
            mat.InsertShader(luminance)  # Insert shader to luminance channel
            mat.InsertShader(alpha)  # Insert shader to alpha channel

            # Other stuff
            mat.Message(c4d.MSG_UPDATE)
            mat.Update(True, True)  # Update material
            matname = f.split(".")[0]  # Get material name from file path
            mat.SetName(matname)  # Set material name
            doc.InsertMaterial(mat)  # Insert new material to document
            doc.AddUndo(c4d.UNDOTYPE_NEW,
                        mat)  # Add undo command for inserting new material
    except:  # If something went wrong
        pass  # Do nothing
    doc.EndUndo()  # Stop recording undos
    c4d.EventAdd()  # Refresh Cinema 4D
Example #28
0
def main():
    doc.StartUndo()
    hexcolor = c4d.gui.InputDialog("HEX-color")
    rgb = hex_to_rgb(hexcolor)
    color = c4d.Vector(
        float(rgb[0]) / 255,
        float(rgb[1]) / 255,
        float(rgb[2]) / 255)
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    mat[c4d.MATERIAL_COLOR_COLOR] = color
    mat.Message(c4d.MSG_UPDATE)
    mat.Update(True, True)
    mat.SetName(str(hexcolor))
    doc.InsertMaterial(mat)
    doc.AddUndo(c4d.UNDOTYPE_NEW, mat)

    c4d.EventAdd()
    doc.EndUndo()
Example #29
0
 def creerTexture(self, relatif=False, win=False):
     self.mat = c4d.BaseMaterial(c4d.Mmaterial)
     self.doc.InsertMaterial(self.mat)
     self.doc.AddUndo(c4d.UNDOTYPE_NEW, self.mat)
     shd = c4d.BaseList2D(c4d.Xbitmap)
     #ATENTION au backslash suivi de t ou de p cela est consid\r\ comme tab ou
     fn = self.fn
     if WIN:
         fn = self.fn.decode('cp1252').encode('utf-8')
     if is_in_doc_path(fn, self.doc):
         shd[c4d.BITMAPSHADER_FILENAME] = os.path.basename(fn)
     else:
         shd[c4d.BITMAPSHADER_FILENAME] = fn
     self.mat[c4d.MATERIAL_COLOR_SHADER] = shd
     self.mat.InsertShader(shd)
     self.mat[c4d.MATERIAL_PREVIEWSIZE] = 12  #taille de pr\visualisation
     self.mat.SetName(os.path.basename(fn)[:-4])
     self.mat.Message(c4d.MSG_UPDATE)
     self.mat.Update(True, True)
def creer_mat(fn, nom, alpha=False):
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    mat.SetName(nom)
    doc.InsertMaterial(mat)
    shd = c4d.BaseList2D(c4d.Xbitmap)
    shd[c4d.BITMAPSHADER_FILENAME] = fn
    mat[c4d.MATERIAL_COLOR_SHADER] = shd
    mat.InsertShader(shd)
    mat[c4d.MATERIAL_USE_SPECULAR] = False

    if alpha:
        mat[c4d.MATERIAL_USE_ALPHA] = True
        shda = c4d.BaseList2D(c4d.Xbitmap)
        shda[c4d.BITMAPSHADER_FILENAME] = fn
        mat[c4d.MATERIAL_ALPHA_SHADER] = shda
        mat.InsertShader(shda)

    mat.Message(c4d.MSG_UPDATE)
    mat.Update(True, True)
    return mat