Example #1
0
def mariProjectCreate():
    "This creates a project with a set of default options. Import each OBJ like this"
    mari.projects.close()
    obj_name = QFileDialog.getOpenFileName(None, "Select a .obj file", "/",
                                           "*.obj")
    if os.path.exists(obj_name):
        #What default layers are created
        mari.projects.create("projectName", obj_name, [
            mari.ChannelInfo(
                'DIFF',
                2048,
                2048,
                16,
                False,
                mari.Color(0, 0, 0),
                mari.setFileTemplate("$ENTITY_$CHANNEL_$UDIM.png"),
                mari.setPath("InsertPathHere"),
            ),
            mari.ChannelInfo(
                'SPEC', 2048, 2048, 16, False, mari.Color(0.5, 0.5, 0.5),
                mari.setFileTemplate("$ENTITY_$CHANNEL_$UDIM.png")),
            mari.ChannelInfo(
                'DSP', 2048, 2048, 16, True, mari.Color(0.5, 0.5, 0.5),
                mari.setFileTemplate("$ENTITY_$CHANNEL_$UDIM.png"))
        ])
    def set_shader_attributes(self):
        attributes = self.preset['attributes']
        for attr, value in attributes.iteritems():
            # value index[0] = value (eg. 0.23),
            # value index[1] = datatype (eg.'float')
            if value[1] == 'enum':
                pass  # TODO
            elif value[1] == 'float3':
                # must convert to 'mari color'
                parameter = mari.Color(value[0][0], value[0][1], value[0][2])
                self.shader.setParameter("%s" % attr, parameter)
            else:
                self.shader.setParameter("%s" % attr, value[0])

        self.shader.setName(self.preset['shader name'])
    def create_channels(self, shader, inputs_list, channel_res, bit_depth):
        for input_channel in inputs_list:
            channel_name = shader.name() + "_" + input_channel
            channel_list = self.geo.channelList()
            channel_list = [chan.name() for chan in channel_list]

            if channel_name in channel_list:
                print "skipping channel as already created..."
            else:
                parameter = shader.getParameter(str(input_channel))
                if type(parameter) == float:
                    parameter = mari.Color(parameter, parameter, parameter)

                channel = self.geo.createChannel(channel_name,
                                                 int(channel_res),
                                                 int(channel_res),
                                                 int(bit_depth))
                channel_layer = channel.createProceduralLayer(
                    "Reference_Colour", "Basic/Color")
                channel_layer.setProceduralParameter("Color", parameter)
                shader.setInput(input_channel, channel)
Example #4
0
def importNewObjectAndMat(obj, channelname, imagepath, res, bitdepth):##update this to receive texture res and other stuff
	version = mari.app.version()
	majority = str(version.major())
	sub = str(version.minor())
	fullver = float(majority + "." + sub)
	geocol = [mari.Color( 0.5, 0.5, 0.5)]
	if fullver > 2.5:##ALREADY GETS A BASE CHANNEL SO DELETE IT
		objecty = mari.geo.load(obj) 
		mari.geo.setCurrent(objecty[0])
		node = mari.geo.current()
		#node = objecty[0]
		delAction = mari.actions.find("/Mari/Channels/Remove Channel")
		delAction.trigger()
		currentChannel = node.createChannel(channelname, res, res, bitdepth)

		if imagepath != "null":
			currentChannel.importImages(imagepath)
		else:#make an empty layer to paint on 
			layer1 = currentChannel.createPaintableLayer("Layer1") 
			createLayers_ImageSetClear( layer1.imageSet(), geocol[0]) 
			#node.setCurrentChannel(node.channel(currentChannel[0]))
	else:##ADD BASE CHANNEL
		objecty = mari.geo.load(obj) 
		mari.geo.setCurrent(objecty[0])
		node = objecty[0]
		currentChannel = node.createChannel(channelname, res, res, bitdepth)
		# Show the color channel so we can see something on the model 
		if imagepath != "null":
			currentChannel.importImages(imagepath)
		else:#make an empty layer to paint on 
			layer1 = currentChannel.createPaintableLayer("Layer1") 
			createLayers_ImageSetClear( layer1.imageSet(), geocol[0])
			#obj = mari.geo.current()
	#select through the meshes to get paint to show up:
	allGeometry = mari.geo.list()
	for x in range(0, int(len(allGeometry))):
	    mari.geo.setCurrent(allGeometry[x])
Example #5
0
def clone_merge_layers(mode):
    ''' Creates a merge duplicate of selected layers - patch modes ALL or SELECTED'''

    suitable = _isProjectSuitable()
    if not suitable[0]:
        return

    deactivateViewportToggle = mari.actions.find(
        '/Mari/Canvas/Toggle Shader Compiling')
    deactivateViewportToggle.trigger()

    geo_data = findLayerSelection()
    # Geo Data = 0 current geo, 1 current channel , 2 current layer, 3 current selection list
    curGeo = geo_data[0]
    curChan = geo_data[2]
    curLayer = geo_data[1]
    curSel = geo_data[3]
    curActiveLayerName = str(curLayer.name())

    patches = list(curGeo.patchList())
    unSelPatches = [patch for patch in patches if not patch.isSelected()]

    mari.app.setWaitCursor()
    mari.history.startMacro('Clone & Merge Layers')

    copyAction = mari.actions.find('/Mari/Layers/Copy')
    copyAction.trigger()

    pasteAction = mari.actions.find('/Mari/Layers/Paste')
    pasteAction.trigger()

    #running search for selection again in order to get a list of all duplicated layers
    geo_data = findLayerSelection()
    # Geo Data = 0 current geo, 1 current channel , 2 current layer, 3 current selection list
    curGeo = geo_data[0]
    curChan = geo_data[2]
    curLayer = geo_data[1]
    curSel = geo_data[3]
    channelLayerLst = []
    #running search from all current selected layers to get a full list of all associated layers such as masks etc.
    nested_layers = getLayerList(curSel, returnTrue)
    # lookin through all layers that are associated with duplicates if there are any channel layers where we duplicated channels
    for layer in nested_layers:
        if layer.isChannelLayer():
            channelLayerLst.append(layer.channel())

    mergeAction = mari.actions.find('/Mari/Layers/Merge Layers')
    mergeAction.trigger()

    # rerunning layer search
    geo_data = findLayerSelection()

    curLayer = geo_data[1]

    if mode == 'selected':
        if len(patches) != len(unSelPatches):

            imgSet = curLayer.imageSet()

            for patch in unSelPatches:
                uv = patch.uvIndex()
                patchImg = imgSet.image(uv, -1)
                patchImg.fill(mari.Color(1, 0, 0, 0))

    curLayer.setName(curActiveLayerName + '_mrgDup')

    # removing any channels we duplicated in the process of copy/paste
    for channel in channelLayerLst:
        try:
            curGeo.removeChannel(channel)
        except Exception:
            continue

    mari.history.stopMacro()
    mari.app.restoreCursor()

    deactivateViewportToggle.trigger()

    return
Example #6
0
def selectionMask(invert):
    suitable = _isProjectSuitable()
    if not suitable[0]:
        return

    mari.history.startMacro('Create Mask from Selection')

    geo_data = findLayerSelection()
    currentObj = geo_data[0]
    currentLayer = geo_data[1]
    currentSelection = geo_data[3]
    selectedPatches = currentObj.selectedPatches()

    for layer in currentSelection:

        currentLayer = layer

        if currentLayer.isShaderLayer():

            if currentLayer.hasMaskStack():
                layerMaskStack = currentLayer.maskStack()
                newMask = layerMaskStack.createPaintableLayer(
                    'MaskFromSelection')
                newMaskImageSet = newMask.imageSet()
            else:
                layerMaskStack = currentLayer.makeMaskStack()
                newMask = layerMaskStack.createPaintableLayer(
                    'MaskFromSelection')
                newMaskImageSet = newMask.imageSet()

        else:

            if currentLayer.hasMaskStack():
                layerMaskStack = currentLayer.maskStack()
                newMask = layerMaskStack.createPaintableLayer(
                    'MaskFromSelection')
                newMaskImageSet = newMask.imageSet()

            elif currentLayer.hasMask():
                layerMaskStack = currentLayer.makeMaskStack()
                newMask = layerMaskStack.createPaintableLayer(
                    'MaskFromSelection')
                newMaskImageSet = newMask.imageSet()
            else:
                newMask = currentLayer.makeMask()
                newMaskImageSet = newMask

        for image in newMaskImageSet.imageList():
            if invert == False:
                image.fill(mari.Color(0.0, 0.0, 0.0, 1.0))
            else:
                image.fill(mari.Color(1.0, 1.0, 1.0, 1.0))

        for patch in selectedPatches:
            selectedImage = currentObj.patchImage(patch, newMaskImageSet)
            if invert == False:
                selectedImage.fill(mari.Color(1.0, 1.0, 1.0, 1.0))
            else:
                selectedImage.fill(mari.Color(0.0, 0.0, 0.0, 1.0))

    mari.history.stopMacro()