Example #1
0
 def load_base_settings(self, plugin_dir):
     """ Loads the base settings of all plugins, even of disabled plugins.
     This is required to verify all overrides. """
     for entry in listdir(plugin_dir):
         abspath = join(plugin_dir, entry)
         if isdir(abspath) and entry not in ("__pycache__", "plugin_prefab"):
             self.load_plugin_settings(entry, abspath)
Example #2
0
    def mount(self):
        """ Inits the VFS Mounts """

        self.debug("Setting up virtual filesystem.")
        vfs = VirtualFileSystem.getGlobalPtr()

        # Mount shaders
        vfs.mountLoop(
            join(self.basePath, 'Shader'), 'Shader', 0)

        # Mount data and models
        vfs.mountLoop(join(self.basePath, 'Data'), 'Data', 0)
        vfs.mountLoop(join(self.basePath, 'Models'), 'Models', 0)
        vfs.mountLoop(join(self.basePath, 'Config'), 'Config', 0)
        vfs.mountLoop(join(self.basePath, 'Demoscene.ignore'), 'Demoscene.ignore', 0)

        # Just mount everything
        # vfs.mountLoop(self.basePath, '.', 0)

        if not isdir(self.writePath):
            self.debug("Creating temp path, as it does not exist yet")
            try:
                makedirs(self.writePath)
            except Exception, msg:
                self.error("Failed to create temp path:",msg)
                import sys
                sys.exit(0)
Example #3
0
    def __init__(self):
        load_prc_file_data("", """
            textures-power-2 none
            window-type offscreen
            win-size 100 100
            gl-coordinate-system default
            notify-level-display error
            print-pipe-types #f
        """)

        ShowBase.__init__(self)

        base_path = realpath(dirname(__file__))
        os.chdir(base_path)
        filter_dir = join(base_path, "tmp/")
        if isdir(filter_dir):
            shutil.rmtree(filter_dir)
        os.makedirs(filter_dir)

        cubemap = self.loader.loadCubeMap(Filename.from_os_specific(join(base_path, "source/#.jpg")))
        mipmap, size = -1, 512

        cshader = Shader.load_compute(Shader.SL_GLSL, "filter.compute.glsl")

        while size > 1:
            size = size // 2
            mipmap += 1
            print("Filtering mipmap", mipmap)

            dest_cubemap = Texture("Dest")
            dest_cubemap.setup_cube_map(size, Texture.T_float, Texture.F_rgba16)
            node = NodePath("")

            for i in range(6):
                node.set_shader(cshader)
                node.set_shader_input("SourceTex", cubemap)
                node.set_shader_input("DestTex", dest_cubemap)
                node.set_shader_input("currentSize", size)
                node.set_shader_input("currentMip", mipmap)
                node.set_shader_input("currentFace", i)
                attr = node.get_attrib(ShaderAttrib)
                self.graphicsEngine.dispatch_compute(
                    ( (size + 15) // 16, (size+15) // 16, 1), attr, self.win.get_gsg())

            print(" Extracting data ..")

            self.graphicsEngine.extract_texture_data(dest_cubemap, self.win.get_gsg())

            print(" Writing data ..")
            dest_cubemap.write(join(filter_dir, "{}-#.png".format(mipmap)), 0, 0, True, False)


        print("Reading in data back in ..")
        tex = self.loader.loadCubeMap(Filename.from_os_specific(join(base_path, "tmp/#-#.png")), readMipmaps="True")

        print("Writing txo ..")
        tex.write("cubemap.txo.pz")

        shutil.rmtree(join(base_path, "tmp"))
Example #4
0
 def load_base_settings(self, plugin_dir):
     """ Loads the base settings of all plugins, even of disabled plugins.
     This is required to verify all overrides. """
     for entry in listdir(plugin_dir):
         abspath = join(plugin_dir, entry)
         if isdir(abspath) and entry not in ("__pycache__",
                                             "plugin_prefab"):
             self.load_plugin_settings(entry, abspath)
Example #5
0
def glob0(dirname, basename):
    if basename == '':
        if file.isdir(dirname):
            return [basename]
    else:
        if file.lexists(os.path.join(dirname, basename)):
            return [basename]
    return []
Example #6
0
def glob0(dirname, basename):
    if basename == '':
        # repr(os.path.split()) returns an empty basename for paths ending with a
        # directory separator.  'q*x/' should match only directories.
        if file.isdir(dirname):
            return [basename]
    else:
        if file.lexists(os.path.join(dirname, basename)):
            return [basename]
    return []
 def get_available_plugins(self):
     """ Returns a list of all installed plugins, no matter if they are
     enabled or not. This also does no check if the plugin names are valid. """
     plugins = []
     files = listdir(join(self._base_dir, "Plugins"))
     for fname in files:
         abspath = join(self._base_dir, "Plugins", fname)
         if isdir(abspath) and fname not in ["PluginPrefab"]:
             plugins.append(fname)
     return plugins
Example #8
0
def glob0(dirname, basename):
    if basename == '':
        # repr(os.path.split()) returns an empty basename for paths ending with a
        # directory separator.  'q*x/' should match only directories.
        if file.isdir(dirname):
            return [basename]
    else:
        if file.lexists(os.path.join(dirname, basename)):
            return [basename]
    return []
    def mount(self):
        """ Inits the VFS Mounts. This creates the following virtual directory
        structure, from which all files can be located:

        /$$rp/  (Mounted from the render pipeline base directory)
           + config/
           + data/
           + rpcore/
           + shader/
           + ...

        /$$rptemp/ (Either ramdisk or user specified)
            + day_time_config
            + shader_auto_config
            + ...

         """
        self.debug("Setting up virtual filesystem")
        self._mounted = True

        def convert_path(pth):
            return Filename.from_os_specific(pth).get_fullpath()

        vfs = VirtualFileSystem.get_global_ptr()

        # Mount the pipeline temp path:
        # If no write path is specified, use a virtual ramdisk
        if self._write_path is None:
            self.debug("Mounting ramdisk as /$$rptemp")
            vfs.mount(VirtualFileMountRamdisk(), "/$$rptemp", 0)
        else:
            # In case an actual write path is specified:
            # Ensure the pipeline write path exists, and if not, create it
            if not isdir(self._write_path):
                self.debug(
                    "Creating temporary path, since it does not exist yet")
                try:
                    os.makedirs(self._write_path)
                except IOError as msg:
                    self.fatal("Failed to create temporary path:", msg)
            self.debug("Mounting", self._write_path, "as /$$rptemp")
            vfs.mount(convert_path(self._write_path), '/$$rptemp', 0)

        get_model_path().prepend_directory("/$$rp")
        get_model_path().prepend_directory("/$$rp/shader")
        get_model_path().prepend_directory("/$$rptemp")
Example #10
0
    def _writeDebugShader(self, name, content):
        """ Internal method to dump shader for debugging """

        if not self._DumpShaders:
            return

        cachePath = "PipelineTemp"
        if not isdir(cachePath):
            print "Cache path does not exist!:", cachePath
            print "Disabling shader dump"
            self._DumpShaders = False
            return

        writeName = name.strip().replace("/", "-").replace(".", "_") + ".bin"

        with open(join(cachePath, writeName), "w") as handle:
            handle.write(str(content))
Example #11
0
    def _writeDebugShader(self, name, content):
        """ Internal method to dump shader for debugging """

        if not self._DumpShaders:
            return

        cachePath = "PipelineTemp"
        if not isdir(cachePath):
            print "Cache path does not exist!:", cachePath
            print "Disabling shader dump"
            self._DumpShaders = False
            return

        writeName = name.strip().replace("/", "-").replace(".", "_") + ".bin"

        with open(join(cachePath, writeName), "w") as handle:
            handle.write(str(content))
Example #12
0
    def mount(self):
        """ Inits the VFS Mounts """

        self.debug("Setting up virtual filesystem.")
        vfs = VirtualFileSystem.getGlobalPtr()

        # Mount data and models
        vfs.mountLoop(join(self.basePath, 'Data'), 'Data', 0)
        vfs.mountLoop(join(self.basePath, 'Models'), 'Models', 0)
        vfs.mountLoop(join(self.basePath, 'Config'), 'Config', 0)

        # Ensure the pipeline write path exists, and if not, create it
        if not isdir(self.writePath):
            self.debug("Creating temp path, as it does not exist yet")
            try:
                os.makedirs(self.writePath, 0777)
            except Exception, msg:
                self.error("Failed to create temp path:",msg)
                import sys
                sys.exit(0)
Example #13
0
    def __init__(self):
        load_prc_file_data("", """
            textures-power-2 none
            window-type offscreen
            win-size 100 100
            gl-coordinate-system default
            notify-level-display error
            print-pipe-types #f
        """)

        ShowBase.__init__(self)

        base_path = realpath(dirname(__file__))
        os.chdir(base_path)
        slice_dir = join(base_path, "slices/")
        if isdir(slice_dir):
            shutil.rmtree(slice_dir)
        os.makedirs(slice_dir)

        node = NodePath("")

        w, h, d = 512, 512, 64

        self.voxel_grid = Texture("voxels")
        self.voxel_grid.setup_3d_texture(w, h, d, Texture.T_unsigned_byte, Texture.F_rgba8)


        # Generate grid
        cshader = Shader.load_compute(Shader.SL_GLSL, "generate_grid.compute.glsl")
        node.set_shader(cshader)
        node.set_shader_input("DestTex", self.voxel_grid)
        attr = node.get_attrib(ShaderAttrib)

        self.graphicsEngine.dispatch_compute(
            ((w + 7) // 8, (h + 7) // 8, (d + 3) // 4), attr, self.win.get_gsg())

        self.graphicsEngine.extract_texture_data(self.voxel_grid, self.win.get_gsg())

        print("Writing data ..")
        self.voxel_grid.write(Filename.from_os_specific(join(slice_dir, "#.png")), 0, 0, True, False)
    def mount(self):
        """ Inits the VFS Mounts """

        self.debug("Setting up virtual filesystem.")
        vfs = VirtualFileSystem.getGlobalPtr()

        # Mount shaders
        vfs.mountLoop(
            join(self.basePath, 'Shader'), 'Shader', 0)

        # Mount data
        vfs.mountLoop(join(self.basePath, 'Data'), 'Data', 0)

        # TODO: Mount core

        if not isdir(self.writePath):
            self.debug("Creating temp path, as it does not exist yet")
            try:
                makedirs(self.writePath)
            except Exception, msg:
                self.error("Failed to create temp path:",msg)
                import sys
                sys.exit(0)
Example #15
0
    def mount(self):
        """ Inits the VFS Mounts """

        self.debug("Setting up virtual filesystem.")
        vfs = VirtualFileSystem.getGlobalPtr()

        # Mount data and models
        vfs.mountLoop(join(self.basePath, 'Data'), 'Data', 0)
        vfs.mountLoop(join(self.basePath, 'Models'), 'Models', 0)
        vfs.mountLoop(join(self.basePath, 'Config'), 'Config', 0)
        vfs.mountLoop(join(self.basePath, 'Effects'), 'Effects', 0)

        # Mount shaders under a different name to access them from the effects
        vfs.mountLoop(join(self.basePath, 'Shader'), 'ShaderMount', 0)

        # Ensure the pipeline write path exists, and if not, create it
        if not isdir(self.writePath):
            self.debug("Creating temp path, as it does not exist yet")
            try:
                os.makedirs(self.writePath, 0777)
            except Exception, msg:
                self.error("Failed to create temp path:", msg)
                import sys
                sys.exit(0)
Example #16
0
    def __init__(self):
        """ Creates a new Scattering object with default settings """
        DebugObject.__init__(self, "AtmosphericScattering")

        self.settings = {
            "radiusGround": 6360.0,
            "radiusAtmosphere": 6420.0,
            "averageGroundReflectance": 0.1,   # AVERAGE_GROUND_REFLECTANCE
            "rayleighFactor": 8.0,  # HR
            "betaRayleigh": Vec3(5.8e-3, 1.35e-2, 3.31e-2),  # betaR
            "mieFactor": 1.2,  # HM
            "betaMieScattering": Vec3(4e-3),  # betaMSca
            "betaMieScatteringAdjusted": (Vec3(2e-3) * (1.0 / 0.9)),
            "mieG": 0.8,  # mieG
            "transmittanceNonLinear": True,
            "inscatterNonLinear": True,

            # Parameters to adjust rendering of the atmosphere.
            # The position is computed by:
            # (inputPosition-atmosphereOffset) * atmosphereScale
            "atmosphereOffset": Vec3(0),
            "atmosphereScale": Vec3(1)

        }
        self.settingsPTA = {}
        self.targets = {}
        self.textures = {}
        self.writeOutput = False
        self.precomputed = False

        if self.writeOutput and not isdir("ScatteringDump"):
            try:
                makedirs("ScatteringDump")
            except:
                self.debug("Failed to create dump dir!")
                self.writeOutput = False
Example #17
0
    def mount(self):
        """ Inits the VFS Mounts. This creates the following virtual directory
        structure, from which all files can be located:

        /$$rp/  (Mounted from the render pipeline base directory)
           + rpcore/
           + shader/
           + ...

        /$rpconfig/ (Mounted from config/, may be set by user)
           + pipeline.yaml
           + ...

        /$$rptemp/ (Either ramdisk or user specified)
            + day_time_config
            + shader_auto_config
            + ...

        /$$rpshader/ (Link to /$$rp/rpcore/shader)

         """
        self.debug("Setting up virtual filesystem")
        self._mounted = True

        def convert_path(pth):
            return Filename.from_os_specific(pth).get_fullpath()
        vfs = VirtualFileSystem.get_global_ptr()

        # Mount config dir as $$rpconf
        if self._config_dir is None:
            config_dir = convert_path(join(self._base_path, "config/"))
            self.debug("Mounting auto-detected config dir:", config_dir)
            vfs.mount(config_dir, "/$$rpconfig", 0)
        else:
            self.debug("Mounting custom config dir:", self._config_dir)
            vfs.mount(convert_path(self._config_dir), "/$$rpconfig", 0)

        # Mount directory structure
        vfs.mount(convert_path(self._base_path), "/$$rp", 0)
        vfs.mount(convert_path(join(self._base_path, "rpcore/shader")), "/$$rp/shader", 0)
        vfs.mount(convert_path(join(self._base_path, "effects")), "effects", 0)

        # Mount the pipeline temp path:
        # If no write path is specified, use a virtual ramdisk
        if self._write_path is None:
            self.debug("Mounting ramdisk as /$$rptemp")
            vfs.mount(VirtualFileMountRamdisk(), "/$$rptemp", 0)
        else:
            # In case an actual write path is specified:
            # Ensure the pipeline write path exists, and if not, create it
            if not isdir(self._write_path):
                self.debug("Creating temporary path, since it does not exist yet")
                try:
                    os.makedirs(self._write_path)
                except IOError as msg:
                    self.fatal("Failed to create temporary path:", msg)
            self.debug("Mounting", self._write_path, "as /$$rptemp")
            vfs.mount(convert_path(self._write_path), '/$$rptemp', 0)

        get_model_path().prepend_directory("/$$rp")
        get_model_path().prepend_directory("/$$rp/shader")
        get_model_path().prepend_directory("/$$rptemp")
Example #18
0
    def __init__(self):
        load_prc_file_data(
            "", """
            textures-power-2 none
            window-type offscreen
            win-size 100 100
            gl-coordinate-system default
            notify-level-display error
            print-pipe-types #f
        """)

        ShowBase.__init__(self)

        base_path = realpath(dirname(__file__))
        os.chdir(base_path)
        filter_dir = join(base_path, "tmp/")
        if isdir(filter_dir):
            shutil.rmtree(filter_dir)
        os.makedirs(filter_dir)

        source_path = join(base_path, "source")
        extension = ".jpg"
        if isfile(join(source_path, "1.png")):
            extension = ".png"

        cubemap = self.loader.loadCubeMap(
            Filename.from_os_specific(join(source_path, "#" + extension)))
        mipmap, size = -1, 1024

        cshader = Shader.load_compute(Shader.SL_GLSL, "filter.compute.glsl")

        while size > 1:
            size = size // 2
            mipmap += 1
            print("Filtering mipmap", mipmap)

            dest_cubemap = Texture("Dest")
            dest_cubemap.setup_cube_map(size, Texture.T_float,
                                        Texture.F_rgba16)
            node = NodePath("")

            for i in range(6):
                node.set_shader(cshader)
                node.set_shader_input("SourceTex", cubemap)
                node.set_shader_input("DestTex", dest_cubemap)
                node.set_shader_input("currentSize", size)
                node.set_shader_input("currentMip", mipmap)
                node.set_shader_input("currentFace", i)
                attr = node.get_attrib(ShaderAttrib)
                self.graphicsEngine.dispatch_compute(
                    ((size + 15) // 16, (size + 15) // 16, 1), attr,
                    self.win.gsg)

            print(" Extracting data ..")

            self.graphicsEngine.extract_texture_data(dest_cubemap,
                                                     self.win.gsg)

            print(" Writing data ..")
            dest_cubemap.write(join(filter_dir, "{}-#.png".format(mipmap)), 0,
                               0, True, False)

        print("Reading in data back in ..")
        tex = self.loader.loadCubeMap(Filename.from_os_specific(
            join(base_path, "tmp/#-#.png")),
                                      readMipmaps="True")

        print("Writing txo ..")
        tex.write("cubemap.txo.pz")

        shutil.rmtree(join(base_path, "tmp"))
Example #19
0
    def mount(self):
        """ Inits the VFS Mounts """

        self.debug("Setting up virtual filesystem.")
        self._mounted = True
        vfs = VirtualFileSystem.get_global_ptr()

        # Mount data and models
        dirs_to_mount = ["Data", "Effects", "Plugins", "Shader"]
        for directory in dirs_to_mount:
            vfs.mount_loop(join(self._base_path, directory), directory, 0)

        if isdir(join(self._base_path, "Models")):
            vfs.mount_loop(join(self._base_path, 'Models'), 'Models', 0)

        # Mount config dir
        if self._config_dir is None:
            config_dir = join(self._base_path, "Config/")
            vfs.mount_loop(config_dir, "$$Config/", 0)
            self.debug("Auto-Detected config dir:", config_dir)
        else:
            vfs.mount_loop(self._config_dir, "$$Config/", 0)
            self.debug("Config dir:", self._config_dir)


        # Convert the base path to something the os can work with
        sys_base_path = Filename(self._base_path).to_os_specific()

        # Add plugin folder to the include path
        sys.path.insert(0, join(sys_base_path, 'Plugins'))

        # Add current folder to the include path
        sys.path.insert(0, sys_base_path)

        # Mount the pipeline temp path:
        # If no write path is specified, use a virtual ramdisk
        if self._write_path is None:
            self.debug("Mounting ramdisk as $$PipelineTemp/")
            vfs.mount(VirtualFileMountRamdisk(), "$$PipelineTemp/", 0)
        else:
            # In case an actual write path is specified:
            # Ensure the pipeline write path exists, and if not, create it
            if not isdir(self._write_path):
                self.debug("Creating temp path, it does not exist yet")
                try:
                    os.makedirs(self._write_path)
                except IOError as msg:
                    self.fatal("Failed to create temp path:", msg)
            self.debug("Mounting", self._write_path, "as $$PipelineTemp/")
            vfs.mount_loop(self._write_path, '$$PipelineTemp/', 0)

        # #pragma include "something" searches in current directory first,
        # and then on the model-path. Append the Shader directory to the
        # modelpath to ensure the shader includes can be found.
        self._model_paths.append(join(self._base_path, "Shader"))

        # Add the pipeline root directory to the model path as well
        self._model_paths.append(self._base_path)
        self._model_paths.append(".")

        # Append the write path to the model directory to make pragma include
        # find the ShaderAutoConfig.include
        self._model_paths.append("$$PipelineTemp")

        # Add the plugins dir to the model path so plugins can include their
        # own resources more easily
        self._model_paths.append(join(self._base_path, "Plugins"))

        # Write the model paths to the global model path
        for pth in self._model_paths:
            get_model_path().append_directory(pth)
Example #20
0
    def mount(self):
        """ Inits the VFS Mounts. This creates the following virtual directory
        structure, from which all files can be located:

        /$$rp/  (Mounted from the render pipeline base directory)
           + rpcore/
           + shader/
           + ...

        /$rpconfig/ (Mounted from config/, may be set by user)
           + pipeline.yaml
           + ...

        /$$rptemp/ (Either ramdisk or user specified)
            + day_time_config
            + shader_auto_config
            + ...

        /$$rpshader/ (Link to /$$rp/rpcore/shader)

         """
        self.debug("Setting up virtual filesystem")
        self._mounted = True

        convert_path = lambda pth: Filename.from_os_specific(pth).get_fullpath(
        )
        vfs = VirtualFileSystem.get_global_ptr()

        # Mount config dir as $$rpconf
        if self._config_dir is None:
            config_dir = convert_path(join(self._base_path, "config/"))
            self.debug("Mounting auto-detected config dir:", config_dir)
            vfs.mount(config_dir, "/$$rpconfig", 0)
        else:
            self.debug("Mounting custom config dir:", self._config_dir)
            vfs.mount(convert_path(self._config_dir), "/$$rpconfig", 0)

        # Mount directory structure
        vfs.mount(convert_path(self._base_path), "/$$rp", 0)
        vfs.mount(convert_path(join(self._base_path, "rpcore/shader")),
                  "/$$rp/shader", 0)
        vfs.mount(convert_path(join(self._base_path, "effects")), "effects", 0)

        # Mount the pipeline temp path:
        # If no write path is specified, use a virtual ramdisk
        if self._write_path is None:
            self.debug("Mounting ramdisk as /$$rptemp")
            vfs.mount(VirtualFileMountRamdisk(), "/$$rptemp", 0)
        else:
            # In case an actual write path is specified:
            # Ensure the pipeline write path exists, and if not, create it
            if not isdir(self._write_path):
                self.debug(
                    "Creating temporary path, since it does not exist yet")
                try:
                    os.makedirs(self._write_path)
                except IOError as msg:
                    self.fatal("Failed to create temporary path:", msg)
            self.debug("Mounting", self._write_path, "as /$$rptemp")
            vfs.mount(convert_path(self._write_path), '/$$rptemp', 0)

        get_model_path().prepend_directory("/$$rp")
        get_model_path().prepend_directory("/$$rp/shader")
        get_model_path().prepend_directory("/$$rptemp")