Exemplo n.º 1
0
    def load(self, path):
        # data:image/png;base64,iVBOR

        # Image is stored in bufferView
        if self.bufferView is not None:
            image = Image.open(io.BytesIO(self.bufferView.read_raw()))
        # Image is embedded
        elif self.uri and self.uri.startswith('data:'):
            data = self.uri[self.uri.find(',') + 1:]
            image = Image.open(io.BytesIO(base64.b64decode(data)))
        else:
            path = path / self.uri
            print("Loading:", self.uri)
            image = Image.open(path)

        texture = t2d.Loader(
            TextureDescription(
                label="gltf",
                image=image,
                flip=False,
                mipmap=True,
            )).load()

        return texture
Exemplo n.º 2
0
import os

from demosys.resources.meta import ProgramDescription, TextureDescription


def local(path):
    """
    Prepend the effect package name to a path so resources
    can still be loaded when copied into a new effect package.
    """
    return os.path.join(__name__.split('.')[-2], path)


effect_packages = []

resources = [
    TextureDescription(label='milkyway', path=local('MilkyWayPanorama4K.jpg')),
    ProgramDescription(label='milkyway', path=local('milkyway.glsl')),

    TextureDescription(label='sun', path=local('2k_sun.jpg'), mipmap=True),
    ProgramDescription(label='sun', path=local('sun.glsl')),

    TextureDescription(label='earth_day', path=local('2k_earth_daymap.jpg'), mipmap=True),
    TextureDescription(label='earth_night', path=local('2k_earth_nightmap.jpg'), mipmap=True),
    TextureDescription(label='earth_clouds', path=local('2k_earth_clouds.jpg'), mipmap=True),
    ProgramDescription(label='earth', path=local('earth.glsl')),
]
Exemplo n.º 3
0
    def load(self):
        """Deferred loading"""
        path = self.find_scene(self.meta.path)

        if not path:
            raise ValueError("Scene '{}' not found".format(self.meta.path))

        if path.suffix == '.bin':
            path = path.parent / path.stem

        data = pywavefront.Wavefront(str(path), create_materials=True, cache=True)
        scene = Scene(self.meta.resolved_path)
        texture_cache = {}

        for _, mat in data.materials.items():
            mesh = Mesh(mat.name)

            # Traditional loader
            if mat.vertices:
                buffer_format, attributes, mesh_attributes = translate_buffer_format(mat.vertex_format)
                vbo = numpy.array(mat.vertices, dtype='f4')

                vao = VAO(mat.name, mode=moderngl.TRIANGLES)
                vao.buffer(vbo, buffer_format, attributes)
                mesh.vao = vao

                for attrs in mesh_attributes:
                    mesh.add_attribute(*attrs)

            # Binary cache loader
            elif hasattr(mat, 'vao'):
                mesh = Mesh(mat.name)
                mesh.vao = mat.vao
                for attrs in mat.mesh_attributes:
                    mesh.add_attribute(*attrs)
            else:
                # Empty
                continue

            scene.meshes.append(mesh)

            mesh.material = Material(mat.name)
            scene.materials.append(mesh.material)
            mesh.material.color = mat.diffuse

            if mat.texture:
                # A texture can be referenced multiple times, so we need to cache loaded ones
                texture = texture_cache.get(mat.texture.path)
                if not texture:
                    print("Loading:", mat.texture.path)
                    texture = textures.load(TextureDescription(
                        label=mat.texture.path,
                        path=mat.texture.path,
                        mipmap=True,
                    ))
                    texture_cache[mat.texture.path] = texture

                mesh.material.mat_texture = MaterialTexture(
                    texture=texture,
                    sampler=None,
                )

            node = Node(mesh=mesh)
            scene.root_nodes.append(node)

        # Not supported yet for obj
        # self.calc_scene_bbox()
        scene.prepare()

        return scene
Exemplo n.º 4
0
from demosys.resources.meta import ProgramDescription, TextureDescription

effect_packages = []

resources = [
    ProgramDescription(label="cube_multi_fade",
                       path='geocubes/cube_multi_fade.glsl'),
    ProgramDescription(label="cube_texture_light",
                       path='geocubes/cube_texture_light.glsl'),
    ProgramDescription(label="quad_fs_uvscale",
                       path='geocubes/quad_fs_uvscale.glsl'),
    TextureDescription(label="texture", path='geocubes/texture.png'),
    TextureDescription(label="GreenFabric", path='geocubes/GreenFabric.png'),
]
Exemplo n.º 5
0
from demosys.resources.meta import ProgramDescription, TextureDescription

effect_packages = []

resources = [
    ProgramDescription(label="transform", path="feedback/transform.glsl"),
    ProgramDescription(label="billboards", path="feedback/billboards.glsl"),
    TextureDescription(label="particle", path="feedback/particle.png"),
]
Exemplo n.º 6
0
from demosys.resources.meta import ProgramDescription, TextureDescription

effect_packages = []

resources = [
    # Program in one single file
    # ProgramDescription(label="terrain", path="terrain/terrain.glsl"),

    # Program split into separate shader files
    ProgramDescription(
        label="terrain",
        vertex_shader="terrain/terrain_vs.glsl",
        tess_control_shader="terrain/terrain_tc.glsl",
        tess_evaluation_shader="terrain/terrain_te.glsl",
        fragment_shader="terrain/terrain_fs.glsl",
    ),
    TextureDescription(label="heightmap", path="terrain/Ridges_01_DISP.jpg"),
]
Exemplo n.º 7
0
from demosys.resources.meta import TextureDescription, ProgramDescription

effect_packages = []

resources = [
    ProgramDescription(label="plain", path="cubes/cube_plain.glsl"),
    ProgramDescription(label="light", path="cubes/cube_light.glsl"),
    ProgramDescription(
        label="textured",
        vertex_shader="cubes/cube_textured_vs.glsl",
        fragment_shader="cubes/cube_textured_fs.glsl",
    ),
    TextureDescription(label="crate", path="cubes/crate.jpg"),
]
Exemplo n.º 8
0
from demosys.resources.meta import TextureDescription, ProgramDescription, DataDescription

effect_packages = []

resources = [
    # Font meta and texture
    DataDescription(
        label='demosys.program.font_meta',
        path='demosys/text/meta.json', loader='json',
    ),
    TextureDescription(
        label='demosys.text.font_texture',
        path='demosys/text/VeraMono.png',
        loader='array',
        layers=190,
        mipmap=True,
    ),

    # Textwriter shader
    ProgramDescription(
        label='demosys.text.program_writer_2d',
        path='demosys/text/textwriter2d.glsl',
    ),

    # TextRenderer shader
    ProgramDescription(
        label='demosys.text.program_renderer_2d',
        path='demosys/text/view_renderer_texture.glsl',
    ),
]
Exemplo n.º 9
0
from demosys.resources.meta import TextureDescription, ProgramDescription

effect_packages = []

resources = [
    ProgramDescription(label="shader", path="warpspeed/shader.glsl"),
    TextureDescription(label="WarpspeedTexture",
                       path="warpspeed/WarpspeedTexture.jpg"),
    TextureDescription(label="WarpspeedTexture2",
                       path="warpspeed/WarpspeedTexture2.jpg"),
]
Exemplo n.º 10
0
 def load_texture_array(self, path, layers=0):
     return resources.textures.load(
         TextureDescription(label=path,
                            path=path,
                            loader='array',
                            layers=layers))
Exemplo n.º 11
0
 def load_texture(self, path):
     return resources.textures.load(
         TextureDescription(label=path, path=path))