-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change: Add transformer & Bump version.
- Loading branch information
1 parent
53a4b38
commit aa06a1e
Showing
3 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,14 @@ on: | |
types: | ||
- published | ||
env: | ||
version: 0.2.0 | ||
version: 0.4.0 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: checkout repository | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Bump pack.mcmeta version | ||
uses: jacobtomlinson/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: transform | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Setup python 3.11 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.11 | ||
- name: Install dependencies & Run transformer | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pillow | ||
python transformer.py | ||
- name: Commit and push changes | ||
uses: Andro999b/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
message: 'change: transform default to labPBR' | ||
branch: ${{ github.ref_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
from PIL import Image | ||
import os | ||
import shutil | ||
|
||
|
||
class transformerLogger: | ||
|
||
def Logger(char): | ||
print(char) | ||
|
||
def transformFile(rawName, newName): | ||
print(f" \033[34m|\033[0m {rawName} \033[34m->\033[0m {newName}") | ||
|
||
|
||
def transformLightToAlpna(image: Image.Image): | ||
|
||
data = image.getdata() | ||
|
||
newData = [] | ||
|
||
for pixel in data: | ||
|
||
red, green, blue, alpha = pixel | ||
|
||
if alpha == 0: | ||
newData.append(pixel) | ||
else: | ||
light = int(red*0.3 + green*0.59 + blue*0.11) - 1 | ||
newData.append((0, 0, 0, light if light < 255 else 254)) | ||
|
||
newImage = Image.new(image.mode, image.size) | ||
newImage.putdata(newData) | ||
|
||
return newImage | ||
|
||
|
||
|
||
def transformLightToAlpnaGlobally(image: Image.Image): | ||
|
||
data = image.getdata() | ||
|
||
newData, tempData = [], [] | ||
temp_R, temp_G, temp_B = 0, 0, 0 | ||
|
||
for pixel in data: | ||
|
||
red, green, blue, alpha = pixel | ||
|
||
if alpha != 0: | ||
tempData.append(pixel) | ||
temp_R += red | ||
temp_G += green | ||
temp_B += blue | ||
|
||
tempDataLen = len(tempData) | ||
lightGlobal = (temp_R + temp_G + temp_B)//3//tempDataLen | ||
#print(lightGlobal) | ||
|
||
for pixel in data: | ||
|
||
red, green, blue, alpha = pixel | ||
|
||
if alpha == 0: | ||
newData.append(pixel) | ||
else: | ||
newData.append((0, 0, 0, lightGlobal)) | ||
|
||
newImage = Image.new(image.mode, image.size) | ||
newImage.putdata(newData) | ||
|
||
return newImage | ||
|
||
|
||
|
||
def main(path: str, entityMode = False): | ||
|
||
for root, _, files in os.walk(path): | ||
|
||
rootPath = root.replace("\\", "/") | ||
transformerLogger.Logger(f"\n{rootPath}") | ||
|
||
for file in files: | ||
|
||
fileName = file | ||
|
||
emissiveSuffix = "_e" | ||
shaderSuffix = "_s" | ||
|
||
rawSuffix = f"{emissiveSuffix}.png" | ||
newSuffix = f"{emissiveSuffix}{shaderSuffix}.png" | ||
|
||
if file.endswith(rawSuffix): | ||
|
||
rawFile = os.path.join(root, file).replace("\\", "/") | ||
newFile = rawFile.replace(rawSuffix, newSuffix) | ||
|
||
image = Image.open(rawFile) | ||
width, height = image.size | ||
|
||
if image.mode != "RGBA": | ||
image = image.convert("RGBA") | ||
|
||
if height//width != 1 and entityMode == False: | ||
invertedImage = transformLightToAlpnaGlobally(image) | ||
invertedImage.save(newFile) | ||
|
||
else: | ||
invertedImage = transformLightToAlpna(image) | ||
invertedImage.save(newFile) | ||
|
||
transformerLogger.transformFile(fileName, fileName.replace(rawSuffix, newSuffix)) | ||
|
||
elif file.endswith(f"{rawSuffix}.mcmeta"): | ||
|
||
rawFile = os.path.join(root, file).replace("\\", "/") | ||
newFile = rawFile.replace(f"{rawSuffix}.mcmeta", f"{newSuffix}.mcmeta") | ||
|
||
if os.path.exists(newFile): | ||
os.remove(newFile) | ||
|
||
shutil.copy2(rawFile, newFile) | ||
|
||
transformerLogger.transformFile(fileName, fileName.replace(f"{rawSuffix}.mcmeta", f"{newSuffix}.mcmeta")) | ||
|
||
|
||
|
||
transformerLogger.Logger("\nTransformer Starting...") | ||
|
||
main("./assets/minecraft/textures/block") | ||
main("./assets/minecraft/textures/entity",True) | ||
main("./assets/minecraft/textures/item") | ||
|
||
transformerLogger.Logger("\n\033[32m Transform Success \033[0m\n") |