def LoadScene(self, sceneContainer): sceneContainer.PrepareSpaceScene(maxPitch=0.0, scenePath=self.scenePath) model = trinity.Load( 'res:/dx9/model/ship/IconPreview/PreviewAmmoShip.red') sceneContainer.AddToScene(model) ammoRedFile = inventorycommon.typeHelpers.GetGraphicFile(self.typeID) ammoRedFile = ammoRedFile[:-4] + '_hi' + ammoRedFile[-4:] ammo = trinity.Load(ammoRedFile) if ammo.__bluetype__ != 'trinity.EveMissile': raise InvalidPreviewType( '{%s (%s) is not a trinity.EveMissile' % (evetypes.GetName(self.typeID), self.typeID)) warhead = ammo.warheads[0] floatHeight = ammo.boundingSphereRadius - ammo.boundingSphereCenter[2] floatHeight += 0.2 * ammo.boundingSphereRadius warhead.translation = (0.0, floatHeight, 0.0) warhead.rotation = geo2.QuaternionRotationAxis((1.0, 0.0, 0.0), -0.5 * math.pi) warhead.startDataValid = True model.children.append(warhead) del warhead.children[:] reflection = warhead.CopyTo() reflection.translation = (0.0, -floatHeight, 0.0) reflection.rotation = geo2.QuaternionRotationAxis((1.0, 0.0, 0.0), 0.5 * math.pi) reflection.startDataValid = True model.children.append(reflection) boundingCenterY = ammo.boundingSphereRadius + 0.5 * floatHeight model.boundingSphereCenter = (0.0, boundingCenterY, 0.0) model.boundingSphereRadius = ammo.boundingSphereRadius + floatHeight SetupSpaceCamera(sceneContainer, model)
def AddExplosion(self, uniqueName, explosionGfxID, spreadOut): if uniqueName not in self.districts: self.logger.error('Could not find district %s for planet with id %s', str(uniqueName), str(self.itemID)) graphics = GetGraphic(explosionGfxID) if graphics is None: self.logger.error("Explosion graphicsID %s doesn't exist!", str(explosionGfxID)) return fx = trinity.Load(graphics.graphicFile) if fx is None: self.logger.error("Explosion %s doesn't exist!", str(graphics.graphicFile)) return if len(fx.curveSets) == 0: self.logger.error('Explosion %s has no curveSets! This is useless...', str(graphics.graphicFile)) return direction = self.districts[uniqueName].centerNormal rotMatrix1 = geo2.MatrixRotationAxis((direction[1], direction[2], direction[0]), random.random() * spreadOut * self.districts[uniqueName].pinRadius) rotMatrix2 = geo2.MatrixRotationAxis(direction, random.uniform(0, 2.0 * math.pi)) direction = geo2.Vec3TransformNormal(direction, rotMatrix1) direction = geo2.Vec3TransformNormal(direction, rotMatrix2) fx.translation = direction fx.scaling = (5000.0 / PLANET_SIZE_SCALE, 5000.0 / PLANET_SIZE_SCALE, 5000.0 / PLANET_SIZE_SCALE) v1 = geo2.Vec3Cross(geo2.Vec3Normalize(direction), (0.0, 1.0, 0.0)) alpha = -math.acos(geo2.Vec3Dot(geo2.Vec3Normalize(direction), (0.0, 1.0, 0.0))) fx.rotation = geo2.QuaternionRotationAxis(v1, alpha) duration = fx.curveSets[0].GetMaxCurveDuration() self.districtExplosions.children.append(fx) uthread.new(self._RemoveExplosionFromDistrict, fx, duration)
def _TransformAxis(self, v): viewMat = trinity.GetViewTransform() viewVec = geo2.Vector(viewMat[0][2], viewMat[1][2], viewMat[2][2]) pos = self.GetTranslation() start = self.startPlanePos - pos start = geo2.Vec3Normalize(start) end = self.endPlanePos - pos end = geo2.Vec3Normalize(end) q = geo2.QuaternionIdentity() dot = geo2.Vec3Dot(start, end) if 1.0 - dot < 1e-05: return q dnormal = geo2.Vec3Cross(start, end) if self.activeManipAxis == 'w': worldInv = geo2.MatrixInverse(self.worldTranslation) axis = geo2.Vec3TransformNormal(viewVec, worldInv) axis = geo2.Vector(*axis) rdot = geo2.Vec3Dot(axis, viewVec) ddot = geo2.Vec3Dot(dnormal, axis) if ddot < 0.0 and rdot > 0.0: axis = -axis elif ddot > 0.0 and rdot < 0.0: axis = -axis elif self.activeManipAxis == 'ww': curP = self._Hemisphere(self.curX, self.curY) preP = self._Hemisphere(self.preX, self.preY) viewInverse = geo2.MatrixInverse(viewMat) norm = geo2.Vec3Cross(preP, curP) worldInv = geo2.MatrixInverse(self.worldTranslation) axis = geo2.Vec3TransformNormal(norm, worldInv) axis = geo2.Vec3TransformNormal(axis, viewInverse) dot = geo2.Vec3Dot(curP, preP) else: axis = self.axis[self.activeManipAxis] if geo2.Vec3Dot(dnormal, axis) < 0.0: axis = -axis if self.activeManipAxis == 'x' and self.worldTranslation[0][ 0] < 0.0 or self.activeManipAxis == 'y' and self.worldTranslation[ 1][1] < 0.0 or self.activeManipAxis == 'z' and self.worldTranslation[ 2][2] < 0.0: axis = -axis self.startPlanePos = self.endPlanePos if dot < -1: dot = -1 elif dot > 1: dot = 1 q = geo2.QuaternionRotationAxis(axis, math.acos(dot)) q = geo2.QuaternionNormalize(q) return q
def PreviewType(self, typeID, subsystems=None): if getattr(self, 'running', False): return self.running = True self.previewingWhat = 'type' if getattr(self, 'btnGroup', None): self.btnGroup.display = False self.SetCaption(localization.GetByLabel('UI/Preview/PreviewCaption')) self.sr.title.display = True self.sr.subtitle.display = True typeID = int(typeID) if typeID != self.typeID: self.CloseSubSystemWnd() isFirst = self.typeID is None typeOb = cfg.invtypes.Get(typeID) groupID = typeOb.groupID groupOb = cfg.invgroups.Get(groupID) categoryID = groupOb.categoryID self.categoryID = categoryID self.groupID = groupID self.typeID = typeID self.sr.title.text = cfg.invtypes.Get(typeID).name rad = 4.0 self.textCont.display = False self.SetMinSize([420, 320]) self.SetMaxSize([None, None]) self.sr.subtitle.text = '' godma = sm.GetService('godma') try: techLevel = godma.GetTypeAttribute(typeID, const.attributeTechLevel) except: techLevel = 1.0 self.loadingWheel.Show() if categoryID == const.categoryShip and techLevel == 3.0: self.sr.sceneContainer.PrepareSpaceScene() if subsystems is None: subsystems = {} subSystemsForType = {} for group in cfg.groupsByCategories.get( const.categorySubSystem, []): if group.groupID not in subSystemsForType: subSystemsForType[group.groupID] = [] for t in cfg.typesByGroups.get(group.groupID, []): if t.published and godma.GetTypeAttribute( t.typeID, const.attributeFitsToShipType) == typeID: subSystemsForType[group.groupID].append(t.typeID) for k, v in subSystemsForType.iteritems(): subsystems[k] = random.choice(v) model = sm.StartService('t3ShipSvc').GetTech3ShipFromDict( typeID, subsystems) radius = round(model.GetBoundingSphereRadius() * 2, 0) self.SetShipSubLabel(typeOb, groupOb, radius) kv = util.KeyVal(typeID=typeID) form.AssembleShip.Open(windowID='PreviewSubSystems', ship=kv, groupIDs=None, isPreview=True, setselected=subsystems) elif self.categoryID in paperDollCategories: desc = typeOb.description desc = desc or '' for each in ('<b>', '</b>', '\r'): desc = desc.replace(each, '') desc = desc.replace('\n', '<br>') self.desc.SetValue(desc) self.textCont.display = True self.SetMinSize([320, 470]) self.SetMaxSize([800, 950]) self.sr.sceneContainer.cameraParent.value = trinity.TriVector( 9.0, -1000, 0.0) self.sr.sceneContainer.PrepareInteriorScene() scene = self.sr.sceneContainer.scene factory = pd.Factory() asset = GetPaperDollResource(typeID) if asset is None: log.LogError('PreviewWnd::PreviewType - Invalid asset') self.loadingWheel.Hide() return path = asset.resPath genderID = asset.resGender self.mannequin = pd.PaperDollCharacter(factory) self.mannequin.doll = pd.Doll( 'mannequin', gender=ccUtil.GenderIDToPaperDollGender(genderID)) if genderID == ccConst.GENDERID_MALE: self.mannequin.doll.Load( 'res:/Graphics/Character/DNAFiles/Mannequin/MaleMannequin.prs', factory) else: self.mannequin.doll.Load( 'res:/Graphics/Character/DNAFiles/Mannequin/FemaleMannequin.prs', factory) while self.mannequin.doll.busyUpdating: blue.synchro.Yield() if self.mannequin is None: return textureQuality = settings.public.device.Get( 'charTextureQuality', sm.GetService('device').GetDefaultCharTextureQuality()) resolution = ccConst.TEXTURE_RESOLUTIONS[textureQuality] self.mannequin.doll.overrideLod = 0 self.mannequin.doll.textureResolution = resolution self.mannequin.Spawn(scene, usePrepass=False) while self.mannequin.doll.busyUpdating: blue.synchro.Yield() if self.mannequin is None: return meshListPre = self.mannequin.doll.buildDataManager.GetMeshes( includeClothMeshes=True) self.mannequin.doll.SetItemType(factory, path, weight=1.0) self.mannequin.Update() while self.mannequin.doll.busyUpdating: blue.synchro.Yield() if self.mannequin is None: return meshListPost = self.mannequin.doll.buildDataManager.GetMeshes( includeClothMeshes=True) animationUpdater = GameWorld.GWAnimation( 'res:/Animation/MorphemeIncarna/Export/Mannequin/Mannequin.mor' ) if animationUpdater is not None: self.mannequin.avatar.animationUpdater = animationUpdater if self.mannequin.doll.gender == pd.GENDER.FEMALE: animationUpdater.network.SetAnimationSetIndex(0) else: animationUpdater.network.SetAnimationSetIndex(1) bBox = (geo2.Vector(1000.0, 1000.0, 1000.0), geo2.Vector(-1000.0, -1000.0, -1000.0)) if groupID in MESH_NAMES_BY_GROUPID: meshName = MESH_NAMES_BY_GROUPID[groupID] found = False for mesh in meshListPost: if mesh.name.startswith( meshName) or mesh not in meshListPre: fromMesh = mesh.geometry.GetBoundingBox(0) bBox[0].x = min(bBox[0].x, fromMesh[0].x) bBox[0].y = min(bBox[0].y, fromMesh[0].y) bBox[0].z = min(bBox[0].z, fromMesh[0].z) bBox[1].x = max(bBox[1].x, fromMesh[1].x) bBox[1].y = max(bBox[1].y, fromMesh[1].y) bBox[1].z = max(bBox[1].z, fromMesh[1].z) found = True if not found: bBox = (geo2.Vector(-0.1, 1.6, -0.1), geo2.Vector(0.1, 1.8, 0.1)) center = ((bBox[1].x + bBox[0].x) / 2.0, (bBox[1].y + bBox[0].y) / 2.0, (bBox[1].z + bBox[0].z) / 2.0) rad = geo2.Vec3Length(bBox[0] - bBox[1]) rad = max(rad, 0.3) self.sr.sceneContainer.cameraParent.value = trinity.TriVector( *center) floor = trinity.Load(ccConst.CUSTOMIZATION_FLOOR) scene.dynamics.append(floor) model = None elif self.groupID in const.turretModuleGroups: self.sr.sceneContainer.PrepareSpaceScene( 0.0, 'res:/dx9/scene/fitting/previewTurrets.red') model = trinity.Load( 'res:/dx9/model/ship/IconPreview/PreviewTurretShip.red') tSet = turretSet.TurretSet.FitTurret(model, None, typeID, 1, checkSettings=False) if tSet is not None: boundingSphere = tSet.turretSets[0].boundingSphere model.boundingSphereRadius = boundingSphere[3] model.boundingSphereCenter = boundingSphere[:3] if model.boundingSphereCenter[1] < 2.0: model.boundingSphereCenter = (boundingSphere[0], 2.0, boundingSphere[2]) for ts in tSet.turretSets: ts.bottomClipHeight = 0.0 ts.FreezeHighDetailLOD() ts.ForceStateDeactive() ts.EnterStateIdle() self.sr.subtitle.text = localization.GetByLabel( 'UI/Preview/ShipSubLabelNoRace', groupName=groupOb.groupName, length=util.FmtDist(model.boundingSphereRadius)) elif self.groupID in const.turretAmmoGroups: self.sr.sceneContainer.PrepareSpaceScene( 0.0, 'res:/dx9/scene/fitting/previewAmmo.red') model = trinity.Load( 'res:/dx9/model/ship/IconPreview/PreviewAmmoShip.red') self.sr.sceneContainer.AddToScene(model) ammoRedFile = typeOb.GraphicFile() ammoRedFile = ammoRedFile[:-4] + '_hi' + ammoRedFile[-4:] ammo = trinity.Load(ammoRedFile) if ammo.__bluetype__ == 'trinity.EveMissile': floatHeight = ammo.boundingSphereRadius - ammo.boundingSphereCenter[ 2] floatHeight += 0.2 * ammo.boundingSphereRadius model.boundingSphereRadius = ammo.boundingSphereRadius + floatHeight model.boundingSphereCenter = (0.0, ammo.boundingSphereRadius + 0.5 * floatHeight, 0.0) warhead = ammo.warheads[0] warhead.rotation = geo2.QuaternionRotationAxis((1.0, 0.0, 0.0), -0.5 * math.pi) warhead.translation = (0.0, floatHeight, 0.0) warhead.startDataValid = True del warhead.children[:] model.children.append(warhead) warheadReflection = warhead.CopyTo() warheadReflection.rotation = geo2.QuaternionRotationAxis( (1.0, 0.0, 0.0), 0.5 * math.pi) warheadReflection.translation = (0.0, -floatHeight, 0.0) warheadReflection.startDataValid = True model.children.append(warheadReflection) self.sr.subtitle.text = localization.GetByLabel( 'UI/Preview/ShipSubLabelNoRace', groupName=groupOb.groupName, length=util.FmtDist(model.boundingSphereRadius)) else: log.LogWarn( 'type', typeID, ' is not an EveMissile but still wants to be previewed as one' ) model = None else: self.sr.sceneContainer.PrepareSpaceScene() fileName = typeOb.GraphicFile() if fileName == '': log.LogWarn('type', typeID, 'has no graphicFile') self.loadingWheel.Hide() return fileName = fileName.replace(':/Model', ':/dx9/Model').replace( '.blue', '.red') fileName = fileName.partition(' ')[0] model = trinity.Load(fileName) radius = round(model.GetBoundingSphereRadius() * 2, 0) self.SetShipSubLabel(typeOb, groupOb, radius) if model is None: self.sr.sceneContainer.ClearScene() self.loadingWheel.Hide() raise UserError('PreviewNoModel') if getattr(model, 'boosters', None) is not None: model.boosters = None if getattr(model, 'modelRotationCurve', None) is not None: model.modelRotationCurve = None if getattr(model, 'modelTranslationCurve', None) is not None: model.modelTranslationCurve = None if hasattr(model, 'ChainAnimationEx'): model.ChainAnimationEx('NormalLoop', 0, 0, 1.0) self.sr.sceneContainer.AddToScene(model) camera = self.sr.sceneContainer.camera navigation = self.sr.navigation spaceObject = False if hasattr(model, 'GetBoundingSphereRadius'): rad = model.GetBoundingSphereRadius() spaceObject = True minZoom = rad + self.sr.sceneContainer.frontClip alpha = self.sr.sceneContainer.fieldOfView / 2.0 if spaceObject: maxZoom = max(rad * (1 / math.tan(alpha)) * 2, 1.0) camera.translationFromParent = minZoom * 2 else: maxZoom = min(rad * (1 / math.tan(alpha * 1.5)), 7.0) camera.translationFromParent = minZoom * 3 navigation.SetMinMaxZoom(minZoom, maxZoom) self.sr.sceneContainer.UpdateViewPort() self.BringToFront() if isFirst: uthread.new(self.OrbitParent) self.loadingWheel.Hide() self.running = False
def UpdateModelRotation(self, dx): if self.model: rotation = geo2.QuaternionRotationAxis((0, 1.0, 0), dx) self.model.modelRotationCurve.value = geo2.QuaternionMultiply( self.model.modelRotationCurve.value, rotation)
def InitModelPosition(self): self.model.rotationCurve = trinity.TriRotationCurve() self.model.rotationCurve.value = geo2.QuaternionRotationAxis((0, 1, 0), math.pi) self.model.translationCurve = trinity.TriVectorCurve()