Exemplo n.º 1
0
 def toggle_cell(self, x, y):
     if self.__nonogram_solved:
         return
     self.__grid.toggle(x, y)
     node_path = self.__grid_nodes[y][x]
     h = util.clamp_angle(node_path.get_h())
     if h > 0:
         h = 180
     else:
         h = 0
     LerpHprInterval(
         node_path,
         common.NG_ANIM_DURATION,
         (h + 180, 0, 0),
         (h, 0, 0),
         blendType='easeInOut'
     ).start()
     if h == 0:
         LerpColorInterval(
             node_path,
             common.NG_ANIM_DURATION,
             core.Vec4(0),
             blendType='easeOut'
         ).start()
     else:
         node_path.set_color(core.Vec4(1))
     self.__check_solved()
Exemplo n.º 2
0
def obelisk(r=(2.5, 1.8)):
    node_path = core.NodePath('obelisk')
    base = node_path.attach_new_node(
        sg.cone(origin=core.Vec3(0),
                direction=core.Vec3.up(),
                radius=r,
                polygon=4,
                length=15.0,
                smooth=False,
                capsule=False,
                origin_offset=0,
                color=core.Vec4(core.Vec3(0.2), 1),
                nac=False))
    top = node_path.attach_new_node(
        sg.cone(origin=core.Vec3(0),
                direction=core.Vec3.up(),
                radius=(r[1], 0),
                polygon=4,
                length=1.5,
                smooth=False,
                capsule=False,
                origin_offset=0,
                color=core.Vec4(core.Vec3(0.2), 1),
                nac=False))
    top.set_z(15)
    # mat = core.Material()
    # mat.set_emission(core.Vec4(.35, 1.0, 0.52, 0.1))
    # mat.set_shininess(5.0)
    # node_path.set_material(mat)
    return node_path
Exemplo n.º 3
0
    def _get_selected_colour(self,
                             selected: highlight_details.HighlightDetails):
        if isinstance(selected.map_object,
                      map_objects.EditorSprite) or isinstance(
                          selected.map_object, map_objects.EditorWall):
            stat = selected.map_object.get_stat_for_part(None)
            if stat.poly_blue:
                return core.Vec4(0, 0, 1, 1)
            elif stat.poly_green:
                return core.Vec4(0, 1, 0, 1)

        return core.Vec4(1, 1, 1, 1)
Exemplo n.º 4
0
    def __init__(self, room):
        self.root = core.NodePath('Room')
        self.room_model = room
        self.room_model.reparent_to(self.root)
        self.name = room.name

        self.doors = [i for i in self.room_model.find_all_matches('**/door*')]
        self.portals = [Portal(self, i) for i in self.doors]

        for i in self.doors:
            i.set_transparency(core.TransparencyAttrib.M_alpha)
            i.set_alpha_scale(0.0)
            i.set_color(core.Vec4(0))
            for np in i.find_all_matches('**/+GeomNode'):
                geom_node = np.node()
                process_geom_node(geom_node)

        portal_vert_str = load_shader_str('portal.vert')
        portal_frag_str = load_shader_str('portal_screenspace.frag')
        portalshader = core.Shader.make(
            core.Shader.SL_GLSL,
            vertex=portal_vert_str,
            fragment=portal_frag_str,
        )
        for i in self.doors:
            i.set_shader(portalshader)
        self._active = False
        self.room_model.node().set_bounds(core.OmniBoundingVolume())
        self.room_model.node().set_final(True)

        for i in self.room_model.find_all_matches('**/Sun*/Sun*'):
            try:
                self.root.set_light(i)
            except AssertionError:
                pass
Exemplo n.º 5
0
def create_content_texture(content, color_bg):
    # this creates a texture of size (360 X 260) in pixels
    # this correspond to a precision of 1 degree in azimuth and 1mm in the z-axis in arena coordinates
    # one subregion of the texture gets a given content
    # the rest is filled with background

    angular_width, z_width = content.shape

    # generate bar texture
    image = pcore.PNMImage(
        360, 260
    )  # only 1 degree steps for the width of the window and 0.1 units steps for the height of the window
    image.fill(color_bg / 255.)
    for i in range(int(angular_width)):
        for j in range(int(np.round(z_width))):
            image.setXelA(i, j, content[i, j] / 255., content[i, j] / 255.,
                          content[i, j] / 255., 1)
    #for i in range(int(angular_width), 360):
    #    for j in range(int(np.round(z_width/0.1))):
    #        image.setXelA(i, 0, color_bg/255., color_bg/255., color_bg/255., 1)

    tex = pcore.Texture()
    tex.load(image)
    tex.setMagfilter(pcore.Texture.FTLinearMipmapLinear)
    tex.setBorderColor(
        pcore.Vec4(color_bg / 255., color_bg / 255., color_bg / 255., 1))
    tex.setWrapU(pcore.Texture.WM_border_color)
    tex.setWrapV(pcore.Texture.WM_border_color)
    tex.setAnisotropicDegree(16)

    return tex
Exemplo n.º 6
0
    def _get_outer_most_wall(self):
        used_walls: typing.Set[wall.EditorWall] = set()
        outermost_wall: wall.EditorWall = None
        bounding_rectangle = core.Vec4(1 < 31, -(1 << 31), 1 << 31, -(1 << 31))

        for editor_wall in self._walls:
            while editor_wall not in used_walls:
                used_walls.add(editor_wall)

                if editor_wall.point_1.x < bounding_rectangle.x:
                    outermost_wall = editor_wall
                    bounding_rectangle.x = editor_wall.point_1.x
                if editor_wall.point_1.y < bounding_rectangle.z:
                    outermost_wall = editor_wall
                    bounding_rectangle.z = editor_wall.point_1.y

                if editor_wall.point_1.x > bounding_rectangle.y:
                    outermost_wall = editor_wall
                    bounding_rectangle.y = editor_wall.point_1.x
                if editor_wall.point_1.y > bounding_rectangle.w:
                    outermost_wall = editor_wall
                    bounding_rectangle.w = editor_wall.point_1.y

                editor_wall = editor_wall.wall_point_2

        return outermost_wall
Exemplo n.º 7
0
def create_window_texture_set_size(angular_width, z_width, color, color_bg,
                                   size_phi, size_z):
    # this creates a texture of size (size_phi X size_z) in pixels
    # one subregion of the texture of size (angular_width X z_width) is colored with "color"
    # the rest of the texture is colored with "color_bg"

    # generate bar texture
    image = pcore.PNMImage(
        size_phi, size_z
    )  # only 1 degree steps for the width of the window and 0.1 units steps for the height of the window
    image.fill(color_bg / 255.)
    for i in range(int(angular_width)):
        for j in range(int(np.round(z_width / 0.1))):
            image.setXelA(i, j, color / 255., color / 255., color / 255., 1)
    for i in range(int(angular_width), size_phi):
        for j in range(int(np.round(z_width / 0.1))):
            image.setXelA(i, 0, color_bg / 255., color_bg / 255.,
                          color_bg / 255., 1)

    tex = pcore.Texture()
    tex.load(image)
    tex.setMagfilter(pcore.Texture.FTLinearMipmapLinear)
    tex.setBorderColor(
        pcore.Vec4(color_bg / 255., color_bg / 255., color_bg / 255., 1))
    tex.setWrapU(pcore.Texture.WM_border_color)
    tex.setWrapV(pcore.Texture.WM_border_color)
    tex.setAnisotropicDegree(16)

    return tex
Exemplo n.º 8
0
def create_circular_window_texture(angular_width, color, color_bg):

    # generate bar texture
    image = pcore.PNMImage(
        360 * 3, 260 * 2
    )  # only 1 degree steps for the width of the window and 0.1 units steps for the height of the window
    #z_width = (angular_width/360. * 2 * math.pi*10) / 26 * (np.degrees(np.arctan(13/10.)) * 2)
    z_width = np.radians(
        angular_width
    ) * 10  # Kleinwinkelnaeherung / approximation for small angular widths
    #print z_width

    image.fill(color_bg / 255.)
    for i in range(min([360 * 3, int(angular_width) * 3])):
        for j in range(min([260 * 2, int(np.round(z_width / 0.1 * 2))])):
            if (i - angular_width / 2. * 3)**2 / (
                    angular_width / 2. *
                    3)**2 + (j - z_width / 0.1 / 2. * 2)**2 / (z_width / 0.1 /
                                                               2. * 2)**2 <= 1:
                image.setXelA(i, j, color / 255., color / 255., color / 255.,
                              1)

    tex = pcore.Texture()
    tex.load(image)
    tex.setMagfilter(pcore.Texture.FTNearest)
    tex.setBorderColor(
        pcore.Vec4(color_bg / 255., color_bg / 255., color_bg / 255., 1))
    tex.setWrapU(pcore.Texture.WM_border_color)
    tex.setWrapV(pcore.Texture.WM_border_color)
    tex.setAnisotropicDegree(16)

    return tex
Exemplo n.º 9
0
def mesh_to_egg(verts: np.ndarray, faces: np.ndarray,
                face_colors: Optional[np.ndarray],
                vertex_pool_name: str) -> egg.EggData:
    """convert a mesh to egg data"""

    # TODO: experiment with different coordinate systems
    z_up = egg.EggCoordinateSystem()
    z_up.setValue(core.CSZupRight)

    data = egg.EggData()
    data.addChild(z_up)

    vp = egg.EggVertexPool(vertex_pool_name)
    data.addChild(vp)

    for vert_np in verts:
        vert_egg = egg.EggVertex()
        vert_egg.setPos(core.Point3D(*vert_np))
        vp.addVertex(vert_egg)

    # TODO: optionally put polygons in multiple EggGroups
    for face_idx, face_np in enumerate(faces):
        poly = egg.EggPolygon()
        for idx in face_np:
            vert = vp.getVertex(int(idx))
            poly.addVertex(vert)
            if face_colors is not None:
                color = core.Vec4(*face_colors[face_idx])
                poly.setColor(color)
        data.addChild(poly)

    return data
Exemplo n.º 10
0
 def __setup_solved_symbols(self):
     c = core.CardMaker('solved')
     c.set_frame(core.Vec4(0, 0.2, -0.3, 0.3))
     c.set_color(core.Vec4(0))
     node_path = self.a2dLeftCenter.attach_new_node(c.generate())
     node_path.set_transparency(core.TransparencyAttrib.M_alpha)
     self.__solved_symbols = []
     c = core.CardMaker('s0')
     c.set_frame(core.Vec4(0.02, 0.18, -0.3, -0.14))
     self.__solved_symbols.append(node_path.attach_new_node(c.generate()))
     c = core.CardMaker('s1')
     c.set_frame(core.Vec4(0.02, 0.18, -0.08, 0.08))
     self.__solved_symbols.append(node_path.attach_new_node(c.generate()))
     c = core.CardMaker('s2')
     c.set_frame(core.Vec4(0.02, 0.18, 0.14, 0.3))
     self.__solved_symbols.append(node_path.attach_new_node(c.generate()))
Exemplo n.º 11
0
def three_rings():
    node_path = core.NodePath('three_rings')
    o1 = obelisk((1.5, 0.8))
    o2 = obelisk((1.5, 0.8))
    o1.reparent_to(node_path)
    o2.reparent_to(node_path)
    o1.set_pos(common.TR_O1_OFFSET)
    o2.set_pos(common.TR_O2_OFFSET)
    random.shuffle(common.TR_COLORS)
    rings = []
    symbol_cards = []
    for r, h, c in zip(common.TR_RADII, common.TR_HEIGHTS, common.TR_COLORS):
        rings.append(
            node_path.attach_new_node(
                sg.cone(origin=core.Vec3(0),
                        direction=core.Vec3.up(),
                        radius=r,
                        polygon=common.TR_POLYGON,
                        length=h,
                        color=c,
                        nac=False)))
        symbol_cards.append([])
        for i in range(6):
            r_node = rings[-1].attach_new_node('rot')
            c = core.CardMaker(f'symbol {len(rings)}/{i}')
            c.set_frame(core.Vec4(-1, 1, -1, 1))
            symbol_cards[-1].append(r_node.attach_new_node(c.generate()))
            r_node.set_h(i * 60)
            r_node.set_transparency(core.TransparencyAttrib.M_alpha)
            r_node.set_alpha_scale(common.TR_SYM_ALPHA)
            symbol_cards[-1][-1].set_y(r - 0.5)
            symbol_cards[-1][-1].set_z(h)
            symbol_cards[-1][-1].set_billboard_axis()

    return node_path, rings, symbol_cards
Exemplo n.º 12
0
def get_buffer(render_node, buff_size=None, clear_color=core.Vec4(0, 0, 0, 1)):
    buff_size = buff_size or core.ConfigVariableInt('portal-buffer-size',
                                                    1024).get_value()
    if _free_buffers:
        bobj = _free_buffers.pop()
        bobj.pipeline.render_node = render_node
        bobj.cam.reparent_to(render_node)
        return bobj
    basic = core.Filename.expand_from('$MAIN_DIR/assets/textures/basic_1.exr')
    basic = loader.load_texture(basic)
    buff = base.win.make_texture_buffer('Room Buffer', buff_size, buff_size)
    buff.set_clear_color(clear_color)
    buff.set_clear_color_active(True)
    buff.set_sort(-100)
    fog = core.Fog("Fog Name")
    fog.set_color(0, 0, 0)
    fog.set_exp_density(0.04)
    render_node.set_fog(fog)
    tex = buff.get_texture()
    cam = base.make_camera(buff)
    cam.reparent_to(render_node)
    pipeline = simplematcap.init(basic,
                                 render_node=render_node,
                                 light_dir=core.Vec3(-1, -1, 0.5).normalized(),
                                 hueshift=core.Vec3(random.uniform(-1.0, 1.0),
                                                    random.uniform(-1.0, 1.0),
                                                    20))
    return BufferObject(buff, tex, cam, pipeline)
Exemplo n.º 13
0
    def __init__(self):
        gamedata.GameData.__init__(self)
        # self.__solution = solution
        self.__nonogram_gen = NonogramGenerator()
        self.__current_symbol_id = None
        self.__solved = [False, False, False]
        self.__yx = tuple(reversed(common.NG_GRID))
        self.__grid = Grid(self.__yx)
        self.__solution = [None, None, None]

        self.__base = self.cam.attach_new_node('NonogramRoot')
        self.__text = self.aspect2d.attach_new_node(
            'NonogrammTextRoot'
        )  # type: core.NodePath
        self.__base.set_pos(common.NG_OFFSET)
        self.__base.set_scale(common.NG_SCALE)
        al = core.AmbientLight('al_nonogramm')
        al.set_color(core.Vec4(0.8))
        al_np = self.render.attach_new_node(al)
        self.__base.set_light(al_np)
        self.__root = None
        self.__grid_nodes = []
        self.__h_txt_grid = [
            [] for _ in range(self.__yx[0])
        ]  # type: List[List[core.NodePath]]
        self.__h_txt_values = [
            [
                '' for _ in range(5)
            ] for _ in range(self.__yx[0])
        ]  # type: List[List[str]]
        for h in self.__h_txt_values:
            h[0] = '0'
        self.__v_txt_grid = [
            [] for _ in range(self.__yx[1])
        ]  # type: List[List[core.NodePath]]
        self.__v_txt_values = [
            [
                '' for _ in range(5)
            ] for _ in range(self.__yx[0])
        ]  # type: List[List[str]]
        for v in self.__v_txt_values:
            v[0] = '0'
        self.__sg = shape.ShapeGen()
        self.__hidden = False
        self.__clicked = False
        self.__current_hover = None, None
        self.accept('mouse1-up', self.__click)
        self.accept('m', self.__nonogram_gen.show_all, [True])
        # self.accept('u', self.__update_cells)
        self.__aspect = self.win.get_y_size() / self.win.get_x_size()
        self.__setup()
        self.task_mgr.add(self.mouse_watch, 'nonogram_mouse_watcher')
        self.hide_nonogram()

        self.__nonogram_loaded = False
        self.__nonogram_solved = False

        self.__callback = None
        self.__cbargs = ()
Exemplo n.º 14
0
    def add(self, w, x, y, z):
        n = core.NodePath('designation')
        n.setPos(x, y, z)
        n.setShader(self.shader)
        n.setShaderInput('color', core.Vec4(0.5, 1.0, 0.5, 0.5))
        self.model.instanceTo(n)

        messenger.send('designation-add', [x, y, z, n])
Exemplo n.º 15
0
    def _debug_sector(self, sector: EditorSector, depth: int):
        if self._can_debug(depth):
            for editor_wall in sector.walls:
                self._debug_wall(editor_wall, 4, core.Vec4(0, 1, 0, 0.5))

                offset_2d = editor_wall.get_normalized_direction() * 2048
                offset = core.Vec3(offset_2d.x, offset_2d.y, 0) + core.Vec3(
                    0, 0, -256)

                position = editor_wall.get_centre() - offset
                position_2 = editor_wall.get_centre() + offset

                theta = editor_wall.get_direction_theta() + 180

                self._debug_wall_projection(editor_wall, theta, position,
                                            core.Vec4(1, 0, 0, 1))
                self._debug_wall_projection(editor_wall.wall_point_2, theta,
                                            position_2, core.Vec4(0, 0, 1, 1))
Exemplo n.º 16
0
def create_ellipse_window_texture_transparent_fg(angular_width, z_width, color,
                                                 color_bg):

    # analogue to create_circular_window_texture, only width an additional z_width
    # (used to account for perspective distortions when showing larger angles).

    # generate bar texture

    precision = 0.2

    image = pcore.PNMImage(
        360 * 3, 260 * 2
    )  # only 1 degree steps for the width of the window and 0.1 units steps for the height of the window
    #z_width = (angular_width/360. * 2 * math.pi*10) / 26 * (np.degrees(np.arctan(13/10.)) * 2)
    #z_width = np.radians(angular_width) * 10  # Kleinwinkelnaeherung / approximation for small angular widths
    #print z_width

    image.fill(color_bg / 255.)
    image.alphaFillVal(255)
    for i in range(min([360 * 3, int(angular_width) * 3])):
        for j in range(min([260 * 2, int(np.round(z_width / precision * 2))])):
            if (i - angular_width / 2. * 3)**2 / (
                    angular_width / 2. *
                    3)**2 + (j - z_width / precision / 2. * 2)**2 / (
                        z_width / precision / 2. * 2)**2 <= 1:
                image.setXelA(i, j, color / 255., color / 255., color / 255.,
                              0)
                #image.setAlphaVal(i,j,0.1)

    print("zwidth")
    print(z_width)
    # SHOW BORDERS OF THE LOOP FROM ABOVE
    #for i in range(0,360*3):
    #        image.setXelA(i,0,color/255.,color/255.,color/255.,1)
    #        image.setXelA(i,1,color/255.,color/255.,color/255.,1)
    #        image.setXelA(i,2,color/255.,color/255.,color/255.,1)
    #        image.setXelA(i,int(np.round(z_width/0.1*2))-1,color/255.,color/255.,color/255.,1)
    #        image.setXelA(i,int(np.round(z_width/0.1*2))-2,color/255.,color/255.,color/255.,1)
    #        image.setXelA(i,int(np.round(z_width/0.1*2))-3,color/255.,color/255.,color/255.,1)
    #for j in range(0,260*2):
    #        image.setXelA(0,j,color/255.,color/255.,color/255.,1)
    #        image.setXelA(1,j,color/255.,color/255.,color/255.,1)
    #        image.setXelA(2,j,color/255.,color/255.,color/255.,1)
    #        image.setXelA(int(angular_width)*3-1,j,color/255.,color/255.,color/255.,1)
    #        image.setXelA(int(angular_width)*3-2,j,color/255.,color/255.,color/255.,1)
    #        image.setXelA(int(angular_width)*3-3,j,color/255.,color/255.,color/255.,1)

    tex = pcore.Texture()
    tex.load(image)
    tex.setMagfilter(pcore.Texture.FTNearest)
    tex.setBorderColor(
        pcore.Vec4(color_bg / 255., color_bg / 255., color_bg / 255., 1))
    tex.setWrapU(pcore.Texture.WM_border_color)
    tex.setWrapV(pcore.Texture.WM_border_color)
    tex.setAnisotropicDegree(16)

    return tex
Exemplo n.º 17
0
 def __init__(self, vid, point, color=core.Vec4(1), texcoord=core.Vec2(0)):
     self._vid = vid
     self._point = point
     self._color = color
     self._texcoord = texcoord
     self._trs = []
     self._normal = None
     self._tangent = core.Vec3(0)
     self._bitangent = core.Vec3(0)
Exemplo n.º 18
0
    def _show_sources(self, target: map_objects.empty_object.EmptyObject):
        colour = core.Vec4(1, 1, 0, 0.85)

        if target.source_event_grouping is None:
            return

        for source_index, source in enumerate(
                target.source_event_grouping.sources):
            self._draw_line(source_index, colour, colour, source.origin,
                            target.origin)
Exemplo n.º 19
0
    def __init__(self, camera_collection: cameras.Cameras,
                 map_scene: core.NodePath):
        self._camera_collection = camera_collection

        self._grid_parent: core.NodePath = map_scene.attach_new_node("grid_3d")
        self._grid_parent.set_transparency(True)

        self._small_grid = shapes.make_grid(
            self._camera_collection,
            "movement_grid",
            2,
            100,
            core.Vec4(0.5, 0.55, 0.8, 0.85),
        )
        self._small_grid.reparent_to(self._grid_parent)

        self._big_grid = shapes.make_grid(
            self._camera_collection,
            "big_movement_grid",
            4,
            100,
            core.Vec4(1, 0, 0, 0.95),
        )
        self._big_grid.reparent_to(self._grid_parent)
        self._big_grid.set_scale(self._LARGE_GRID_SIZE)

        self._vertical_grid = shapes.make_z_grid(
            self._camera_collection,
            "big_movement_grid",
            2,
            100,
            core.Vec4(0, 0, 1, 0.95),
        )
        self._vertical_grid.reparent_to(self._grid_parent)

        self._grid_parent.set_depth_offset(constants.DEPTH_OFFSET, 1)
        self._grid_parent.hide()

        self.set_color_scale = self._grid_parent.set_color_scale
        self.show = self._grid_parent.show
        self.hide = self._grid_parent.hide
        self.is_hidden = self._grid_parent.is_hidden
Exemplo n.º 20
0
    def place_devils_tower(self):
        self.devils_tower = self.render.attach_new_node(
            shape.ShapeGen().elliptic_cone(a=(240, 70),
                                           b=(200, 80),
                                           h=250,
                                           max_seg_len=20.0,
                                           exp=2.5,
                                           top_xy=(40, -20),
                                           color=core.Vec4(
                                               0.717, 0.635, 0.558, 1),
                                           nac=False))
        h = random.randint(0, 360)
        self.collision.add(collision.CollisionCircle(
            core.Vec2(0),
            230,
        ))
        self.devils_tower.set_h(h)
        z = []
        for x in (-220, 0, 220):
            for y in (-220, 0, 220):
                z.append(self.sample_terrain_z(x, y))
        self.devils_tower.set_z(min(z) - 5)

        self.noise.setup_fns(noise_type=fns.NoiseType.Value, )
        y, x = common.DT_TEX_SHAPE
        c = fns.empty_coords(y * x)
        c[0, :] = np.tile(
            np.cos(np.linspace(-np.pi, np.pi, x, False)) * common.DT_XY_RADIUS,
            y)
        c[1, :] = np.tile(
            np.sin(np.linspace(-np.pi, np.pi, x, False)) * common.DT_XY_RADIUS,
            y)
        c[2, :] = np.repeat(
            np.linspace(-np.pi, np.pi, x, False) * common.DT_Z_RADIUS, y)
        a = self.noise.fns.genFromCoords(c).reshape((y, x))
        normal_map = util.sobel(a, 0.15)
        # Image.fromarray(normal_map).show()
        tex = self.loader.load_texture('rock.jpg')
        ts = core.TextureStage('ts')
        tex.set_wrap_u(core.Texture.WM_clamp)
        tex.set_wrap_v(core.Texture.WM_clamp)
        self.devils_tower.set_texture(ts, tex)
        self.devils_tower.set_tex_scale(ts, 1)
        tex = core.Texture('dt_normal_map')
        tex.setup_2d_texture(y, x, core.Texture.T_unsigned_byte,
                             core.Texture.F_rgb)
        tex.set_ram_image_as(normal_map, 'RGB')
        tex.set_wrap_u(core.Texture.WM_clamp)
        tex.set_wrap_v(core.Texture.WM_clamp)
        ts = core.TextureStage('ts')
        ts.set_mode(core.TextureStage.M_normal)
        tex.reload()
        self.devils_tower.set_texture(ts, tex)
Exemplo n.º 21
0
 def get_bounding_rectangle(self):
     result = core.Vec4(
         constants.REALLY_BIG_NUMBER,
         -constants.REALLY_BIG_NUMBER,
         constants.REALLY_BIG_NUMBER,
         -constants.REALLY_BIG_NUMBER,
     )
     for editor_wall in self._walls:
         result.x = min(result.x, editor_wall.point_1.x)
         result.y = max(result.y, editor_wall.point_1.x)
         result.z = min(result.z, editor_wall.point_1.y)
         result.w = max(result.w, editor_wall.point_1.y)
     return result
Exemplo n.º 22
0
    def add_vertex(self, point, color=core.Vec4(1), texcoord=core.Vec2(0)):
        # type: (core.Vec3, core.Vec4, core.Vec2) -> int
        """
        Return unique vertex id, inserting a new one only if necessary.

        Args:
            point:
            color:
            texcoord:
        """
        if point not in self._pts:
            self._pts[point] = Point(point, self)
        return self._pts[point].add_vertex(color, texcoord)
Exemplo n.º 23
0
    def _update_markers(self):
        self._clear_markers()
        if self._sector.get_type() < 1:
            return

        first_marker, second_marker = self._sector.markers
        self._marker_display = self._camera_collection.scene.attach_new_node(
            "markers")
        self._marker_display.set_depth_test(False)

        if first_marker is not None:
            if second_marker is not None:
                self._make_slide_marker(first_marker, second_marker)
            else:
                self._make_rotate_marker(first_marker)

        first_marker, second_marker = self._sector.floor_z_motion_markers
        self._make_z_motion_marker(first_marker, second_marker,
                                   core.Vec4(0, 0.8, 1, 0.8))

        first_marker, second_marker = self._sector.ceiling_z_motion_markers
        self._make_z_motion_marker(first_marker, second_marker,
                                   core.Vec4(0.8, 0, 1, 0.8))
Exemplo n.º 24
0
    def _make_rotate_marker(self, marker: map_objects.EditorMarker):
        bounding_rectangle = self._sector.get_bounding_rectangle()
        delta_x = bounding_rectangle.y - bounding_rectangle.x
        delta_y = bounding_rectangle.w - bounding_rectangle.z

        radius = 3 * min(delta_x, delta_y) / 8

        display = shapes.make_circle(self._marker_display, marker.origin,
                                     radius * 1.5, 12)
        self._setup_display(display, colour=core.Vec4(0, 1, 0, 0.5))

        display = shapes.make_arc(self._marker_display, marker.origin, radius,
                                  marker.theta - 90, 12)
        self._setup_display(display)
Exemplo n.º 25
0
    def insert_vertex(self, point, color, texcoord):
        """
        Return vertex id of a new vertex, not preventing duplication.
        Convenience function for Point, do not use otherwise.

        Args:
            point:
            color:
            texcoord:
        """
        if color.num_components == 3:
            color = core.Vec4(*tuple(color), 1)
        self._vts[self._vid] = Vertex(self._vid, point, color, texcoord)
        self._vid += 1
        return self._vid - 1
Exemplo n.º 26
0
 def toggle_hover(self, x=None, y=None):
     cx, cy = self.__current_hover
     if self.__current_hover != (x, y):
         if cx is not None:
             node_path = self.__grid_nodes[cy][cx]
             ps = node_path.get_pos()
             p = ps + core.Vec3(0, 0, 0)
             p.y = 0
             LerpPosInterval(
                 node_path,
                 common.NG_ANIM_DURATION,
                 p,
                 ps,
                 blendType='easeInOut'
             ).start()
             for n in self.__h_txt_grid[cy]:
                 n.set_color(core.Vec4(1))
             for n in self.__v_txt_grid[cx]:
                 n.set_color(core.Vec4(1))
         if x is not None:
             node_path = self.__grid_nodes[y][x]
             ps = node_path.get_pos()
             p = ps + core.Vec3(0, 0, 0)
             p.y = common.NG_HOVER_Y_OFFSET
             LerpPosInterval(
                 node_path,
                 common.NG_ANIM_DURATION,
                 p,
                 ps,
                 blendType='easeInOut'
             ).start()
             for n in self.__h_txt_grid[y]:
                 n.set_color(core.Vec4(0.7, 0.3, 0.3, 1.0))
             for n in self.__v_txt_grid[x]:
                 n.set_color(core.Vec4(0.3, 0.7, 0.3, 1.0))
         self.__current_hover = x, y
Exemplo n.º 27
0
    def _show_targets(self, source: map_objects.empty_object.EmptyObject,
                      colour: core.Vec4):
        if source in self._seen:
            return
        self._seen.add(source)

        next_colour = core.Vec4(0, 0.5, 1, colour.w / 2)

        if source.target_event_grouping is None:
            return

        for target_index, target in enumerate(
                source.target_event_grouping.targets):
            self._draw_line(target_index, colour, next_colour, source.origin,
                            target.origin)
            self._show_targets(target, next_colour)
Exemplo n.º 28
0
    def __init__(self, parent):
        AssetBrowser.__init__(self, parent)

        self.currentLoadContext = None

        # Set up an offscreen buffer to render the thumbnails of our models.

        props = core.WindowProperties()
        props.setSize(96, 96)
        fbprops = core.FrameBufferProperties()
        fbprops.setSrgbColor(True)
        fbprops.setRgbaBits(8, 8, 8, 0)
        flags = (core.GraphicsPipe.BFRefuseWindow
                 | core.GraphicsPipe.BFSizeSquare)
        self.buffer = base.graphicsEngine.makeOutput(base.pipe,
                                                     "modelBrowserBuffer", 0,
                                                     fbprops, props, flags,
                                                     None, None)
        gsg = self.buffer.getGsg()
        self.buffer.setClearColor(
            BSPUtils.vec3GammaToLinear(
                core.Vec4(82 / 255.0, 82 / 255.0, 82 / 255.0, 1.0)))
        self.buffer.setActive(False)

        self.displayRegion = self.buffer.makeDisplayRegion()

        self.render = core.NodePath("modelBrowserRoot")
        self.render.setShaderAuto()

        camNode = core.Camera("modelBrowserRenderCam")
        lens = core.PerspectiveLens()
        lens.setFov(40)
        camNode.setLens(lens)
        self.lens = lens
        self.camera = self.render.attachNewNode(camNode)
        # Isometric camera angle
        self.camera.setHpr(225, -30, 0)

        self.displayRegion.setCamera(self.camera)

        shgen = BSPShaderGenerator(self.buffer, gsg, self.camera, self.render)
        gsg.setShaderGenerator(shgen)
        for shader in ShaderGlobals.getShaders():
            shgen.addShader(shader)
        self.shaderGenerator = shgen

        base.graphicsEngine.openWindows()
Exemplo n.º 29
0
 def __generate_solution_cards(self):
     for i in range(3):
         c = core.CardMaker('nbg')
         c.set_frame(core.Vec4(-0.5, 0.5, -0.5, 0.5))
         self.__solution[i] = self.aspect2d.attach_new_node(c.generate())
         im = self.symbols[self.__nonogram_gen.chosen_symbols[i]][0]
         a = np.zeros(im.size + (3,), dtype=np.uint8)
         a[:, :, 0] = np.array(im)
         a[:, :, 1] = np.array(im)
         a[:, :, 2] = np.array(im)
         tex = core.Texture(f'solution{i}')
         tex.setup_2d_texture(
             *a.shape[:2],
             core.Texture.T_unsigned_byte,
             core.Texture.F_rgb
         )
         tex.set_ram_image_as(a, 'RGB')
         tex.reload()
         self.__solution[i].set_texture(tex, 1)
         self.__solution[i].hide()
Exemplo n.º 30
0
    def project(self):

        # project field of view of beamer
        N_x = int(self.arena.omega_h * 3)
        N_y = int(self.arena.omega_v * 3)
        grid_image = pcore.PNMImage(N_x, N_y)
        for i in range(N_x - 2):
            for j in range(N_y - 2):
                grid_image.setXelA(i + 1, j + 1, 0, 0, 0, 1)
        for i in range(N_x):
            grid_image.setXelA(i, 0, 1, 1, 1, 1)
            grid_image.setXelA(i, int(N_y / 2), 1, 1, 1, 1)
            grid_image.setXelA(i, N_y - 1, 1, 1, 1, 1)
        for i in range(N_y):
            grid_image.setXelA(0, i, 1, 1, 1, 1)
            grid_image.setXelA(int(N_x / 2), i, 1, 1, 1, 1)
            grid_image.setXelA(N_x - 1, i, 1, 1, 1, 1)

        self.tex_grid = pcore.Texture()
        self.tex_grid.load(grid_image)
        self.tex_grid.setMagfilter(pcore.Texture.FTNearest)

        self.proj = render.attachNewNode(pcore.LensNode('proj'))
        self.proj.node().setLens(self.lens)
        self.proj.reparentTo(self.beamer)

        self.ts = pcore.TextureStage('ts_proj')
        self.ts.setMode(pcore.TextureStage.MBlend)
        self.ts.setColor(
            pcore.Vec4(self.color[0], self.color[1], self.color[2],
                       self.color[3]))
        self.tex_grid.setWrapU(pcore.Texture.WMBorderColor)
        self.tex_grid.setWrapV(pcore.Texture.WMBorderColor)

        self.screen.projectTexture(self.ts, self.tex_grid, self.proj)

        self.proj.node().showFrustum()
        self.proj.find('frustum').setColor(self.color[0], self.color[1],
                                           self.color[2], self.color[3])