# -*- coding: utf-8 -*
import maya.cmds as cmds
import pymel.core as pm
import mtoa.ui.ae.lightTemplate as lightTemplate
import mtoa.ui.ae.aiSwatchDisplay as aiSwatchDisplay
import mtoa.ui.ae.templates as templates
import mtoa.utils as utils

def inMeshReplace(plugName):
    nodeAndAttrs = plugName.split(".")
    node = nodeAndAttrs[0]
    cmds.attrNavigationControlGrp("aiMeshLightInMeshCtrl", edit=True, attribute=("%s.inMesh" % node))

def inMeshNew(plugName):
    cmds.attrNavigationControlGrp("aiMeshLightInMeshCtrl", label="In网格")
    inMeshReplace(plugName)

class AEaiMeshLightTemplate(lightTemplate.LightTemplate):

    def addSwatch(self):
        self.addCustom("message", aiSwatchDisplay.aiSwatchDisplayNew, aiSwatchDisplay.aiSwatchDisplayReplace)

    def setup(self):
        self.addSwatch()
        self.beginScrollLayout()

        self.beginLayout("网格属性", collapse=False)
        self.addCustom("inMesh", inMeshNew, inMeshReplace)
        self.addControl("showOriginalMesh", label = "显示原始网格")
        self.endLayout()

        self.beginLayout("灯光属性", collapse=False)
        self.addControl("color", label = "颜色")
        self.addControl("intensity", label = "强度")
        self.addControl("aiExposure", label = "曝光")
        self.addSeparator()
        self.setupColorTemperature("ArnoldMesh")
        self.addSeparator()
        self.addControl("lightVisible", label = "灯光可见")
        self.addSeparator()
        self.addControl("aiSamples", label = "采样")
        self.addControl("aiNormalize", label = "规格化")
        self.addSeparator()
        self.addControl("aiCastShadows", label = "投射阴影")
        self.addControl("aiShadowDensity", label = "阴影密度")
        self.addControl("aiShadowColor", label = "阴影颜色")
        self.addSeparator()
        self.commonLightAttributes()
        self.endLayout()

        # Do not show extra attributes
        extras = ["visibility",
                  "intermediateObject",
                  "template",
                  "ghosting",
                  "instObjGroups",
                  "useObjectColor",
                  "objectColor",
                  "drawOverride",
                  "lodVisibility",
                  "renderInfo",
                  "renderLayerInfo",
                  "ghostingControl",
                  "ghostCustomSteps",
                  "ghostFrames",
                  "ghostRangeStart",
                  "ghostRangeEnd",
                  "ghostDriver",
                  "ghostColorPreA",
                  "ghostColorPre",
                  "ghostColorPostA",
                  "ghostColorPost",
                  "motionBlur",
                  "visibleInReflections",
                  "visibleInRefractions",
                  "castsShadows",
                  "receiveShadows",
                  "maxVisibilitySamplesOverride",
                  "maxVisibilitySamples",
                  "geometryAntialiasingOverride",
                  "antialiasingLevel",
                  "shadingSamplesOverride",
                  "shadingSamples",
                  "maxShadingSamples",
                  "volumeSamplesOverride",
                  "volumeSamples",
                  "depthJitter",
                  "ignoreSelfShadowing",
                  "primaryVisibility",
                  "compInstObjGroups",
                  "localPosition",
                  "localScale"]

        for extra in extras:
            self.suppress(extra)
        
        pm.mel.AEdependNodeTemplate(self.nodeName)

        self.addExtraControls()
        self.endScrollLayout()
