Exemplo n.º 1
0
def main():
    # Creates a Standard C4D Material
    mat = c4d.Material()
    if mat is None:
        raise RuntimeError("Failed to create a new default material.")

    # Creates a bitmap shader
    sha = c4d.BaseList2D(c4d.Xbitmap)
    if sha is None:
        raise RuntimeError("Failed to create a bitmap shader.")

    # Defines the path of the bitmap shader
    sha[c4d.BITMAPSHADER_FILENAME] = "FileName"

    # Defines the material color shader to new created one.
    mat[c4d.MATERIAL_COLOR_SHADER] = sha

    # Inserts the shader into the material
    mat.InsertShader(sha)

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

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
def UpdateMaterial():
    global Polygon
    global shader

    _mat = doc.SearchMaterial("OBJ Sequence Material")
    _tags = [t for t in Polygon.GetTags() if t.GetType() == c4d.Ttexture]
    _tag = None

    for t in _tags:
        if t.GetName() == "OBJ Sequence Texture Tag":
            _tag = t
            break

    if not _mat:
        _mat = c4d.Material()
        _mat.SetName("OBJ Sequence Material")
        _mat.SetChannelState(c4d.CHANNEL_COLOR, False)
        _mat.SetChannelState(c4d.CHANNEL_LUMINANCE, True)

        _mat[c4d.MATERIAL_LUMINANCE_SHADER] = shader
        _mat.InsertShader(shader)
        doc.InsertMaterial(_mat)

    if not _tag:
        _tag = c4d.TextureTag()
        _tag.SetMaterial(_mat)
        _tag.SetName("OBJ Sequence Texture Tag")
        Polygon.InsertTag(_tag)
def main():
    # Creates a standard C4D Material
    mat = c4d.Material()
    if mat is None:
        raise RuntimeError("Failed to create a new default material.")

    # Removes the default specular layer
    mat.RemoveReflectionLayerIndex(0)

    # Adds a layer
    layer = mat.AddReflectionLayer()
    if layer is None:
        raise RuntimeError("Failed to create a new reflection layer.")

    # Sets the Layer to GGX mode
    mat[layer.GetDataID() + c4d.REFLECTION_LAYER_MAIN_DISTRIBUTION] = c4d.REFLECTION_DISTRIBUTION_GGX

    # Defines the Roughness float value
    mat[layer.GetDataID() + c4d.REFLECTION_LAYER_MAIN_VALUE_ROUGHNESS] = 0.75

    # Defines the layer color value
    mat[layer.GetDataID() + c4d.REFLECTION_LAYER_COLOR_COLOR] = c4d.Vector(1, 0.25, 0.25)

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

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
Exemplo n.º 4
0
    def create_material(self, name):
        mat = c4d.Material()
        mat.SetName(name)
        mat[c4d.MATERIAL_USE_ALPHA] = False
        mat[c4d.MATERIAL_USE_COLOR] = False
        mat[c4d.MATERIAL_USE_LUMINANCE] = False
        mat[c4d.MATERIAL_USE_NORMAL] = False
        mat[c4d.MATERIAL_USE_SPECULAR] = False
        mat[c4d.MATERIAL_USE_TRANSPARENCY] = False

        return mat
Exemplo n.º 5
0
def main():
    
    mat = c4d.Material(c4d.Mbase)
    mat.SetName('rope')
    
    for i in obj_list():       
    
        if i.GetType() == 5181 or i.GetType() == 5186 or i.GetType() == 5101:            
            doc.StartUndo()
                
            sweep = c4d.BaseObject(c4d.Osweep)
            doc.AddUndo(c4d.UNDOTYPE_NEW, sweep)
            
            sweep.InsertUnderLast(i)
            sweep.InsertAfter(i)

            sweep.SetPhong(True,True, 45)
            sweep.SetName('Rope')
            nGone = c4d.BaseObject(5179)
            doc.AddUndo(c4d.UNDOTYPE_NEW, nGone)
            nGone[c4d.PRIM_NSIDE_RADIUS]=0.65
            nGone[c4d.PRIM_NSIDE_SIDES]=12

            nGone.InsertUnder(sweep)
            doc.AddUndo(c4d.UNDOTYPE_CHANGE, i)
            i.InsertAfter(nGone)
            
            tag = sweep.MakeTag(c4d.Ttexture)
            tag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
            tag[c4d.TEXTURETAG_TILESY] = len_spline(i)/10*3
            
            doc.InsertMaterial(mat)
            doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
            tag.SetMaterial(mat)
            
            if press_button() == 1:
                tag = sweep.MakeTag(1036222)
                tag[c4d.REDSHIFT_OBJECT_GEOMETRY_OVERRIDE]=True
                tag[c4d.REDSHIFT_OBJECT_GEOMETRY_SUBDIVISIONENABLED]=True
                tag[c4d.REDSHIFT_OBJECT_GEOMETRY_DISPLACEMENTENABLED]=True
                
                doc.EndUndo()
        
        else: print 'This is not a spline'
        
    c4d.EventAdd()
Exemplo n.º 6
0
def main():
    f=open('/Users/david/Desktop/goxel-to-c4d/fish.txt', 'r')
    t=f.readlines()
    f.close()

    # Generates matrices and colors for 100 instances
    for l in t:
        if(not l.startswith("#")):
            inf = l.split(" ")

            obj = c4d.BaseObject(c4d.Ocube)

            obj.SetRelPos(c4d.Vector(int(inf[0]) * 20, int(inf[1]) * 20, int(inf[2]) * 20))
            obj.SetRelScale(c4d.Vector(0.1, 0.1, 0.1))
            doc.InsertObject(obj)

            mat = c4d.Material()
            mat.RemoveReflectionLayerIndex(0)
            color = mat[c4d.MATERIAL_COLOR_COLOR]

            #res = c4d.modules.colorchooser.ColorHarmonyGetComplementary(color, False)
            #print(res)

            he = inf[3]
            print(he)

            r, g, b = he[:2], he[2:4], he[4:]
            r, g, b = [int(n, 16) for n in (r, g, b)]
            print(str(float(r) / 255.0) + " " + str(float(g) / 255.0) + " " + " " + str(float(b) / 255.0))



            mat[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(float(r) / 255.0,float(g) / 255.0,float(b) / 255.0)

            doc.InsertMaterial(mat)

            textureTag = obj.MakeTag(c4d.Ttexture)
            textureTag[c4d.TEXTURETAG_MATERIAL] = mat

            c4d.EventAdd()

    c4d.EventAdd()
Exemplo n.º 7
0
def main():

    mat = c4d.Material(c4d.Mbase)
    mat.SetName('ROPE')
    doc.InsertMaterial(mat)
    for i in obj_list():
        if i.GetType() == 5181 or i.GetType() == 5186 or i.GetType() == 5101:
            doc.StartUndo()
            rope = c4d.BaseObject(1033577)
            rope.SetName('ROPE')
            doc.AddUndo(c4d.UNDOTYPE_NEW, rope)
            tag = rope.GetTag(c4d.Ttexture)
            tag = rope.MakeTag(c4d.Ttexture)
            tag[c4d.TEXTURETAG_PROJECTION] = c4d.TEXTURETAG_PROJECTION_UVW
            tag[c4d.TEXTURETAG_TILESY] = len_spline(i) * 5 / 10
            tag.SetMaterial(mat)

            doc.AddUndo(c4d.UNDOTYPE_CHANGE, i)
            rope.InsertBefore(i)
            rope.SetRelPos(i.GetRelPos())
            rope[c4d.REEPER_RAD] = 0.25
            rope[c4d.REEPER_STRANDS] = 6
            rope[c4d.REEPER_DIS] = 0.6
            rope[c4d.REEPER_COILS] = int(len_spline(i) * 5 / 10)
            if press_button() == 1:
                tag = rope.MakeTag(1036222)
                tag[c4d.REDSHIFT_OBJECT_GEOMETRY_OVERRIDE] = True
                tag[c4d.REDSHIFT_OBJECT_GEOMETRY_SUBDIVISIONENABLED] = True
                tag[c4d.REDSHIFT_OBJECT_GEOMETRY_DISPLACEMENTENABLED] = True
                rope[c4d.REEPER_DIS] = 0.55
            i.InsertUnder(rope)
            i.SetRelPos(c4d.Vector())
            c4d.EventAdd()
            doc.EndUndo()

        else:
            print "This isn't a spline"
Exemplo n.º 8
0
def CreateMaterial(name="New Material", active_channels=[c4d.CHANNEL_COLOR]):

	"""
		Creates a new C4D Material, enabling the specified channels. This function does not insert the material
		into the C4D document. For this, do 'doc.InsertMaterial(mat)' , where 'mat' is the newly created Material
		returned bt this function.

		Args:
			[optional] name (str): The name of the material
			[optional] active_channels (list): A list of C4D channel types to enable.
		Returns:
			The newly created Material
	"""

	_mat = c4d.Material()
	_mat.SetName(name)

	for c in D.MaterialChannels.values():
		if c in active_channels:
			_mat.SetChannelState(c,True)
		else:
			_mat.SetChannelState(c,False)

	return _mat
Exemplo n.º 9
0
def DefaultMaterial(texture_set_name, texture_path, material_type):

    #Material
    material = c4d.Material(c4d.Mbase)

    if (material_type == 0):
        material.SetName(texture_set_name + "_Dielectric_Material")

    if (material_type == 1):
        material.SetName(texture_set_name + "_Conductor_Material")

    if (material_type == 2):
        material.SetName(texture_set_name + "_Transparent_Material")

    doc.InsertMaterial(material)
    doc.AddUndo(c4d.UNDOTYPE_NEW, material)

    #Local Texture Path
    if (texture_path == doc.GetDocumentPath()):
        texture_path = ''
    else:
        texture_path = texture_path + '\\'

    #Diffuse
    material[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(1)
    diffuse_shader = c4d.BaseList2D(c4d.Xbitmap)
    diffuse_shader[
        c4d.
        BITMAPSHADER_FILENAME] = texture_path + texture_set_name + '_Diffuse.png'
    diffuse_shader[c4d.BITMAPSHADER_INTERPOLATION] = 0
    diffuse_shader[c4d.BITMAPSHADER_COLORPROFILE] = 2
    material.InsertShader(diffuse_shader)
    material[c4d.MATERIAL_COLOR_SHADER] = diffuse_shader

    #Normal
    material[c4d.MATERIAL_USE_NORMAL] = 1
    material[c4d.MATERIAL_NORMAL_REVERSEY] = 1
    normal_shader = c4d.BaseList2D(c4d.Xbitmap)
    normal_shader[
        c4d.
        BITMAPSHADER_FILENAME] = texture_path + texture_set_name + '_Normal.png'
    normal_shader[c4d.BITMAPSHADER_INTERPOLATION] = 0
    normal_shader[c4d.BITMAPSHADER_COLORPROFILE] = 1
    material.InsertShader(normal_shader)
    material[c4d.MATERIAL_NORMAL_SHADER] = normal_shader

    #Glossiness & Specular
    material.RemoveReflectionLayerIndex(0)

    #Reflection Layer
    material.AddReflectionLayer()
    reflection_layer = material.GetReflectionLayerIndex(0).GetDataID()

    #Reflection Settings
    material[c4d.REFLECTION_LAYER_MAIN_DISTRIBUTION + reflection_layer] = 3
    material[c4d.REFLECTION_LAYER_MAIN_ADDITIVE + reflection_layer] = 2
    material[c4d.REFLECTION_LAYER_MAIN_VALUE_SPECULAR + reflection_layer] = 0
    material[c4d.REFLECTION_LAYER_MAIN_VALUE_ROUGHNESS + reflection_layer] = 1

    #Specular Shader
    specular_shader = c4d.BaseList2D(c4d.Xbitmap)
    specular_shader[
        c4d.
        BITMAPSHADER_FILENAME] = texture_path + texture_set_name + '_Specular.png'
    specular_shader[c4d.BITMAPSHADER_INTERPOLATION] = 0
    specular_shader[c4d.BITMAPSHADER_COLORPROFILE] = 2
    material.InsertShader(specular_shader)
    material[c4d.REFLECTION_LAYER_COLOR_TEXTURE +
             reflection_layer] = specular_shader

    #Roughness Shader
    roughness_shader = c4d.BaseList2D(c4d.Xbitmap)
    roughness_shader[
        c4d.
        BITMAPSHADER_FILENAME] = texture_path + texture_set_name + '_Glossiness.png'
    roughness_shader[c4d.BITMAPSHADER_INTERPOLATION] = 0
    roughness_shader[c4d.BITMAPSHADER_COLORPROFILE] = 1
    roughness_shader[c4d.BITMAPSHADER_BLACKPOINT] = 1
    roughness_shader[c4d.BITMAPSHADER_WHITEPOINT] = 0
    material.InsertShader(roughness_shader)
    material[c4d.REFLECTION_LAYER_MAIN_SHADER_ROUGHNESS +
             reflection_layer] = roughness_shader

    #Alpha
    if (material_type == 1):
        material[c4d.MATERIAL_USE_ALPHA] = 1
        alpha_shader = c4d.BaseList2D(c4d.Xbitmap)
        alpha_shader[
            c4d.
            BITMAPSHADER_FILENAME] = texture_path + texture_set_name + '_Metallic.png'
        alpha_shader[c4d.BITMAPSHADER_INTERPOLATION] = 0
        alpha_shader[c4d.BITMAPSHADER_COLORPROFILE] = 2
        material[c4d.MATERIAL_ALPHA_SHADER] = alpha_shader
        material.InsertShader(alpha_shader)

    return material
Exemplo n.º 10
0
    def Command(self, id, msg):
        #Image Picker
        if (id == 12):
            path = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_IMAGES,
                                          "HDRI",
                                          c4d.FILESELECT_LOAD,
                                          def_path=self.GetString(1))

            if (path != None):
                self.SetString(11, path)

                for i in range(len(paths)):
                    self.SetBool(i + 17, False)

                self.SetBool(14, True)

        if (id == 13):
            for i in range(len(paths)):
                if (self.GetBool(i + 17) == True):
                    self.SetString(11, paths.values()[i])

        if (id == 1):
            doc.StartUndo()

            #Sky
            if (self.GetBool(10) == True):
                sky = c4d.BaseObject(c4d.Osky)
                doc.InsertObject(sky)
                doc.AddUndo(c4d.UNDOTYPE_NEW, sky)

                #Material
                material = c4d.Material(c4d.Mbase)
                material.SetName('Sky')
                doc.InsertMaterial(material)
                doc.AddUndo(c4d.UNDOTYPE_NEW, material)
                material[c4d.MATERIAL_USE_REFLECTION] = 0
                material[c4d.MATERIAL_USE_COLOR] = 0
                material[c4d.MATERIAL_USE_LUMINANCE] = 1

                #Luminance Shader
                luminance_shader = c4d.BaseList2D(c4d.Xbitmap)
                luminance_shader[c4d.BITMAPSHADER_FILENAME] = self.GetString(
                    11)
                material.InsertShader(luminance_shader)
                material[c4d.MATERIAL_LUMINANCE_SHADER] = luminance_shader

                #Tag
                tag = sky.MakeTag(c4d.Ttexture)
                tag[c4d.TEXTURETAG_PROJECTION] = 0
                tag.SetMaterial(material)

                #Visibility
                if (self.GetBool(15) == False):
                    tag = sky.MakeTag(c4d.Tcompositing)
                    tag[c4d.COMPOSITINGTAG_SEENBYCAMERA] = 0

            #Background
            if (self.GetBool(20) == True):
                #Background
                background = c4d.BaseObject(c4d.Obackground)
                doc.InsertObject(background)
                doc.AddUndo(c4d.UNDOTYPE_NEW, background)

                #Material
                material = c4d.Material(c4d.Mbase)
                material.SetName('Background')
                doc.InsertMaterial(material)
                doc.AddUndo(c4d.UNDOTYPE_NEW, material)
                material[c4d.MATERIAL_USE_REFLECTION] = 0
                material[c4d.MATERIAL_COLOR_COLOR] = self.GetColorField(
                    21).values()[0]

                #Tag
                tag = background.MakeTag(c4d.Ttexture)
                tag[c4d.TEXTURETAG_PROJECTION] = 6
                tag.SetMaterial(material)

            doc.EndUndo()
            c4d.EventAdd()
            self.Close()

        return True