def setupWheel(): global wheel model = loader.loadModel('models/shipparts/pir_m_shp_prt_wheel') wheel = NodePath('wheelRoot') r = model.find('**/+LODNode') r.flattenStrong() collisions = model.find('**/collisions') high = r.find('**/lod_high') med = r.find('**/lod_med') low = r.find('**/lod_low') high.reparentTo(wheel.attachNewNode(ModelNode('high'))) med.reparentTo(wheel.attachNewNode(ModelNode('med'))) low.reparentTo(wheel.attachNewNode(ModelNode('low'))) collisions.reparentTo(wheel)
def announceGenerate(self): DistributedInteractive.announceGenerate(self) ship = self.cr.doId2do[self._shipId] NodePath.__init__(self, 'ship-%s-repairSpot-%s' % (ship.doId, self._index)) ship.repairSpots[self.doId] = self root = ModelNode('ship-%s-repairSpot-%s' % (ship.doId, self._index)) root.setPreserveTransform(1) self.assign(NodePath(root)) locName = PVPGlobals.RepairSpotLocatorNames[self._index] locator = ship.findLocator('**/%s;+s' % locName) self.setPos(locator.getPos(ship.getModelRoot())) self.setHpr(locator.getHpr(ship.getModelRoot())) self.setScale(locator.getScale(ship.getModelRoot())) self.reparentTo(ship.getModelRoot()) self.setInteractOptions(proximityText = PLocalizer.InteractRepairSpot, diskRadius = 10.0, sphereScale = 6.0) self.setAllowInteract(1) self.checkInUse() self._statePushes = DestructiveScratchPad(evalUsable = FunctionCall(self._evalUsableState, ship._repairSpotMgr._state.fullHealth, ship.getWheelInUseSV()).pushCurrentState())
def getShip(self, shipClass, style=ShipGlobals.Styles.Undefined, logo=ShipGlobals.Logos.Undefined, hullDesign=None, detailLevel=2, wantWheel=True, hullMaterial=None, sailMaterial=None, sailPattern=None, prowType=None, invertLogo=False): Ship = Ship import pirates.ship modelClass = ShipGlobals.getModelClass(shipClass) shipConfig = ShipGlobals.getShipConfig(shipClass) if style == ShipGlobals.Styles.Undefined: style = shipConfig['defaultStyle'] complexCustomization = 0 if sailPattern and sailMaterial and hullMaterial or SailReplace.has_key( shipClass): complexCustomization = 1 if not prowType: prowType = shipConfig['prow'] if not hullMaterial: hullMaterial = style if not sailMaterial: if SailReplace.has_key(shipClass): sailMaterial = SailReplace[shipClass] else: sailMaterial = style if not sailPattern: sailPattern = style shipHullTexture = ShipBlueprints.getShipTexture(hullMaterial) shipTextureSail = ShipBlueprints.getShipTexture(sailMaterial) logoTex = None if logo: logoTex = ShipBlueprints.getLogoTexture(logo) sailPatternTex = None if sailPattern: sailPatternTex = ShipBlueprints.getSailTexture(sailPattern) self.notify.debug('%s %s' % (sailPattern, logo)) if logo == ShipGlobals.Logos.Undefined: logo = shipConfig['sailLogo'] if logo in ShipGlobals.MAST_LOGO_PLACEMENT_LIST: placeLogos = 1 else: placeLogos = 0 if modelClass <= ShipGlobals.INTERCEPTORL3: mastHax = True else: mastHax = False customHull = hullDesign is not None if not logo != 0: pass customMasts = sailPattern != 0 hull = self.getHull(modelClass, customHull) breakAnims = {} metaAnims = {} hitAnims = {} root = NodePath('Ship') hull.locators.reparentTo(root) charRoot = root.attachNewNode(Character('ShipChar')) collisions = root.attachNewNode('collisions') lodNode = charRoot.attachNewNode(LODNode('lod')) if detailLevel == 0: lodNode.node().addSwitch(200, 0) lodNode.node().addSwitch(800, 200) lodNode.node().addSwitch(100000, 800) high = lodNode.attachNewNode('high') low = lodNode.attachNewNode('low') med = NodePath('med') superlow = lodNode.attachNewNode('superlow') elif detailLevel == 1: lodNode.node().addSwitch(300, 0) lodNode.node().addSwitch(1000, 300) lodNode.node().addSwitch(2000, 1000) lodNode.node().addSwitch(100000, 2000) high = lodNode.attachNewNode('high') med = lodNode.attachNewNode('med') low = lodNode.attachNewNode('low') superlow = lodNode.attachNewNode('superlow') else: lodNode.node().addSwitch(750, 0) lodNode.node().addSwitch(3000, 750) lodNode.node().addSwitch(8000, 3000) lodNode.node().addSwitch(100000, 8000) high = lodNode.attachNewNode('high') med = lodNode.attachNewNode('med') low = lodNode.attachNewNode('low') superlow = lodNode.attachNewNode('superlow') mastSetup = ShipGlobals.getMastSetup(shipClass) for data in [(0, 'location_mainmast_0'), (1, 'location_mainmast_1'), (2, 'location_mainmast_2'), (3, 'location_aftmast*'), (4, 'location_foremast*')]: mastData = mastSetup.get(data[0]) if mastData: mast = self.mastSets[mastData[0]].getMastSet( mastData[1] - 1, customMasts) mastRoot = hull.locators.find('**/%s' % data[1]).getTransform( hull.locators) model = NodePath(mast.charRoot) model.setTransform(mastRoot) if complexCustomization: model.setTexture(shipTextureSail) useLogoTex = logoTex if placeLogos: mastNum = data[0] if mastNum not in ShipGlobals.MAST_LOGO_PLACEMENT.get( modelClass): useLogoTex = None charBundle = mast.charRoot.getBundle(0) if data[0] < 3: for side in ['left', 'right']: ropeNode = hull.locators.find( '**/location_ropeLadder_%s_%s' % (side, data[0])) if ropeNode: transform = ropeNode.getTransform( NodePath(mast.charRoot)) charBundle.findChild('def_ladder_0_%s' % side).applyFreeze(transform) continue if sailPatternTex and useLogoTex: for node in model.findAllMatches('**/sails'): node.setTextureOff(TextureStage.getDefault()) node.setTexture(self.colorLayer, sailPatternTex) if invertLogo: node.setTexture(self.logoLayerInv, logoTex) else: node.setTexture(self.logoLayer, logoTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) elif sailPatternTex: for node in model.findAllMatches('**/sails'): node.setTextureOff(TextureStage.getDefault()) node.setTexture(self.colorLayer, sailPatternTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) elif useLogoTex: for node in model.findAllMatches('**/sails'): node.setTextureOff(TextureStage.getDefault()) if invertLogo: node.setTexture(self.logoLayerNoColorInv, logoTex) else: node.setTexture(self.logoLayerNoColor, logoTex) node.setTexture(self.vertLayer, shipTextureSail) node.setTexture(self.baseLayer, shipTextureSail) model.flattenLight() if detailLevel == 0: model.find('**/low').copyTo(high) model.find('**/low').copyTo(low) model.find('**/superlow').copyTo(superlow) elif detailLevel == 1: model.find('**/med').copyTo(high) model.find('**/med').copyTo(med) low.node().stealChildren(model.find('**/low').node()) superlow.node().stealChildren( model.find('**/superlow').node()) elif detailLevel == 2: high.node().stealChildren(model.find('**/high').node()) med.node().stealChildren(model.find('**/med').node()) low.node().stealChildren(model.find('**/low').node()) superlow.node().stealChildren( model.find('**/superlow').node()) mastRoot = mast.collisions.find('**/collision_masts') if modelClass > ShipGlobals.INTERCEPTORL3 or data[0] != 3: mastCode = str(data[0]) mastRoot.setTag('Mast Code', mastCode) else: mastRoot.setName('colldision_sub_mast') mastRoot.reparentTo(collisions.find('**/collision_masts')) mastCode = '0' for coll in mast.collisions.findAllMatches( '**/collision_sail_*'): coll.setName('Sail-%s' % data[0]) coll.setTag('Mast Code', mastCode) for coll in mast.collisions.findAllMatches('**/sail_*'): coll.setName('Sail-%s' % data[0]) coll.setTag('Mast Code', mastCode) collisions.node().stealChildren(mast.collisions.node()) charBundle = mast.charRoot.getBundle(0) if mastHax and data[0] == 3: breakAnims[0][0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[0], -1, MastSubset, True), '1') breakAnims[0][1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[1], -1, MastSubset, True), '1') tempHit = hitAnims[0] tempHit[0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, HitMastSubset, True), '1') tempHit[1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, PartSubset(), True), '1') else: breakAnims[data[0]] = (AnimControlCollection(), AnimControlCollection()) breakAnims[data[0]][0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[0], -1, MastSubset, True), '0') breakAnims[data[0]][1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.breakAnim[1], -1, MastSubset, True), '0') tempHit = [ AnimControlCollection(), AnimControlCollection() ] tempHit[0].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, HitMastSubset, True), '0') tempHit[1].storeAnim( charBundle.loadBindAnim(loader.loader, mast.hitAnim, -1, PartSubset(), True), '0') hitAnims[data[0]] = tempHit for (anim, fileName) in mast.metaAnims.iteritems(): if anim not in metaAnims: metaAnims[anim] = AnimControlCollection() if anim not in MissingAnims.get(modelClass, []): ac = charBundle.loadBindAnim(loader.loader, fileName, -1, SailSubset, True) if ac: metaAnims[anim].storeAnim( ac, str(metaAnims[anim].getNumAnims())) charRoot.node().combineWith(mast.charRoot) continue if self.wantProws and prowType: (highSprit, medSprit, lowSprit) = self.sprits[prowType].getAsset() transform = hull.locators.find( '**/location_bowsprit').getTransform(hull.locators) highSprit.setTransform(transform) medSprit.setTransform(transform) lowSprit.setTransform(transform) highSprit.reparentTo(hull.geoms[0]) medSprit.reparentTo(hull.geoms[1]) lowSprit.reparentTo(hull.geoms[2]) if wantWheel: shipWheel = ShipBlueprints.getWheel() wheelPoint = hull.locators.find( '**/location_wheel;+s').getTransform(hull.locators) shipWheel.setTransform(wheelPoint) shipWheel.flattenLight() shipWheel.find('**/collisions').copyTo(collisions) hull.geoms[0].node().stealChildren( shipWheel.find('**/high').node()) hull.geoms[1].node().stealChildren(shipWheel.find('**/med').node()) hull.geoms[2].node().stealChildren(shipWheel.find('**/low').node()) if complexCustomization: hull.geoms[0].setTexture(shipHullTexture) hull.geoms[0].flattenLight() hull.geoms[1].setTexture(shipHullTexture) hull.geoms[1].flattenLight() hull.geoms[2].setTexture(shipHullTexture) hull.geoms[2].flattenLight() hull.geoms[3].setTexture(shipHullTexture) hull.geoms[3].flattenLight() high.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[0].node()) med.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[1].node()) low.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[2].node()) superlow.attachNewNode(ModelNode('non-animated')).node().stealChildren( hull.geoms[3].node()) collisions.node().stealChildren(hull.collisions.node()) hull.locators.stash() charRoot.flattenStrong() ship = Ship.Ship(shipClass, root, breakAnims, hitAnims, metaAnims, collisions, hull.locators) if not complexCustomization: ship.char.setTexture(shipHullTexture) return ship
def generateMastCache(mastClass): data = MastCache() prefix = MastData[mastClass]['prefix'] height = MastData[mastClass]['maxHeight'] model_prefix = 'models/char/pir_r_shp_mst_%s' % prefix anim_prefix = 'models/char/pir_a_shp_mst_%s_' % prefix geom = loader.loadModel(model_prefix).find('**/+Character') stripPrefix(geom, 'model:') if mastClass == ShipGlobals.Masts.Fore_Multi: geom.findAllMatches('**/sail_0*').detach() for name in ('_1', '_1_rope', '_2', '_2_rope'): for node in geom.findAllMatches('**/boom%s' % name): node.setName('boom') preFlatten(geom) if mastClass in (6, 7, 8, 9, 10): for node in geom.findAllMatches('**/sail_0'): node.setName('skel_sail_0') for node in geom.findAllMatches('**/sail_1'): node.setName('skel_sail_1') for node in geom.findAllMatches('**/sail_2'): node.setName('skel_sail_2') for node in geom.findAllMatches('**/sail_0'): stripAttribs(node, TextureAttrib) for node in geom.findAllMatches('**/sail_1'): stripAttribs(node, TextureAttrib) for node in geom.findAllMatches('**/sail_2'): stripAttribs(node, TextureAttrib) geomSet = [ geom.find('**/lod_high'), geom.find('**/lod_medium'), geom.find('**/lod_low'), geom.find('**/lod_superlow') ] tex = geomSet[0].find('**/static').findAllTextures('*')[0] logic = loader.loadModel(model_prefix + '_logic') stripPrefix(logic, 'model:') data.collisions = logic.find('**/collisions') if not data.collisions.find('**/collision_masts'): data.collisions.find('**/collision_mast_0').setName('collision_masts') sails = data.collisions.findAllMatches('**/collision_sails') for node in sails: node.setTag('Sail', '1') sails.wrtReparentTo(data.collisions.find('**/collision_masts')) geomSet[0].setName('high') geomSet[1].setName('med') geomSet[2].setName('low') geomSet[3].setName('superlow') data.charRoot = geom.node() data.breakAnim = (anim_prefix + 'break', anim_prefix + 'broken') data.hitAnim = anim_prefix + 'hit' for anim in metaAnims: data.metaAnims[anim] = anim_prefix + anim geom.findAllMatches('**/rigging_anchors').detach() geom.findAllMatches('**/breaks').detach() geom.findAllMatches('**/def_mast_base').detach() height = MastData[mastClass]['maxHeight'] matchSet = range(height) for i in range(height): matchSet = [x for x in matchSet if x > i] reducedSet = [] foundReduction = False for j in range(len(geomSet)): currGeom = geomSet[j].copyTo(NodePath()) for match in matchSet: cruft = currGeom.findAllMatches('**/*_%s*' % match) if cruft: cruft.detach() foundReduction = True if foundReduction or not matchSet: for group in ['static', 'transparent']: for node in currGeom.findAllMatches('**/%s' % group): node.flattenStrong() node.setName(group) reducedSet.append(currGeom) customSet = [] for np in reducedSet: sails = np.find('**/sails;+s') if not sails: np.attachNewNode(ModelNode('sails')) customSet.append(np.copyTo(NodePath())) for np in reducedSet: np.find('static').node().setPreserveTransform(ModelNode.PTDropNode) np.find('custom').node().setPreserveTransform(ModelNode.PTDropNode) np.find('**/sails').node().setPreserveTransform( ModelNode.PTDropNode) np.flattenStrong() trans = np.findAllMatches('**/transparent') if trans: for node in trans: node.node().setPreserveTransform(ModelNode.PTDropNode) node.stash() stripAttribs(np, TextureAttrib) for node in trans: node.unstash() else: stripAttribs(np, TextureAttrib) for np in customSet: np.flattenStrong() np.find('static').node().setPreserveTransform(ModelNode.PTDropNode) np.find('custom').node().setPreserveTransform(ModelNode.PTDropNode) np.find('**/sails').node().setPreserveTransform( ModelNode.PTDropNode) trans = np.findAllMatches('**/transparent') if trans: for node in trans: node.node().setPreserveTransform(ModelNode.PTDropNode) node.stash() stripAttribs(np, TextureAttrib) for node in trans: node.unstash() data.genericGeomSets.append(reducedSet) data.customGeomSets.append(customSet) NodePath(data.charRoot).get_children().detach() data.collisions.reparentTo(NodePath(data.charRoot)) return data
def generateHullCache(modelClass): geom = loader.loadModel('models/shipparts/pir_m_shp_%s' % HullDict[modelClass]) stripPrefix(geom, 'model:') for node in geom.findAllMatches('**/omit'): parent = node.getParent() omit = parent.attachNewNode(ModelNode('omit')) node.reparentTo(omit) node.setName('geom') preFlatten(geom) logic = loader.loadModel('models/shipparts/pir_m_shp_%s_logic' % HullDict[modelClass]) locators = logic.find('**/locators') for side in ['left', 'right']: bad = locators.find('**/location_ropeLadder_0_%s' % side) if bad: bad.setName('location_ropeLadder_%s_0' % side) bad = locators.find('**/location_ropeLadder_1_%s' % side) if bad: bad.setName('location_ropeLadder_%s_1' % side) bad = locators.find('**/location_ropeLadder_1_%s1' % side) if bad: bad.setName('location_ropeLadder_%s_2' % side) collisions = logic.find('**/collisions') badPanel = collisions.find('**/collision_panel_3') if badPanel: badPanel.setName('collision_panel_2') collisions.find('**/collision_panel_0').setTag('Hull Code', '0') collisions.find('**/collision_panel_1').setTag('Hull Code', '1') collisions.find('**/collision_panel_2').setTag('Hull Code', '2') walls = collisions.find('**/collision_walls') if walls: walls.setTag('Hull Code', '255') else: collisions.attachNewNode('collision_walls') shipToShipCollide = collisions.find('**/collision_shiptoship') shipToShipCollide.setCollideMask(PiratesGlobals.ShipCollideBitmask) deck = collisions.find('**/collision_deck') if not deck: deck = collisions.attachNewNode('deck') mask = deck.getCollideMask() mask ^= PiratesGlobals.FloorBitmask mask |= PiratesGlobals.ShipFloorBitmask deck.setCollideMask(mask) floors = collisions.find('**/collision_floors') if not floors: floors = collisions.find('**/collision_floor') mask = floors.getCollideMask() mask ^= PiratesGlobals.FloorBitmask mask |= PiratesGlobals.ShipFloorBitmask floors.setCollideMask(mask) floors.setTag('Hull Code', str(255)) geomHigh = geom.find('**/lod_high') geomMed = geom.find('**/lod_medium') if not geomMed: geomMed = geom.find('**/low_medium') if not geomMed: geomMed = geomHigh.copyTo(NodePath()) geomLow = geom.find('**/lod_low') if not geomLow: geomLow = geomMed.copyTo(NodePath()) geomSuperLow = geom.find('**/lod_superlow') if not geomSuperLow: geomSuperLow = geomLow.copyTo(NodePath()) geomHigh.setName('high') geomMed.setName('med') geomLow.setName('low') geomSuperLow.setName('superlow') if modelClass in [21, 22, 23]: spike = loader.loadModel('models/shipparts/pir_m_shp_ram_spike') spikeTrans = locators.find('**/location_ram').getTransform(locators) spike.setTransform(spikeTrans) spike.flattenLight() spikeHi = spike.find('**/lod_high') spikeMed = spike.find('**/lod_medium') spikeLow = spike.find('**/lod_low') spikeHi.copyTo(geomHigh) spikeMed.copyTo(geomMed) spikeLow.copyTo(geomLow) spikeLow.copyTo(geomSuperLow) flipRoot = NodePath('root') collisions.reparentTo(flipRoot) locators.reparentTo(flipRoot) geomHigh.reparentTo(flipRoot) geomMed.reparentTo(flipRoot) geomLow.reparentTo(flipRoot) geomSuperLow.reparentTo(flipRoot) flipRoot.setH(180) flipRoot.flattenLight() omits = flipRoot.findAllMatches('**/omit') for node in omits: node.flattenStrong() for group in [ 'static', 'transparent', 'ropeLadder_*', 'stripeA', 'stripeB', 'pattern' ]: for node in flipRoot.findAllMatches('**/%s' % group): name = node.getName() for subNode in node.findAllMatches('**/*'): subNode.setName(name) node.flattenStrong() node.setName(name) geomHigh.detachNode() geomMed.detachNode() geomLow.detachNode() geomSuperLow.detachNode() locators.detachNode() collisions.detachNode() genericGeoms = [geomHigh, geomMed, geomLow, geomSuperLow] customGeoms = [x.copyTo(NodePath()) for x in genericGeoms] for np in genericGeoms: trans = np.find('**/transparent') if trans: trans.stash() np.flattenLight() sails = np.findAllMatches('**/sails') sails.stash() omits = np.findAllMatches('**/omit') omits.stash() for node in omits: node.node().setPreserveTransform(node.node().PTDropNode) generic = NodePath('generic') np.findAllMatches('**/+GeomNode').wrtReparentTo(generic) np.findAllMatches('*').detach() generic.flattenStrong() generic.reparentTo(np) stripAttribs(generic, TextureAttrib) stripAttribs(generic, TransparencyAttrib) stripAttribs(generic, CullBinAttrib) generic.setBin('ground', 1) collapse(generic) sails.unstash() sails.reparentTo(np) for node in sails: node.node().setPreserveTransform(node.node().PTDropNode) if trans: trans.unstash() trans.flattenStrong() if trans.node().isOfType(ModelNode.getClassType()): trans.node().setPreserveTransform(ModelNode.PTDropNode) deck = np.find('**/=cam=shground') if deck: deck.setName('deck') omits.unstash() for np in customGeoms: collapse(np.find('**/static')) data = HullCache() data.root = NodePath('hull') data.genericGeoms = genericGeoms data.customGeoms = customGeoms data.collisions = collisions data.locators = locators return data
def setupCannons(self, cannons, broadsides, detailLevel=2): self.cannons = {} if detailLevel in (1, 2): self.cannonsHigh = self.lod.getChild(0).attachNewNode( ModelNode('cannons')) self.cannonsMed = self.lod.getChild(1).attachNewNode( ModelNode('cannons')) self.cannonsLow = self.lod.getChild(2).attachNewNode( ModelNode('cannons')) else: self.cannonsHigh = self.lod.getChild(0).attachNewNode( ModelNode('cannons')) self.cannonsMed = self.lod.getChild(1).attachNewNode( ModelNode('cannons')) self.cannonColl = self.modelCollisions.attachNewNode('cannons') for i in cannons: transform = self.locators.find('**/cannon_%s;+s' % i).getTransform( self.locators) cannon = cannons[i][0] cannon.root.setTransform(transform) cannon.root.flattenLight() char = cannon.root.node() bundle = char.getBundle(0) if detailLevel in (1, 2): high = cannon.lod.getChild(0) med = cannon.lod.getChild(1) low = cannon.lod.getChild(2) self.char.node().combineWith(char) high.reparentTo(self.cannonsHigh) med.reparentTo(self.cannonsMed) low.reparentTo(self.cannonsLow) else: low = cannon.lod.getChild(2) superlow = cannon.lod.getChild(3) self.char.node().combineWith(char) low.reparentTo(self.cannonsHigh) superlow.reparentTo(self.cannonsMed) cannon.propCollisions.setTransform(transform) cannon.propCollisions.reparentTo(self.cannonColl) cannon.hNode.reparentTo(self.locators.find('**/cannon_%s;+s' % i)) self.cannons[i] = cannon if broadsides: broadsideLeft = broadsides[0][0] broadsideRight = broadsides[0][1] self.broadsides = [broadsideLeft, broadsideRight] leftRoot = self.locators.find('**/broadsides_left') rightRoot = self.locators.find('**/broadsides_right') for (broadsideSet, side) in zip(broadsides[0], ((leftRoot, 'left'), (rightRoot, 'right'))): for i in range(len(broadsideSet)): port = broadsideSet[i] if not port: continue locator = side[0].find('broadside_%s_%s;+s' % (side[1], i)) transform = locator.getTransform(self.locators) port.locator = locator port.root.setTransform(transform) port.root.flattenLight() char = port.root.node() bundle = char.getBundle(0) if detailLevel in (1, 2): high = port.lod.getChild(0) med = port.lod.getChild(1) low = port.lod.getChild(2) self.char.node().combineWith(char) high.reparentTo(self.cannonsHigh) med.reparentTo(self.cannonsMed) low.reparentTo(self.cannonsLow) continue geom = port.lod.getChild(2) self.char.node().combineWith(char) geom.copyTo(self.cannonsHigh) geom.copyTo(self.cannonsMed) else: self.broadsides = [] self.cannonsHigh.flattenStrong() self.cannonsMed.flattenStrong() if detailLevel != 0: self.cannonsLow.flattenStrong() for cannon in self.cannons.values(): cannon.finalize() for side in self.broadsides: for port in side: if port: port.finalize() continue
def generateHullCache(modelClass): geom = loader.loadModel("models/shipparts/pir_m_shp_%s" % HullDict[modelClass]) stripPrefix(geom, "model:") for node in geom.findAllMatches("**/omit"): parent = node.getParent() omit = parent.attachNewNode(ModelNode("omit")) node.reparentTo(omit) node.setName("geom") preFlatten(geom) logic = loader.loadModel("models/shipparts/pir_m_shp_%s_logic" % HullDict[modelClass]) locators = logic.find("**/locators") for side in ["left", "right"]: bad = locators.find("**/location_ropeLadder_0_%s" % side) if bad: bad.setName("location_ropeLadder_%s_0" % side) bad = locators.find("**/location_ropeLadder_1_%s" % side) if bad: bad.setName("location_ropeLadder_%s_1" % side) bad = locators.find("**/location_ropeLadder_1_%s1" % side) if bad: bad.setName("location_ropeLadder_%s_2" % side) continue collisions = logic.find("**/collisions") badPanel = collisions.find("**/collision_panel_3") if badPanel: badPanel.setName("collision_panel_2") collisions.find("**/collision_panel_0").setTag("Hull Code", "0") collisions.find("**/collision_panel_1").setTag("Hull Code", "1") collisions.find("**/collision_panel_2").setTag("Hull Code", "2") walls = collisions.find("**/collision_walls") if walls: walls.setTag("Hull Code", "255") else: collisions.attachNewNode("collision_walls") shipToShipCollide = collisions.find("**/collision_shiptoship") shipToShipCollide.setCollideMask(PiratesGlobals.ShipCollideBitmask) deck = collisions.find("**/collision_deck") if not deck: deck = collisions.attachNewNode("deck") mask = deck.getCollideMask() mask ^= PiratesGlobals.FloorBitmask mask |= PiratesGlobals.ShipFloorBitmask deck.setCollideMask(mask) floors = collisions.find("**/collision_floors") if not floors: floors = collisions.find("**/collision_floor") mask = floors.getCollideMask() mask ^= PiratesGlobals.FloorBitmask mask |= PiratesGlobals.ShipFloorBitmask floors.setCollideMask(mask) floors.setTag("Hull Code", str(255)) geomHigh = geom.find("**/lod_high") geomMed = geom.find("**/lod_medium") if not geomMed: geomMed = geom.find("**/low_medium") if not geomMed: geomMed = geomHigh.copyTo(NodePath()) geomLow = geom.find("**/lod_low") if not geomLow: geomLow = geomMed.copyTo(NodePath()) geomSuperLow = geom.find("**/lod_superlow") if not geomSuperLow: geomSuperLow = geomLow.copyTo(NodePath()) geomHigh.setName("high") geomMed.setName("med") geomLow.setName("low") geomSuperLow.setName("superlow") if modelClass in [21, 22, 23]: spike = loader.loadModel("models/shipparts/pir_m_shp_ram_spike") spikeTrans = locators.find("**/location_ram").getTransform(locators) spike.setTransform(spikeTrans) spike.flattenLight() spikeHi = spike.find("**/lod_high") spikeMed = spike.find("**/lod_medium") spikeLow = spike.find("**/lod_low") spikeHi.copyTo(geomHigh) spikeMed.copyTo(geomMed) spikeLow.copyTo(geomLow) spikeLow.copyTo(geomSuperLow) flipRoot = NodePath("root") collisions.reparentTo(flipRoot) locators.reparentTo(flipRoot) geomHigh.reparentTo(flipRoot) geomMed.reparentTo(flipRoot) geomLow.reparentTo(flipRoot) geomSuperLow.reparentTo(flipRoot) flipRoot.setH(180) flipRoot.flattenLight() omits = flipRoot.findAllMatches("**/omit") for node in omits: node.flattenStrong() for group in ["static", "transparent", "ropeLadder_*", "stripeA", "stripeB", "pattern"]: for node in flipRoot.findAllMatches("**/%s" % group): name = node.getName() for subNode in node.findAllMatches("**/*"): subNode.setName(name) node.flattenStrong() node.setName(name) geomHigh.detachNode() geomMed.detachNode() geomLow.detachNode() geomSuperLow.detachNode() locators.detachNode() collisions.detachNode() genericGeoms = [geomHigh, geomMed, geomLow, geomSuperLow] customGeoms = [x.copyTo(NodePath()) for x in genericGeoms] for np in genericGeoms: trans = np.find("**/transparent") if trans: trans.stash() np.flattenLight() sails = np.findAllMatches("**/sails") sails.stash() omits = np.findAllMatches("**/omit") omits.stash() for node in omits: node.node().setPreserveTransform(node.node().PTDropNode) generic = NodePath("generic") np.findAllMatches("**/+GeomNode").wrtReparentTo(generic) np.findAllMatches("*").detach() generic.flattenStrong() generic.reparentTo(np) stripAttribs(generic, TextureAttrib) stripAttribs(generic, TransparencyAttrib) stripAttribs(generic, CullBinAttrib) generic.setBin("ground", 1) collapse(generic) sails.unstash() sails.reparentTo(np) for node in sails: node.node().setPreserveTransform(node.node().PTDropNode) if trans: trans.unstash() trans.flattenStrong() if trans.node().isOfType(ModelNode.getClassType()): trans.node().setPreserveTransform(ModelNode.PTDropNode) deck = np.find("**/=cam=shground") if deck: deck.setName("deck") omits.unstash() for np in customGeoms: collapse(np.find("**/static")) data = HullCache() data.root = NodePath("hull") data.genericGeoms = genericGeoms data.customGeoms = customGeoms data.collisions = collisions data.locators = locators return data
def generateHullCache(modelClass): geom = loader.loadModel('models/shipparts/pir_m_shp_%s' % HullDict[modelClass]) stripPrefix(geom, 'model:') for node in geom.findAllMatches('**/omit'): parent = node.getParent() omit = parent.attachNewNode(ModelNode('omit')) node.reparentTo(omit) node.setName('geom') preFlatten(geom) logic = loader.loadModel('models/shipparts/pir_m_shp_%s_logic' % HullDict[modelClass]) locators = logic.find('**/locators') for side in [ 'left', 'right']: bad = locators.find('**/location_ropeLadder_0_%s' % side) if bad: bad.setName('location_ropeLadder_%s_0' % side) bad = locators.find('**/location_ropeLadder_1_%s' % side) if bad: bad.setName('location_ropeLadder_%s_1' % side) bad = locators.find('**/location_ropeLadder_1_%s1' % side) if bad: bad.setName('location_ropeLadder_%s_2' % side) continue collisions = logic.find('**/collisions') badPanel = collisions.find('**/collision_panel_3') if badPanel: badPanel.setName('collision_panel_2') collisions.find('**/collision_panel_0').setTag('Hull Code', '0') collisions.find('**/collision_panel_1').setTag('Hull Code', '1') collisions.find('**/collision_panel_2').setTag('Hull Code', '2') walls = collisions.find('**/collision_walls') if walls: walls.setTag('Hull Code', '255') else: collisions.attachNewNode('collision_walls') shipToShipCollide = collisions.find('**/collision_shiptoship') shipToShipCollide.setCollideMask(PiratesGlobals.ShipCollideBitmask) deck = collisions.find('**/collision_deck') if not deck: deck = collisions.attachNewNode('deck') mask = deck.getCollideMask() mask ^= PiratesGlobals.FloorBitmask mask |= PiratesGlobals.ShipFloorBitmask deck.setCollideMask(mask) floors = collisions.find('**/collision_floors') if not floors: floors = collisions.find('**/collision_floor') mask = floors.getCollideMask() mask ^= PiratesGlobals.FloorBitmask mask |= PiratesGlobals.ShipFloorBitmask floors.setCollideMask(mask) floors.setTag('Hull Code', str(255)) geomHigh = geom.find('**/lod_high') geomMed = geom.find('**/lod_medium') if not geomMed: geomMed = geom.find('**/low_medium') if not geomMed: geomMed = geomHigh.copyTo(NodePath()) geomLow = geom.find('**/lod_low') if not geomLow: geomLow = geomMed.copyTo(NodePath()) geomSuperLow = geom.find('**/lod_superlow') if not geomSuperLow: geomSuperLow = geomLow.copyTo(NodePath()) geomHigh.setName('high') geomMed.setName('med') geomLow.setName('low') geomSuperLow.setName('superlow') if modelClass in [ 21, 22, 23]: spike = loader.loadModel('models/shipparts/pir_m_shp_ram_spike') spikeTrans = locators.find('**/location_ram').getTransform(locators) spike.setTransform(spikeTrans) spike.flattenLight() spikeHi = spike.find('**/lod_high') spikeMed = spike.find('**/lod_medium') spikeLow = spike.find('**/lod_low') spikeHi.copyTo(geomHigh) spikeMed.copyTo(geomMed) spikeLow.copyTo(geomLow) spikeLow.copyTo(geomSuperLow) flipRoot = NodePath('root') collisions.reparentTo(flipRoot) locators.reparentTo(flipRoot) geomHigh.reparentTo(flipRoot) geomMed.reparentTo(flipRoot) geomLow.reparentTo(flipRoot) geomSuperLow.reparentTo(flipRoot) flipRoot.setH(180) flipRoot.flattenLight() omits = flipRoot.findAllMatches('**/omit') for node in omits: node.flattenStrong() for group in [ 'static', 'transparent', 'ropeLadder_*', 'stripeA', 'stripeB', 'pattern']: for node in flipRoot.findAllMatches('**/%s' % group): name = node.getName() for subNode in node.findAllMatches('**/*'): subNode.setName(name) node.flattenStrong() node.setName(name) geomHigh.detachNode() geomMed.detachNode() geomLow.detachNode() geomSuperLow.detachNode() locators.detachNode() collisions.detachNode() genericGeoms = [ geomHigh, geomMed, geomLow, geomSuperLow] customGeoms = [ x.copyTo(NodePath()) for x in genericGeoms ] for np in genericGeoms: trans = np.find('**/transparent') if trans: trans.stash() np.flattenLight() sails = np.findAllMatches('**/sails') sails.stash() omits = np.findAllMatches('**/omit') omits.stash() for node in omits: node.node().setPreserveTransform(node.node().PTDropNode) generic = NodePath('generic') np.findAllMatches('**/+GeomNode').wrtReparentTo(generic) np.findAllMatches('*').detach() generic.flattenStrong() generic.reparentTo(np) stripAttribs(generic, TextureAttrib) collapse(generic) sails.unstash() sails.reparentTo(np) for node in sails: node.node().setPreserveTransform(node.node().PTDropNode) if trans: trans.unstash() trans.flattenStrong() if trans.node().isOfType(ModelNode.getClassType()): trans.node().setPreserveTransform(ModelNode.PTDropNode) deck = np.find('**/=cam=shground') if deck: deck.setName('deck') omits.unstash() for np in customGeoms: collapse(np.find('**/static')) data = HullCache() data.root = NodePath('hull') data.genericGeoms = genericGeoms data.customGeoms = customGeoms data.collisions = collisions data.locators = locators return data