Mercurial > games > semicongine
changeset 1342:34ae5835bfa8
add: a few static helpers
author | sam <sam@basx.dev> |
---|---|
date | Mon, 26 Aug 2024 18:51:25 +0700 |
parents | f65f25233127 |
children | edb0b650fc5f |
files | semicongine/audio/resources.nim semicongine/gltf.nim semicongine/image.nim semicongine/resources.nim tools/blender_gltf_converter.py |
diffstat | 5 files changed, 58 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/semicongine/audio/resources.nim Sat Aug 24 23:03:19 2024 +0700 +++ b/semicongine/audio/resources.nim Mon Aug 26 18:51:25 2024 +0700 @@ -121,3 +121,13 @@ loadResource_intern(path, package = package).readVorbis() else: raise newException(Exception, "Unsupported audio file type: " & path) + +proc loadAudio*( + path: static string, package: static string = DEFAULT_PACKAGE +): SoundData = + if path.splitFile().ext.toLowerAscii == ".au": + loadResource_intern(path, package = package).readAU() + elif path.splitFile().ext.toLowerAscii == ".ogg": + loadResource_intern(path, package = package).readVorbis() + else: + raise newException(Exception, "Unsupported audio file type: " & path)
--- a/semicongine/gltf.nim Sat Aug 24 23:03:19 2024 +0700 +++ b/semicongine/gltf.nim Mon Aug 26 18:51:25 2024 +0700 @@ -422,3 +422,16 @@ meshAttributesMapping = meshAttributesMapping, materialAttributesMapping = materialAttributesMapping, ) + +# static version, for better checks +proc loadMeshes*[TMesh, TMaterial]( + path: static string, + meshAttributesMapping: static MeshAttributeNames, + materialAttributesMapping: static MaterialAttributeNames, + package: static string = DEFAULT_PACKAGE, +): GltfData[TMesh, TMaterial] = + ReadglTF[TMesh, TMaterial]( + stream = loadResource_intern(path, package = package), + meshAttributesMapping = meshAttributesMapping, + materialAttributesMapping = materialAttributesMapping, + )
--- a/semicongine/image.nim Sat Aug 24 23:03:19 2024 +0700 +++ b/semicongine/image.nim Mon Aug 26 18:51:25 2024 +0700 @@ -53,9 +53,9 @@ func `$`*[S, IsArray](img: ImageObject[S, IsArray]): string = let pixelTypeName = S.name if IsArray == false: - &"{img.width}x{img.height} {pixelTypeName}" + $img.width & "x" & $img.height & " " & pixelTypeName else: - &"{img.width}x{img.height}[{img.nLayers}] {pixelTypeName}" + $img.width & "x" & $img.height & "[" & $img.nLayers & "] " & pixelTypeName func copy*[S, T](img: ImageObject[S, T]): ImageObject[S, T] = for bf, rf in fields(img, result): @@ -92,6 +92,7 @@ for i in 0 ..< result.data.len: swap(result.data[i][0], result.data[i][2]) +# TODO: static versions to check for existing of files during compilation proc loadImage*[T: PixelType](path: string, package = DEFAULT_PACKAGE): Image[T] = assert path.splitFile().ext.toLowerAscii == ".png", "Unsupported image type: " & path.splitFile().ext.toLowerAscii
--- a/semicongine/resources.nim Sat Aug 24 23:03:19 2024 +0700 +++ b/semicongine/resources.nim Mon Aug 26 18:51:25 2024 +0700 @@ -128,9 +128,14 @@ const bundledResources = loadResources() proc loadResource_intern*(path: string, package: string): Stream = - if not (path in bundledResources[package]): + if path notin bundledResources[package]: raise newException(Exception, &"Resource {path} not found") - newStringStream(bundledResources[package][path]) + result = newStringStream(bundledResources[package][path]) + + proc loadResource_intern*(path: static string, package: static string): Stream = + static: + assert path in bundledResources[package], "Resource file '" & path & "' not found" + result = newStringStream(bundledResources[package][path]) proc modList_intern(): seq[string] = result = bundledResources.keys().toSeq() @@ -165,6 +170,22 @@ proc loadConfig*(path: string, package = DEFAULT_PACKAGE): Config = path.loadResource_intern(package = package).loadConfig(filename = path) +# static versions of the above 3 calls +proc loadResource*( + path: static string, package: static string = DEFAULT_PACKAGE +): Stream = + loadResource_intern(path, package = package) + +proc loadJson*( + path: static string, package: static string = DEFAULT_PACKAGE +): JsonNode = + path.loadResource_intern(package = package).readAll().parseJson() + +proc loadConfig*( + path: static string, package: static string = DEFAULT_PACKAGE +): Config = + path.loadResource_intern(package = package).loadConfig(filename = path) + proc packages*(): seq[string] = modList_intern()
--- a/tools/blender_gltf_converter.py Sat Aug 24 23:03:19 2024 +0700 +++ b/tools/blender_gltf_converter.py Mon Aug 26 18:51:25 2024 +0700 @@ -17,7 +17,15 @@ quit(1) bpy.ops.wm.open_mainfile(filepath=inputfile) - bpy.ops.export_scene.gltf(filepath=outputfile[:-4], export_apply=True) + bpy.ops.export_scene.gltf( + filepath=outputfile[:-4], + export_apply=True, + export_yup=True, + check_existing=False, + export_image_format="AUTO", + export_format="GLB", + export_materials="EXPORT", + ) if __name__ == "__main__":