def __init__(self, name, resource): """Arguments: resource -- name of a directory in assets/skyboxes that contains 6 images. """ ManagedAsset.__init__(self, "sky") self.name = name tex = None for ext in ("png", "jpg", "tga"): f = Filename("skyboxes/{}/0.{}".format(resource, ext)) if f.resolveFilename(getModelPath().getValue()): tex = TexturePool.loadCubeMap("skyboxes/{}/#.{}".format(resource, ext)) break if tex is None: raise ResourceLoadError("assets/skyboxes/%s" % resource, "maybe wrong names or different extensions?") self.node = loader.loadModel("misc/invcube") self.node.clearTexture() self.node.clearMaterial() self.node.setScale(10000) self.node.setTwoSided(True) self.node.setBin('background', 0) self.node.setDepthTest(False) self.node.setDepthWrite(False) self.node.setLightOff() self.node.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldPosition) self.node.setTexProjector(TextureStage.getDefault(), render, self.node); self.node.setTexture(tex, 1) self.node.flattenLight() #self.node.setCompass() # not needed with world-space-UVs self.addTask(self.update, "sky repositioning", sort=10, taskChain="world")
def loadPlaneModel(self, modelname): """Loads models and animations from the planes directory.""" animcontrols = {} model = loader.loadModel("planes/{0}/{0}".format(modelname)) actor = Actor(model, setFinal=True, mergeLODBundles=True, allowAsyncBind=False, okMissing=False) #actor = Actor(model, lodNode="mid") subparts = ( # subpart, joints, animations ("Doors", ["Windscreen*", "Door*"], ("Open", "Close")), #("Landing Gear", ["Landing?Gear*", "LG*"], ("LG Out", "LG In")), ("Landing Gear", ["Landing?Gear*", "LG*"], ("LG Out", )), ("Ailerons", ["Aileron*"], ("Roll Left", "Roll Right")), ("Rudders", ["Rudder*"], ("Head Left", "Head Right")), ("Elevators", ["Elevator*"], ("Pitch Up", "Pitch Down"))) for line in subparts: subpart, joints, anims = line actor.makeSubpart(subpart, joints) path = "planes/{0}/{0}-{{0}}".format(modelname) d = dict((anim, path.format(anim)) for anim in anims) #actor.loadAnims(d, subpart, "mid") actor.loadAnims(d, subpart) for anim in anims: #actor.bindAnim(anim, subpart, "mid") actor.bindAnim(anim, subpart) #animcontrols[anim] = actor.getAnimControls(anim, subpart, # "mid", False)[0] animcontrols[anim] = actor.getAnimControls( anim, subpart, None, False)[0] actor.makeSubpart("propellers", "Propeller*") actor.verifySubpartsComplete() actor.setSubpartsComplete(True) for p in actor.getJoints("propellers", "Propeller*", "lodRoot"): self.propellers.append( actor.controlJoint(None, "propellers", p.getName())) #actor.pprint() cams = model.findAllMatches("**/camera ?*") if not cams.isEmpty(): cameras = actor.attachNewNode("cameras") cams.reparentTo(cameras) return actor, animcontrols