Skip to content

Commit

Permalink
add gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
madjin committed Feb 16, 2024
1 parent f4f7b33 commit 16c50b6
Show file tree
Hide file tree
Showing 23 changed files with 247 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Asset Pallet Generator

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install screenshot-glb
run: npm install --save @shopify/screenshot-glb

- name: Update pallet site
run: |
chmod +x scripts/generate_html_gallery.sh
./scripts/generate_html_gallery.sh models --head > index.html
- name: Take screenshots and make pallet
run: |
chmod +x scripts/process_files.sh
./scripts/process_files.sh models glb png 512 512
./scripts/generate_html_gallery.sh models --body >> index.html
- name: Update README
run: |
python scripts/table.py --head > README.md
python scripts/table.py models >> README.md
- name: Commit changes
run: |
git config --global user.name "madjin"
git config --global user.email "[email protected]"
git add .
git commit -m "Update READMEs"
git push
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
85 changes: 85 additions & 0 deletions scripts/generate_html_gallery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash


# Function to print HTML header
print_html_header() {
echo "<!DOCTYPE html>"
echo "<html>"
echo "<head>"
echo "<meta charset=\"UTF-8\">"
echo "<title>Image Gallery</title>"
echo "<style>"
echo " .gallery {"
echo " display: grid;"
echo " grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));"
echo " grid-gap: 10px;"
echo " }"
echo " .gallery img {"
echo " width: 100%;"
echo " height: 100%;"
echo " object-fit: cover;"
echo " }"
echo "</style>"
echo "</head>"
echo "<body>"
echo "<div class=\"gallery\">"
}

# Function to generate HTML gallery
generate_html_gallery() {
local dir="$1"

## Add ability to find gif if thumbnails become animated in future
find "$dir" -type f -name "*.png" | while read -r file; do
local glb_file="${file%.*}.glb"
echo " <a href="$glb_file"><img src="$file"></a>"
done
}

# Main function
main() {
local dir="$1"
local print_header=false
local print_footer=false
local print_body=false

# Check if optional flag is passed
while [[ $# -gt 0 ]]; do
case "$2" in
--head)
print_header=true
shift
;;
--body)
print_body=true
shift
;;
--tail)
print_footer=true
shift
;;
*)
break
;;
esac
done

# Generate HTML gallery
if [[ $print_header == true ]]; then
print_html_header
fi

if [[ $print_body == true ]]; then
generate_html_gallery "$dir"
fi

# Print closing HTML tags if --tail flag is passed
if [[ $print_footer == true ]]; then
echo "</div>"
echo "</body>"
echo "</html>"
fi
}

main "$@"

54 changes: 54 additions & 0 deletions scripts/process_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Function to process files
process_files() {
# Check for required arguments
if [[ $# -ne 5 ]]; then
echo "Usage: $0 directory filetype output_type output_width output_height"
exit 1
fi

local dir="$1"
local filetype="$2"
local output_type="$3"
local output_width="$4"
local output_height="$5"

# Loop through all files of given filetype in the directory
find "$dir" -type f -name "*.$filetype" -print0 | while IFS= read -r -d '' file; do
echo "Processing $file..."
local base_filename=$(basename "$file" ".$filetype")
local skip_gif=false skip_png=false

# Store the directory path of the current file
local output_dir=$(dirname "$file")

[[ -f "$output_dir/$base_filename.gif" ]] && skip_gif=true
[[ -f "$output_dir/$base_filename.png" ]] && skip_png=true

# Process gif files
if [[ $output_type == "gif" || $output_type == "both" ]]; then
if [[ $skip_gif == false ]]; then
for i in {0..5}; do
local yaw=$((i 45 % 315))
local filename="$base_filename-$i.png"
node ./node_modules/.bin/screenshot-glb -i "$file" -w 512 -h 512 -m "orientation=0 0 $yaw" -o "$output_dir/$filename"
done

montage "$output_dir/$base_filename"-*.png -tile 6x1 -geometry +0+0 -background none -resize 3072x512 "$output_dir/montage-$base_filename.png"
convert -dispose background -delay 50 -loop 0 "$output_dir/$base_filename"-*.png "$output_dir/$base_filename.gif"
rm "$output_dir/$base_filename"-*.png
fi
fi

# Process png files
if [[ $output_type == "png" || $output_type == "both" ]]; then
if [[ $skip_png == false ]]; then
node ./node_modules/.bin/screenshot-glb -i "$file" -w "$output_width" -h "$output_height" -m "orientation=0 0 180" -o "$output_dir/$base_filename.png"
fi
fi
done
}

# Call process_files function with command line arguments
process_files "$@"
63 changes: 63 additions & 0 deletions scripts/table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import os
import sys
import math
from pathlib import Path

def main():
if "--head" in sys.argv:
print("# Metaville\n")
print("[![Asset Pallet Generator](https://github.com/m3-org/metaville/actions/workflows/main.yml/badge.svg)](https://github.com/m3-org/metaville/actions/workflows/main.yml)\n")
print("Download templates: https://sketchfab.com/3d-models/remixable-booth-templates-d565cb7935744d6190b7d23b260e743b\n")
print("\n")
sys.exit(0)

if len(sys.argv) < 2:
print("Usage: python table.py directory/")
sys.exit(1)

directory = sys.argv[1]
pairs = {}

for root, dirs, files in os.walk(directory):
for glb in files:
if glb.endswith(".glb"):
base = Path(glb).stem
png = Path(root) / (base + ".png")
if png.exists():
pairs[base] = (Path(root) / glb, png)

count = len(pairs)
size = int(math.sqrt(count))

## Change this later to be based on repo name
print(f" ## {directory}")
print("\n")

print("|", end="")
for i in range(size):
print(f" {i + 1} |", end="")
print()

print("|", end="")
for i in range(size):
print(" --- |", end="")
print()

index = 0
for key, value in pairs.items():
if index % size == 0:
print("|", end="")

glb, png = value
print(f" [![{key}]({png})]({glb}) |", end="")

index += 1

if index % size == 0:
print()

print()

if __name__ == "__main__":
main()

0 comments on commit 16c50b6

Please sign in to comment.