Пример #1
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)
    def build(self):

        # configure beamer
        self.set_arena_mode('greenHDMI')


        self.cylinder_height, self.cylinder_radius, self.cylinder = tools.standard_cylinder(self.parent.mainNode)

        # paint the cylinder black on the ground
        tex_ground = tools.create_plain_texture(0)
        self.ts_ground = pcore.TextureStage('ts_ground')
        self.cylinder.setTexture(self.ts_ground, tex_ground)

        # generate textures
        anti_alias_texture_size = int(math.ceil(608./(math.degrees(math.atan(self.cylinder_height/2./self.cylinder_radius))*2/self.wave_length/0.9) - 2*4)/2. + 2) # empirically

        # unfortunately, MAdd Texture mode does not work together with the setColorScale - command from base.py
        # this means, that those textures that are added onto another one cannot be tinted in a certain color
        # hence, here we generate differently coloured texture from the beginning, depending on the temporal offset of the Stimulus World
        if self.t_offset == 0.:
            color_vector = [0,0,1] # blue
        elif self.t_offset == 1.:
            color_vector = [1,0,0] # red
        elif self.t_offset == 2.:
            color_vector = [0,1,0] # green

        # generate two sine gratings that are anti-phasic
        # then in the beginning everything is gray and on the left edge (phi = 0) the first polarity is dark
        self.tex = tools.create_coloured_sine_grating_texture(anti_alias_texture_size, self.min_intensity, self.max_intensity, color_vector=color_vector)
        self.tex2 = tools.create_coloured_sine_grating_texture(anti_alias_texture_size, self.max_intensity, self.min_intensity, color_vector=color_vector)

        # add the two sine gratings onto each other to generate a counterphase flicker
        self.ts1 = pcore.TextureStage('ts1')
        self.ts1.setMode(pcore.TextureStage.MAdd)
        self.ts2 = pcore.TextureStage('ts2')
        self.ts2.setMode(pcore.TextureStage.MAdd)

        self.cylinder.setTexture(self.ts1, self.tex)
        self.cylinder.setTexScale(self.ts1, 360.0/self.wave_length, math.degrees(math.atan(self.cylinder_height/2./self.cylinder_radius))*2/self.wave_length)
        self.cylinder.setTexRotate(self.ts1, -self.rotation)

        self.cylinder.setTexture(self.ts2, self.tex2)
        self.cylinder.setTexScale(self.ts2, 360.0/self.wave_length, math.degrees(math.atan(self.cylinder_height/2./self.cylinder_radius))*2/self.wave_length)
        self.cylinder.setTexRotate(self.ts2, -self.rotation)

        self.tex_offset = 0.
        self.cylinder.setTexOffset(self.ts1, (self.tex_offset + self.angle_function(0))/self.wave_length % 1, 0)
        self.cylinder.setTexOffset(self.ts2, (self.tex_offset - self.angle_function(0))/self.wave_length % 1, 0)
Пример #3
0
    def build(self):

        # configure beamer
        self.set_arena_mode('greenHDMI')

        self.cylinder_height, self.cylinder_radius, self.cylinder = tools.standard_cylinder(self.parent.mainNode)
        self.cylinder.setColor(self.bg_intensity/255.,self.bg_intensity/255.,self.bg_intensity/255.,1)

        self.z = self.z * 10/5.
        self.dz = self.dz * 10/5.
        if self.dz > 26.:
            self.dz = 26.
        if self.dphi > 360.:
            self.dphi = 360.


        self.ts_window = pcore.TextureStage('ts_bar')
        tex_window = tools.create_window_texture(self.dphi, self.dz, self.bar_intensity, self.bg_intensity)
        self.cylinder.clearColor()
        self.cylinder.setTexture(self.ts_window, tex_window)

        # set starting point of bar depending if it will go rightwards or leftwards
        if self.velocity > 0:
            self.phi0 = -(90. + self.dphi/2.)
        elif self.velocity <= 0:
            self.phi0 = +(90. + self.dphi/2.)

        self.cylinder.setTexOffset(self.ts_window, -0.25 + self.dphi/2./360. - self.phi0/360., 0.5 - self.dz/2./26. - self.z/26.)

        self.T = (180. + self.dphi)/math.fabs(self.velocity)
Пример #4
0
    def build(self):

        # configure beamer
        self.set_arena_mode('greenHDMI')

        self.cylinder_height, self.cylinder_radius, self.cylinder = tools.standard_cylinder(self.parent.mainNode)
        self.cylinder.setColor(self.bg_intensity/255.,self.bg_intensity/255.,self.bg_intensity/255.,1)

        # scale cylinder up in height in case the window texture is overlapping the edges
        self.cylinder_height = self.cylinder_height + self.dz * 2
        self.cylinder.setScale(self.cylinder_radius,self.cylinder_radius,self.cylinder_height)

        self.dz = self.dz * 10/5.
        self.velocity = self.velocity * 10/5.
        if self.dz > 26.:
            self.dz = 26.
        if self.dphi > 360.:
            self.dphi = 360.
        self.ts_window = pcore.TextureStage('ts_bar')


        tex_window = tools.create_window_texture_set_size(self.dphi, self.dz, self.bar_intensity, self.bg_intensity, 360, int(self.cylinder_height/0.1))
        self.cylinder.clearColor()
        self.cylinder.setTexture(self.ts_window, tex_window)

        # set starting point depending whether direction is downwards or upwards
        if self.velocity > 0:
            self.z0 = -(13 + self.dz/2.)
        elif self.velocity <= 0:
            self.z0 = (13 + self.dz/2.)


        self.cylinder.setTexOffset(self.ts_window, -0.25 + self.dphi/2./360. - self.phi/360., 0.5 - self.dz/2./self.cylinder_height - self.z0/self.cylinder_height)

        self.T = (26. + self.dz)/math.fabs(self.velocity)
    def build(self):

        # configure beamer
        if self.color == 'b':
            self.set_arena_mode('optoblueHDMI')
        elif self.color == 'r':
            self.set_arena_mode('optoredHDMI')
        elif self.color == 'g':
            self.set_arena_mode('optogreenHDMI')

        self.cylinder_height, self.cylinder_radius, self.cylinder = tools.standard_cylinder(self.parent.mainNode)
        self.cylinder.setColor(self.min_intensity/255.,self.min_intensity/255.,self.min_intensity/255.,1) # set background color

        self.min_intensity = (self.min_intensity)/255.
        self.max_intensity = (self.max_intensity)/255.
        self.bg_intensity = self.min_intensity

        # create window
        self.ts_window = pcore.TextureStage('ts_window')
        #self.ts_window.setMode(pcore.TextureStage.MBlend)


        self.worlds_share(self.cylinder) # store cylinder in shared space to change its color synchronously in all color worlds
        self.pulse_done = False
        self.pulse_end = False
Пример #6
0
    def build(self):

        # configure beamer
        self.set_arena_mode('greenHDMI')

        self.cylinder_height, self.cylinder_radius, self.cylinder = tools.standard_cylinder(
            self.parent.mainNode)

        self.cylinder_height = self.cylinder_height + self.dz * 2
        self.cylinder.setScale(self.cylinder_radius, self.cylinder_radius,
                               self.cylinder_height)

        self.ts_window = pcore.TextureStage('ts_window')
        self.plain_tex = tools.create_plain_texture(self.bg_intensity)
        self.cylinder.setTexture(self.ts_window, self.plain_tex)

        self.nr_before = 0

        self.z = self.z * 10 / 5.
        self.dz = self.dz * 10 / 5.
        if self.dz > 26:
            self.dz = 26
        if self.dphi > 360.:
            self.dphi = 360.

        self.tex_windowA = tools.create_window_texture_set_size(
            self.dphi, self.dz, self.max_intensity, self.bg_intensity, 360,
            int(self.cylinder_height / 0.1))
        self.tex_windowB = tools.create_window_texture_set_size(
            self.dphi, self.dz, self.min_intensity, self.bg_intensity, 360,
            int(self.cylinder_height / 0.1))

        self.cylinder.setTexOffset(
            self.ts_window, -(-self.dphi / 2. / 360. + self.phi / 360.),
            0.5 - self.dz / 2. / self.cylinder_height -
            self.z / self.cylinder_height)

        # set up shared variables for synchronizing all color worlds
        self.shared.phi = self.phi
        self.shared.z = self.z
        self.shared.factor = 1

        # set up keyboard commands for moving the window
        base.accept("arrow_right", self.increase_phi)
        base.accept("arrow_left", self.decrease_phi)
        base.accept("arrow_up", self.increase_z)
        base.accept("arrow_down", self.decrease_z)
        base.accept("arrow_right-repeat", self.increase_phi)
        base.accept("arrow_left-repeat", self.decrease_phi)
        base.accept("arrow_up-repeat", self.increase_z)
        base.accept("arrow_down-repeat", self.decrease_z)
Пример #7
0
    def item_type(self, item_type: str) -> None:
        """
        """
    
        self._item_type = item_type
        item_data = runtime.library.itemData[item_type]
        images = item_data['Images']

        detail = runtime.loader.load_texture(images['detail'])
        mask = runtime.loader.load_texture(images['mask'])
        mask_stage = p3d.TextureStage('mask')

        runtime.itemCard.set_texture_off()
        runtime.itemCard.set_texture(detail)
        runtime.itemCard.set_texture(mask_stage, mask)
        runtime.itemCard.set_transparency(True)
Пример #8
0
 def place_trees(self):
     tex = core.Texture('roads')
     ts = core.TextureStage('ts')
     # noinspection PyArgumentList
     tex.setup_2d_texture(1024, 1024, core.Texture.T_float,
                          core.Texture.F_rgb)
     bounds_tex = np.zeros((1024, 1024, 3), np.float32)
     bounds_tex[self.__bounds[:1024, :1024], :] = -0.05
     # print(bounds_tex.shape)
     tex.set_ram_image_as(bounds_tex, 'RGB')
     tex.reload()
     ts.set_mode(core.TextureStage.M_add)
     # ts.set_combine_rgb(
     #     core.TextureStage.CM_subtract,
     #     core.TextureStage.CS_texture,
     #     core.TextureStage.CO_src_color,
     #     tex,
     #     core.TextureStage.CO_src_color
     # )
     self.terrain_root.set_texture(ts, tex)
     trees = [
         random.choice((modelgen.fir_tree, modelgen.leaf_tree))()
         for _ in range(common.W_INDIVIDUAL_TREES)
     ]
     x = 3
     y = 3
     hs = common.T_XY * common.T_XY_SCALE / 2
     while y < self.__woods.shape[0] - 3:
         step = np.random.randint(9, 30)
         x += step
         if x > self.__woods.shape[0] - 3:
             y += np.random.randint(10, 20)
             if y >= self.__woods.shape[0] - 3:
                 break
             x = max(3, x % self.__woods.shape[0])
         if not self.__woods[y, x]:
             continue
         node_path = self.tree_root.attach_new_node('fir_tree')
         orig, r = random.choice(trees)
         orig.copy_to(node_path)
         pos = core.Vec3(
             (x + random.random() - 0.5) * common.T_XY_SCALE - hs,
             (y + random.random() - 0.5) * common.T_XY_SCALE - hs, 0)
         self.collision.add(collision.CollisionCircle(pos.xy, r))
         pos.z = self.sample_terrain_z(pos.x, pos.y)
         node_path.set_pos(pos)
Пример #9
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])
from panda3d import core

# Some dummy textures we can use for our texture attributes.
stage1 = core.TextureStage("stage1")
stage2 = core.TextureStage("stage2")
stage3 = core.TextureStage("stage3")
tex1 = core.Texture("tex1")
tex2 = core.Texture("tex2")
tex3 = core.Texture("tex3")


def test_textureattrib_compose_add():
    # Tests a case in which a child node adds another texture.
    tattr1 = core.TextureAttrib.make()
    tattr1 = tattr1.add_on_stage(stage1, tex1)

    tattr2 = core.TextureAttrib.make()
    tattr2 = tattr2.add_on_stage(stage2, tex2)

    tattr3 = tattr1.compose(tattr2)
    assert tattr3.get_num_on_stages() == 2

    assert stage1 in tattr3.on_stages
    assert stage2 in tattr3.on_stages


def test_textureattrib_compose_subtract():
    # Tests a case in which a child node disables a texture.
    tattr1 = core.TextureAttrib.make()
    tattr1 = tattr1.add_on_stage(stage1, tex1)
    tattr1 = tattr1.add_on_stage(stage2, tex2)
    def build(self):  #, old_geometry):

        # configure beamer
        self.set_arena_mode('greenHDMI')

        self.cylinder_height, self.cylinder_radius, self.cylinder = tools.standard_cylinder(
            self.parent.mainNode)

        # make cylinder bigger in case the window is overlapping the edges and needs more space
        self.cylinder_height = self.cylinder_height + self.dz * 2
        self.cylinder.setScale(self.cylinder_radius, self.cylinder_radius,
                               self.cylinder_height)

        # like in default.PDNDgrating
        self.period = self.motion_T * 2 + self.pause * 2
        self.T = 100000  # go on for eternity
        self.count_period = 0

        # load texture
        anti_alias_texture_size = int(
            math.ceil(608. / (math.degrees(
                math.atan(self.cylinder_height / 2. / self.cylinder_radius)) *
                              2 / self.wave_length / 0.9) - 2 * 4) / 2. +
            2)  # empirically
        if self.mode == 'sin':
            self.tex = tools.create_sine_grating_texture(
                anti_alias_texture_size, self.min_intensity,
                self.max_intensity)
        elif self.mode == 'sq':
            self.tex = tools.create_grating_texture(anti_alias_texture_size,
                                                    self.min_intensity,
                                                    self.max_intensity)
        self.cylinder.setTexture(self.tex)

        # scale like in the normal PDNDgrating and then scale down even more by the factor between the bigger cylinder and the "normal" cylinder of height 26.
        #factor_visible = math.degrees(math.atan(26/2./self.cylinder_radius))*2/self.wave_length * self.cylinder_height/26.
        #self.cylinder.setTexScale(pcore.TextureStage.getDefault(), 360.0/self.wave_length, factor_visible) # visible cylinder height is 26

        # generate wavelength by rescaling the texture ( which contains exact one period of the grating) in relation to the desired wavelength
        # for the horizontal component the scaling factor is given by the ratio between the cylinder width (360 degree) and the wavelength
        # for the vertical component the scaling factor is given by the ratio between 180 degree (because we would see the whole texture if the scaling factor would be 1)
        #       and the wavelength times the aspect ratio of the arena screen (such that 45 degree remains 45 degree)
        #
        # NOTE: Using this convention the vertical scaling factor is given by the requirement that 45 degree generates exactly 45 degree on the arena screen
        #       This scaling factor also defines how wide the bars will be in vertical direction.
        #       Hence, the wavelength is strictly speaking defined only for horizontal gratings moving along the azimuth

        self.cylinder.setTexture(self.tex)
        #self.cylinder.setTexScale(pcore.TextureStage.getDefault(), 360.0/self.wave_length, math.degrees(math.atan(self.cylinder_height/2./self.cylinder_radius))*2/self.wave_length)
        self.cylinder.setTexScale(
            pcore.TextureStage.getDefault(), 360.0 / self.wave_length, 360.0 /
            self.wave_length / 2. / (10. * math.pi / self.cylinder_height))

        self.cylinder.setTexRotate(pcore.TextureStage.getDefault(),
                                   -self.rotation)
        self.velocity = -self.velocity

        self.tex_offset = 0.
        self.cylinder.setTexOffset(pcore.TextureStage.getDefault(),
                                   (self.tex_offset + self.angle_function(0)) /
                                   self.wave_length % 1, 0)

        # create window
        self.z = self.z * 10 / 5.
        self.dz = self.dz * 10 / 5.
        if self.dz > 26:
            self.dz = 26
        if self.dphi > 360.:
            self.dphi = 360.

        # create black/white mask for transparent area
        self.ts_window = pcore.TextureStage('ts_window')
        self.ts_window.setMode(pcore.TextureStage.MBlend)
        tex_window = tools.create_window_texture_set_size(
            self.dphi, self.dz, 0, 255, 360, int(self.cylinder_height / 0.1))
        self.cylinder.setTexture(self.ts_window, tex_window)
        self.cylinder.setTexOffset(
            self.ts_window, -(-self.dphi / 2. / 360. + self.phi / 360.),
            0.5 - self.dz / 2. / self.cylinder_height -
            self.z / self.cylinder_height)

        # set color of the background around the window
        self.ts_window.setColor(
            pcore.Vec4(self.bg_intensity / 255., self.bg_intensity / 255.,
                       self.bg_intensity / 255., 1))

        # initialize variables to memorize phase of the stimulus
        self.stop1stdirection_trigger = True
        self.start2ndirection_trigger = True

        # set up shared variables for synchronizing all color worlds
        self.shared.phi = self.phi
        self.shared.z = self.z
        self.shared.factor = 1

        # set up keyboard commands for moving the window
        base.accept("arrow_right", self.increase_phi)
        base.accept("arrow_left", self.decrease_phi)
        base.accept("arrow_up", self.increase_z)
        base.accept("arrow_down", self.decrease_z)
        base.accept("arrow_right-repeat", self.increase_phi)
        base.accept("arrow_left-repeat", self.decrease_phi)
        base.accept("arrow_up-repeat", self.increase_z)
        base.accept("arrow_down-repeat", self.decrease_z)
Пример #12
0
    def __setup(self):
        # self.start_nonogram(0)
        if None in self.__solution:
            self.__generate_solution_cards()

        self.__root = None
        self.__base.get_children().detach()
        self.__root = self.__base.attach_new_node('CellRoot')
        self.__root.set_pos(
            -(common.NG_RADIUS * 2 + common.NG_PAD) * self.__yx[1] / 2,
            0,
            (common.NG_RADIUS * 2 + common.NG_PAD) * self.__yx[0] / 2
        )

        c = core.CardMaker('nbg')
        c.set_frame(core.Vec4(-100, 100, -100, 100))
        self.__card = self.__base.attach_new_node(c.generate())
        self.__card.set_color(common.NG_BG_COLOR)
        self.__card.set_transparency(core.TransparencyAttrib.M_alpha)
        o = core.Vec3(0)
        o.xz = common.NG_OFFSET.xz
        self.__card.set_pos(o)
        self.__card.set_bin('fixed', 0)
        self.__card.set_depth_test(False)
        self.__card.set_depth_write(False)

        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'

        tex = core.Texture('cell_tex')
        tex.setup_2d_texture(
            *tuple(reversed(common.NG_TEX)),
            core.Texture.T_float,
            core.Texture.F_rgba
        )
        tex.set_ram_image_as(util.bw_tex(*common.NG_TEX), 'RGBA')
        tex.set_wrap_u(core.Texture.WM_clamp)
        tex.set_wrap_v(core.Texture.WM_clamp)
        tex.reload()
        if self.__grid_nodes:
            self.__grid_nodes = []
            self.__root.get_children().detach()

        cell_np = self.__root.attach_new_node(
            self.__sg.sphere(
                core.Vec3(0),
                core.Vec3.up(),
                common.NG_RADIUS,
                common.NG_POLY,
                name='cell 0/0',
                nac=False
            )
        )
        ts = core.TextureStage('ts')
        cell_np.set_texture(ts, tex, 1)
        cell_np.set_tex_offset(ts, 0.25, 0)
        cell_np.set_bin('fixed', 0)
        cell_np.set_depth_test(False)
        cell_np.set_depth_write(False)

        for y in range(self.__yx[0]):
            self.__grid_nodes.append([])
            for x in range(self.__yx[1]):
                if x or y:
                    node_path = self.__root.attach_new_node(f'cell {x}/{y}')
                    cell_np.copy_to(node_path)
                    node_path.set_pos(
                        x * (common.NG_RADIUS + common.NG_PAD),
                        0,
                        -y * (common.NG_RADIUS + common.NG_PAD)
                    )
                    self.__grid_nodes[-1].append(node_path)
                else:
                    self.__grid_nodes[-1].append(cell_np)