def __init__(self, name, model=None, physics=False): """Arguments: name -- Aircraft name. model -- Model to load on init. Same as name if none given. A string with the name of a plane in assets/planes/ is expected. 0 or False = don't load a model physics -- When True, makes this plane physical. info: invisible planes (without model) are for tracking only. you should assign them models when they get into visible range. The idea behind the 'node' is pretty simple: working with a virtual container prevents accidential replacement and seperates things. """ AssetBase.__init__(self) self.node = NodePath("aeroplane " + name) self.name = name self.model = None self.animcontrols = None self.hud = None self.ailerons = 0.0 self.elevator = 0.0 self.rudder = 0.0 self.propellers = [] if model is None: model = name if model: self.model, self.animcontrols = self.loadPlaneModel(model) self.model.reparentTo(self.node) self.physics = None if physics: self.activatePhysics()
def __init__(self, name): AssetBase.__init__(self) self.name = name self.node = NodePath(name)
def __init__(self, name, size=10000, resolution=1024): """Arguments: size -- Edge length of the water square. resolution -- Texture size of the rendered reflection buffer. """ # Uncomment to see the output of the refclection buffer. base.bufferViewer.toggleEnable() AssetBase.__init__(self) self.name = name self.cm = CardMaker("water surface") self.cm.setFrame(-0.5 * size, 0.5 * size, -0.5 * size, 0.5 * size) self.cm.setHasUvs(True) self.node = NodePath(self.cm.generate()) self.node.setP(self.node, -90) self.node.flattenLight() self.node.hide(BitMask32.bit(1)) # self.node.setTwoSided(True) self.node.setShaderOff() # size of one texture tile in meters self.tex_size = 100.0 diffuse = TexturePool.loadTexture("textures/water.diffuse.png") diffuse.setWrapU(Texture.WMRepeat) diffuse.setWrapV(Texture.WMRepeat) diffuse.setMinfilter(Texture.FTLinearMipmapLinear) diffuse.setMagfilter(Texture.FTLinearMipmapLinear) self.diffuse_stage = TextureStage("diffuse") self.diffuse_stage.setSort(2) self.node.setTexture(self.diffuse_stage, diffuse) self.node.setTexScale(self.diffuse_stage, size / self.tex_size, size / self.tex_size) # Reflection camera renders to 'buffer' which is projected onto the # water surface. buffer = base.win.makeTextureBuffer("water reflection", resolution, resolution) buffer.setClearColor(Vec4(0, 0, 0, 1)) self.refl_cam = base.makeCamera(buffer) self.refl_cam.reparentTo(self.node) self.refl_cam.node().setCameraMask(BitMask32.bit(1)) self.refl_cam.node().getLens().setFov(base.camLens.getFov()) self.refl_cam.node().getLens().setNearFar(1, 100000) plane = PlaneNode("water culling plane", Plane(Vec3(0, 0, 1), Point3(0, 0, 0))) cfa = CullFaceAttrib.makeReverse() cpa = ClipPlaneAttrib.make(PlaneNode.CEVisible, plane) rs = RenderState.make(cfa, cpa) self.refl_cam.node().setInitialState(rs) reflection = buffer.getTexture() reflection.setMinfilter(Texture.FTLinear) reflection.setMagfilter(Texture.FTLinear) self.refl_stage = TextureStage("reflection") self.refl_stage.setSort(1) self.node.projectTexture(self.refl_stage, reflection, base.cam) self.node.setTexture(self.refl_stage, reflection) # Blend between diffuse and reflection. self.diffuse_stage.setColor(VBase4(1, 1, 1, 0.2)) # opacity of 20% self.diffuse_stage.setCombineRgb( TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor, TextureStage.CSPrevious, TextureStage.COSrcColor, TextureStage.CSConstant, TextureStage.COSrcAlpha, ) self.addTask(self.update, name="water update", sort=1, taskChain="world")
def __init__(self, name, size=10000, resolution=1024): """Arguments: size -- Edge length of the water square. resolution -- Texture size of the rendered reflection buffer. """ # Uncomment to see the output of the refclection buffer. base.bufferViewer.toggleEnable() AssetBase.__init__(self) self.name = name self.cm = CardMaker("water surface") self.cm.setFrame(-0.5 * size, 0.5 * size, -0.5 * size, 0.5 * size) self.cm.setHasUvs(True) self.node = NodePath(self.cm.generate()) self.node.setP(self.node, -90) self.node.flattenLight() self.node.hide(BitMask32.bit(1)) #self.node.setTwoSided(True) self.node.setShaderOff() # size of one texture tile in meters self.tex_size = 100.0 diffuse = TexturePool.loadTexture("textures/water.diffuse.png") diffuse.setWrapU(Texture.WMRepeat) diffuse.setWrapV(Texture.WMRepeat) diffuse.setMinfilter(Texture.FTLinearMipmapLinear) diffuse.setMagfilter(Texture.FTLinearMipmapLinear) self.diffuse_stage = TextureStage("diffuse") self.diffuse_stage.setSort(2) self.node.setTexture(self.diffuse_stage, diffuse) self.node.setTexScale(self.diffuse_stage, size / self.tex_size, size / self.tex_size) # Reflection camera renders to 'buffer' which is projected onto the # water surface. buffer = base.win.makeTextureBuffer("water reflection", resolution, resolution) buffer.setClearColor(Vec4(0, 0, 0, 1)) self.refl_cam = base.makeCamera(buffer) self.refl_cam.reparentTo(self.node) self.refl_cam.node().setCameraMask(BitMask32.bit(1)) self.refl_cam.node().getLens().setFov(base.camLens.getFov()) self.refl_cam.node().getLens().setNearFar(1, 100000) plane = PlaneNode("water culling plane", Plane(Vec3(0, 0, 1), Point3(0, 0, 0))) cfa = CullFaceAttrib.makeReverse() cpa = ClipPlaneAttrib.make(PlaneNode.CEVisible, plane) rs = RenderState.make(cfa, cpa) self.refl_cam.node().setInitialState(rs) reflection = buffer.getTexture() reflection.setMinfilter(Texture.FTLinear) reflection.setMagfilter(Texture.FTLinear) self.refl_stage = TextureStage("reflection") self.refl_stage.setSort(1) self.node.projectTexture(self.refl_stage, reflection, base.cam) self.node.setTexture(self.refl_stage, reflection) # Blend between diffuse and reflection. self.diffuse_stage.setColor(VBase4(1, 1, 1, 0.2)) # opacity of 20% self.diffuse_stage.setCombineRgb( TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor, TextureStage.CSPrevious, TextureStage.COSrcColor, TextureStage.CSConstant, TextureStage.COSrcAlpha) self.addTask(self.update, name="water update", sort=1, taskChain="world")
def __init__(self, category): AssetBase.__init__(self) if category in ManagedAsset.assets: if "destroy" in dir(ManagedAsset.assets[category]): ManagedAsset.assets[category].destroy() ManagedAsset.assets[category] = self
def __init__(self, name="ambient light", color=Vec4(0.6, 0.6, 0.8, 1)): AssetBase.__init__(self) self.light = AL("ambient light") self.light.setColor(color) self.node = NodePath(self.light)
def __init__(self, name="default light"): AssetBase.__init__(self) self.ambient = AmbientLight() self.sun = DirectionalLight()
def __init__(self, name="directional light", color=Vec4(1,1,1,1)): AssetBase.__init__(self) self.light = DL("directional light") self.light.setColor(color) self.node = NodePath(self.light)