diff --git a/manyfold/README.md b/manyfold/README.md index 2f480f1..b1eaea8 100644 --- a/manyfold/README.md +++ b/manyfold/README.md @@ -16,6 +16,8 @@ $ mkdir mnt config $ docker run -t xrforge docker.io/coderofsalvation/xrforge:latest -v ./mnt:/mnt -v ./config:/config ``` +> To scan all (mounted) libraries run this once: `$ docker exec xrforge /manyfold/cli/manyfold.sh scan_libraries` + # Build & Run the container-image > **NOTE**: [nix](https://nixos.org) is used to promote reproducability-over-repeatability diff --git a/manyfold/cli/manyfold.sh b/manyfold/cli/manyfold.sh index bf61e20..4f4d03d 100755 --- a/manyfold/cli/manyfold.sh +++ b/manyfold/cli/manyfold.sh @@ -210,8 +210,7 @@ start_syslog(){ scan_libraries(){ cd /usr/src/app echocolor "scanning libraries" - test -f ${db}.startupscan || bin/manyfold libraries scan - touch ${db}.startupscan # only do once + bin/manyfold libraries scan } scan_experience(){ @@ -248,6 +247,7 @@ get_xrfragment_assets(){ } init_database(){ + test -f ${db}.xrforgeinit && exit 0 # already inited sleep 3 test -z "$THEME" || set_global theme "'$THEME'" set_admin @@ -256,12 +256,11 @@ init_database(){ set_global model_tags_auto_tag_new "replace('--- \"\"\\n','\\n',char(10))" set_global model_path_template "replace('--- \"{creator}/{modelId} \"\\n','\\n',char(10))" #set_global about "$ABOUT" - mount_rclone set_upload_path & - force_public & get_xrfragment_assets mount_dir scan_libraries & + touch ${db}.xrforgeinit } # The new entrypoint of the docker @@ -272,6 +271,8 @@ boot(){ rename_app set_homepage start_hook_daemon + mount_rclone + force_public & # enable development mode (disables template caching etc) test -n "$DEV" && { diff --git a/manyfold/root/hook.d/experience_updated/1000-scan-dir.sh b/manyfold/root/hook.d/experience_updated/1000-scan-dir.sh index 068cb69..659b605 100755 --- a/manyfold/root/hook.d/experience_updated/1000-scan-dir.sh +++ b/manyfold/root/hook.d/experience_updated/1000-scan-dir.sh @@ -4,6 +4,6 @@ cd "$dir" echo "[v] scan (new) files of model" id="$(basename "$dir" | sed 's/\#//g')" # TODO: better ratelimiting -test -f /tmp/.scan && test $id = "$(cat /tmp/.scan)" && exit +#test -f /tmp/.scan && test $id = "$(cat /tmp/.scan)" && exit /manyfold/cli/manyfold.sh scan_experience $id echo $id > /tmp/.scan diff --git a/manyfold/root/hook.d/experience_updated/200-to-gltf.rb b/manyfold/root/hook.d/experience_updated/200-to-gltf.rb index 076c998..85891d5 100755 --- a/manyfold/root/hook.d/experience_updated/200-to-gltf.rb +++ b/manyfold/root/hook.d/experience_updated/200-to-gltf.rb @@ -33,7 +33,6 @@ begin XRForge.log("✅ generating gltf", logfile) gltf_path = ".xrforge/scene.gltf" system("assimp export #{filename} #{gltf_path}") - system("assimp extract #{filename} | sed 's|/.*/||g'") # tag it! if ! data['keywords'].include?('gltf') diff --git a/manyfold/root/hook.d/experience_updated/300-package_godot_zip.sh b/manyfold/root/hook.d/experience_updated/300-package_godot_zip.sh index 88180da..bcb4963 100755 --- a/manyfold/root/hook.d/experience_updated/300-package_godot_zip.sh +++ b/manyfold/root/hook.d/experience_updated/300-package_godot_zip.sh @@ -4,7 +4,7 @@ cd "$dir" echo "[package_godot_zip.sh] zipping godot.zip" # overwrite empty godot template project-zip with given URL -test -n "$GODOT_TEMPLATE_ZIP" && timeout 50 wget "$GODOT_TEMPLATE_ZIP" -O ~/template_godot.zip +test -n "$GODOT_TEMPLATE_ZIP" && timeout 50 wget "$GODOT_TEMPLATE_ZIP" -O ~/templates/template_godot.zip -cp ~/template_godot.zip .xrforge/godot.zip +cp ~/templates/template_godot.zip .xrforge/godot.zip zip .xrforge/godot.zip *.glb *.usdz *.obj diff --git a/manyfold/root/hook.d/experience_updated/500-mastodon-post2image.rb b/manyfold/root/hook.d/experience_updated/500-mastodon-post.rb similarity index 67% rename from manyfold/root/hook.d/experience_updated/500-mastodon-post2image.rb rename to manyfold/root/hook.d/experience_updated/500-mastodon-post.rb index f9c3d2e..b55d0b3 100755 --- a/manyfold/root/hook.d/experience_updated/500-mastodon-post2image.rb +++ b/manyfold/root/hook.d/experience_updated/500-mastodon-post.rb @@ -21,7 +21,8 @@ end begin # Change the directory - Dir.chdir( File.dirname(filename) ) + dir = File.dirname(filename) + Dir.chdir( dir ) # Read and parse the JSON file data = JSON.parse( File.read( "datapackage.json" ) ) @@ -67,16 +68,25 @@ begin if img and img[1] and img[1].match(/(png|jpg)/) imgurl = img[1] end + + cmd = "cp -r /root/assets/template/mastodon-post .xrforge/. && rm .xrforge/mastodon-post/mastodon-post.png && " - text = "\n\"#{description}\"\n\n~ #{feed.channel.title}\n#{feed.channel.link}" - textFile = ".xrforge/mastodon-post.txt" + text = "\n\"#{description}\"" + textFile = ".xrforge/mastodon-post/mastodon-post.txt" File.open(textFile,'w') do |file| file.puts text end - cmd = "magick -size 800x800 -background white -pointsize 48 -interline-spacing 10 -fill \\#555 -gravity center -font /usr/local/lib/ruby/3.4.0/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf caption:@#{textFile} mastodon-post.png" - puts cmd - system(cmd) + cmd = cmd + "magick -size 800x800 -background white -pointsize 48 -interline-spacing 10 -fill \\#555 -gravity center -font /usr/local/lib/ruby/3.4.0/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf caption:@#{textFile}" + cmd = cmd + " -pointsize 18 -fill \\#FFFFFF -gravity NorthWest -annotate +152+100 #{APHandle} " + cmd = cmd + " -fill \\#9c9cc9 -gravity NorthWest -annotate +152+130 #{feed.channel.title} " + cmd = cmd + " -fill \\#9c9cc9 -gravity NorthWest -annotate +40+470 #{feed.channel.link} " + cmd = cmd + " PNG8:.xrforge/mastodon-post/mastodon-post.png &&" + cmd = cmd + "cd .xrforge/mastodon-post && assimp export mastodon-post.gltf mastodon-post.glb && mv mastodon-post.glb ../../." + ret = system(cmd) + if ret != 0 + XRForge.log("❌ something went wrong :(", logfile) + end XRForge.log(" ", logfile) diff --git a/manyfold/root/templates/mastodon-post/mastodon-post-bg.png b/manyfold/root/templates/mastodon-post/mastodon-post-bg.png new file mode 100644 index 0000000..47c43df Binary files /dev/null and b/manyfold/root/templates/mastodon-post/mastodon-post-bg.png differ diff --git a/manyfold/root/templates/mastodon-post/mastodon-post.bin b/manyfold/root/templates/mastodon-post/mastodon-post.bin new file mode 100644 index 0000000..177ec5b Binary files /dev/null and b/manyfold/root/templates/mastodon-post/mastodon-post.bin differ diff --git a/manyfold/root/templates/mastodon-post/mastodon-post.gltf b/manyfold/root/templates/mastodon-post/mastodon-post.gltf new file mode 100644 index 0000000..f9e83de --- /dev/null +++ b/manyfold/root/templates/mastodon-post/mastodon-post.gltf @@ -0,0 +1,154 @@ +{ + "asset":{ + "generator":"Khronos glTF Blender I/O v4.4.56", + "version":"2.0" + }, + "extensionsUsed":[ + "KHR_materials_unlit" + ], + "scene":0, + "scenes":[ + { + "name":"Scene", + "nodes":[ + 0 + ] + } + ], + "nodes":[ + { + "mesh":0, + "name":"mastodon-post", + "rotation":[ + 0.70710688829422, + 0, + 0, + 0.7071066498756409 + ], + "scale":[ + 2.471118211746216, + 2.471118450164795, + 2.471118450164795 + ] + } + ], + "materials":[ + { + "doubleSided":true, + "extensions":{ + "KHR_materials_unlit":{} + }, + "name":"unlit.001", + "pbrMetallicRoughness":{ + "baseColorTexture":{ + "index":0 + }, + "metallicFactor":0, + "roughnessFactor":0.9 + } + } + ], + "meshes":[ + { + "name":"Plane", + "primitives":[ + { + "attributes":{ + "POSITION":0, + "NORMAL":1, + "TEXCOORD_0":2 + }, + "indices":3, + "material":0 + } + ] + } + ], + "textures":[ + { + "sampler":0, + "source":0 + } + ], + "images":[ + { + "mimeType":"image/png", + "name":"mastodon-post", + "uri":"mastodon-post.png" + } + ], + "accessors":[ + { + "bufferView":0, + "componentType":5126, + "count":20, + "max":[ + 1, + 0, + 1 + ], + "min":[ + -1, + 0, + -1 + ], + "type":"VEC3" + }, + { + "bufferView":1, + "componentType":5126, + "count":20, + "type":"VEC3" + }, + { + "bufferView":2, + "componentType":5126, + "count":20, + "type":"VEC2" + }, + { + "bufferView":3, + "componentType":5123, + "count":54, + "type":"SCALAR" + } + ], + "bufferViews":[ + { + "buffer":0, + "byteLength":240, + "byteOffset":0, + "target":34962 + }, + { + "buffer":0, + "byteLength":240, + "byteOffset":240, + "target":34962 + }, + { + "buffer":0, + "byteLength":160, + "byteOffset":480, + "target":34962 + }, + { + "buffer":0, + "byteLength":108, + "byteOffset":640, + "target":34963 + } + ], + "samplers":[ + { + "magFilter":9729, + "minFilter":9987 + } + ], + "buffers":[ + { + "byteLength":748, + "uri":"mastodon-post.bin" + } + ] +} diff --git a/manyfold/root/templates/mastodon-post/mastodon-post.png b/manyfold/root/templates/mastodon-post/mastodon-post.png new file mode 100644 index 0000000..8ba0114 Binary files /dev/null and b/manyfold/root/templates/mastodon-post/mastodon-post.png differ diff --git a/manyfold/root/templates/mastodon-post/mastodon-post.sh b/manyfold/root/templates/mastodon-post/mastodon-post.sh new file mode 100755 index 0000000..d950219 --- /dev/null +++ b/manyfold/root/templates/mastodon-post/mastodon-post.sh @@ -0,0 +1,30 @@ +#!/bin/sh +test -n "$6" || { echo "usage: ./mastodon-post.sh <link> <handle> <ttf-file> </abs/path/to/out.glb>"; exit 0; } + +out="$6" +tmpdir=/tmp/.mastodon-post +mydir="$(dirname $(readlink -f $0))" +cd $mydir + +# create tmp workspace +test -d $tmpdir && rm -rf $tmpdir +mkdir $tmpdir +cp * $tmpdir/. +rm $tmpdir/mastodon-post.png # IMPORTANT: prevent newer/older imagemagick -clobber (non)existence + +set -x +magick $tmpdir/mastodon-post-bg.png \ + \( -background none -pointsize 48 -interline-spacing 10 -fill \#FFF -font "$5" "caption:$1" \) \ + -gravity center -composite \ + -pointsize 18 \ + -fill \#FFFFFF -gravity NorthWest -annotate +152+100 "$4" \ + -fill \#9c9cc9 -gravity NorthWest -annotate +152+130 "$2" \ + -fill \#9c9cc9 -gravity NorthWest -annotate +40+470 "$3" \ + PNG8:$tmpdir/mastodon-post.png + +# -define png:compression-level=9 \ +# -define png:compression-filter=5 \ +# -define png:compression-strategy=1 \ + +cd $tmpdir +assimp export mastodon-post.gltf $out diff --git a/manyfold/root/template_godot.zip b/manyfold/root/templates/template_godot.zip similarity index 100% rename from manyfold/root/template_godot.zip rename to manyfold/root/templates/template_godot.zip diff --git a/nix/docker.nix b/nix/docker.nix index 83ce7d2..f54ea26 100644 --- a/nix/docker.nix +++ b/nix/docker.nix @@ -38,18 +38,18 @@ let finalImageTag = "latest"; }; - # generate the reproducable blob below via: - # $ nix-shell -p nix-prefetch-github --command 'nix-prefetch-github assimp assimp --rev e778c84cd62bc8b38d8e491ad3d2c27cb8ed37d5' - assimpSrc = pkgs.fetchFromGitHub { - "owner" = "assimp"; - "repo" = "assimp"; - "rev" = "e778c84cd62bc8b38d8e491ad3d2c27cb8ed37d5"; - "hash" = "sha256-ja5pFwpnzLT2MDIR8ISwC6+eA5UXyqRZW2CMCCrF1Q0="; - }; - myAssimp = pkgs.pkgsStatic.assimp.overrideAttrs (oldAttrs: { - inherit assimpSrc; # Set the source to the fetched commit - src = assimpSrc; - }); +# # generate the reproducable blob below via: +# # $ nix-shell -p nix-prefetch-github --command 'nix-prefetch-github assimp assimp --rev e778c84cd62bc8b38d8e491ad3d2c27cb8ed37d5' +# assimpSrc = pkgs.fetchFromGitHub { +# "owner" = "assimp"; +# "repo" = "assimp"; +# "rev" = "e778c84cd62bc8b38d8e491ad3d2c27cb8ed37d5"; +# "hash" = "sha256-ja5pFwpnzLT2MDIR8ISwC6+eA5UXyqRZW2CMCCrF1Q0="; +# }; +# myAssimp = pkgs.pkgsStatic.assimp.overrideAttrs (oldAttrs: { +# inherit assimpSrc; # Set the source to the fetched commit +# src = assimpSrc; +# }); in @@ -76,7 +76,8 @@ rec pkgs.pkgsStatic.inotify-tools # inotifywait e.g. pkgs.pkgsStatic.zip # inotifywait e.g. pkgs.pkgsStatic.ts # job management - myAssimp # cli 3D editing/conversion + pkgs.pkgsStatic.assimp # job management +# myAssimp # cli 3D editing/conversion ./.. ]; };