Register loaders and add engine.loadScene that chooses the appropriate loader.
This commit is contained in:
parent
9af1322937
commit
924fa2413a
|
@ -33,8 +33,11 @@
|
|||
{.warning[UseBase]: off.} # can't seem to satisy this...
|
||||
{.warning[UnusedImport]: off.} # for ./loader_base
|
||||
|
||||
const myouUseBlendLoader {.booldefine.} = true
|
||||
|
||||
import ../types
|
||||
import ./loader_base
|
||||
export loader_base
|
||||
import std/tables
|
||||
import std/strutils
|
||||
import std/strformat
|
||||
|
@ -66,8 +69,9 @@ import float16
|
|||
when defined(nimdoc):
|
||||
type TYPES* = BlendLoader
|
||||
|
||||
proc newBlendLoader*(engine: MyouEngine, use_indices:bool = true,
|
||||
shader_library: string = "", shader_textures = initTable[string, Texture]()): BlendLoader =
|
||||
proc newBlendLoader*(engine: MyouEngine,
|
||||
shader_library: string = "",
|
||||
shader_textures = initTable[string, Texture]()): BlendLoader =
|
||||
result = new BlendLoader
|
||||
result.engine = engine
|
||||
if shader_library != "":
|
||||
|
@ -76,8 +80,13 @@ proc newBlendLoader*(engine: MyouEngine, use_indices:bool = true,
|
|||
else:
|
||||
result.shader_library = get_builtin_shader_library()
|
||||
result.shader_textures = get_builtin_shader_textures()
|
||||
result.file_extensions = @["blend"]
|
||||
result.use_indices = use_indices
|
||||
result.use_indices = true
|
||||
|
||||
proc registerBlendLoader*(engine: MyouEngine) =
|
||||
when myouUseBlendLoader:
|
||||
engine.registerLoader(@["blend"], proc(e: MyouEngine): Loader =
|
||||
e.newBlendLoader()
|
||||
)
|
||||
|
||||
var used_resources: seq[LoadableResource]
|
||||
|
||||
|
@ -583,4 +592,5 @@ method loadScene*(self: BlendLoader, name: string="", scene: Scene=nil, callback
|
|||
assert false, &"Scene {name} not found"
|
||||
|
||||
proc debug_dump*(self: BlendLoader) =
|
||||
self.blend_file.debug_dump
|
||||
self.blend_file.debug_dump
|
||||
|
||||
|
|
|
@ -31,13 +31,22 @@
|
|||
# version of this file under either the CPAL or the [AGPL-3] License.
|
||||
|
||||
import ../types
|
||||
import std/tables
|
||||
|
||||
when defined(nimdoc):
|
||||
type TYPES* = Loader
|
||||
|
||||
method openAssetFile*(self: Loader, path: string) {.base, locks: "unknown".} =
|
||||
method openAssetFile*(self: Loader, path: string) {.base.} =
|
||||
discard
|
||||
method loadScene*(self: Loader, name: string="", scene: Scene=nil): Scene {.base, locks: "unknown".} =
|
||||
method loadScene*(self: Loader, name: string="", scene: Scene=nil,
|
||||
callback: proc(scene: Scene)) {.base.} =
|
||||
discard
|
||||
method loadImageImpl*(self: Loader) {.base, locks: "unknown".} =
|
||||
discard
|
||||
method loadImageImpl*(self: Loader) {.base.} =
|
||||
discard
|
||||
|
||||
proc registerLoader*(engine: MyouEngine,
|
||||
extensions: seq[string],
|
||||
constructor: proc(e: MyouEngine): Loader) =
|
||||
|
||||
for ext in extensions:
|
||||
engine.loaders_by_ext.mgetOrPut(ext, @[]).add constructor
|
||||
|
|
|
@ -74,6 +74,7 @@ import std/monotimes
|
|||
import ./graphics/render
|
||||
import ./screen
|
||||
import ./platform/platform
|
||||
import ./loaders/blend
|
||||
import ./util
|
||||
import arr_ref
|
||||
|
||||
|
@ -129,6 +130,8 @@ proc newMyouEngine*(
|
|||
when not defined(nimdoc):
|
||||
init_graphics(result, width, height, title, opengl_version, opengl_es)
|
||||
discard result.newScreen(width, height, title)
|
||||
|
||||
registerBlendLoader(result)
|
||||
|
||||
proc get_builtin_shader_library*(use_cubemap_prefiltering = true): string =
|
||||
## Returns a string with the code of the default shader library of the
|
||||
|
@ -179,3 +182,18 @@ proc run*(self: MyouEngine) =
|
|||
last_time = getmonotime().ticks.float/1000000000
|
||||
when not defined(nimdoc):
|
||||
start_platform_main_loop(self, myou_main_loop)
|
||||
|
||||
proc loadScene*(self: MyouEngine, uri: string, callback: proc(scene: Scene), name = "", ext = "") =
|
||||
let ext = if ext == "":
|
||||
uri.rsplit('.', 1)[1]
|
||||
else:
|
||||
ext
|
||||
|
||||
if ext notin self.loaders_by_ext:
|
||||
raise ValueError.newException "File extension not supported: " & ext
|
||||
|
||||
# TODO: use the next loader if the first one fails
|
||||
let loaders = self.loaders_by_ext[ext]
|
||||
let loader = loaders[0](self)
|
||||
loader.openAssetFile(uri)
|
||||
loader.loadScene(name, nil, callback)
|
||||
|
|
|
@ -38,6 +38,16 @@ when defined(nimdoc):
|
|||
type TYPES* = ProbeInfluenceType | ProbeParallaxType | CubemapProbe | CubemapProbeUniform | SH9Uniform
|
||||
|
||||
# Forward declarations and ob type methods
|
||||
proc newCubemapProbe*(engine: MyouEngine, name: string="camera", scene: Scene = nil,
|
||||
influence_type: ProbeInfluenceType = SphereInfluence,
|
||||
influence_distance: float32 = 2.5,
|
||||
falloff: float32 = 0.2,
|
||||
intensity: float32 = 1,
|
||||
clipping_start: float32 = 0.8,
|
||||
clipping_end: float32 = 40,
|
||||
parallax_type: ProbeParallaxType = NoParallax,
|
||||
parallax_distance: float32 = 0.0, # 0 means auto
|
||||
): CubemapProbe
|
||||
func getCubemapSideMatrix*(side: int, position = vec3()): Mat4
|
||||
proc render_cubemap*(self: CubemapProbe, use_roughness_prefiltering = false, mipmap_shader: Material = nil)
|
||||
proc render_background_cubemap*(scene: Scene, use_roughness_prefiltering = false, mipmap_shader: Material = nil, world_to_cube_matrix: Mat4 = mat4(), upload_UBO = true)
|
||||
|
|
|
@ -81,6 +81,7 @@ type
|
|||
renderer*: RenderManager
|
||||
tone_mapping_library*: string
|
||||
tone_mapping_function*: string
|
||||
loaders_by_ext*: Table[string, seq[proc(e: MyouEngine): Loader]]
|
||||
# TODO: remove this and query it when screen is created
|
||||
width*, height*: int
|
||||
glsl_version*: string
|
||||
|
@ -738,6 +739,16 @@ type
|
|||
influence_distance*: float32
|
||||
falloff*: float32
|
||||
|
||||
# loader_base.nim
|
||||
|
||||
Loader* = ref object of RootObj
|
||||
engine*: MyouEngine
|
||||
shader_library*: string
|
||||
shader_textures*: Table[string, Texture]
|
||||
# on_destroy*: OnDestroy
|
||||
path_handler*: proc(path: string): string
|
||||
override_textures_sampler_type*: Table[string, string]
|
||||
|
||||
# INCOMPLETE
|
||||
|
||||
Armature* = ref object of GameObject
|
||||
|
@ -806,15 +817,6 @@ const HARDCODED_MAXUBOS* = 80
|
|||
|
||||
# LOADERS
|
||||
|
||||
type Loader* = ref object of RootObj
|
||||
engine*: MyouEngine
|
||||
file_extensions*: seq[string]
|
||||
shader_library*: string
|
||||
shader_textures*: Table[string, Texture]
|
||||
# on_destroy*: OnDestroy
|
||||
path_handler*: proc(path: string): string
|
||||
override_textures_sampler_type*: Table[string, string]
|
||||
|
||||
type BlendLoader* = ref object of Loader
|
||||
blend_file_path*: string ## private
|
||||
blend_file*: BlendFile ## private
|
||||
|
@ -823,10 +825,6 @@ type BlendLoader* = ref object of Loader
|
|||
(string, seq[Varying], OrderedTable[string, string], OrderedTable[string, TexturePixels])] ## private
|
||||
resource*: LoadableResource
|
||||
|
||||
template AllLoaders*: untyped = @[
|
||||
newBlendLoader,
|
||||
]
|
||||
|
||||
template enqueue*(self: RenderManager, fun: proc()) =
|
||||
if self.initialized:
|
||||
fun()
|
||||
|
|
Loading…
Reference in a new issue