예제 #1
0
def FindOrAddMat4(effect, name):
    for r in effect.parameters:
        if r.name == name:
            return r

    p = trinity.Tr2Matrix4Parameter()
    p.name = name
    effect.parameters.append(p)
    return p
def FindOrAddMat4(effect, name):
    """
    Find a matrix4 with this name, or create it.  Returns the found/created Matrix4Parameter
    """
    for r in effect.parameters:
        if r.name == name:
            return r

    p = trinity.Tr2Matrix4Parameter()
    p.name = name
    effect.parameters.append(p)
    return p
def AddPrepassAreasToStandardMesh(mesh,
                                  processDepthAreas,
                                  processDepthNormalAreas,
                                  avatar=None,
                                  doll=None,
                                  useLightControlMap=False):
    opaqueAreas = mesh.opaqueAreas
    processDepthAreas = len(mesh.depthAreas) <= 0
    if processDepthNormalAreas:
        mesh.depthNormalAreas.removeAt(-1)
    mesh.decalPrepassAreas.removeAt(-1)
    mesh.opaquePrepassAreas.removeAt(-1)
    for area in mesh.transparentAreas:
        if area.name[0:8] == 'Prepass_':
            mesh.transparentAreas.remove(area)

    newAreas = []
    for area in opaqueAreas:
        if IsGlassRelated(area):
            newArea = CopyAreaOnly(area)
            if newArea is not None:
                newArea.name = 'Prepass_' + newArea.name
                newArea.effect = ConvertEffectToTr2ShaderMaterial(
                    area.effect, 'SHLighting', mesh.name)
                newArea.useSHLighting = True
                newAreas.append(newArea)
                area.debugIsHidden = True
            if processDepthAreas:
                newArea = CopyAreaForPrePassShadows(area,
                                                    SOURCE_AREA_TYPE_OPAQUE)
                if newArea is not None:
                    mesh.depthAreas.append(newArea)
            continue
        if area.effect is not None and hasattr(
                area.effect, 'effectFilePath'
        ) and 'hair' in area.effect.effectFilePath.lower():
            continue
        if processDepthNormalAreas:
            newArea = CopyAreaForPrePassDepthNormal(area,
                                                    SOURCE_AREA_TYPE_OPAQUE)
            if newArea is not None:
                mesh.depthNormalAreas.append(newArea)
        if processDepthAreas:
            newArea = CopyAreaForPrePassShadows(area, SOURCE_AREA_TYPE_OPAQUE)
            if newArea is not None:
                mesh.depthAreas.append(newArea)
        newArea = CopyAreaOnly(area)
        if newArea is not None:
            if mesh.name.startswith('head') and useLightControlMap:
                newArea.effect = ConvertEffectToTr2ShaderMaterial(
                    area.effect, 'Prepass SHLighting', mesh.name)
                useLightControl = trinity.Tr2FloatParameter()
                useLightControl.name = 'UseLightControl'
                useLightControl.value = 0.5
                newArea.effect.parameters[
                    useLightControl.name] = useLightControl
                lightControlMap = trinity.TriTexture2DParameter()
                lightControlMap.name = 'LightControlMap'
                lcmPath = LIGHT_CONTROL_MAP_FEMALE_PATH
                if doll and doll.gender == pdDef.GENDER.MALE:
                    lcmPath = LIGHT_CONTROL_MAP_MALE_PATH
                lightControlMap.resourcePath = lcmPath
                newArea.effect.parameters[
                    lightControlMap.name] = lightControlMap
                lightControlMatrix = trinity.Tr2Matrix4Parameter()
                lightControlMatrix.name = 'LightControlMatrix'
                newArea.effect.parameters[
                    lightControlMatrix.name] = lightControlMatrix
                newArea.useSHLighting = True
                if avatar:
                    headMatrixCurves = None
                    boneMatrixCurve = None
                    for cs in avatar.curveSets:
                        if cs.name == 'HeadMatrixCurves':
                            headMatrixCurves = cs
                            for curve in headMatrixCurves.curves:
                                if curve.bone == 'Head':
                                    boneMatrixCurve = curve

                            break

                    if not headMatrixCurves:
                        headMatrixCurves = trinity.TriCurveSet()
                        headMatrixCurves.name = 'HeadMatrixCurves'
                        avatar.curveSets.append(headMatrixCurves)
                    if not boneMatrixCurve:
                        boneMatrixCurve = trinity.Tr2BoneMatrixCurve()
                        boneMatrixCurve.bone = 'Head'
                        boneMatrixCurve.name = 'HeadMatrixCurve'
                        boneMatrixCurve.skinnedObject = avatar
                        headMatrixCurves.curves.append(boneMatrixCurve)
                    if len(headMatrixCurves.bindings):
                        bind = headMatrixCurves.bindings[0]
                    else:
                        bind = trinity.TriValueBinding()
                        headMatrixCurves.bindings.append(bind)
                    bind.sourceObject = boneMatrixCurve
                    bind.destinationObject = lightControlMatrix
                    bind.sourceAttribute = 'currentValue'
                    bind.destinationAttribute = 'value'
                    headMatrixCurves.Play()
            else:
                newArea.effect = ConvertEffectToTr2ShaderMaterial(
                    area.effect, 'Prepass', mesh.name)
            mesh.opaquePrepassAreas.append(newArea)

    def FixCutMask(area):
        if area.effect and 'CutMaskInfluence' in area.effect.parameters:
            area.effect.parameters['CutMaskInfluence'].value = 1.0

    def AddAreasForRegularPLP(area,
                              materialLookupTable=None,
                              isTransparent=False):
        if area.effect is not None and hasattr(
                area.effect, 'effectFilePath'
        ) and 'hair' in area.effect.effectFilePath.lower():
            return
        if processDepthNormalAreas:
            newArea = CopyAreaForPrePassDepthNormal(
                area,
                SOURCE_AREA_TYPE_DECAL,
                materialLookupTable=materialLookupTable)
            if newArea is not None:
                if isTransparent:
                    FixCutMask(newArea)
                mesh.depthNormalAreas.append(newArea)
        if processDepthAreas:
            newArea = CopyAreaForPrePassShadows(area, SOURCE_AREA_TYPE_DECAL)
            if newArea is not None:
                if isTransparent:
                    FixCutMask(newArea)
                mesh.depthAreas.append(newArea)
        newArea = CopyAreaOnly(area)
        if newArea is not None:
            newArea.effect = ConvertEffectToTr2ShaderMaterial(
                area.effect, 'Prepass Decal', mesh.name)
            if isTransparent:
                FixCutMask(newArea)
            mesh.decalPrepassAreas.append(newArea)
        area.debugIsHidden = True

    for area in mesh.decalAreas:
        if IsGlassRelated(area):
            newArea = CopyAreaOnly(area)
            if newArea is not None:
                newArea.name = 'Prepass_' + newArea.name
                newArea.effect = ConvertEffectToTr2ShaderMaterial(
                    area.effect, 'SHLighting', mesh.name)
                newArea.useSHLighting = True
                newAreas.append(newArea)
                area.debugIsHidden = True
            if processDepthAreas:
                newArea = CopyAreaForPrePassShadows(area,
                                                    SOURCE_AREA_TYPE_DECAL)
                if newArea is not None:
                    mesh.depthAreas.append(newArea)
        else:
            AddAreasForRegularPLP(area)

    for area in mesh.transparentAreas:
        if area.effect is None:
            continue
        if hasattr(area.effect, 'effectFilePath'
                   ) and 'hair' in area.effect.effectFilePath.lower():
            continue
        if USE_DECAL_PLP_FOR_TRANSPARENT_AREAS and not IsEyeRelated(
                area) and not IsGlassRelated(area):
            AddAreasForRegularPLP(
                area,
                materialLookupTable=MATERIAL_ID_TRANSPARENT_HACK_EXACT,
                isTransparent=True)
            area.effect = None
        else:
            newArea = CopyAreaOnly(area)
            if newArea is not None:
                if 'C_SkinShiny' in area.effect.name:
                    newArea.effect = ConvertEffectToTr2ShaderMaterial(
                        area.effect, 'Prepass Decal', mesh.name)
                    mesh.decalPrepassAreas.append(newArea)
                else:
                    newArea.effect = ConvertEffectToTr2ShaderMaterial(
                        area.effect, 'SHLighting', mesh.name)
                    newArea.useSHLighting = True
                    newAreas.append(newArea)
                area.debugIsHidden = True

    mesh.transparentAreas.extend(newAreas)