Exemplo n.º 1
0
    geometry = ngl.Triangle(p0, p1, p2)
    return _render_shape(geometry, color)


@test_fingerprint(samples=4)
@scene(sz=scene.Range(range=[0.1, 2], unit_base=100), color=scene.Color())
def shape_triangle_msaa(cfg, sz=1, color=COLORS.orange):
    cfg.aspect_ratio = (1, 1)
    p0, p1, p2 = equilateral_triangle_coords(sz)
    geometry = ngl.Triangle(p0, p1, p2)
    return _render_shape(geometry, color)


@test_fingerprint()
@scene(
    corner=scene.Vector(n=3, minv=(-1, -1, -1), maxv=(1, 1, 1)),
    width=scene.Vector(n=3, minv=(0, 0, 0), maxv=(2, 2, 2)),
    height=scene.Vector(n=3, minv=(0, 0, 0), maxv=(2, 2, 2)),
    color=scene.Color(),
)
def shape_quad(cfg,
               corner=(-0.5, -0.8, 0),
               width=(0.9, 0.2, 0),
               height=(0.1, 1.3, 0),
               color=COLORS.sgreen):
    cfg.aspect_ratio = (1, 1)
    geometry = ngl.Quad(corner, width, height)
    return _render_shape(geometry, color)


@test_fingerprint()
Exemplo n.º 2
0
import pynodegl as ngl
from pynodegl_utils.misc import scene


@scene(uv_corner=scene.Vector(n=2),
       uv_width=scene.Vector(n=2),
       uv_height=scene.Vector(n=2),
       progress_bar=scene.Bool())
def centered_media(cfg,
                   uv_corner=(0, 0),
                   uv_width=(1, 0),
                   uv_height=(0, 1),
                   progress_bar=True):
    '''A simple centered media with an optional progress bar in the shader'''
    m0 = cfg.medias[0]
    cfg.duration = m0.duration
    cfg.aspect_ratio = (m0.width, m0.height)

    q = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0), uv_corner, uv_width,
                 uv_height)
    m = ngl.Media(m0.filename)
    t = ngl.Texture2D(data_src=m)
    p = ngl.Program(vertex=cfg.get_vert('texture'),
                    fragment=cfg.get_frag('texture'))
    p.update_vert_out_vars(var_tex0_coord=ngl.IOVec2(),
                           var_uvcoord=ngl.IOVec2())
    render = ngl.Render(q, p)
    render.update_frag_resources(tex0=t)

    if progress_bar:
        p.set_fragment(cfg.get_frag('progress-bar'))
Exemplo n.º 3
0
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

from pynodegl_utils.misc import scene
from pynodegl_utils.toolbox.colors import COLORS

import pynodegl as ngl


@scene(
    txt=scene.Text(),
    fg_color=scene.Color(),
    bg_color=scene.Color(),
    box_corner=scene.Vector(n=3, minv=(-1, -1, -1), maxv=(1, 1, 1)),
    box_width=scene.Vector(n=3, minv=(-10, -10, -10), maxv=(10, 10, 10)),
    box_height=scene.Vector(n=3, minv=(-10, -10, -10), maxv=(10, 10, 10)),
    padding=scene.Range(range=[0, 100]),
    font_scale=scene.Range(range=[0, 15], unit_base=100),
    valign=scene.List(choices=("top", "center", "bottom")),
    halign=scene.List(choices=("left", "center", "right")),
)
def text(
    cfg,
    txt="the quick brown fox\njumps over the lazy dog",
    fg_color=COLORS.cgreen,
    bg_color=(0.3, 0.3, 0.3),
    box_corner=(-1 + 0.25, -1 + 0.25, 0),
    box_width=(1.5, 0, 0),
    box_height=(0, 1.5, 0),
Exemplo n.º 4
0
@scene()
def transform_eye_camera(cfg):
    cfg.duration = 3.0
    cfg.aspect_ratio = (1, 1)

    node = ngl.RenderGradient4(geometry=ngl.Circle(radius=0.7, npoints=128))
    animkf = [
        ngl.AnimKeyFrameVec3(0, (0, -0.5, 0)),
        ngl.AnimKeyFrameVec3(cfg.duration / 2, (0, 1, 0)),
        ngl.AnimKeyFrameVec3(cfg.duration, (0, -0.5, 0)),
    ]
    return ngl.Camera(node, eye=ngl.AnimatedVec3(animkf))


@test_fingerprint()
@scene(vector=scene.Vector(n=3, minv=(-1, -1, -1), maxv=(1, 1, 1)))
def transform_translate(cfg, vector=(0.2, 0.7, -0.4)):
    cfg.aspect_ratio = (1, 1)
    shape = _transform_shape(cfg)
    return ngl.Translate(shape, vector)


@test_fingerprint()
@scene()
def transform_translate_animated(cfg):
    cfg.aspect_ratio = (1, 1)
    cfg.duration = 3.0
    p0, p1, p2 = equilateral_triangle_coords()
    anim = [
        ngl.AnimKeyFrameVec3(0, p0),
        ngl.AnimKeyFrameVec3(1 * cfg.duration / 3.0, p1),
from pynodegl_utils.misc import scene

import pynodegl as ngl


@scene(uv_corner=scene.Vector(n=2), uv_width=scene.Vector(n=2), uv_height=scene.Vector(n=2), progress_bar=scene.Bool())
def centered_media(cfg, uv_corner=(0, 0), uv_width=(1, 0), uv_height=(0, 1), progress_bar=True):
    """A simple centered media with an optional progress bar in the shader"""
    m0 = cfg.medias[0]
    cfg.duration = m0.duration
    cfg.aspect_ratio = (m0.width, m0.height)

    q = ngl.Quad((-1, -1, 0), (2, 0, 0), (0, 2, 0), uv_corner, uv_width, uv_height)
    m = ngl.Media(m0.filename)
    t = ngl.Texture2D(data_src=m)
    p = ngl.Program(vertex=cfg.get_vert("texture"), fragment=cfg.get_frag("texture"))
    p.update_vert_out_vars(var_tex0_coord=ngl.IOVec2(), var_uvcoord=ngl.IOVec2())
    render = ngl.Render(q, p)
    render.update_frag_resources(tex0=t)

    if progress_bar:
        p.set_fragment(cfg.get_frag("progress-bar"))

        media_duration = ngl.UniformFloat(m0.duration)
        ar = ngl.UniformFloat(cfg.aspect_ratio_float)
        render.update_frag_resources(media_duration=media_duration, ar=ar)
    return render


@scene(speed=scene.Range(range=[0.01, 2], unit_base=1000))
def playback_speed(cfg, speed=1.0):
Exemplo n.º 6
0
    rot_animkf = [ngl.AnimKeyFrameFloat(0, 0),
                  ngl.AnimKeyFrameFloat(cfg.duration, 360)]
    eye_transform = ngl.Rotate(eye_transform, axis=(0, 1, 0), anim=ngl.AnimatedFloat(rot_animkf))

    camera.set_eye_transform(eye_transform)

    fov_animkf = [ngl.AnimKeyFrameFloat(0.5, 60.0),
                  ngl.AnimKeyFrameFloat(cfg.duration, 45.0)]
    camera.set_fov_anim(ngl.AnimatedFloat(fov_animkf))

    return camera


@test_fingerprint()
@scene(vector=scene.Vector(n=3, minv=(-1, -1, -1), maxv=(1, 1, 1)))
def transform_translate(cfg, vector=(0.2, 0.7, -0.4)):
    cfg.aspect_ratio = (1, 1)
    shape = _transform_shape(cfg)
    return ngl.Translate(shape, vector)


@test_fingerprint()
@scene()
def transform_translate_animated(cfg):
    cfg.aspect_ratio = (1, 1)
    cfg.duration = 3.
    p0, p1, p2 = equilateral_triangle_coords()
    anim = [
        ngl.AnimKeyFrameVec3(0, p0),
        ngl.AnimKeyFrameVec3(1 * cfg.duration / 3., p1),