# HG changeset patch # User sam # Date 1724673085 -25200 # Node ID 34ae5835bfa87ec2a7691cf9961a60aaa89e35ce # Parent f65f252331274f5cf6c51bf8447cc9126c0afb5f add: a few static helpers diff -r f65f25233127 -r 34ae5835bfa8 semicongine/audio/resources.nim --- 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) diff -r f65f25233127 -r 34ae5835bfa8 semicongine/gltf.nim --- 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, + ) diff -r f65f25233127 -r 34ae5835bfa8 semicongine/image.nim --- 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 diff -r f65f25233127 -r 34ae5835bfa8 semicongine/resources.nim --- 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() diff -r f65f25233127 -r 34ae5835bfa8 tools/blender_gltf_converter.py --- 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__":