def set_lgt_args(self, idx, lgt): self.set_default_args(idx) pref = 'lights[%s].' % idx if lgt.node().__class__ == AmbientLight: render.setShaderInput(pref + 'amb', lgt.node().get_color()) elif lgt.node().__class__ == PointLight: lgt_pos = lgt.get_mat(base.cam).xform(LVector4f(0, 0, 0, 1)) render.setShaderInput(pref + 'pos', lgt_pos) render.setShaderInput(pref + 'diff', lgt.node().get_color()) render.setShaderInput(pref + 'spec', lgt.node().get_color()) elif lgt.node().__class__ == DirectionalLight: lgt_pos = lgt.get_pos() lgt_vec = -render.getRelativeVector(lgt, Vec3(0, 1, 0)) lgt_pos = LVector4f(lgt_vec[0], lgt_vec[1], lgt_vec[2], 0) render.setShaderInput(pref + 'pos', lgt_pos) render.setShaderInput(pref + 'diff', lgt.node().get_color()) render.setShaderInput(pref + 'spec', lgt.node().get_color()) elif lgt.node().__class__ == Spotlight: lgt_pos = lgt.get_mat(base.cam).xform(LVector4f(0, 0, 0, 1)) lgt_vec = base.cam.getRelativeVector(lgt, Vec3(0, 1, 0)) render.setShaderInput(pref + 'pos', lgt_pos) render.setShaderInput(pref + 'diff', lgt.node().get_color()) render.setShaderInput(pref + 'spec', lgt.node().get_color()) render.setShaderInput(pref + 'dir', lgt_vec) render.setShaderInput(pref + 'exp', lgt.node().get_exponent()) cutoff = lgt.node().getLens().getFov()[0] render.setShaderInput(pref + 'cutoff', cutoff)
def __init__(self, name): DNANode.DNANode.__init__(self, name) self.code = '' self.streetTexture = '' self.sideWalkTexture = '' self.curbTexture = '' self.streetColor = LVector4f(1, 1, 1, 1) self.sideWalkColor = LVector4f(1, 1, 1, 1) self.curbColor = LVector4f(1, 1, 1, 1)
def __init__(self, x_extend=None, y_extend=None, x_size=1, y_size=1, z=-0.01, tickness=2., name='Grid', x_color=None, y_color=None): GeomNode.__init__(self, name) if x_color is None: x_color = LVector4f(1.0, 1.0, 1.0, 1.0) if y_color is None: y_color = LVector4f(1.0, 1.0, 1.0, 1.0) if x_extend is None: x_extend = [0, 10] if y_extend is None: y_extend = [0, 10] self.vertexData = GeomVertexData("Chunk", GeomVertexFormat.getV3c4(), Geom.UHStatic) self.vertex = GeomVertexWriter(self.vertexData, 'vertex') self.color = GeomVertexWriter(self.vertexData, 'color') self.mesh = Geom(self.vertexData) self.lines = GeomLines(Geom.UHStatic) nb_lines_x = int((x_extend[1] - x_extend[0]) / x_size) nb_lines_y = int((y_extend[1] - y_extend[0]) / y_size) vertex_nb = 0 for ix in range(nb_lines_x): for iy in range(nb_lines_y): x = x_extend[0] + ix * x_size y = y_extend[0] + iy * y_size self.vertex.addData3f(x, y, z) self.color.addData4f(x_color) self.vertex.addData3f(x + x_size, y, z) self.color.addData4f(x_color) self.vertex.addData3f(x, y, z) self.color.addData4f(y_color) self.vertex.addData3f(x, y + y_size, z) self.color.addData4f(y_color) self.lines.add_vertices(vertex_nb, vertex_nb + 1, vertex_nb + 2, vertex_nb + 3) vertex_nb += 4 self.lines.closePrimitive() self.mesh.addPrimitive(self.lines) self.addGeom(self.mesh) NodePath(self).setRenderModeThickness(tickness) NodePath(self).setLightOff() NodePath(self).setColorOff() NodePath(self).setTransparency(TransparencyAttrib.MAlpha)
def __init__(self, gameEngine): DirectObject.DirectObject.__init__(self) self.gameEngine = gameEngine self.elements = [] self.font = gameEngine.loader.loadFont( self.gameEngine.params("font_path") + self.gameEngine.params("default_font")) iH = PNMImageHeader() self.image_path = self.gameEngine.params("control_screen_image_path") iH.readHeader(Filename(self.image_path + "screen.png")) self._x0 = 2 / iH.get_x_size() self._y0 = 2 / iH.get_y_size() # setting 16/9 screen self.props = WindowProperties() self.props.set_size((1024, 576)) self.window = self.gameEngine.win self.window.requestProperties(self.props) self.gui_camera = self.gameEngine.cam2d # this could be simply removed self.gui_render_node = self.gui_camera self.lens = self.gui_camera.node().getLens() self.fg_color = LVector4f(0.3, 0.26, 0.227, 1.0) self.fg_color_red = LVector4f(0.709, 0.180, 0.090, 1.0) self.fg_color_green = LVector4f(0.501, 0.807, 0.337, 1.0) self.background_image = OnscreenImage(image=self.image_path + "default.png", pos=(0, 0, 0), sort=5, parent=self.gui_render_node) self._previous_screen = None self._keyboard_hardware_map = read_ini_file( self.gameEngine.params("hardware_keyboard_map_file")) self.current_screen = None self.on_screen_info = InfoOverScreen(self) self.enter_func = None self.limited_update = self.gameEngine.params( "control_screen_limited_refresh") if not self.limited_update: self.window.setActive(True) else: self.update()
def __init__(self, name): DNANode.DNANode.__init__(self, name) self.code = '' self.color = LVector4f(1, 1, 1, 1) self.width = 0 self.height = 0 self.bDefaultColor = True
def __init__(self, name): DNANode.DNANode.__init__(self, name) self.code = '' self.wallColor = LVector4f(1, 1, 1, 1) self.title = '' self.article = '' self.buildingType = '' self.door = None
def __init__(self, engine): self.basis = CartesianBasis(tickness=5, shade=0.3) engine.render.attachNewNode(self.basis) for n, p in zip(['x', 'y', 'z'], [LVector3f(1, 0, 0), LVector3f(0, 1, 0), LVector3f(0, 0, 1)]): text = TextNode(n) text.set_text(n) np = engine.render.attachNewNode(text) np.set_scale(0.4) np.set_color(LVector4f(p, 1) + LVector4f(0.2, 0.2, 0.2, 1)) np.setPos(p * 1.5) np.setBillboardPointEye() self.grid = Grid(x_extend=[-10, 10], y_extend=[-10, 10], x_color=(0.4, .4, 0.3, 0.5), y_color=(0.4, .4, 0.3, 0.5), tickness=3) engine.render.attach_new_node(self.grid) self.dome = SkyDome(engine)
def set_default_args(self, idx): pref = 'lights[%s].' % idx render.setShaderInput(pref + 'pos', LVector4f(0, 0, 0, 1)) render.setShaderInput(pref + 'amb', LVector3f(0, 0, 0)) render.setShaderInput(pref + 'diff', LVector3f(0, 0, 0)) render.setShaderInput(pref + 'spec', LVector3f(0, 0, 0)) render.setShaderInput(pref + 'dir', LVector3f(0, 0, 0)) render.setShaderInput(pref + 'exp', .0) render.setShaderInput(pref + 'cutoff', .0)
def load_preview_model(self): p_str = "{}/{}_{}_{}.bam".format(self.path, self.name, self.preview_type, self.preview_rec) model_file = Filename(p_str) self.pre_model_np = loader.loadModel(model_file).getChildren()[0] SM.set_planet_shaders(self, self.pre_model_np, self.preview_type) self.pre_model_np.setShaderInput("light_vec", LVector3f(-1, 0, 0)) self.pre_model_np.setShaderInput("atmos_vals", LVector4f(0, 0, 0, 0)) self.pre_model_np.setShaderInput("body_dir", LVector3f(0, 1, 0)) ### return self.pre_model_np
def _post_update_(self, dist_from_cam, body_pos=LVector3f(0, 0, 0)): # Switch model LOD. for near, far in self.__lod_list: if dist_from_cam >= near and dist_from_cam < far: if near != self.__c_near: self.show_model(near) break # Shader updates. if dist_from_cam < self.near_radius: cull_dist = dist_from_cam**2 - self.radius**2 self.MODEL_NP.setShaderInput("cull_dist", cull_dist) if "atmos_ceiling" in self.__dict__: # The outer 'env.atmos_sphere_np' completes its fade in at the halfway height # between the planet's 'sea_level' and 'atmos_ceiling' values; while the # inner 'atmos_np' of this planet completes its fade out at the same point. cam_height = dist_from_cam - self.radius half_ceiling = self.atmos_ceiling / 2 atmos_np = self.current_model_np.find("atmos") if cam_height < half_ceiling: atmos_np.hide() else: atmos_np.show() fade_multi = 1 if cam_height < self.atmos_ceiling: fade_multi = min( (cam_height - half_ceiling) / half_ceiling, 1) # Better to determine body and atmos angles here and pass them to shader, # rather than having them recalculated for every pixel. See 'planet_atmos_FRAG' # for their use. body_angle = abs(degrees(asin(self.radius / dist_from_cam))) atmos_angle = abs( degrees( asin( min((self.radius + self.atmos_ceiling) / dist_from_cam, 1)))) atmos_vals = LVector4f(dist_from_cam, fade_multi, body_angle, atmos_angle) self.MODEL_NP.setShaderInput("atmos_vals", atmos_vals) # 'body_dir' allows the body_pos.set(*self.render_pos) body_pos.normalize() self.MODEL_NP.setShaderInput("body_dir", LVector3f(*body_pos))
def _main_loop_(self, ue, dt, atmos_col=LVector4f(0, 0, 0, 0), body_dir=LVector3f(0, 0, 0)): # User events. self._handle_user_events_(ue, dt) self.CAMERA._handle_user_events_(ue, dt) # System State. light_vec = self.client.SYS.STARS[0].MODEL_NP.getPos() light_vec.normalize() cam = self.CAMERA for obj_id, obj in self.LIVE_OBJECTS.items(): obj._update_(ue, dt, cam) obj.MODEL_NP.setShaderInput("light_vec", light_vec) # Atmosphere effects for bg atmos sphere. if obj is self.CAMERA.FOCUS and "atmos_ceiling" in obj.__dict__: cam_height = self.CAMERA.focus_pos.length() - obj.radius if cam_height < obj.atmos_ceiling: # Full oppacity at 1/2 ceiling. half_ceiling = obj.atmos_ceiling / 2 atmos_col.set(*obj.atmos_colour) atmos_col *= max( min((1 - (cam_height - half_ceiling) / half_ceiling), 1), 0) # Day/night fades in/out along a band that extends # around the planet along the terminator. body_dir.set(*obj.render_pos) body_dir.normalize() night_factor = max( min(((1 - (body_dir.dot(light_vec) * .5 + .5)) - .45) * 10, 1), 0) atmos_col *= night_factor else: atmos_col.set(0, 0, 0, 0) self.atmos_sphere_np.setShaderInput("atmos_colour", atmos_col) # Gui. self.GUI._main_loop_(ue, dt)
def __init__(self, MainScreen, text=""): self.main_screen = MainScreen self._image = OnscreenImage(image=self.main_screen.image_path + "comm.png", pos=(0, 0, 0), parent=self.main_screen.gui_render_node, ) # image in front self._image.set_bin("fixed", 10) self._image.setTransparency(TransparencyAttrib.MAlpha) self._text = OnscreenText(text=text, align=TextNode.ALeft, mayChange=True, pos=self.main_screen.gimp_pos(210, 230), scale=(0.06, 0.08), fg=LVector4f(1, 1, 1, 1), parent=self._image, wordwrap=20, ) self._show = False self._image.hide() self._text.hide()
def update(self): if self.frame is not None: # Set background color and texture self.frame["frameColor"] = self.bg_color if self.bg_image is not None: self.frame["frameTexture"] = self.bg_image # Set bbox x, y, width, height = GUIUtils.get_panda_coords( self.bbox.x, self.bbox.y, self.bbox.width, self.bbox.height) self.frame.setPos(x, 0, y) self.frame["frameSize"] = (-width / 2, width / 2, -height / 2, height / 2) self.frame.resetFrameSize() # Set up scissor test clip_x, clip_y, clip_w, clip_h = GUIUtils.get_panda_clip_coords( self.clip_region.x, self.clip_region.y, self.clip_region.width, self.clip_region.height) render_attrib = ScissorAttrib.make( LVector4f(clip_x, clip_x + clip_w, clip_y - clip_h, clip_y)) self.frame.setAttrib(render_attrib) # Adjust child bbox if self.child is not None: self.child.bbox.x = self.bbox.x + self.padding self.child.bbox.y = self.bbox.y + self.padding if self.fit_width_to_content: self.bbox.width = self.child.bbox.width + 2 * self.padding else: self.child.bbox.width = self.bbox.width - 2 * self.padding if self.fit_height_to_content: self.bbox.height = self.child.bbox.height + 2 * self.padding else: self.child.bbox.height = self.bbox.height - 2 * self.padding self.child.set_clip_region( self.clip_region.get_intersection(self.bbox)) self.child.update()
def __init__(self, scene, agentId, agentRadius=0.25): self.scene = scene self.agentId = agentId agentsNp = self.scene.scene.find('**/agents') agentNp = agentsNp.attachNewNode(agentId) agentNp.setTag('agent-id', agentId) scene.agents.append(agentNp) # Define a simple sphere model modelId = 'sphere-0' modelFilename = os.path.join(CDIR, 'sphere.egg') agentNp.setTag('model-id', modelId) model = loadModel(modelFilename) model.setColor( LVector4f(np.random.uniform(), np.random.uniform(), np.random.uniform(), 1.0)) model.setName('model-' + os.path.basename(modelFilename)) model.setTransform(TransformState.makeScale(agentRadius)) model.reparentTo(agentNp) model.hide(BitMask32.allOn()) # Calculate the center of this object minBounds, maxBounds = model.getTightBounds() centerPos = minBounds + (maxBounds - minBounds) / 2.0 # Add offset transform to make position relative to the center agentNp.setTransform(TransformState.makePos(centerPos)) model.setTransform(model.getTransform().compose( TransformState.makePos(-centerPos))) self.agentNp = agentNp self.model = model self.agentRbNp = None self.rotationStepCounter = -1 self.rotationsStepDuration = 40
def __build_Atmos_Sphere(self): sphere_path = "{}/sphere_simp_6.bam".format(_path.MODELS) atmos_model_np = loader.loadModel(sphere_path).getChild(0) atmos_model_np.setName("atmos") atmos_model = Model(atmos_model_np) pts = atmos_model.read("vertex") pts = list(map(lambda pt: pt * _env.ATMOS_RADIUS, pts)) atmos_model.modify("vertex", pts) atmos_model.NP.setAttrib( CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise)) atmos_model.NP.setAttrib( TransparencyAttrib.make(TransparencyAttrib.MAlpha)) atmos_vert_path = "{}/env_atmos_VERT.glsl".format(_path.SHADERS) atmos_frag_path = "{}/env_atmos_FRAG.glsl".format(_path.SHADERS) atmos_shader = Shader.load(Shader.SL_GLSL, atmos_vert_path, atmos_frag_path) atmos_model.NP.setShader(atmos_shader) atmos_model.NP.setShaderInput("atmos_colour", LVector4f(0, 0, 0, 0)) atmos_model.NP.setBin("fixed", 10) atmos_model.NP.reparentTo(self.NP) return atmos_model.NP
def update(self): if self.frame is not None: self.frame["text"] = self.text self.frame["text_fg"] = self.text_color self.frame["frameColor"] = self.bg_color self.frame["text_font"] = self.font bounds = self.frame.getBounds() scale = (self.text_size * 2.5) / (GUIUtils.square_size + 1) self.bbox.width, self.bbox.height = GUIUtils.get_screen_space_size( (bounds[1] - bounds[0]) * scale, (bounds[3] - bounds[2]) * scale) x, y, width, height = GUIUtils.get_panda_text_coords( self.bbox.x, self.bbox.y, self.bbox.width, self.bbox.height) self.frame.setPos(x, 0, y) self.frame.setScale(scale) # Set up scissor test clip_x, clip_y, clip_w, clip_h = GUIUtils.get_panda_clip_coords( self.clip_region.x, self.clip_region.y, self.clip_region.width, self.clip_region.height) render_attrib = ScissorAttrib.make( LVector4f(clip_x, clip_x + clip_w, clip_y - clip_h, clip_y)) self.frame.setAttrib(render_attrib)
def __init__(self, recipe): _Body_.__init__(self, recipe) self.path = "{}/{}".format(_path.BODIES, self.name) self.MODEL_NP = NodePath("model") self.MODEL_NP.setShaderInput("atmos_vals", LVector4f(0, 0, 0, 0)) self.__Reset()
def __init__(self, name): DNAGroup.DNAGroup.__init__(self, name) self.code = '' self.color = LVector4f(1, 1, 1, 1)
def setStreetColor(self, color): self.streetColor = LVector4f(int(color))
def __init__(self, name): DNANode.DNANode.__init__(self, name) self.code = '' self.color = LVector4f(1)
def setColor(self, color): self.color = LVector4f(int(color))
def __init__(self, name): DNANode.DNANode.__init__(self, name) self.code = '' self.height = 0 self.color = LVector4f(1, 1, 1, 1)
def dgiExtractColor(dgi): a, b, c, d = (dgi.getUint8() / 255.0 for _ in range(4)) return LVector4f(a, b, c, d)
def setWallColor(self, color): self.wallColor = LVector4f(int(color))
def setSidewalkColor(self, color): self.sidewalkColor = LVector4f(int(color))
#Embedded file name: toontown.weather.WeatherGlobals from panda3d.core import LVector4f STORM_TYPE_RAIN = 0 STORM_TYPE_SNOW = 1 STORM_TYPE_HAIL = 2 STORM_TYPE_WIND = 3 cycleColors = [ LVector4f(1, 1, 1, 1), LVector4f(0.7, 0.7, 0.7, 1), LVector4f(0.5, 0.5, 0.5, 1), LVector4f(0.3, 0.3, 0.3, 1) ]
def dgiExtractColor(dgi): return LVector4f(*(dgi.getUint8() / 255.0 for _ in xrange(4)))
def set_color(self, r, g, b): self.model.set_color(LVector4f(r, g, b, 1.0))
def renderShaders(app): app.render.setShaderInput("tint", LVector4f(1.0, 0.5, 0.5, 1.0)) # Check video card capabilities. if not app.win.getGsg().getSupportsBasicShaders(): OnscreenText( "Toon Shader: Video driver reports that Cg shaders are not supported." ) return # This shader's job is to render the model with discrete lighting # levels. The lighting calculations built into the shader assume # a single nonattenuating point light. # tempnode = NodePath(PandaNode("temp node")) app.parentNode.setShader(app.loader.loadShader("Lighting/lightingGen.sha")) app.cam.node().setInitialState(app.parentNode.getState()) # This is the object that represents the single "light", as far # the shader is concerned. It's not a real Panda3D LightNode, but # the shader doesn't care about that. light = app.render.attachNewNode("light") light.setPos(30, -50, 0) # this call puts the light's nodepath into the render state. # this enables the shader to access this light by name. app.render.setShaderInput("light", light) # The "normals buffer" will contain a picture of the model colorized # so that the color of the model is a representation of the model's # normal at that point. normalsBuffer = app.win.makeTextureBuffer("normalsBuffer", 0, 0) normalsBuffer.setClearColor(LVecBase4(0.5, 0.5, 0.5, 1)) app.normalsBuffer = normalsBuffer normalsCamera = app.makeCamera(normalsBuffer, lens=app.cam.node().getLens()) normalsCamera.reparentTo(app.cam) normalsCamera.lookAt(app.parentNode) normalsCamera.node().setScene(app.render) tempnode = NodePath(PandaNode("temp node")) tempnode.setShader(app.loader.loadShader("Lighting/normalGen.sha")) normalsCamera.node().setInitialState(tempnode.getState()) # normalsCamera.node().reparentTo(app.parentNode) # what we actually do to put edges on screen is apply them as a texture to # a transparent screen-fitted card drawnScene = normalsBuffer.getTextureCard() drawnScene.setTransparency(1) drawnScene.setColor(1, 1, 1, 0) drawnScene.reparentTo(app.render2d) app.drawnScene = drawnScene # this shader accepts, as input, the picture from the normals buffer. # it compares each adjacent pixel, looking for discontinuities. # wherever a discontinuity exists, it emits black ink. app.separation = 0.001 app.cutoff = 0.3 inkGen = app.loader.loadShader("Lighting/inkGen.sha") drawnScene.setShader(inkGen) drawnScene.setShaderInput("separation", LVecBase4(app.separation, 0, app.separation, 0)) drawnScene.setShaderInput("cutoff", LVecBase4(app.cutoff)) # Panda contains a built-in viewer that lets you view the results of # your render-to-texture operations. This code configures the viewer. app.accept("v", app.bufferViewer.toggleEnable) app.accept("V", app.bufferViewer.toggleEnable) app.bufferViewer.setPosition("llcorner")
def __init__(self): DNANode.DNANode.__init__(self, '') self.code = '' self.color = LVector4f(1, 1, 1, 1)