def SetupCurve(effect): doll = scene.dynamics[0] if doll is None: return setName = 'Dropshadow foot tracker' set = None for s in doll.curveSets: if s.name == setName: set = s set.curves.removeAt(-1) set.bindings.removeAt(-1) break else: set = trinity.TriCurveSet() set.name = setName doll.curveSets.append(set) bones = ['LeftFoot', 'RightFoot'] for bone in bones: curve = trinity.Tr2BoneMatrixCurve() curve.skinnedObject = doll curve.bone = bone curve.name = bone param = PD.FindOrAddVec4(effect, bone) bind = trinity.TriValueBinding() bind.destinationObject = param bind.destinationAttribute = 'value' bind.sourceObject = curve bind.sourceAttribute = 'currentValue' bind.name = bone set.curves.append(curve) set.bindings.append(bind) set.Play()
def GetOrMakeCurve(bone, set, curveDictionary, name): curve = curveDictionary.get((weakAvatar, bone), None) if curve is not None: return curve curve = trinity.Tr2BoneMatrixCurve() curve.bone = bone curve.name = name curveDictionary[weakAvatar, bone] = curve set.curves.append(curve) return curve
def ApplyParticleEffect(self, *args): if not sm.GetService('device').GetAppFeatureState('Interior.ParticlesEnabled', True): return True entityID, effectFilePath, boneName, duration, xOffset, yOffset, zOffset = args[:7] yawOffset, pitchOffset, rollOffset, ignoreTransform, effectStringID = args[7:] effectID = self._GetNextEffectID() zaction.AddPropertyForCurrentPythonProc({effectStringID: effectID}) translation = geo2.MatrixTranslation(xOffset, yOffset, zOffset) rotation = geo2.MatrixRotationYawPitchRoll(math.radians(yawOffset), math.radians(pitchOffset), math.radians(rollOffset)) offset = geo2.MatrixMultiply(rotation, translation) with self.activeParticlesSemaphore: trinityObject = trinity.Load(effectFilePath) entity = self.entityClient.FindEntityByID(entityID) scene = self.graphicClient.GetScene(entity.scene.sceneID) scene.AddDynamic(trinityObject) curveSet = None positionComponent = entity.GetComponent('position') if boneName or positionComponent: curveSet = trinity.TriCurveSet() scene.AddCurveSetToScene(curveSet) if boneName: paperDollComponent = entity.GetComponent('paperdoll') model = paperDollComponent.doll.avatar curve = trinity.Tr2BoneMatrixCurve() curve.skinnedObject = model curve.bone = boneName if not ignoreTransform: offset = geo2.MatrixMultiply(offset, trinityObject.transform) curve.transform = offset else: curve = GameWorld.PositionComponentCurve() curve.positionComponent = positionComponent curve.positionOffset = geo2.Vector(xOffset, yOffset, zOffset) curve.rotationOffset = geo2.QuaternionRotationSetYawPitchRoll(yawOffset, pitchOffset, rollOffset) bind = trinity.TriValueBinding() bind.destinationObject = trinityObject bind.destinationAttribute = 'transform' bind.sourceObject = curve bind.sourceAttribute = 'currentValue' curveSet.curves.append(curve) curveSet.bindings.append(bind) curveSet.Play() expireTime = blue.os.GetWallclockTime() + duration * const.MSEC effectData = util.KeyVal(effectID=effectID, entityID=entityID, effectFilePath=effectFilePath, expireTime=expireTime, offset=offset, trinityObject=trinityObject, sceneID=entity.scene.sceneID, curveSet=curveSet) self.activeParticleEffects[effectID] = effectData if duration > 0: self.timedParticleEffects.append(effectData) self.timedParticleEffects.sort(key=lambda entry: entry.expireTime) self.updateTaskletLock.set() self._ConnectEffectCurveSets(effectData, effectStringID) return True
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)