Adding first batch of Makefiles

This commit is contained in:
yannk 2021-12-15 21:55:20 +01:00
parent 27fbdbdad5
commit 676a2494a7
4 changed files with 162 additions and 0 deletions

91
Makefile Normal file
View file

@ -0,0 +1,91 @@
# Variables definitions
SHELL=/bin/bash
# executables used
export MAKESBSAR=sbscooker --quiet --output-name {inputName} --includes "/opt/Allegorithmic/Substance_Automation_Toolkit/resources/packages/" --includes "sbs/utilities/"
export GETPRESET=sbsmutator info --print-presets
export GETOUTPUT=sbsmutator info --print-outputs
export SBSRENDER=sbsrender
# sbsar files generation part
export SBS_DIR=sbs
export SBSAR_DIR=sbsar
export SBSFILES = $(wildcard $(SBS_DIR)/*.sbs)
export SBSARDESTINATION = $(subst $(SBS_DIR)/, $(SBSAR_DIR)/, $(SBSFILES))
export SBSARFILES = $(SBSARDESTINATION:.sbs=.sbsar)
# texturesets files
export TEXTURESET_FOLDER := texturesets
# png files folders - Veiller à changer dans le script create_pngsets_makefile.sh également si besoin
export PNG1024_DIR := png_1024
export PNG512_DIR := png_512
export PNG256_DIR := png_256
# Blender related
export BLENDFILES_FOLDER := blenderfiles/master
export BLENDEREXEC := /home/yann/Documents/3D/blender_builds/daily/blender-3.1.0-alpha+daily.c1f5d8d023c6/blender
# Logo file
export LOGO := logo/YKtextures.png
# Destination folder
export BUILD_FOLDER := build
# Material list
export MATERIALLIST := material_list.json
all : previews subformats
previews: $(SBSARFILES)
$(MAKE) -f Makefile_previews all
subformats: $(SBSARFILES)
$(MAKE) -f Makefile_subformats all
export: $(SBSARFILES)
$(MAKE) -f Makefile_export all
# Recipe to make sbsar, its main PNG files and its preset textureset file
$(SBSAR_DIR)/%.sbsar: $(SBS_DIR)/%.sbs
@ echo $$(basename $@ ".sbsar")
@ echo "Processing" $< "->" $@
@ mkdir -p $(SBSAR_DIR)
@ $(MAKESBSAR) --output-path $(SBSAR_DIR) $<
# Then build png imageset from sbsar
# There is a png imageset for each preset of a base texture
# All png are stored in a png_1024 folder
@ mkdir -p $(PNG1024_DIR)
@ echo "Building 1024 png imageset(s) from presets of" $@
# Get all presets from this base material
@ $(eval PRESETLIST=`$(GETPRESET) --input $< | grep PRESET | sed -r 's/PRESET "(.*)"/\1/g'`)
@ declare -i graphcount=0 ;\
output_list="" ;\
for line in $$($(GETOUTPUT) $<) ; do \
if [ "$$line" = "GRAPH-URL" ] ;\
then ((graphcount++)) ;\
fi ;\
if [ $$graphcount -le 1 ] ;\
then if [ "$$line" != "OUTPUT" ] && [ "$$line" != "GRAPH-URL" ] && [ "$${line:0:4}" != "pkg:" ] ;\
then output_list+=" $${line}" ;\
fi ;\
else : ;\
fi ;\
done;\
echo "output_list :"$$output_list;\
pngfiles="";\
material=$$(basename $@ ".sbsar");\
echo "material :"$$material;\
for preset in $(PRESETLIST) ; do \
echo "- Preset" $$preset; \
listitem="";\
for item in $$output_list;\
do itemfull="$(PNG1024_DIR)/$${material}_$${preset}_$${item}.png";\
listitem="$$listitem $$itemfull";\
done;\
echo "listitem :"$$listitem;\
mkdir --parents $(TEXTURESET_FOLDER);\
echo $$listitem > $(TEXTURESET_FOLDER)/$$(basename $@ ".sbsar")_$$preset;\
$(SBSRENDER) render $@ --use-preset $$preset --output-name {inputGraphUrl}\_$$preset\_{outputNodeName} --set-value \$$outputsize@10,10# --output-path $(PNG1024_DIR); \
done;\

7
Makefile_export Normal file
View file

@ -0,0 +1,7 @@
# Variables définitions
SRC := $(wildcard $(PNG1024_DIR)/*.png)
all:
echo "MATERIALLIST :"$(MATERIALLIST);\
rendertype=$$(cat $(MATERIALLIST) | jq -r --arg folder "$$presetname" '.[] | select(.name==$$folder) | .type');\

46
Makefile_previews Normal file
View file

@ -0,0 +1,46 @@
TEXTURESETS := $(foreach file, $(TEXTURESET_FOLDER), $(basename $(notdir $(wildcard $(TEXTURESET_FOLDER)/*))))
BLENDFILES := $(foreach file, $(BLENDFILES_FOLDER), $(basename $(notdir $(wildcard $(BLENDFILES_FOLDER)/*.blend))))
BLENDFILES_SUFFIX := $(foreach file, $(BLENDFILES), $(addsuffix $(file), _))
TARGET := $(foreach file, $(TEXTURESETS), $(addprefix $(file), $(BLENDFILES_SUFFIX)))
TARGET := $(foreach file, $(TARGET), $(addsuffix .png, $(file)))
TARGET := $(foreach file, $(TARGET), $(addprefix $(BUILD_FOLDER)/, $(file)))
RENDERS := $(foreach file, $(BLENDFILES_SUFFIX), $(addprefix %, $(file)))
RENDERS := $(foreach file, $(RENDERS), $(addsuffix .png, $(file)))
RENDERS := $(foreach file, $(RENDERS), $(addprefix $(BUILD_FOLDER)/, $(file)))
all: $(TARGET)
$(RENDERS): $(TEXTURESET_FOLDER)/%
@ echo "RENDERS :" $(RENDERS)
@ echo "BLENDFILES :" $(BLENDFILES)
@ echo "Prerequisite :" $<
@ pngset=`cat $<`;\
echo "pngset :" $$pngset ;\
for file in $$pngset ;\
do basename=$$(basename "$$file");\
newname=$$(echo $$basename | sed -r 's/.*_[0-9]{2}_(.*)/\\\1/' | sed -r 's/\\//');\
mkdir --parents blenderfiles/textures;\
echo "Copying "$$file ;\
cp $$file blenderfiles/textures/$$newname ; done ;\
presetname=$$(echo $$(basename $< ".png") | sed -r 's/(.*_[0-9]{2})_.*/\\\1/' | sed -r 's/\\//');\
echo "presetname :"$$presetname;\
echo "MATERIALLIST :"$(MATERIALLIST);\
rendertype=$$(cat $(MATERIALLIST) | jq -r --arg folder "$$presetname" '.[] | select(.name==$$folder) | .type');\
echo "foldername :" $$rendertype;\
blender_render_files=$$(ls blenderfiles/$$rendertype/*.blend | sed -r 's/blenderfiles\/.*\///' | sed -r 's/\.blend//' | tr '\n' ' ') ;\
echo "blender_render_files :"$$blender_render_files;\
for blendname in $$blender_render_files;\
do echo "blendname :" $$blendname;\
destination=$$(echo $$presetname"_"$$blendname.png);\
echo "destination :"$(BUILD_FOLDER)"/"$$destination;\
blendfile=$$(echo "blenderfiles/"$$rendertype"/"$$blendname".blend");\
echo "blendfile :" $$blendfile;\
mkdir --parents render;\
echo "Rendering "$(BUILD_FOLDER)/$$destination;\
$(BLENDEREXEC) -b $$blendfile --render-output //../../render/render##.png -f 1 --addons > nul 2>&1;\
mkdir --parents $(BUILD_FOLDER);\
composite -compose atop -gravity southeast -dissolve 90% $(LOGO) render/render01.png $(BUILD_FOLDER)/$$destination;\
done
# Clean the subfolder with temp textures
@ rm -Rf blenderfiles/textures

18
Makefile_subformats Normal file
View file

@ -0,0 +1,18 @@
# Variables définitions
SRC := $(wildcard $(PNG1024_DIR)/*.png)
TARGET_512 :=$(subst $(PNG1024_DIR)/, $(PNG512_DIR)/, $(SRC))
TARGET_256 :=$(subst $(PNG1024_DIR)/, $(PNG256_DIR)/, $(SRC))
all: $(TARGET_512) $(TARGET_256)
$(PNG512_DIR)/%.png: $(PNG1024_DIR)/%.png
@ echo "Converting $< -> $@"
@ mkdir --parents $(PNG512_DIR)
@ convert $< -resize 50% $@
$(PNG256_DIR)/%.png: $(PNG1024_DIR)/%.png
@ echo "Converting $< -> $@"
@ mkdir --parents $(PNG256_DIR)
@ convert $< -resize 25% $@