def SetupLotsOfIcons(parent, curveSet, n): for i in xrange(n): sprite = CreateRandomIcon() curve = trinity.TriPerlinCurve() curve.scale = 100.0 curve.offset = 0.0 curve.speed = random.random() binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = sprite binding.destinationAttribute = 'displayX' curveSet.curves.append(curve) curveSet.bindings.append(binding) curve = trinity.TriPerlinCurve() curve.scale = 100.0 curve.offset = 0.0 curve.speed = random.random() binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = sprite binding.destinationAttribute = 'displayY' curveSet.curves.append(curve) curveSet.bindings.append(binding) sprite.color = (random.random(), random.random(), random.random(), 1.0) parent.children.append(sprite)
def SetupMyPositionTracker(self, transform): solarSystemSunID = self.sunID bp = sm.GetService('michelle').GetBallpark() if bp is not None: ball = bp.GetBall(solarSystemSunID) if ball is not None: vectorCurve = trinity.TriVectorCurve() vectorCurve.value = (-1.0, -1.0, -1.0) vectorSequencer = trinity.TriVectorSequencer() vectorSequencer.operator = trinity.TRIOP_MULTIPLY vectorSequencer.functions.append(ball) vectorSequencer.functions.append(vectorCurve) binding = trinity.TriValueBinding() binding.sourceAttribute = 'value' binding.destinationAttribute = 'translation' binding.scale = 1.0 binding.sourceObject = vectorSequencer binding.destinationObject = transform curveSet = trinity.TriCurveSet() curveSet.name = 'translationCurveSet' curveSet.playOnLoad = True curveSet.curves.append(vectorSequencer) curveSet.bindings.append(binding) transform.curveSets.append(curveSet) curveSet.Play()
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 CreateBinding(self, curve, attribute): binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'currentValue' binding.destinationObject = self.owner binding.destinationAttribute = attribute return binding
def HighlightEntity(self, entity, highlight): highlightComponent = entity.GetComponent('highlight') if highlightComponent is None: return if highlightComponent.highlighted == highlight: return if highlightComponent.curve is None: return placeableComponent = entity.GetComponent('interiorPlaceable') if placeableComponent is None: return if placeableComponent.renderObject is None: return highlightParameters = [] curveSets = None object = placeableComponent.renderObject if hasattr(object, 'detailMeshes'): rebind = False for mesh in object.detailMeshes: rebind |= self._FindMeshHighlightParameters( mesh, highlightComponent.highlightAreas, highlightParameters, highlight) if rebind: object.BindLowLevelShaders() curveSets = object.curveSets elif hasattr( object, 'placeableRes' ) and object.placeableRes is not None and object.placeableRes.visualModel is not None: rebind = False for mesh in object.placeableRes.visualModel.meshes: rebind |= self._FindMeshHighlightParameters( mesh, highlightComponent.highlightAreas, highlightParameters, highlight) if rebind: object.BindLowLevelShaders() curveSets = object.placeableRes.curveSets if curveSets is not None and len(highlightParameters) > 0: if highlight: highlightComponent.curveSet = trinity.TriCurveSet() highlightComponent.curveSet.curves.append( highlightComponent.curve) for parameter in highlightParameters: binding = trinity.TriValueBinding() binding.sourceObject = highlightComponent.curve binding.sourceAttribute = 'value' binding.destinationObject = parameter binding.destinationAttribute = 'value' highlightComponent.curveSet.bindings.append(binding) curveSets.append(highlightComponent.curveSet) highlightComponent.curveSet.Play() elif highlightComponent.curveSet is not None and not highlight: curveSets.remove(highlightComponent.curveSet) highlightComponent.curveSet = None for parameter in highlightParameters: parameter.value = (0.0, 0.0, 0.0, 0.0) highlightComponent.highlighted = highlight
def PrepareAnimationSetupFor(self, fileName): if fileName in BUILD_MODEL: self.model.highDetailMesh.Freeze() self.model.mediumDetailMesh.Freeze() self.model.lowDetailMesh.Freeze() alphas = nodemanager.FindNodes(self.model, 'AlphaThreshold', 'trinity.TriVector4Parameter') curves = nodemanager.FindNodes(self.model, 'STATE_BUILD', 'trinity.TriCurveSet') curve = curves[0] src = curve.curves[0] while len(curve.bindings) > 0: curve.bindings.fremove(curve.bindings[0]) for eachAlpha in alphas: binding = trinity.TriValueBinding() binding.sourceAttribute = 'value' binding.destinationAttribute = 'v1' binding.scale = 1.0 binding.sourceObject = src binding.destinationObject = eachAlpha curve.bindings.append(binding) binding = None curve.scale = 0.0 curve.Play() if fileName == ONLINE_MODEL: holograms = nodemanager.FindNodes(self.model.children, 'Holograms', 'trinity.EveTransform') projectors = nodemanager.FindNodes(self.model.children, 'Projectors', 'trinity.EveTransform') for each in holograms + projectors: each.display = False curves = nodemanager.FindNodes(self.model, 'STATE_ONLINE', 'trinity.TriCurveSet') for curve in curves: curve.scale = 0.0 curve.Play()
def AddBinding(self, sourceObject, sourceAttribute, destObject, destAttribute, curveSet): binding = trinity.TriValueBinding() binding.sourceObject = sourceObject binding.sourceAttribute = sourceAttribute binding.destinationObject = destObject.GetRenderObject() binding.destinationAttribute = destAttribute curveSet.bindings.append(binding) return binding
def CreateBinding(self, sourceObject, sourceAttribute, destObject, destAttribute, offset, curveSet): binding = trinity.TriValueBinding() binding.sourceObject = sourceObject binding.sourceAttribute = sourceAttribute binding.destinationObject = destObject binding.destinationAttribute = destAttribute binding.offset = offset curveSet.bindings.append(binding) return binding
def bindAudioParameterToAttribute(sourceObject, attributeName, bindingsList): audparam = audio2.AudParameter() audparam.name = u'ship_invulnerability_link_strength' binding = trinity.TriValueBinding() binding.name = 'AudParameterBinding' binding.sourceObject = sourceObject binding.sourceAttribute = attributeName binding.destinationObject = audparam binding.destinationAttribute = 'value' bindingsList.append(binding) return audparam
def BindValueToExpression(destObj, valueName, expression): curve = trinity.Tr2ScalarExprCurve() curve.expr = expression curve.length = 86400 bind = trinity.TriValueBinding() bind.destinationObject = destObj bind.destinationAttribute = valueName bind.sourceObject = curve bind.sourceAttribute = 'currentValue' self.curveSet.curves.append(curve) self.curveSet.bindings.append(bind)
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 Flash(self, enable = True): if enable and self.highlightBinding is None: binding = trinity.TriValueBinding() binding.sourceAttribute = 'value' binding.destinationAttribute = 'value' binding.scale = 1.0 binding.sourceObject = self.controller.highlightCurve binding.destinationObject = self.highlight self.highlightBinding = binding if enable: if self.highlightBinding not in self.controller.highlightCurveSet.bindings: self.controller.highlightCurveSet.bindings.append(self.highlightBinding) else: if self.highlightBinding in self.controller.highlightCurveSet.bindings: self.controller.highlightCurveSet.bindings.remove(self.highlightBinding) self.highlight.value = 0.0
def SetupTracking(self): self.TearDownTracking() bp = sm.GetService('michelle').GetBallpark() if not bp: return sunBall = None if self.trackObjectID == session.shipid: for itemID, each in bp.slimItems.iteritems(): if each.groupID == const.groupSun: sunBall = bp.GetBall(itemID) break trackBallID = self.trackObjectID ball = bp.GetBall(trackBallID) if ball is None or sunBall is None: return vectorCurve = trinity.TriVectorCurve() vectorCurve.value = (-SOLARSYSTEM_SCALE, -SOLARSYSTEM_SCALE, -SOLARSYSTEM_SCALE) invSunPos = trinity.TriVectorSequencer() invSunPos.operator = trinity.TRIOP_MULTIPLY invSunPos.functions.append(sunBall) invSunPos.functions.append(vectorCurve) vectorCurve = trinity.TriVectorCurve() vectorCurve.value = (SOLARSYSTEM_SCALE, SOLARSYSTEM_SCALE, SOLARSYSTEM_SCALE) ballPos = trinity.TriVectorSequencer() ballPos.operator = trinity.TRIOP_MULTIPLY ballPos.functions.append(ball) ballPos.functions.append(vectorCurve) vectorSequencer = trinity.TriVectorSequencer() vectorSequencer.operator = trinity.TRIOP_ADD vectorSequencer.functions.append(invSunPos) vectorSequencer.functions.append(ballPos) bind = trinity.TriValueBinding() bind.copyValueCallable = self.OnBallPositionUpdate bind.sourceObject = vectorSequencer bind.sourceAttribute = 'value' self.binding = bind self.vectorSequencer = vectorSequencer if self.curveSet: curveSet = self.curveSet() if curveSet: curveSet.curves.append(vectorSequencer) curveSet.bindings.append(bind)
def LoadOrbitalObjects(self, scene): orbitalObjects = sm.GetService('planetInfo').GetOrbitalsForPlanet( self.planetID, const.groupPlanetaryCustomsOffices) park = sm.GetService('michelle').GetBallpark() addedObjects = [] for orbitalObjectID in orbitalObjects: invItem = park.GetInvItem(orbitalObjectID) fileName = None if evetypes.GetGraphicID(invItem.typeID) is not None: if type(evetypes.GetGraphicID(invItem.typeID)) != type(0): raise RuntimeError('NeedGraphicIDNotMoniker', invItem.itemID) if inventorycommon.typeHelpers.GetGraphic(invItem.typeID): fileName = inventorycommon.typeHelpers.GetGraphicFile( invItem.typeID) if not (fileName.lower().endswith('.red') or fileName.lower().endswith('.blue')): filenameAndTurretType = fileName.split(' ') fileName = filenameAndTurretType[0] if fileName is None: self.LogError( 'Error: Object type %s has invalid graphicFile, using graphicID: %s' % (invItem.typeID, evetypes.GetGraphicID(invItem.typeID))) continue tryFileName = fileName.replace(':/Model', ':/dx9/Model').replace( '.blue', '.red') tryFileName = tryFileName.replace('.red', '_UI.red') model = None if tryFileName is not None: try: model = blue.resMan.LoadObject(tryFileName) except: model = None if model is None: self.LogError('Was looking for:', tryFileName, 'but it does not exist!') if model is None: try: model = blue.resMan.LoadObject(fileName) except: model = None if not model: log.LogError( 'Could not load model for orbital object. FileName:', fileName, ' id:', invItem.itemID, ' typeID:', getattr(invItem, 'typeID', '?unknown?')) if invItem is not None and hasattr(invItem, 'typeID'): log.LogError('Type is:', evetypes.GetName(invItem.typeID)) continue model.name = '%s' % invItem.itemID model.display = 0 model.scaling = (0.002, 0.002, 0.002) addedObjects.append(model) orbitRoot = trinity.EveTransform() orbitRoot.children.append(model) inclinationRoot = trinity.EveTransform() inclinationRoot.children.append(orbitRoot) orbitalInclination = orbitalObjectID / math.pi % ( math.pi / 4.0) - math.pi / 8.0 if orbitalInclination <= 0.0: orbitalInclination -= math.pi / 8.0 else: orbitalInclination += math.pi / 8.0 inclinationRoot.rotation = geo2.QuaternionRotationSetYawPitchRoll( 0.0, orbitalInclination, 0.0) rotationCurveSet = trinity.TriCurveSet() rotationCurveSet.playOnLoad = False rotationCurveSet.Stop() rotationCurveSet.scaledTime = 0.0 rotationCurveSet.scale = 0.25 orbitRoot.curveSets.append(rotationCurveSet) ypr = trinity.TriYPRSequencer() ypr.YawCurve = trinity.TriScalarCurve() ypr.YawCurve.extrapolation = trinity.TRIEXT_CYCLE ypr.YawCurve.AddKey(0.0, 0.0, 0.0, 0.0, trinity.TRIINT_LINEAR) ypr.YawCurve.AddKey(200.0, 360.0, 0.0, 0.0, trinity.TRIINT_LINEAR) ypr.YawCurve.Sort() rotationCurveSet.curves.append(ypr) binding = trinity.TriValueBinding() binding.sourceObject = ypr binding.sourceAttribute = 'value' binding.destinationObject = orbitRoot binding.destinationAttribute = 'rotation' rotationCurveSet.bindings.append(binding) rotationCurveSet.Play() model.translation = (0.0, 0.0, 1500.0) model.rotation = geo2.QuaternionRotationSetYawPitchRoll( math.pi, 0.0, 0.0) scene.objects.append(inclinationRoot) ls = trinity.EveCurveLineSet() ls.scaling = (1.0, 1.0, 1.0) tex2D1 = trinity.TriTextureParameter() tex2D1.name = 'TexMap' tex2D1.resourcePath = 'res:/UI/Texture/Planet/link.dds' ls.lineEffect.resources.append(tex2D1) tex2D2 = trinity.TriTextureParameter() tex2D2.name = 'OverlayTexMap' tex2D2.resourcePath = 'res:/UI/Texture/Planet/link.dds' ls.lineEffect.resources.append(tex2D2) lineColor = (1.0, 1.0, 1.0, 0.05) p1 = SurfacePoint(0.0, 0.0, -1500.0, 1000.0) p2 = SurfacePoint(5.0, 0.0, 1498.0, 1000.0) l1 = ls.AddSpheredLineCrt(p1.GetAsXYZTuple(), lineColor, p2.GetAsXYZTuple(), lineColor, (0.0, 0.0, 0.0), 3.0) p1 = SurfacePoint(0.0, 0.0, -1500.0, 1000.0) p2 = SurfacePoint(-5.0, 0.0, 1498.0, 1000.0) l2 = ls.AddSpheredLineCrt(p1.GetAsXYZTuple(), lineColor, p2.GetAsXYZTuple(), lineColor, (0.0, 0.0, 0.0), 3.0) animationColor = (0.3, 0.3, 0.3, 0.5) ls.ChangeLineAnimation(l1, animationColor, 0.25, 1.0) ls.ChangeLineAnimation(l2, animationColor, -0.25, 1.0) ls.ChangeLineSegmentation(l1, 100) ls.ChangeLineSegmentation(l2, 100) ls.SubmitChanges() orbitRoot.children.append(ls) trinity.WaitForResourceLoads() for model in addedObjects: model.display = 1
def CreateBoneDriver(set, bone1, bone2, zone, min, max, oldMin, oldMax, curveDictionary, name, tweakData): if bone1 in pdDoll.bindPose and bone1 in pdDoll.boneOffsets and bone2 in pdDoll.bindPose and bone2 in pdDoll.boneOffsets: bindPosePos1 = pdDoll.bindPose[bone1]['translation'] offset1 = pdDoll.boneOffsets[bone1]['translation'] bindPosePos2 = pdDoll.bindPose[bone2]['translation'] offset2 = pdDoll.boneOffsets[bone2]['translation'] realPos1 = (bindPosePos1[0] / 100.0 + offset1[0], bindPosePos1[1] / 100.0 + offset1[1], bindPosePos1[2] / 100.0 + offset1[2]) realPos2 = (bindPosePos2[0] / 100.0 + offset2[0], bindPosePos2[1] / 100.0 + offset2[1], bindPosePos2[2] / 100.0 + offset2[2]) bindPoseDist = geo2.Vec3Distance(bindPosePos1, bindPosePos2) / 100.0 dist = geo2.Vec3Distance(realPos1, realPos2) multiplier = dist / bindPoseDist oldMin = oldMin * multiplier oldMax = oldMax * multiplier 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 curve1 = GetOrMakeCurve(bone1, set, curveDictionary, 'bone1') curve2 = GetOrMakeCurve(bone2, set, curveDictionary, 'bone2') bind = trinity.TriValueBinding() set.bindings.append(bind) def distanceBinding(curve1, curve2, min, max, parameters, index, gamma): avatar = weakAvatar.object if avatar is None: return curve1.skinnedObject = avatar curve2.skinnedObject = avatar if curve1.startValue == curve1.currentValue or curve2.startValue == curve2.currentValue: curve1.skinnedObject = None curve2.skinnedObject = None return p1 = curve1.currentValue[3] p2 = curve2.currentValue[3] dist = geo2.Vec3Distance(p1, p2) d = 1.0 - (dist - min) * 1 / (max - min) if d < 0: d = 0 elif d > 1: d = 1 if gamma != 1.0: d = math.pow(d, gamma) if False: trinity.GetDebugRenderer().DrawLine((p1[0], p1[1], p1[2]), 4294967295L, (p2[0], p2[1], p2[2]), 4294967295L) trinity.GetDebugRenderer().Print3D((p1[0], p1[1], p1[2]), 4294967295L, str(dist)) trinity.GetDebugRenderer().Print3D((p2[0], p2[1], p2[2]), 4294967295L, str(d)) for p_ in parameters: p = p_.object if p is None: continue if index == 1: p.v1 = d if index == 2: p.v2 = d if index == 3: p.v3 = d if index == 4: p.v4 = d curve1.skinnedObject = None curve2.skinnedObject = None zone = zone - 1 paramIndex = zone / 4 + 1 index = zone % 4 + 1 param = 'WrinkleNormalStrength' + str(paramIndex) parameters = [] for fx in effects: for p in fx.parameters: if p.name == param: parameters.append(blue.BluePythonWeakRef(p)) gammaCurves = tweakData.get('gammaCurves', {}) gamma = gammaCurves.get(name, gammaCurves.get('default', 1.0)) bind.copyValueCallable = lambda source, dest: distanceBinding(curve1, curve2, oldMin, oldMax, parameters, index, gamma)
def CreateAxisDriver(set, jointName, zone, axis, maxValue, name, tweakData, pdDoll): avatar = weakAvatar.object if avatar is None or not hasattr(avatar, 'animationUpdater') or avatar.animationUpdater is None or not hasattr(avatar.animationUpdater, 'network') or avatar.animationUpdater.network is None: return bind = trinity.TriValueBinding() set.bindings.append(bind) if not hasattr(avatar.animationUpdater, 'network'): return jointIndex = avatar.animationUpdater.network.GetBoneIndex(jointName) if jointIndex == -1: print "Error: Can't find bone for axis control: " + jointName return if not type(jointIndex) == type(1): print 'Non-int returned for bone in axis: ' + str(jointIndex) + ', name:' + jointName return bindPosePos = pdDoll.bindPose[jointName] if jointName in pdDoll.boneOffsets: offset = pdDoll.boneOffsets[jointName] else: offset = {'translation': [0, 0, 0]} startPos = [0, 0, 0, 0, 0, 0, 0, 0, 0, (bindPosePos['translation'][0] + offset['translation'][0]) / 100.0, (bindPosePos['translation'][1] + offset['translation'][1]) / 100.0, (bindPosePos['translation'][2] + offset['translation'][2]) / 100.0] def AxisBinding(startPos, jointIndex, axis, maxValue, parameters, index, gamma): avatar = weakAvatar.object if avatar is None: return if not hasattr(avatar.animationUpdater, 'network') or avatar.animationUpdater.network is None: return newPos = avatar.animationUpdater.network.GetRawTrackData(jointIndex) diff = (newPos[9] - startPos[9], newPos[10] - startPos[10], newPos[11] - startPos[11]) value = 0 if axis == 'x': value = diff[0] elif axis == 'y': value = diff[1] elif axis == 'z': value = diff[2] finalValue = 0 max = maxValue if max < 0: max = -max value = -value if value > max: finalValue = 1.0 elif value < 0: finalValue = 0.0 else: finalValue = value / max if gamma != 1.0: finalValue = math.pow(finalValue, gamma) for p_ in parameters: p = p_.object if p is None: continue if index == 1: p.v1 = finalValue if index == 2: p.v2 = finalValue if index == 3: p.v3 = finalValue if index == 4: p.v4 = finalValue zone = zone - 1 paramIndex = zone / 4 + 1 index = zone % 4 + 1 param = 'WrinkleNormalStrength' + str(paramIndex) parameters = [] for fx in effects: for p in fx.parameters: if p.name == param: parameters.append(blue.BluePythonWeakRef(p)) gammaCurves = tweakData.get('gammaCurves', {}) gamma = gammaCurves.get(name, gammaCurves.get('default', 1.0)) bind.name = 'AxisBind' bind.copyValueCallable = lambda source, dest: AxisBinding(startPos, jointIndex, axis, maxValue, parameters, index, gamma)
def _AddTarget(): import trinity import uiconst import random import uicls par = uicls.Container(parent=uicore.desktop, left=256, top=random.randint(1, 500), align=uiconst.RELATIVE, width=300, height=128) curveSet = par.CreateCurveSet() curveSet.scale = 1.0 curve = trinity.TriPerlinCurve() curve.scale = 1000.0 curve.offset = -0.0 curve.N = 2 curve.speed = 1.0 curve.alpha = 1000.0 curve.beta = 5000.0 curveSet.curves.append(curve) binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = par binding.destinationAttribute = 'displayY' binding.scale = 1 curveSet.bindings.append(binding) curve = trinity.TriPerlinCurve() curve.scale = 1200.0 curve.offset = -300.0 curve.N = 2 curve.speed = 1.0 curve.alpha = 1200.0 curve.beta = 8000.0 curveSet.curves.append(curve) binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = par binding.destinationAttribute = 'displayX' binding.scale = 1 curveSet.bindings.append(binding) inTime = 0.5 mainParent = uicls.Container(parent=par, name='mainParent', align=uiconst.RELATIVE, width=200, height=64, top=32, left=96) maintext = uicls.Sprite(parent=mainParent, texturePath='res:/UICore/texture/text.dds', left=96.0, width=200, height=64, effect=trinity.S2D_RFX_BLUR) caption = uicls.Sprite(parent=mainParent, texturePath='res:/UICore/texture/caption.dds', left=50, top=56, width=160, height=32, effect=trinity.S2D_RFX_BLUR) bracket = uicls.Sprite(parent=mainParent, texturePath='res:/UICore/texture/brackettext.dds', left=200, top=56, width=100, height=32, effect=trinity.S2D_RFX_BLUR) scrolltext = uicls.Label(parent=mainParent, text='0123456789', align=uiconst.TOPLEFT, left=237, top=7, fontsize=9, color=(1.0, 1.0, 1.0, 0.5)) curve, binding = CreateColorCurve(bracket, curveSet, length=0.5, startValue=(1, 1, 1, 1), endValue=(1, 1, 1, 0), cycle=True) curve.AddKey(0.0, (1, 1, 1, 0.0)) curve.AddKey(0.1, (1, 1, 1, 1)) curve.AddKey(0.5, (1, 1, 1, 0.0)) AddBinding(curve, 'currentValue', caption, 'color', curveSet) curve, binding = CreateScalarCurve(mainParent, 'currentValue', 'displayX', curveSet, length=inTime, startValue=-500.0, endValue=0.0, endTangent=-1000.0, cycle=False) correction = -0.5 curve = trinity.TriPerlinCurve() curve.scale = 400.0 curve.offset = 200.0 curveSet.curves.append(curve) innerTransform = trinity.Tr2Sprite2dTransform() innerTransform.translation = (0, 0) innerTransform.rotationCenter = (64, 64) par.children.insert(0, innerTransform) inner = trinity.Tr2Sprite2d() innerTransform.children.append(inner) inner.displayWidth = inner.displayHeight = 128 inner.displayX = correction inner.displayY = correction inner.texturePrimary = trinity.Tr2Sprite2dTexture() inner.texturePrimary.resPath = 'res:/uicore/Texture/innercircles.dds' binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = innerTransform binding.destinationAttribute = 'rotation' binding.scale = 0.025 curveSet.bindings.append(binding) curve = trinity.TriSineCurve() curve.scale = 500.0 curve.offset = 300.0 curve.speed = 0.3 curveSet.curves.append(curve) outerTransform = trinity.Tr2Sprite2dTransform() outerTransform.translation = (0, 0) outerTransform.rotationCenter = (64, 64) par.children.insert(0, outerTransform) outer = trinity.Tr2Sprite2d() outerTransform.children.append(outer) outer.displayWidth = outer.displayHeight = 128 outer.displayX = correction outer.displayY = correction outer.texturePrimary = trinity.Tr2Sprite2dTexture() outer.texturePrimary.resPath = 'res:/uicore/Texture/outercircles.dds' outer.effect = trinity.S2D_RFX_BLUR outer.blurFactor = 0.1 binding = trinity.TriValueBinding() binding.sourceObject = curve binding.sourceAttribute = 'value' binding.destinationObject = outerTransform binding.destinationAttribute = 'rotation' binding.scale = 0.00125 curveSet.bindings.append(binding) curveSet.Play()
def PrepareModelForConstruction(self, builtAlready, onlineAlready): self.LogInfo(' PrepareModelForConstruction - Built:', builtAlready, ' Online:', onlineAlready) if not self.model: return (None, None) if not hasattr(self.model, 'curveSets'): return (None, None) model = self.model alphaParams = [] if model.meshLod: self.PrepareAreasForConstruction(model.meshLod.opaqueAreas, alphaParams, 'high_opaque') self.PrepareAreasForConstruction(model.meshLod.decalAreas, alphaParams, 'high_decal') self.PrepareAreasForConstruction(model.meshLod.transparentAreas, alphaParams, 'high_transparent') else: self.PrepareAreasForConstruction(model.mesh.opaqueAreas, alphaParams, 'high_opaque') self.PrepareAreasForConstruction(model.mesh.decalAreas, alphaParams, 'high_decal') self.PrepareAreasForConstruction(model.mesh.transparentAreas, alphaParams, 'high_transparent') buildCurve = trinity.TriCurveSet() buildCurve.name = 'Build' buildCurve.playOnLoad = False buildCurve.Stop() buildCurve.scaledTime = 0.0 model.curveSets.append(buildCurve) curve = trinity.TriScalarCurve() curve.value = 1.0 curve.extrapolation = trinity.TRIEXT_CONSTANT buildCurve.curves.append(curve) curve.AddKey(0.0, 1.0, 0.0, 0.0, trinity.TRIINT_HERMITE) curve.AddKey(10.0, 0.0, 0.0, 0.0, trinity.TRIINT_HERMITE) curve.Sort() for alphaParam in alphaParams: binding = trinity.TriValueBinding() binding.sourceAttribute = 'value' binding.destinationAttribute = 'value.x' binding.scale = 1.0 binding.sourceObject = curve binding.destinationObject = alphaParam buildCurve.bindings.append(binding) glows = nodemanager.FindNodes(model, 'GlowColor', 'trinity.Tr2Vector4Parameter') finalColor = (1.0, 1.0, 1.0) if glows: r, g, b, a = glows[0].value finalColor = (r, g, b) onlineCurve = trinity.TriCurveSet() onlineCurve.name = 'Online' onlineCurve.playOnLoad = False onlineCurve.Stop() onlineCurve.scaledTime = 0.0 model.curveSets.append(onlineCurve) curve = trinity.TriVectorCurve() onlineCurve.curves.append(curve) curve.value = finalColor curve.extrapolation = trinity.TRIEXT_CONSTANT curve.AddKey(0.0, ONLINE_GLOW_OFF, (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), trinity.TRIINT_HERMITE) curve.AddKey(1.9, ONLINE_GLOW_MID, (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), trinity.TRIINT_LINEAR) curve.AddKey(2.0, finalColor, (0.0, 0.0, 0.0), (0.0, 0.0, 0.0), trinity.TRIINT_HERMITE) curve.Sort() for each in glows: binding = trinity.TriValueBinding() binding.sourceAttribute = 'value' binding.destinationAttribute = 'value' binding.scale = 1.0 binding.sourceObject = curve binding.destinationObject = each onlineCurve.bindings.append(binding) if builtAlready: buildCurve.Stop() buildCurve.scale = 0.0 buildCurve.scaledTime = buildCurve.GetMaxCurveDuration() buildCurve.PlayFrom(buildCurve.scaledTime) self.LogInfo( ' PrepareModelForConstruction - Already Built, set curve to:', buildCurve.scaledTime) if onlineAlready: onlineCurve.Stop() onlineCurve.scale = 0.0 onlineCurve.scaledTime = onlineCurve.GetMaxCurveDuration() onlineCurve.PlayFrom(onlineCurve.scaledTime) self.LogInfo( ' PrepareModelForConstruction - Already Online, Set curve Time to:', onlineCurve.scaledTime) trinity.WaitForResourceLoads() if model.meshLod: for each in model.meshLod.opaqueAreas: each.effect.PopulateParameters() else: for each in model.mesh.opaqueAreas: each.effect.PopulateParameters() return (buildCurve, onlineCurve)
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)