def init(self, config): skynode = base.camera.attachNewNode('skybox') base.camera.hide(BaseObject.AllCamerasMask) base.camera.show(BaseObject.DefaultCameraMask | BaseObject.WaterCameraMask) self.skybox = loader.loadModel('ralph-data/models/rgbCube') self.skybox.reparentTo(skynode) self.skybox.setTextureOff(1) self.skybox.setShaderOff(1) self.skybox.setTwoSided(True) # make big enough to cover whole terrain, else there'll be problems with the water reflections self.skybox.setScale(1.5 * config.tile_size) self.skybox.setBin('background', 1) self.skybox.setDepthWrite(False) self.skybox.setDepthTest(False) self.skybox.setLightOff(1) self.skybox.setShaderOff(1) self.skybox.setFogOff(1) #self.skybox.setColor(.55, .65, .95, 1.0) self.skybox_color = LColor(pow(0.5, 1 / 2.2), pow(0.6, 1 / 2.2), pow(0.7, 1 / 2.2), 1.0) self.sun_color = LColor(pow(1.0, 1 / 2.2), pow(0.9, 1 / 2.2), pow(0.7, 1 / 2.2), 1.0) self.skybox.setColor(self.skybox_color)
def get_color(value): if len(value) == 4: return LColor(*value) if len(value) == 3: return LColor(value[0], value[1], value[2], 1.0) print("Invalid color", value) return None
def __init__(self, name, ship_object, radius): ShipBase.__init__(self, name) self.ship_object = ship_object self.radius = radius #TODO: Should be refactored with StellarBody ! self.shown = True self.visible = True self.resolved = True self.oid_color = LColor() self.world_body_center_offset = LVector3d() self.model_body_center_offset = LVector3d() self.light_color = LColor(1, 1, 1, 1) self.rel_position = None self.scene_rel_position = None self.distance_to_obs = None self.vector_to_obs = None self.vector_to_star = None self.star = None self.directional_light = None self.light_source = None self.scene_position = None self.scene_distance = None self.scene_scale_factor = None self.scene_orientation = None self.ship_object.set_parent(self) #TODO: Temporary workaround as some code need the shape to have an owner self.ship_object.set_owner(self) self.ship_object.set_scale(LVector3d(self.radius, self.radius, self.radius)) self.shadow_caster = None self.create_own_shadow_caster = True
def set(self, text, duration=3.0, fade=1.0): TextLine.set(self, text) self.instance.setColorScale(LColor(1, 1, 1, 1)) if self.fade_sequence is not None: self.fade_sequence.pause() self.fade_sequence = Sequence(Wait(duration), self.instance.colorScaleInterval(fade, LColor(1, 1, 1, 0))) self.fade_sequence.start()
def test_texture_peek_srgb(): # 188 = roughly middle gray data = array('B', [188, 188, 188]) peeker = peeker_from_pixel(Texture.T_unsigned_byte, Texture.F_srgb, data) col = LColor() peeker.fetch_pixel(col, 0, 0) # We allow some imprecision. assert col.almost_equal((0.5, 0.5, 0.5, 1.0), 1 / 255.0)
def test_texture_peek_srgba(): # 188 = middle gray data = array('B', [188, 188, 188, 188]) peeker = peeker_from_pixel(Texture.T_unsigned_byte, Texture.F_srgb_alpha, data) col = LColor() peeker.fetch_pixel(col, 0, 0) # We allow some imprecision. assert col.almost_equal((0.5, 0.5, 0.5, 188 / 255.0), 1 / 255.0)
def show_cell(self, cell): print(cell.center, cell.width) position = cell.center - self.context.observer.get_position() self.octree_points.add_point_scale(position, LColor(1, 1, 1, 1), 5) self.octree_points.add_point_scale( position + LPoint3d(-cell.width, -cell.width, -cell.width), LColor(1, 0, 1, 1), 5) self.octree_points.add_point_scale( position + LPoint3d(cell.width, -cell.width, -cell.width), LColor(1, 0, 1, 1), 5) self.octree_points.add_point_scale( position + LPoint3d(cell.width, -cell.width, cell.width), LColor(1, 0, 1, 1), 5) self.octree_points.add_point_scale( position + LPoint3d(-cell.width, -cell.width, cell.width), LColor(1, 0, 1, 1), 5) self.octree_points.add_point_scale( position + LPoint3d(cell.width, cell.width, -cell.width), LColor(1, 1, 0, 1), 5) self.octree_points.add_point_scale( position + LPoint3d(-cell.width, cell.width, -cell.width), LColor(0, 1, 0, 1), 5) self.octree_points.add_point_scale( position + LPoint3d(-cell.width, cell.width, cell.width), LColor(0, 1, 0, 1), 5) self.octree_points.add_point_scale( position + LPoint3d(cell.width, cell.width, cell.width), LColor(1, 1, 0, 1), 5)
def configure_scene(self): #Force frame update to render the last status of the splash screen base.graphicsEngine.renderFrame() self.splash.close() self.observer = Camera(self.cam, self.camLens) self.autopilot = AutoPilot(self.observer, self) self.mouse = Mouse(self) if self.nav is None: self.nav = FreeNav() if self.gui is None: self.gui = Gui(self, self.time, self.observer, self.mouse, self.nav, self.autopilot) self.set_nav(self.nav) self.nav.register_events(self) self.gui.register_events(self) self.observer.init() self.pointset = PointsSet(use_sprites=True, sprite=GaussianPointSprite(size=16)) if settings.render_sprite_points: self.pointset.instance.reparentTo(self.world) self.haloset = PointsSet(use_sprites=True, sprite=ExpPointSprite(size=256, max_value=0.6), background=settings.halo_depth) if settings.render_sprite_points: self.haloset.instance.reparentTo(self.world) #render.setAntialias(AntialiasAttrib.MAuto)#MMultisample) self.setFrameRateMeter(False) self.set_ambient(settings.global_ambient) self.equatorial_grid = Grid("Equatorial", J2000EquatorialReferenceFrame.orientation, LColor(0.28, 0.28, 0.38, 1)) self.equatorial_grid.set_shown(settings.show_equatorial_grid) self.ecliptic_grid = Grid("Ecliptic", J2000EclipticReferenceFrame.orientation, LColor(0.28, 0.28, 0.38, 1)) self.ecliptic_grid.set_shown(settings.show_ecliptic_grid) self.time.set_current_date() self.universe.first_update() self.window_event(None) self.time_task(None) taskMgr.add(self.time_task, "time-task") self.start_universe()
def __init__(self, label_color=LColor(), orbit_color=LColor(), show_label=False, show_orbit=True): self.label_color = label_color self.orbit_color = orbit_color self.show_label = show_label self.show_orbit = show_orbit self.show = True self.name = None
def __init__(self, radius=1.0, scale=None): Shape.__init__(self) self.radius = radius if scale is None: self.radius = radius self.scale = LVecBase3(self.radius, self.radius, self.radius) else: self.scale = LVecBase3(*scale) * radius self.radius = max(scale) * radius self.nb_points = 1 self.size = 1.0 self.yellow_color = LColor(255.0 / 255, 248.0 / 255, 231.0 / 255, 1.0) self.blue_color = LColor(102.0 / 255, 153.0 / 255, 255.0 / 255, 1.0)
def updateWireframe(self, value): for cell in self.cells: cell.updateWireframe(value) if value: self.__columnBox.setRenderModeFilledWireframe(LColor(0, 0, 0, 1.0)) else: self.__columnBox.setRenderModeFilled()
def temp_to_RGB(kelvin): temp = kelvin // 100 if temp <= 66: red = 255 green = temp green = 99.4708025861 * log(green) - 161.1195681661 if temp <= 19: blue = 0 else: blue = temp - 10 blue = 138.5177312231 * log(blue) - 305.0447927307 else: red = temp - 60 red = 329.698727446 * pow(red, -0.1332047592) green = temp - 60 green = 288.1221695283 * pow(green, -0.0755148492) blue = 255 return LColor(clamp(0, 1, red / 255.0), clamp(0, 1, green / 255.0), clamp(0, 1, blue / 255.0), 1.0)
def create(self): winprops = WindowProperties.size(self.size, self.size) props = FrameBufferProperties() props.setRgbColor(0) props.setAlphaBits(0) props.setDepthBits(1) self.buffer = base.graphicsEngine.makeOutput( base.pipe, "shadowsBuffer", -2, props, winprops, GraphicsPipe.BFRefuseWindow, base.win.getGsg(), base.win) if not self.buffer: print("Video driver cannot create an offscreen buffer.") return self.depthmap = Texture() self.buffer.addRenderTexture(self.depthmap, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPDepthStencil) self.depthmap.setMinfilter(Texture.FTShadow) self.depthmap.setMagfilter(Texture.FTShadow) self.depthmap.setBorderColor(LColor(1, 1, 1, 1)) self.depthmap.setWrapU(Texture.WMBorderColor) self.depthmap.setWrapV(Texture.WMBorderColor) self.cam = base.makeCamera(self.buffer, lens=OrthographicLens()) self.cam.reparent_to(render) self.node = self.cam.node() self.node.setInitialState( RenderState.make( CullFaceAttrib.make_reverse(), ColorWriteAttrib.make(ColorWriteAttrib.M_none), )) self.node.setScene(render) if settings.debug_shadow_frustum: self.node.showFrustum()
def window_event(self, window): if self.win is None: return if self.win.is_closed(): self.userExit() wp = self.win.getProperties() width = wp.getXSize() height = wp.getYSize() if settings.win_fullscreen: # Only save config is the switch to FS is successful if wp.getFullscreen(): if self.request_fullscreen or width != settings.win_fs_width or height != settings.win_fs_height: settings.win_fs_width = width settings.win_fs_height = height configParser.save() if self.request_fullscreen: if self.gui is not None: self.gui.update_info("Press <Alt-Enter> to leave fullscreen mode", 0.5, 2.0) else: if self.gui is not None: self.gui.update_info("Could not switch to fullscreen mode", 0.5, 2.0) settings.win_fullscreen = False self.request_fullscreen = False else: if width != settings.win_width or height != settings.win_height: settings.win_width = width settings.win_height = height configParser.save() if self.observer is not None: self.observer.set_film_size(width, height) self.render.setShaderInput("near_plane_height", self.observer.height / self.observer.tan_fov2) self.render.setShaderInput("pixel_size", self.observer.pixel_size) if self.gui is not None: self.gui.update_size(width, height) if settings.color_picking and self.oid_texture is not None: self.oid_texture.clear() self.oid_texture.setup_2d_texture(width, height, Texture.T_unsigned_byte, Texture.F_rgba8) self.oid_texture.set_clear_color(LColor(0, 0, 0, 0))
def get_height(self, x, y): if self.texture_peeker is None: print("No peeker") traceback.print_stack() return 0.0 try: color = LColor() #pos = LVector2(x * self.texture_scale[0], ((self.height - 1) - y) * self.texture_scale[1]) + self.texture_offset new_x = x * self.texture_scale[0] + self.texture_offset[0] * self.width #new_y = y * self.texture_scale[1] + self.texture_offset[1] * self.height #new_y = ((self.height - 1) - new_y) new_y = ((self.height - 1) - y) * self.texture_scale[1] + self.texture_offset[1] * self.height #print(x, y, int(new_x), int(new_y), self.texture_scale, self.texture_offset) self.texture_peeker.fetch_pixel(color, min(int(new_x), self.width - 1), min(int(new_y), self.height - 1)) #self.texture_peeker.fetch_pixel(color, x, y) if settings.encode_float: height = color[0] + color[1] / 255.0 + color[2] / 65025.0 + color[3] / 16581375.0 else: height = color[0] except AssertionError as e: #traceback.print_stack() #print(e) print(x, y) print(int(new_x), int(new_y)) print(((self.height - 1) - y), self.texture_scale[1], ((self.height - 1) - y) * self.texture_scale[1], self.texture_offset[1] * self.height) height = 0.0 #print(height, self.parent.height_scale) return height * self.height_scale# + self.offset
def __init__(self, name, fireType): NodePath.__init__(self, "fire" + str(name)) NodePath.setPythonTag(self, "fireSystem", self) self.setScale(1, 1, 1) self.fire = ParticleEffect() self.fire.loadConfig('fire.ptf') try: file = open(fireType + ".txt") lines = file.readlines() newFireColor = LColor() colorLine = lines[0].split(",") for i in range(4): newFireColor[i] = float(colorLine[i]) self.fire.getParticlesList()[0].getRenderer().setColor( newFireColor) self.lifeSpanSeconds = float(lines[1]) file.close() except IOError: print("Firetype not found") self.lifeRemaining = self.lifeSpanSeconds fireSphere = CollisionSphere(0, 0, 1.25, 2.5) self.collisionNodeName = "fire{}Collision".format(self.id) fireCollisionNode = CollisionNode(self.collisionNodeName) fireCollisionNode.addSolid(fireSphere) self.collision = self.attachNewNode(fireCollisionNode) base.cTrav.addCollider(self.collision, base.handler) self.fire.start(self, self) self.fire.softStop() self.burn = taskMgr.add(self.burnTask, "burnTask") self.notifier = CollisionHandlerEvent
def __init__(self, anchor, scale, y_offset, align, down, pos, font, size, color=None): HUDObject.__init__(self, anchor, scale) if down: y_offset = -y_offset self.y_offset = y_offset self.align = align self.down = down self.text = "" self.instance = None self.font = font self.size = size if self.down: self.pos = -(pos + 1) else: self.pos = pos + 0.1 if color is None: color = LColor(1, 1, 1, 1) self.color = color self.instance = self.create()
def CreateBasement( self ): # it will create basement object, just for case that nothing is drawn to be not lost # Load the environment model. self.cube = self.base.loader.loadModel( "models/cube") # /media/Data/Data/Panda3d/ # Reparent the model to render. self.cube.reparentTo(self.render) # Apply scale and position transforms on the model. self.cube.setScale(10, 10, 10) self.cube.setPos(-8, -40, 0) self.cube.setColor(1.0, 0, 0, 1.0) self.cube.setRenderModeThickness(5) self.cube.setRenderModeFilledWireframe(LColor(0, 0, 0, 1.0)) # COLLISION collBox = CollisionBox(self.cube.getPos(), 10.0, 10.0, 10.0) cnodePath = self.cube.attachNewNode(CollisionNode("cnode")) cnodePath.node().addSolid(collBox) self.cube.setTag("clickable", "1")
def test_texture_peek_float(): data = array('f', (1.0, 0.0, -2.0, 10000.0)) peeker = peeker_from_pixel(Texture.T_float, Texture.F_rgba, data) col = LColor() peeker.fetch_pixel(col, 0, 0) assert col == (-2.0, 0.0, 1.0, 10000.0)
def test_texture_peek_cube(): maxval = 255 data_list = [] for z in range(6): for y in range(3): for x in range(3): data_list += [z, y, x, maxval] data = array('B', data_list) tex = Texture("") tex.setup_cube_map(3, Texture.T_unsigned_byte, Texture.F_rgba8i) tex.set_ram_image(data) peeker = tex.peek() assert peeker.has_pixel(0, 0) assert peeker.has_pixel(0, 0, 0) # If no z is specified, face 0 is used by default col = LColor() peeker.fetch_pixel(col, 1, 2) assert col == (1, 2, 0, maxval) # Now try each face for faceidx in range(6): col = LColor() peeker.fetch_pixel(col, 0, 0, faceidx) assert col == (0, 0, faceidx, maxval) # Try some vector lookups. def lookup(*vec): col = LColor() peeker.lookup(col, *vec) return col assert lookup(1, 0, 0) == (1, 1, 0, maxval) assert lookup(-1, 0, 0) == (1, 1, 1, maxval) assert lookup(0, 1, 0) == (1, 1, 2, maxval) assert lookup(0, -1, 0) == (1, 1, 3, maxval) assert lookup(0, 0, 1) == (1, 1, 4, maxval) assert lookup(0, 0, -1) == (1, 1, 5, maxval) # Magnitude shouldn't matter assert lookup(0, 2, 0) == (1, 1, 2, maxval) assert lookup(0, 0, -0.5) == (1, 1, 5, maxval) # Sample in corner (slight bias to disambiguate which face is selected) assert lookup(1.00001, 1, 1) == (0, 0, 0, maxval) assert lookup(1.00001, 1, 0) == (1, 0, 0, maxval) assert lookup(1, 1.00001, 0) == (2, 1, 2, maxval)
def __init__(self, names, orbit=None, rotation=None, body_class=None, point_color=None, description=''): LabelledObject.__init__(self, names) self.description = description self.system = None self.body_class = body_class if orbit is None: orbit = FixedOrbit() self.orbit = orbit if rotation is None: rotation = UnknownRotation() self.rotation = rotation if point_color is None: point_color = LColor(1.0, 1.0, 1.0, 1.0) self.point_color = srgb_to_linear(point_color) self.abs_magnitude = 99.0 self.oid = None self.oid_color = None #Flags self.visible = False self.resolved = False self.in_view = False self.selected = False self.update_id = 0 self.visibility_override = False #Cached values self._position = LPoint3d() self._global_position = LPoint3d() self._local_position = LPoint3d() self._orientation = LQuaterniond() self._equatorial = LQuaterniond() self._app_magnitude = None self._extend = 0.0 #Scene parameters self.rel_position = None self.distance_to_obs = None self.vector_to_obs = None self.distance_to_star = None self.vector_to_star = None self.height_under = 0.0 self.star = None self.light_color = (1.0, 1.0, 1.0, 1.0) self.visible_size = 0.0 self.scene_position = None self.scene_orientation = None self.scene_scale_factor = None self.world_body_center_offset = LVector3d() self.model_body_center_offset = LVector3d() self.projected_world_body_center_offset = LVector3d() #Components self.orbit_object = None self.rotation_axis = None self.reference_axis = None self.init_annotations = False self.init_components = False self.update_frozen = False #TODO: Should be done properly self.orbit.body = self self.rotation.body = self objectsDB.add(self)
def test_texture_peek_ubyte_i(): maxval = 255 data = array('B', (2, 1, 0, maxval)) peeker = peeker_from_pixel(Texture.T_unsigned_byte, Texture.F_rgba8i, data) col = LColor() peeker.fetch_pixel(col, 0, 0) assert col == (0, 1, 2, maxval)
def updateWireframe(self, value): for cell in self.cells: cell.updateWireframe(value) if value: self.__rhombusEnvelope.setRenderModeFilledWireframe( LColor(0, 0, 0, 1.0)) else: self.__rhombusEnvelope.setRenderModeFilled()
def linear_to_srgb(color): if settings.srgb: return LColor(linear_to_srgb_channel(color[0]), linear_to_srgb_channel(color[1]), linear_to_srgb_channel(color[2]), color[3]) else: return color
def srgb_to_linear(color): if settings.srgb: return LColor(srgb_to_linear_channel(color[0]), srgb_to_linear_channel(color[1]), srgb_to_linear_channel(color[2]), color[3]) else: return color
def test_texture_peek_byte_i(): minval = -128 maxval = 127 data = array('b', (0, -1, minval, maxval)) peeker = peeker_from_pixel(Texture.T_byte, Texture.F_rgba8i, data) col = LColor() peeker.fetch_pixel(col, 0, 0) assert col == (minval, -1, 0, maxval)
def test_texture_peek_short_i(): minval = -32768 maxval = 32767 data = array('h', (0, -1, minval, maxval)) peeker = peeker_from_pixel(Texture.T_short, Texture.F_rgba16i, data) col = LColor() peeker.fetch_pixel(col, 0, 0) assert col == (minval, -1, 0, maxval)
def test_texture_peek_uint_i(): # Highest integer that fits inside float maxval = 2147483648 data = array('I', (2, 1, 0, maxval)) peeker = peeker_from_pixel(Texture.T_unsigned_int, Texture.F_rgba32i, data) col = LColor() peeker.fetch_pixel(col, 0, 0) assert col == (0, 1, 2, maxval)
def test_texture_peek_uint(): maxval = 4294967295 data = array('I', (2, 1, 0, maxval)) peeker = peeker_from_pixel(Texture.T_unsigned_int, Texture.F_rgba, data) col = LColor() peeker.fetch_pixel(col, 0, 0) col *= maxval assert col == (0, 1, 2, maxval)
def test_texture_peek_ushort(): maxval = 65535 data = array('H', (2, 1, 0, maxval)) peeker = peeker_from_pixel(Texture.T_unsigned_short, Texture.F_rgba, data) col = LColor() peeker.fetch_pixel(col, 0, 0) col *= maxval assert col == (0, 1, 2, maxval)
def test_texture_peek_int_i(): minval = -2147483648 maxval = 2147483647 data = array('i', (0, -1, minval, maxval)) peeker = peeker_from_pixel(Texture.T_int, Texture.F_rgba32i, data) col = LColor() peeker.fetch_pixel(col, 0, 0) assert col == (minval, -1, 0, maxval)