Textures_factory/Makefile_previews

63 lines
3.2 KiB
Text
Raw Normal View History

2021-12-15 20:55:20 +00:00
TEXTURESETS := $(foreach file, $(TEXTURESET_FOLDER), $(basename $(notdir $(wildcard $(TEXTURESET_FOLDER)/*))))
RENDER_FOLDER = $(shell cat $(MATERIALLIST) | jq -r --arg folder "$(SET)" '.[] | select(.name==$$folder) | .type')
RENDER_FILES = $(foreach RENDER, $(basename $(notdir $(wildcard $(BLENDFILES_FOLDER)/$(shell cat $(MATERIALLIST) | jq -r --arg folder "$(SET)" '.[] | select(.name==$$folder) | .type')/*.blend))), $(SET)_$(RENDER))
RENDER_LIST := $(foreach SET, $(TEXTURESETS), $(RENDER_FILES))
BLENDFILES := $(foreach file, $(BLENDFILES_FOLDER)/master, $(basename $(notdir $(wildcard $(BLENDFILES_FOLDER)/master/*.blend))))
2021-12-15 20:55:20 +00:00
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 $(PREVIEW_FOLDER)/, $(file)))
2021-12-15 20:55:20 +00:00
RENDERS := $(foreach file, $(BLENDFILES_SUFFIX), $(addprefix %, $(file)))
RENDERS := $(foreach file, $(RENDERS), $(addsuffix .png, $(file)))
RENDERS := $(foreach file, $(RENDERS), $(addprefix $(PREVIEW_FOLDER)/, $(file)))
2021-12-15 20:55:20 +00:00
all: $(TARGET)
$(RENDERS): $(TEXTURESET_FOLDER)/%
@ echo "RENDER_LIST : $(RENDER_LIST)"
@ echo "RENDER_FILES : $(RENDER_FILES)"
2021-12-15 20:55:20 +00:00
@ echo "RENDERS :" $(RENDERS)
@ echo "BLENDFILES :" $(BLENDFILES)
@ echo "BLENDFILES_SUFFIX :" $(BLENDFILES_SUFFIX)
@ echo "TARGET : $(TARGET)"
@ echo "TEXTURESETS : $(TEXTURESETS)"
2021-12-15 20:55:20 +00:00
@ echo "Prerequisite :" $<
@ pngset=`cat $<`;\
echo "pngset :" $$pngset ;\
for file in $$pngset ;\
do basename=$$(basename "$$file");\
newname=$$(echo $$basename | sed -r 's/.*($(TEXTURES_NAMES))/\\\1/' | sed -r 's/\\//');\
mkdir --parents $(BLENDFILES_FOLDER)/textures;\
2021-12-15 20:55:20 +00:00
echo "Copying "$$file ;\
cp $$file $(BLENDFILES_FOLDER)/textures/$$newname ; done ;\
2021-12-15 20:55:20 +00:00
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 $(BLENDFILES_FOLDER)/$$rendertype/*.blend | sed -r 's|$(BLENDFILES_FOLDER)/.*/||' | sed -r 's/\.blend//' | tr '\n' ' ') ;\
2021-12-15 20:55:20 +00:00
echo "blender_render_files :"$$blender_render_files;\
for blendname in $$blender_render_files;\
do echo "blendname :" $$blendname;\
destination=$$(echo $$presetname"_"$$blendname.png);\
echo "destination :"$(PREVIEW_FOLDER)"/"$$destination;\
blendfile=$$(echo "$(BLENDFILES_FOLDER)/"$$rendertype"/"$$blendname".blend");\
2021-12-15 20:55:20 +00:00
echo "blendfile :" $$blendfile;\
mkdir --parents $(BLENDFILES_FOLDER)/render;\
temp_render_dir=$$(realpath $(BLENDFILES_FOLDER)/render);\
echo "Rendering "$(PREVIEW_FOLDER)/$$destination;\
$(BLENDEREXEC) -b $$blendfile --render-output $$temp_render_dir/render##.png -f 1 --addons > /dev/null 2>&1;\
mkdir --parents $(PREVIEW_FOLDER);\
composite -compose atop -gravity southeast -dissolve 90% $(LOGO) $(BLENDFILES_FOLDER)/render/render01.png $(PREVIEW_FOLDER)/$$destination;\
2021-12-15 20:55:20 +00:00
done
# Clean the subfolder with temp textures
@ rm -Rf $(BLENDFILES_FOLDER)/textures
# Clean the temp render folder
@ rm -Rf $(BLENDFILES_FOLDER)/render