def activate(self): if self.__activated or self._vehicle is None: return else: player = BigWorld.player() isPlayerVehicle = self._vehicle.isPlayerVehicle or self._vehicle.id == player.observedVehicleID self.__originalFilter = self._vehicle.filter if isPlayerVehicle and self.collisions is not None: colliderData = (self.collisions.getColliderID(), (TankPartNames.getIdx(TankPartNames.HULL), TankPartNames.getIdx(TankPartNames.TURRET), TankPartNames.getIdx(TankPartNames.GUN))) BigWorld.appendCameraCollider(colliderData) self.__inSpeedTreeCollision = True BigWorld.setSpeedTreeCollisionBody( self.compoundModel.getBoundsForPart(TankPartIndexes.HULL)) self.__linkCompound() self.__createTerrainCircle() super(CompoundAppearance, self).activate() self.onModelChanged() if not self.isObserver: self.__dirtUpdateTime = BigWorld.time() BigWorld.player().arena.onPeriodChange += self.__arenaPeriodChanged BigWorld.player().arena.onVehicleUpdated += self.__vehicleUpdated BigWorld.player( ).inputHandler.onCameraChanged += self._onCameraChanged if self.detailedEngineState is not None: engine_state.checkEngineStart(self.detailedEngineState, BigWorld.player().arena.period) self.__activated = True return
def start(self, prereqs=None): self.collisions = prereqs['collisionAssembler'] self.__typeDesc.chassis.hitTester.bbox = self.collisions.getBoundingBox( TankPartNames.getIdx(TankPartNames.CHASSIS)) self.__typeDesc.hull.hitTester.bbox = self.collisions.getBoundingBox( TankPartNames.getIdx(TankPartNames.HULL)) self.__typeDesc.turret.hitTester.bbox = self.collisions.getBoundingBox( TankPartNames.getIdx(TankPartNames.TURRET)) self.__typeDesc.gun.hitTester.bbox = self.collisions.getBoundingBox( TankPartNames.getIdx(TankPartNames.GUN)) self.__compoundModel = prereqs[self.__typeDesc.name] self.__boundEffects = bound_effects.ModelBoundEffects( self.__compoundModel) isCurrentModelDamaged = self.__currentDamageState.isCurrentModelDamaged fashions = camouflages.prepareFashions(isCurrentModelDamaged) if not isCurrentModelDamaged: model_assembler.setupTracksFashion(self.__typeDesc, fashions.chassis) self.__setFashions(fashions, self.__isTurretDetached) self.__setupModels() if not isCurrentModelDamaged: self.__splineTracks = model_assembler.setupSplineTracks( self.__fashion, self.__typeDesc, self.__compoundModel, prereqs) self.crashedTracksController = CrashedTrackController( self.__typeDesc, self.__fashion) else: self.__trackScrollCtl = None if self.__currentDamageState.effect is not None: self.__playEffect(self.__currentDamageState.effect, SpecialKeyPointNames.STATIC) self.__chassisDecal.create() return
def onEnterWorld(self, prereqs): LOG_DEBUG('onEnterWorld', self.__vehDescr.name, self.spaceID) self.model = prereqs[self.__vehDescr.name] self.model.matrix = self.matrix self.collisions = prereqs['collisionAssembler'] self.__detachConfirmationTimer.onEnterWorld() self.__vehDescr.keepPrereqs(prereqs) turretDescr = self.__vehDescr.turret if self.isUnderWater == 0: self.__detachmentEffects = _TurretDetachmentEffects( self.model, turretDescr.turretDetachmentEffects, self.isCollidingWithWorld == 1) self.addComponent(self.__detachmentEffects) else: self.__detachmentEffects = None self.__hitEffects = _HitEffects(self.model) self.addComponent(self.__hitEffects) self.__componentsDesc = (self.__vehDescr.turret, self.__vehDescr.gun) from helpers.CallbackDelayer import CallbackDelayer self.__isBeingPulledCallback = CallbackDelayer() self.__isBeingPulledCallback.delayCallback(self.__checkIsBeingPulled(), self.__checkIsBeingPulled) DetachedTurret.allTurrets.append(self) collisionData = ((TankPartNames.getIdx(TankPartNames.TURRET), self.model.matrix), (TankPartNames.getIdx(TankPartNames.GUN), self.model.node(TankPartNames.GUN))) self.collisions.connect(self.id, ColliderTypes.DYNAMIC_COLLIDER, collisionData) ScriptGameObject.activate(self) return
def addCameraCollider(self): collider = self.collisions if collider is not None: colliderData = (collider.getColliderID(), (TankPartNames.getIdx(TankPartNames.HULL), TankPartNames.getIdx(TankPartNames.TURRET))) BigWorld.appendCameraCollider(colliderData) return
def __reloadColliderType(self, state): if not self.collisions: return if state != CameraMovementStates.FROM_OBJECT: colliderData = (self.collisions.getColliderID(), (TankPartNames.getIdx(TankPartNames.GUN) + 1, TankPartNames.getIdx(TankPartNames.GUN) + 2, TankPartNames.getIdx(TankPartNames.GUN) + 3)) BigWorld.appendCameraCollider(colliderData) else: BigWorld.removeCameraCollider(self.collisions.getColliderID())
def computeVehicleHeight(self): gunLength = 0.0 height = 0.0 if self.collisions is not None: desc = self.__typeDesc hullBB = self.collisions.getBoundingBox(TankPartNames.getIdx(TankPartNames.HULL)) turretBB = self.collisions.getBoundingBox(TankPartNames.getIdx(TankPartNames.TURRET)) gunBB = self.collisions.getBoundingBox(TankPartNames.getIdx(TankPartNames.GUN)) hullTopY = desc.chassis.hullPosition[1] + hullBB[1][1] turretTopY = desc.chassis.hullPosition[1] + desc.hull.turretPositions[0][1] + turretBB[1][1] gunTopY = desc.chassis.hullPosition[1] + desc.hull.turretPositions[0][1] + desc.turret.gunPosition[1] + gunBB[1][1] gunLength = math.fabs(gunBB[1][2] - gunBB[0][2]) height = max(hullTopY, max(turretTopY, gunTopY)) return (height, gunLength)
def attach(self, compoundModel, isDamaged, showDamageStickers): for componentName, attachNodeName in VehicleStickers.COMPONENT_NAMES: idx = TankPartNames.getIdx(componentName) node = compoundModel.node(attachNodeName) if node is None: continue geometryLink = compoundModel.getPartGeometryLink(idx) componentStickers = self.__stickers[componentName] componentStickers.stickers.attachStickers(geometryLink, node, isDamaged) if showDamageStickers: for damageSticker in componentStickers.damageStickers.itervalues(): if damageSticker.handle is not None: componentStickers.stickers.delDamageSticker(damageSticker.handle) damageSticker.handle = None LOG_WARNING('Adding %s damage sticker to occupied slot' % componentName) damageSticker.handle = componentStickers.stickers.addDamageSticker(damageSticker.stickerID, damageSticker.rayStart, damageSticker.rayEnd) if self.__animateGunInsignia: gunNode = compoundModel.node(TankNodeNames.GUN_INCLINATION) if isDamaged else compoundModel.node(VehicleStickers.__INSIGNIA_NODE_NAME) else: gunNode = compoundModel.node(TankNodeNames.GUN_INCLINATION) if gunNode is None: return else: gunGeometry = compoundModel.getPartGeometryLink(TankPartIndexes.GUN) self.__stickers['gunInsignia'].stickers.attachStickers(gunGeometry, gunNode, isDamaged) return
def __init__(self, spaceID, vehicleDesc, insigniaRank=0, outfit=None): self.__defaultAlpha = vehicleDesc.type.emblemsAlpha self.__show = True self.__animateGunInsignia = vehicleDesc.gun.animateEmblemSlots self.__currentInsigniaRank = insigniaRank self.__vDesc = vehicleDesc self.__componentNames = [(TankPartNames.HULL, TankPartNames.HULL), (TankPartNames.TURRET, TankPartNames.TURRET), (TankPartNames.GUN, TankNodeNames.GUN_INCLINATION)] if outfit is None: outfit = Outfit(vehicleCD=vehicleDesc.makeCompactDescr()) componentSlots = self._createComponentSlots(vehicleDesc, vehicleDesc.turret.showEmblemsOnGun, outfit) if not isUseDebugStickers(): self.__stickerPacks = self._createStickerPacks(vehicleDesc, outfit, insigniaRank) else: self.__stickerPacks = self._createDebugStickerPacks(vehicleDesc, outfit, insigniaRank) self.__stickers = {} for componentName, emblemSlots in componentSlots: if componentName == Insignia.Types.SINGLE: componentIdx = Insignia.Indexes.SINGLE elif componentName == Insignia.Types.DUAL_LEFT: componentIdx = Insignia.Indexes.DUAL_LEFT elif componentName == Insignia.Types.DUAL_RIGHT: componentIdx = Insignia.Indexes.DUAL_RIGHT else: componentIdx = TankPartNames.getIdx(componentName) modelStickers = ModelStickers(spaceID, componentIdx, self.__stickerPacks, vehicleDesc, emblemSlots) self.__stickers[componentName] = ComponentStickers(modelStickers, {}, 1.0) return
def computeVehicleLength(self): vehicleLength = 0.0 if self.collisions is not None: hullBB = self.collisions.getBoundingBox( TankPartNames.getIdx(TankPartNames.HULL)) vehicleLength = abs(hullBB[1][2] - hullBB[0][2]) return vehicleLength
def __prepareModelAssembler(self): assembler = BigWorld.CompoundAssembler(self.__vehDescr.name, self.spaceID) turretModel = self.__vehDescr.turret.models.exploded gunModel = self.__vehDescr.gun.models.exploded assembler.addRootPart(turretModel, TankPartNames.TURRET) assembler.emplacePart(gunModel, TankNodeNames.GUN_JOINT, TankPartNames.GUN) bspModels = ((TankPartNames.getIdx(TankPartNames.TURRET), self.__vehDescr.turret.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.GUN), self.__vehDescr.gun.hitTester.bspModelName)) collisionAssembler = BigWorld.CollisionAssembler( bspModels, BigWorld.player().spaceID) return [assembler, collisionAssembler]
def __prepareModelAssembler(self): LOG_DEBUG('__prepareModelAssembler', self.__vehDescr.name, self.spaceID) assembler = BigWorld.CompoundAssembler(self.__vehDescr.name, self.spaceID) turretModel, gunModel = self.__getModels() assembler.addRootPart(turretModel, TankPartNames.TURRET) assembler.emplacePart(gunModel, TankNodeNames.GUN_JOINT, TankPartNames.GUN) parts = { TankPartNames.TURRET: self.__vehDescr.turret, TankPartNames.GUN: self.__vehDescr.gun } bspModels = () for partName, part in parts.iteritems(): partID = TankPartNames.getIdx(partName) crashedHT = part.hitTesterManager.crashedModelHitTester modelHT = part.hitTesterManager.modelHitTester hitTester = crashedHT if crashedHT is not None else modelHT bspModel = (partID, hitTester.bspModelName) bspModels = bspModels + (bspModel, ) collisionAssembler = BigWorld.CollisionAssembler( bspModels, self.spaceID) return [assembler, collisionAssembler]
def prerequisites(self, typeDescriptor, vID, health, isCrewActive, isTurretDetached, outfitCD, renderState=None): self.damageState.update(health, isCrewActive, False) self.__typeDesc = typeDescriptor self.__vID = vID self._isTurretDetached = isTurretDetached self.__outfit = self._prepareOutfit(outfitCD) if self.damageState.isCurrentModelUndamaged: self.__attachments = camouflages.getAttachments(self.outfit, self.typeDescriptor) self.__renderState = renderState prereqs = self.typeDescriptor.prerequisites(True) prereqs.extend(camouflages.getCamoPrereqs(self.outfit, self.typeDescriptor)) prereqs.extend(camouflages.getModelAnimatorsPrereqs(self.outfit, self.worldID)) prereqs.extend(camouflages.getAttachmentsAnimatorsPrereqs(self.__attachments, self.worldID)) splineDesc = self.typeDescriptor.chassis.splineDesc if splineDesc is not None: modelsSet = self.outfit.modelsSet prereqs.append(splineDesc.segmentModelLeft(modelsSet)) prereqs.append(splineDesc.segmentModelRight(modelsSet)) segment2ModelLeft = splineDesc.segment2ModelLeft(modelsSet) if segment2ModelLeft is not None: prereqs.append(segment2ModelLeft) segment2ModelRight = splineDesc.segment2ModelRight(modelsSet) if segment2ModelRight is not None: prereqs.append(segment2ModelRight) modelsSetParams = self.modelsSetParams compoundAssembler = model_assembler.prepareCompoundAssembler(self.typeDescriptor, modelsSetParams, self.worldID, self.isTurretDetached, renderState=self.renderState) prereqs.append(compoundAssembler) if renderState == RenderStates.OVERLAY_COLLISION: self.damageState.update(0, isCrewActive, False) if not isTurretDetached: bspModels = ((TankPartNames.getIdx(TankPartNames.CHASSIS), typeDescriptor.chassis.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.HULL), typeDescriptor.hull.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.TURRET), typeDescriptor.turret.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.GUN), typeDescriptor.gun.hitTester.bspModelName)) else: bspModels = ((TankPartNames.getIdx(TankPartNames.CHASSIS), typeDescriptor.chassis.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.HULL), typeDescriptor.hull.hitTester.bspModelName)) collisionAssembler = BigWorld.CollisionAssembler(bspModels, self.worldID) prereqs.append(collisionAssembler) physicalTracksBuilders = self.typeDescriptor.chassis.physicalTracks for name, builders in physicalTracksBuilders.iteritems(): for index, builder in enumerate(builders): prereqs.append(builder.createLoader(self.worldID, '{0}{1}PhysicalTrack'.format(name, index), modelsSetParams.skin)) return prereqs
def collideDynamic(startPoint, endPoint, exceptIDs, skipGun=False): ignoreID = 0 if exceptIDs: ignoreID = exceptIDs[0] res = BigWorld.wg_collideDynamic( BigWorld.player().spaceID, startPoint, endPoint, ignoreID, -1 if skipGun else TankPartNames.getIdx(TankPartNames.GUN)) if res is not None: isVehicle = res[2] == ColliderTypes.VEHICLE_COLLIDER res = (res[0], EntityCollisionData(res[3], res[4], res[5], isVehicle)) return res
def attach(self, compoundModel, isDamaged, showDamageStickers, isDetachedTurret=False): for componentName, attachNodeName in VehicleStickers.COMPONENT_NAMES: idx = DetachedTurretPartNames.getIdx( componentName) if isDetachedTurret else TankPartNames.getIdx( componentName) node = compoundModel.node(attachNodeName) if node is None: continue geometryLink = compoundModel.getPartGeometryLink(idx) componentStickers = self.__stickers[componentName] componentStickers.stickers.attachStickers(geometryLink, node, isDamaged) if showDamageStickers: for damageSticker in componentStickers.damageStickers.itervalues( ): if damageSticker.handle is not None: componentStickers.stickers.delDamageSticker( damageSticker.handle) damageSticker.handle = None LOG_WARNING( 'Adding %s damage sticker to occupied slot' % componentName) damageSticker.handle = componentStickers.stickers.addDamageSticker( damageSticker.stickerID, damageSticker.rayStart, damageSticker.rayEnd) if isDamaged: gunNode = compoundModel.node(TankPartNames.GUN) elif self.__animateGunInsignia: gunNode = compoundModel.node(VehicleStickers.__INSIGNIA_NODE_NAME) else: gunNode = compoundModel.node(TankNodeNames.GUN_INCLINATION) if gunNode is None: return else: gunGeometry = compoundModel.getPartGeometryLink( DetachedTurretPartIndexes.GUN ) if isDetachedTurret else compoundModel.getPartGeometryLink( TankPartIndexes.GUN) if isDamaged: toPartRoot = mathUtils.createIdentityMatrix() else: toPartRoot = Math.Matrix(gunNode) toPartRoot.invert() toPartRoot.preMultiply( compoundModel.node(TankNodeNames.GUN_INCLINATION)) self.__stickers['gunInsignia'].stickers.attachStickers( gunGeometry, gunNode, isDamaged, toPartRoot) return
def applyPlayerCache(outfit, vehName, seasonCache): itemsCache = dependency.instance(IItemsCache) for itemTypeName in seasonCache.keys(): if itemTypeName not in ('paint', 'modification', 'emblem', 'inscription'): if itemTypeName != 'camo': print '%s: invalid item type in outfit cache for %s:' % ( g_config.ID, vehName), itemTypeName del seasonCache[itemTypeName] continue itemDB = items.vehicles.g_cache.customization20().itemTypes[ C11N_ITEM_TYPE_MAP[GUI_ITEM_TYPE_INDICES[itemTypeName]]] for areaName in seasonCache[itemTypeName].keys(): if itemTypeName == 'modification': if areaName != 'misc': print g_config.ID + ': wrong area name for', vehName, 'modification:' % ( g_config.ID, vehName), areaName del seasonCache[itemTypeName][areaName] continue else: areaId = Area.MISC else: try: areaId = TankPartNames.getIdx(areaName) except Exception as e: print g_config.ID + ': exception while reading outfit cache for', vehName, 'in', areaName + ':', e.message continue slot = outfit.getContainer(areaId).slotFor( GUI_ITEM_TYPE_INDICES[itemTypeName]) for regionIdx in seasonCache[itemTypeName][areaName].keys(): itemID = seasonCache[itemTypeName][areaName][regionIdx] if not itemID: try: slot.remove(int(regionIdx)) except KeyError: # a paint is being deleted while not applied at all. possible change after last cache del seasonCache[itemTypeName][areaName][ regionIdx] # so we remove an obsolete key continue if itemID not in itemDB: print '%s: wrong item ID for %s, idx %s:' % ( g_config.ID, areaName, regionIdx), itemID del seasonCache[itemTypeName][areaName][regionIdx] continue intCD = itemDB[itemID].compactDescr if itemsCache.items.isSynced(): item = itemsCache.items.getItemByCD(intCD) else: item = itemsCache.items.itemsFactory.createCustomization( intCD) slot.set(item, int(regionIdx)) if not seasonCache[itemTypeName][areaName]: del seasonCache[itemTypeName][areaName] outfit.invalidate()
def __setupModel(self, buildIdx): self.__assembleModel() matrix = math_utils.createSRTMatrix(Math.Vector3(1.0, 1.0, 1.0), Math.Vector3(self.__vEntity.yaw, self.__vEntity.pitch, self.__vEntity.roll), self.__vEntity.position) self.__vEntity.model.matrix = matrix self.__doFinalSetup(buildIdx) self.__vEntity.typeDescriptor = self.__vDesc typeDescr = self.__vDesc wheelConfig = typeDescr.chassis.generalWheelsAnimatorConfig if self.wheelsAnimator is not None and wheelConfig is not None: self.wheelsAnimator.createCollision(wheelConfig, self.collisions) gunColBox = self.collisions.getBoundingBox(TankPartNames.getIdx(TankPartNames.GUN) + 3) center = 0.5 * (gunColBox[1] - gunColBox[0]) gunoffset = Math.Matrix() gunoffset.setTranslate((0.0, 0.0, center.z + gunColBox[0].z)) gunNode = self.__getGunNode() gunLink = math_utils.MatrixProviders.product(gunoffset, gunNode) collisionData = ((TankPartNames.getIdx(TankPartNames.CHASSIS), self.__vEntity.model.matrix), (TankPartNames.getIdx(TankPartNames.HULL), self.__vEntity.model.node(TankPartNames.HULL)), (TankPartNames.getIdx(TankPartNames.TURRET), self.__vEntity.model.node(TankPartNames.TURRET)), (TankPartNames.getIdx(TankPartNames.GUN), gunNode)) self.collisions.connect(self.__vEntity.id, ColliderTypes.VEHICLE_COLLIDER, collisionData) collisionData = ((TankPartNames.getIdx(TankPartNames.GUN) + 1, self.__vEntity.model.node(TankPartNames.HULL)), (TankPartNames.getIdx(TankPartNames.GUN) + 2, self.__vEntity.model.node(TankPartNames.TURRET)), (TankPartNames.getIdx(TankPartNames.GUN) + 3, gunLink)) self.collisions.connect(self.__vEntity.id, self._getColliderType(), collisionData) self._reloadColliderType(self.__vEntity.state) self.__reloadShadowManagerTarget(self.__vEntity.state) return
def prerequisites(self, typeDescriptor, vID, health=1, isCrewActive=True, isTurretDetached=False, outfitCD=''): prereqs = self.__appearance.prerequisites(typeDescriptor, vID, health, isCrewActive, isTurretDetached, outfitCD) compoundAssembler = prepareCompoundAssembler( typeDescriptor, self.__appearance.modelsSetParams, BigWorld.player().spaceID, isTurretDetached) if not isTurretDetached: bspModels = ((TankPartNames.getIdx(TankPartNames.CHASSIS), typeDescriptor.chassis.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.HULL), typeDescriptor.hull.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.TURRET), typeDescriptor.turret.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.GUN), typeDescriptor.gun.hitTester.bspModelName)) else: bspModels = ((TankPartNames.getIdx(TankPartNames.CHASSIS), typeDescriptor.chassis.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.HULL), typeDescriptor.hull.hitTester.bspModelName)) collisionAssembler = BigWorld.CollisionAssembler( bspModels, BigWorld.player().spaceID) prereqs += [compoundAssembler, collisionAssembler] return (compoundAssembler, prereqs)
def activate(self): if self.collisions is not None and self.isTurretDetached: self.collisions.removeAttachment(TankPartNames.getIdx(TankPartNames.TURRET)) self.collisions.removeAttachment(TankPartNames.getIdx(TankPartNames.GUN)) super(CommonTankAppearance, self).activate() if not self.isObserver: self._chassisDecal.attach() self._createAndAttachStickers() if not self.isObserver: if not self.damageState.isCurrentModelDamaged and not self.__systemStarted: self._startSystems() self.filter.enableLagDetection(not self.damageState.isCurrentModelDamaged) if self.__periodicTimerID is not None: BigWorld.cancelCallback(self.__periodicTimerID) self.__periodicTimerID = BigWorld.callback(PERIODIC_UPDATE_TIME, self.__onPeriodicTimer) self.setupGunMatrixTargets(self.filter) for lodCalculator in self.allLodCalculators: lodCalculator.setupPosition(DataLinks.linkMatrixTranslation(self.compoundModel.matrix)) for modelAnimator in self.__modelAnimators: modelAnimator.animator.start() if hasattr(self.filter, 'placingCompensationMatrix') and self.swingingAnimator is not None: self.swingingAnimator.placingCompensationMatrix = self.filter.placingCompensationMatrix self.swingingAnimator.worldMatrix = self.compoundModel.matrix if self.isObserver: self.compoundModel.visible = False if self.collisions is not None: chassisColisionMatrix, gunNodeName = self._vehicleColliderInfo collisionData = ((TankPartNames.getIdx(TankPartNames.HULL), self.compoundModel.node(TankPartNames.HULL)), (TankPartNames.getIdx(TankPartNames.TURRET), self.compoundModel.node(TankPartNames.TURRET)), (TankPartNames.getIdx(TankPartNames.CHASSIS), chassisColisionMatrix), (TankPartNames.getIdx(TankPartNames.GUN), self.compoundModel.node(gunNodeName))) self.collisions.connect(self.id, ColliderTypes.VEHICLE_COLLIDER, collisionData) return
def __startBuild(self, vDesc, vState): self.__curBuildInd += 1 self.__vState = vState self.__resources = {} self.__vehicleStickers = None cfg = hangarCFG() if vState == 'undamaged': self.__currentEmblemsAlpha = cfg['emblems_alpha_undamaged'] self.__isVehicleDestroyed = False else: self.__currentEmblemsAlpha = cfg['emblems_alpha_damaged'] self.__isVehicleDestroyed = True self.__vDesc = vDesc resources = camouflages.getCamoPrereqs(self.__outfit, vDesc) splineDesc = vDesc.chassis.splineDesc if splineDesc is not None: resources.append(splineDesc.segmentModelLeft) resources.append(splineDesc.segmentModelRight) if splineDesc.leftDesc is not None: resources.append(splineDesc.leftDesc) if splineDesc.rightDesc is not None: resources.append(splineDesc.rightDesc) if splineDesc.segment2ModelLeft is not None: resources.append(splineDesc.segment2ModelLeft) if splineDesc.segment2ModelRight is not None: resources.append(splineDesc.segment2ModelRight) from vehicle_systems import model_assembler resources.append(model_assembler.prepareCompoundAssembler(self.__vDesc, ModelsSetParams(self.__outfit.modelsSet, self.__vState), self.__spaceId)) g_eventBus.handleEvent(CameraRelatedEvents(CameraRelatedEvents.VEHICLE_LOADING, ctx={'started': True, 'vEntityId': self.__vEntity.id}), scope=EVENT_BUS_SCOPE.DEFAULT) cfg = hangarCFG() gunScale = Math.Vector3(1.0, 1.0, 1.1) capsuleScale = Math.Vector3(1.5, 1.5, 1.5) loadedGunScale = cfg.get('cam_capsule_gun_scale', gunScale) if loadedGunScale is not None: gunScale = loadedGunScale loadedCapsuleScale = cfg.get('cam_capsule_scale', capsuleScale) if loadedCapsuleScale is not None: capsuleScale = loadedCapsuleScale bspModels = ((TankPartNames.getIdx(TankPartNames.CHASSIS), vDesc.chassis.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.HULL), vDesc.hull.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.TURRET), vDesc.turret.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.GUN), vDesc.gun.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.GUN) + 1, vDesc.hull.hitTester.bspModelName, capsuleScale), (TankPartNames.getIdx(TankPartNames.GUN) + 2, vDesc.turret.hitTester.bspModelName, capsuleScale), (TankPartNames.getIdx(TankPartNames.GUN) + 3, vDesc.gun.hitTester.bspModelName, gunScale)) collisionAssembler = BigWorld.CollisionAssembler(bspModels, self.__spaceId) resources.append(collisionAssembler) physicalTracksBuilders = vDesc.chassis.physicalTracks for name, builder in physicalTracksBuilders.iteritems(): resources.append(builder.createLoader('{0}PhysicalTrack'.format(name))) BigWorld.loadResourceListBG(tuple(resources), makeCallbackWeak(self.__onResourcesLoaded, self.__curBuildInd)) return
def attach(self, compoundModel, isDamaged, showDamageStickers, isDetachedTurret=False): for componentName, attachNodeName in self.__componentNames: idx = DetachedTurretPartNames.getIdx( componentName) if isDetachedTurret else TankPartNames.getIdx( componentName) node = compoundModel.node(attachNodeName) if node is None: continue if idx is None: node = compoundModel.node(componentName + ( '_normal' if not isDamaged else '_destroyed')) idx = compoundModel.findPartHandleByNode(node) geometryLink = compoundModel.getPartGeometryLink(idx) componentStickers = self.__stickers[componentName] componentStickers.stickers.attachStickers(geometryLink, node, isDamaged) if showDamageStickers: for damageSticker in componentStickers.damageStickers.itervalues( ): if damageSticker.handle is not None: componentStickers.stickers.delDamageSticker( damageSticker.handle) damageSticker.handle = None LOG_WARNING( 'Adding %s damage sticker to occupied slot' % componentName) damageSticker.handle = componentStickers.stickers.addDamageSticker( damageSticker.stickerID, damageSticker.rayStart, damageSticker.rayEnd) if isDetachedTurret: gunGeometry = compoundModel.getPartGeometryLink( DetachedTurretPartIndexes.GUN) else: gunGeometry = compoundModel.getPartGeometryLink( TankPartIndexes.GUN) for key in set(Insignia.Types.ALL) & set(self.__stickers.keys()): gunNode, toPartRoot = self.__getInsigniaAttachNode( key, isDamaged, compoundModel) if gunNode is None: return self.__stickers[key].stickers.attachStickers( gunGeometry, gunNode, isDamaged, toPartRoot) return
def setupCollisions(vehicleDesc, collisions): hitTestersByPart = {TankPartNames.CHASSIS: vehicleDesc.chassis.hitTester, TankPartNames.HULL: vehicleDesc.hull.hitTester, TankPartNames.TURRET: vehicleDesc.turret.hitTester, TankPartNames.GUN: vehicleDesc.gun.hitTester} for partName, hitTester in hitTestersByPart.iteritems(): partID = TankPartNames.getIdx(partName) hitTester.bbox = collisions.getBoundingBox(partID) if not hitTester.bbox: _logger.error("Couldn't find bounding box for the part '%s' (collisions=%s)", partName, collisions) trackPairs = vehicleDesc.chassis.trackPairs[1:] for idx, trackPair in enumerate(trackPairs): trackPair.hitTester.bbox = collisions.getBoundingBox(trackPairIdxToCollisionIdx(idx)) if not trackPair.hitTester.bbox: _logger.error("Couldn't find bounding box for the track pair '%i' (collisions=%s)", idx, collisions)
def onAddedSticker(self, shotDamage, damageSticker, transform): geometryLink = shotDamage.compound.getPartGeometryLink( TankPartNames.getIdx(shotDamage.partName)) m = Math.Matrix() m.setIdentity() stickerModel = damageSticker.stickerModel stickerModel.setupSuperModel(geometryLink, m) node = shotDamage.compound.node(shotDamage.partName) node.attach(damageSticker.stickerModel) stickerModel.setLODDistance(damageSticker.lodDistance) stickerId = vehicles.g_cache.damageStickers['ids'][ damageSticker.damageSticker] segStart = transform.transform.applyPoint( Math.Vector3(0, 0, -damageSticker.offset)) segEnd = transform.transform.applyPoint( Math.Vector3(0, 0, damageSticker.offset)) stickerModel.addDamageSticker(stickerId, segStart, segEnd, True) stickerModel.setupFadeout(damageSticker.fadeoutTime)
def applyCamoCache(outfit, vehName, seasonCache): itemsCache = dependency.instance(IItemsCache) camouflages = items.vehicles.g_cache.customization20().camouflages applied = False cleaned = False for areaName in seasonCache.keys(): try: areaId = TankPartNames.getIdx(areaName) except Exception as e: print g_config.ID + ': exception while reading camouflages cache for', vehName, 'in', areaName + ':', e.message continue slot = outfit.getContainer(areaId).slotFor(GUI_ITEM_TYPE.CAMOUFLAGE) if not seasonCache[areaName]: slot.remove(0) continue camoID, paletteIdx, scale = seasonCache[areaName] if camoID not in camouflages: print '%s: wrong camouflage ID for %s:' % (g_config.ID, areaName), camoID del seasonCache[areaName] continue intCD = camouflages[camoID].compactDescr if itemsCache.items.isSynced(): item = itemsCache.items.getItemByCD(intCD) else: item = Camouflage(intCD) if paletteIdx > len(item.palettes): print g_config.ID + ': wrong palette idx for', areaName, 'camouflage:', paletteIdx, '(available: %s)' % range( len(item.palettes)) del seasonCache[areaName] continue if scale > len(item.scales): print g_config.ID + ': wrong scale for', areaName, 'camouflage:', scale, '(available: %s)' % range( len(item.scales)) slot.set(item) component = slot.getComponent() component.palette = paletteIdx component.patternSize = scale applied = True if not seasonCache: cleaned = True outfit.invalidate() return applied, cleaned
def prepareCollisionAssembler(vehicleDesc, isTurretDetached, worldID): hitTestersByPart = {TankPartNames.CHASSIS: vehicleDesc.chassis.hitTester, TankPartNames.HULL: vehicleDesc.hull.hitTester} if not isTurretDetached: hitTestersByPart[TankPartNames.TURRET] = vehicleDesc.turret.hitTester hitTestersByPart[TankPartNames.GUN] = vehicleDesc.gun.hitTester bspModels = [] for partName, hitTester in hitTestersByPart.iteritems(): partId = TankPartNames.getIdx(partName) bspModel = (partId, hitTester.bspModelName, (0.0, 0.0, 0.0)) bspModels.append(bspModel) trackPairs = vehicleDesc.chassis.trackPairs[1:] for idx, trackPair in enumerate(trackPairs): totalDefaultParts = len(TankPartNames.ALL) bspModels.append((totalDefaultParts + idx, trackPair.hitTester.bspModelName)) assembler = BigWorld.CollisionAssembler(tuple(bspModels), worldID) return assembler
def collideDynamicAndStatic(startPoint, endPoint, exceptIDs, collisionFlags=128, skipGun=False): ignoreDynamicID = 0 if exceptIDs: ignoreDynamicID = exceptIDs[0] testRes = BigWorld.wg_collideDynamicStatic( BigWorld.player().spaceID, startPoint, endPoint, collisionFlags, ignoreDynamicID, -1 if not skipGun else TankPartNames.getIdx(TankPartNames.GUN)) if testRes is not None: if testRes[1]: return (testRes[0], EntityCollisionData(testRes[2], testRes[3], testRes[4], True)) return (testRes[0], None) else: return
def __setupModel(self, buildIdx): self.__assembleModel() cfg = hangarCFG() matrix = mathUtils.createSRTMatrix( Math.Vector3(cfg['v_scale'], cfg['v_scale'], cfg['v_scale']), Math.Vector3(self.__vEntity.yaw, self.__vEntity.pitch, self.__vEntity.roll), self.__vEntity.position) self.__vEntity.model.matrix = matrix self.__doFinalSetup(buildIdx) self.__vEntity.typeDescriptor = self.__vDesc gunColBox = self.collisions.getBoundingBox( TankPartNames.getIdx(TankPartNames.GUN) + 3) center = 0.5 * (gunColBox[1] - gunColBox[0]) gunoffset = Math.Matrix() gunoffset.setTranslate((0.0, 0.0, center.z + gunColBox[0].z)) gunLink = mathUtils.MatrixProviders.product( gunoffset, self.__vEntity.model.node(TankPartNames.GUN)) collisionData = ((TankPartNames.getIdx(TankPartNames.CHASSIS), self.__vEntity.model.matrix), (TankPartNames.getIdx(TankPartNames.HULL), self.__vEntity.model.node(TankPartNames.HULL)), (TankPartNames.getIdx(TankPartNames.TURRET), self.__vEntity.model.node(TankPartNames.TURRET)), (TankPartNames.getIdx(TankPartNames.GUN), self.__vEntity.model.node(TankPartNames.GUN))) self.collisions.connect(self.__vEntity.id, ColliderTypes.VEHICLE_COLLIDER, collisionData) collisionData = ((TankPartNames.getIdx(TankPartNames.GUN) + 1, self.__vEntity.model.node(TankPartNames.HULL)), (TankPartNames.getIdx(TankPartNames.GUN) + 2, self.__vEntity.model.node(TankPartNames.TURRET)), (TankPartNames.getIdx(TankPartNames.GUN) + 3, gunLink)) self.collisions.connect(self.__vEntity.id, ColliderTypes.HANGAR_VEHICLE_COLLIDER, collisionData) self.__reloadColliderType(self.__vEntity.state) self.__reloadShadowManagerTarget(self.__vEntity.state)
def __correctEmblemLookAgainstGun(self, hitPos, dir, up, emblem): checkDirWorld = dir * -10.0 cornersWorld = self.__getEmblemCorners(hitPos, dir, up, emblem) result = self.collisions.collideShape(TankPartNames.getIdx(TankPartNames.GUN), (cornersWorld[0], cornersWorld[1], cornersWorld[2], cornersWorld[3]), checkDirWorld) if result < 0.0: return dir dirRot = Math.Matrix() angle = _HANGAR_UNDERGUN_EMBLEM_ANGLE_SHIFT turretMat = Math.Matrix(self.__vEntity.model.node(TankPartNames.TURRET)) fromTurretToHit = hitPos - turretMat.translation gunDir = turretMat.applyVector(Math.Vector3(0, 0, 1)) if Math.Vector3(0, 1, 0).dot(gunDir * fromTurretToHit) < 0: angle = -angle dirRot.setRotateY(angle) normRot = Math.Matrix() normRot.setRotateYPR((dir.yaw, dir.pitch, 0)) dirRot.postMultiply(normRot) dir = dirRot.applyVector(Math.Vector3(0, 0, 1)) return dir
def __init__(self, vehicleDesc, insigniaRank=0, outfit=None): self.__showEmblemsOnGun = vehicleDesc.turret.showEmblemsOnGun self.__defaultAlpha = vehicleDesc.type.emblemsAlpha self.__show = True self.__animateGunInsignia = vehicleDesc.gun.animateEmblemSlots self.__currentInsigniaRank = insigniaRank if outfit is None: outfit = Outfit() componentSlots = ((TankPartNames.HULL, vehicleDesc.hull.emblemSlots), (TankPartNames.GUN if self.__showEmblemsOnGun else TankPartNames.TURRET, vehicleDesc.turret.emblemSlots), (TankPartNames.TURRET if self.__showEmblemsOnGun else TankPartNames.GUN, []), ('gunInsignia', vehicleDesc.gun.emblemSlots)) self.__stickers = {} for componentName, emblemSlots in componentSlots: try: componentIdx = TankPartNames.getIdx(componentName) except Exception: componentIdx = -1 container = outfit.getContainer(componentIdx) emblems = None inscriptions = None if container: emblems = container.slotFor(GUI_ITEM_TYPE.EMBLEM) inscriptions = container.slotFor(GUI_ITEM_TYPE.INSCRIPTION) decals = { SlotTypes.PLAYER: emblems, SlotTypes.INSCRIPTION: inscriptions } modelStickers = ModelStickers(vehicleDesc, emblemSlots, decals, componentName == TankPartNames.HULL, self.__currentInsigniaRank) self.__stickers[componentName] = ComponentStickers( modelStickers, {}, 1.0) return
def _connectCollider(self): if self.collisions is not None: chassisColisionMatrix, gunNodeName = self._vehicleColliderInfo if self.isTurretDetached: self.collisions.removeAttachment( TankPartNames.getIdx(TankPartNames.TURRET)) self.collisions.removeAttachment( TankPartNames.getIdx(TankPartNames.GUN)) collisionData = ((TankPartNames.getIdx(TankPartNames.HULL), self.compoundModel.node(TankPartNames.HULL)), (TankPartNames.getIdx(TankPartNames.CHASSIS), chassisColisionMatrix)) else: collisionData = ((TankPartNames.getIdx(TankPartNames.HULL), self.compoundModel.node(TankPartNames.HULL)), (TankPartNames.getIdx(TankPartNames.TURRET), self.compoundModel.node( TankPartNames.TURRET)), (TankPartNames.getIdx(TankPartNames.CHASSIS), chassisColisionMatrix), (TankPartNames.getIdx(TankPartNames.GUN), self.compoundModel.node(gunNodeName))) defaultPartLength = len(TankPartNames.ALL) additionalChassisParts = [] trackPairs = self.typeDescriptor.chassis.trackPairs if not trackPairs: trackPairs = [None] for x in xrange(len(trackPairs) - 1): additionalChassisParts.append( (defaultPartLength + x, chassisColisionMatrix)) if additionalChassisParts: collisionData += tuple(additionalChassisParts) self.collisions.connect(self.id, ColliderTypes.VEHICLE_COLLIDER, collisionData) return
def applyOutfitCache(outfit, seasonCache, clean=True): itemsCache = dependency.instance(IItemsCache) for itemTypeName, itemCache in seasonCache.items(): itemType = GUI_ITEM_TYPE_INDICES[itemTypeName] itemDB = items.vehicles.g_cache.customization20().itemTypes[ C11N_ITEM_TYPE_MAP[itemType]] for areaName, areaCache in itemCache.items(): areaId = (Area.MISC if areaName == 'misc' else TankPartNames.getIdx(areaName)) slot = outfit.getContainer(areaId).slotFor(itemType) for regionIdx in areaCache.keys(): itemID = areaCache[regionIdx]['id'] if itemID is None: if slot.getItem(int(regionIdx)) is not None: slot.remove(int(regionIdx)) elif clean: # item is being deleted while not applied at all. possible change after last cache del areaCache[ regionIdx] # so we remove an obsolete key continue if itemID not in itemDB: print g_config.ID + ': wrong item ID for %s, idx %s:' % ( areaName, regionIdx), itemID del areaCache[regionIdx] continue intCD = itemDB[itemID].compactDescr item = ( itemsCache.items.getItemByCD if itemsCache.items.isSynced() else itemsCache.items.itemsFactory.createCustomization)(intCD) component = emptyComponent(itemType) [ setattr(component, k, v) for k, v in areaCache[regionIdx].items() ] slot.set(item, int(regionIdx), component) outfit.invalidate()
def prerequisites(self, typeDescriptor, vID, health=1, isCrewActive=True, isTurretDetached=False, outfitCD=''): prereqs = self.__appearance.prerequisites(typeDescriptor, vID, health, isCrewActive, isTurretDetached, outfitCD) compoundAssembler = prepareCompoundAssembler( typeDescriptor, self.__appearance.modelsSetParams, BigWorld.player().spaceID, isTurretDetached) if not isTurretDetached: bspModels = ((TankPartNames.getIdx(TankPartNames.CHASSIS), typeDescriptor.chassis.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.HULL), typeDescriptor.hull.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.TURRET), typeDescriptor.turret.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.GUN), typeDescriptor.gun.hitTester.bspModelName)) else: bspModels = ((TankPartNames.getIdx(TankPartNames.CHASSIS), typeDescriptor.chassis.hitTester.bspModelName), (TankPartNames.getIdx(TankPartNames.HULL), typeDescriptor.hull.hitTester.bspModelName)) collisionAssembler = BigWorld.CollisionAssembler( bspModels, BigWorld.player().spaceID) prereqs += [compoundAssembler, collisionAssembler] physicalTracksBuilders = typeDescriptor.chassis.physicalTracks for name, builder in physicalTracksBuilders.iteritems(): prereqs.append( builder.createLoader('{0}PhysicalTrack'.format(name))) return (compoundAssembler, prereqs)