Learn More →
Learn More →
Learn More →
Get just the attributes into a more simplified JSON (old)
#!/bin/bash
# Find all *_renamed.json files in subdirectories
find . -type f -name '*_renamed.json' -print0 | while IFS= read -r -d '' renamed_json_file; do
# Extract folder name
folder_name=$(dirname "$renamed_json_file")
# Extract data from the renamed JSON file
name=$(jq -r '.name' "$renamed_json_file")
attributes=$(jq '.attributes' "$renamed_json_file")
# Create a new JSON object with "name" as the root and "attributes" field
new_json="{\"$name\": $attributes}"
# Save the new JSON object to a file named "$folder_attributes.json"
echo "$new_json" > "$folder_name/${name}_attributes.json"
done
#!/bin/bash
# Find all *_renamed.json files in subdirectories
find . -type f -name '*_renamed.json' -print0 | while IFS= read -r -d '' renamed_file; do
# Read the existing JSON content
json_content=$(cat "$renamed_file")
# Extract the "name" and "attributes" fields
name=$(jq -r '.name' <<< "$json_content")
attributes=$(jq -r '.attributes' <<< "$json_content")
if [ -n "$name" ] && [ -n "$attributes" ]; then
# Create a new JSON object with only "name" and "attributes"
formatted_json="{ \"name\": \"$name\", \"attributes\": $attributes }"
# Determine the directory and filename for the *_attributes.json file
attributes_file="${renamed_file%_renamed.json}_attributes.json"
# Save the formatted JSON as *_attributes.json
echo "$formatted_json" > "$attributes_file"
fi
done
Example output
{
"0": [
{
"trait_type": "BODY",
"value": "Feminine"
},
{
"trait_type": "CLOTHING",
"value": "QiPao"
},
{
"trait_type": "HAIR",
"value": "Long_OrangeRed"
},
{
"trait_type": "TYPE",
"value": "Human"
},
{
"trait_type": "MASKS",
"value": "Tech_Mask_Kabuki"
},
{
"trait_type": "WEAPON",
"value": "Quicksilver_Spear"
},
{
"trait_type": "SET",
"value": "Assassins_Guild"
}
]
}
Copy the glb and png for each item into the vrm folder
#!/bin/bash
# Set the source directories for glb and png files
source_dirs=(
"/home/jin/repo/anata/files/female/"
"/home/jin/repo/anata/files/shared/"
)
# Define the trait_type order from low to high
trait_type_order=(
"BRACE"
"CLIPS_AND_KANZASHI"
"CLOTHING"
"EARRING"
"EYES"
"FACE_OTHER"
"GLASSES"
"HAIR"
"HAIR_ACCESSORY_OTHER"
"HALOS"
"HATS"
"HEAD"
"HEAD_ACCESSORY_OTHER"
"MASKS"
"NECK"
"RIBBONS_AND_BOWS"
"SET"
"SIGIL"
"SPECIAL_OTHER"
"TAIL"
"TATTOO"
"TYPE"
"WEAPON"
"WEAPON_BRACE"
"WINGS"
)
# Find all numeric folders containing *_attributes.json files and sort them numerically
folders=($(find . -type d -name '[0-9]*' -exec test -e "{}/{}_attributes.json" \; -print | sort -n))
# Loop through each folder
for folder in "${folders[@]}"; do
attributes_file="${folder}/${folder}_attributes.json"
# Extract the "name" from the JSON file
name=$(jq -r '.name' "$attributes_file")
echo "Processing JSON file: $attributes_file"
echo "Extracted name: $name"
# Loop through each source directory
for source_dir in "${source_dirs[@]}"; do
# Loop through trait_type in order
for trait_type in "${trait_type_order[@]}"; do
value=$(jq -r ".attributes[] | select(.trait_type == \"$trait_type\") | .value" "$attributes_file")
if [ -n "$value" ]; then
# Construct the paths to .glb and .png files based on "trait_type" and "value"
glb_path="${source_dir}/${trait_type}/${value}/${value}.glb"
png_path="${source_dir}/${trait_type}/${value}/${value}.png"
echo "Checking .glb file: $glb_path"
echo "Checking .png file: $png_path"
# Check if the .glb and .png files exist and copy them to the folder
if [ -f "$glb_path" ]; then
echo "Copying .glb file to: $folder/"
cp "$glb_path" "$folder/"
fi
if [ -f "$png_path" ]; then
echo "Copying .png file to: $folder/"
cp "$png_path" "$folder/"
fi
fi
done
done
done
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up