Browse Source

Added automated asset building

* Build Ogre meshes and convert .png textures to dds, all in a
pre-build step. There's plenty of room for improvement, but it's a
good stop-gap for now
* Added more ignores
pitch-detection
Macoy Madson 10 months ago
parent
commit
5cdc86a550
  1. 13
      .gitignore
  2. 2
      test/data/Materials/Monkey_Fur.material
  3. 90
      test/src/VocalGame.cake
  4. 63
      tools/BlenderToOgre.py

13
.gitignore

@ -50,7 +50,18 @@ Dependencies/SDL/
test/100000000PixelShader_ps.glsl
test/100000000VertexShader_vs.glsl
test/100000001PixelShader_ps.glsl
test/100000001VertexShader_vs.glsl
test/100000002PixelShader_ps.glsl
test/100000002VertexShader_vs.glsl
test/SDLOgreApp
test/out.dat
test/converted.dat
test/Loader
test/Loader
*.log
# These should be stored in assets/, then converted by the build system
test/data/Models/*.mesh.xml
test/data/Materials/Textures/*.dds

2
test/data/Materials/Monkey_Fur.material

@ -4,7 +4,7 @@ hlms MonkeyFur pbs
roughness 0.4
fresnel 1.33
diffuse_map MonkeyTexture.dds
diffuse_map Monkey_Texture.dds
// normal_map Rocks_Normal.tga
// roughness_map Rocks_Spec.tga
// specular_map Rocks_Diffuse.tga

90
test/src/VocalGame.cake

@ -520,6 +520,96 @@
(return true)))
(return false))
;;
;; Assets
;;
;; TODO Improvements:
;; - Check blender command for changes to cause rebuild
;; - Check linked Blender files (would need to hard code because blender is too slow to start)
;; - Don't rebuild due to different build configuration (assets remain unchanged)
;; - Actually check assets instead of just cache file
(defun-comptime process-3d-assets (manager (& ModuleManager) module (* Module) &return bool)
(scope ;; Models/meshes
;; Make sure output dir exists and we have an absolute path to it
(var model-relative-dir (* (const char)) "test/data/Models")
(makeDirectory model-relative-dir)
;; Output must be absolute or OgreMeshTool will fail (probably due to different working dir)
(var model-output-dir (* (const char)) (makeAbsolutePath_Allocated null model-relative-dir))
(unless model-output-dir
(Logf "Asset-Building: could not make directory %s absolute\n" model-relative-dir)
(return false))
(var model-assets ([] (* (const char))) (array "Monkey"))
(var i int 0)
(while (< i (array-size model-assets))
(var blend-asset ([] MAX_PATH_LENGTH char) (array 0))
(PrintfBuffer blend-asset "test/assets/%s.blend" (at i model-assets))
;; It is too slow to check Blender for all the files the blend will export, then check whether
;; the .blend file is more recently modified. Instead, create a file in the cache to represent
;; the last time the .blend was known to have been exported. Hack, especially because other
;; configurations don't need to rebuild assets. Probably better to just leave asset building to
;; another executable
(var cache-reference-filename ([] MAX_PATH_LENGTH char) (array 0))
(unless (outputFilenameFromSourceFilename (on-call (field manager buildOutputDir) c_str)
blend-asset
"txt" ;; Add to end of file for type
cache-reference-filename (sizeof cache-reference-filename))
(free (type-cast model-output-dir (* void)))
(return false))
(unless (fileIsMoreRecentlyModified blend-asset cache-reference-filename)
(incr i)
(continue))
(run-process-sequential-or
("blender"
"--background" blend-asset
"--python-exit-code" "1" ;; If there's a python exception, return 1
"--python" "tools/BlenderToOgre.py"
"--" model-output-dir)
(Log "Asset-Building: failed to build 3D asset. Is Blender on your path? Is blender2ogre set
up on your Blender default preferences? See https://github.com/OGRECave/blender2ogre for setup\n")
(free (type-cast model-output-dir (* void)))
(return false))
(scope ;; Write reference file
(var cache-reference (* FILE) (fopen cache-reference-filename "w"))
(unless cache-reference
(Logf "Asset-Building: failed to open cache reference file %s\n" cache-reference-filename)
(free (type-cast model-output-dir (* void)))
(return false))
(fprintf cache-reference "%s exported\n" blend-asset)
(fclose cache-reference))
(incr i))
(free (type-cast model-output-dir (* void))))
(scope ;; Textures
(var texture-assets ([] (* (const char))) (array "Monkey_Texture"))
(var i int 0)
(while (< i (array-size texture-assets))
(var texture-asset ([] MAX_PATH_LENGTH char) (array 0))
(PrintfBuffer texture-asset "test/assets/%s.png" (at i texture-assets))
(var texture-converted ([] MAX_PATH_LENGTH char) (array 0))
(PrintfBuffer texture-converted "test/data/Materials/Textures/%s.dds" (at i texture-assets))
(unless (fileIsMoreRecentlyModified texture-asset texture-converted)
(incr i)
(continue))
(run-process-sequential-or
("convert" texture-asset texture-converted)
(Log "Asset-Building: failed to convert 2D texture. Is `convert` on your path? You may need to
install ImageMagick. See https://www.imagemagick.org/script/download.php\n")
(return false))
(incr i)))
(return true))
;; TODO: This should be a post-build hook
(add-compile-time-hook-module pre-build process-3d-assets)
;;
;; Building
;;

63
tools/BlenderToOgre.py

@ -0,0 +1,63 @@
"""import bpy
import sys
import os
import re
from os.path import join, split
def export(object_names):
for name in object_names:
index = bpy.data.objects.find(name)
if index != -1:
obj = bpy.data.objects[index]
obj.data.update()
obj.data.calc_loop_triangles()
export_mesh(obj, '/tmp')
if __name__ == "__main__":
idx = sys.argv.index('--')
argv = sys.argv[idx+2:]
outputPath = sys.argv[idx+1]
# cut off file name
io_ogre = os.path.split(__file__)[0]
# cut off io_ogre dir
io_ogre = os.path.split(io_ogre)[0]
sys.path.append(io_ogre)
os.makedirs(outputPath, exist_ok=True, mode=0o775)
from io_ogre import config
from io_ogre.ogre.scene import dot_scene
from io_ogre.ogre.mesh import dot_mesh
from io_ogre.ogre.skeleton import dot_skeleton
match = re.compile("scene (.*)").match(argv[0])
if match:
scene_name = match.group(1)
dot_scene(outputPath, scene_name=scene_name)
else:
print("Did not understand arg {}. Expected scene blah".format(argv[0]))
"""
import sys
if __name__ == "__main__":
idx = sys.argv.index('--')
restArgv = sys.argv[idx+2:]
outputPath = sys.argv[idx+1]
# Not necessary if plugin is enabled by default, I think
# (besides, the options would all need to be set here too)
# io_ogre_path = "Dependencies/blender2ogre"
# sys.path.append(io_ogre_path)
from io_ogre import config
from io_ogre.ogre.scene import dot_scene
from io_ogre.ogre.mesh import dot_mesh
from io_ogre.ogre.skeleton import dot_skeleton
# dot_scene does this for us
# os.makedirs(outputPath, exist_ok=True, mode=0o775)
# Export the root scene
dot_scene(outputPath)
Loading…
Cancel
Save