From 597fcd2f64135921c4d0958f5dad3e739b411036 Mon Sep 17 00:00:00 2001 From: empathicqubit Date: Tue, 8 Jun 2021 01:03:44 -0400 Subject: [PATCH] It's hard to believe setting the freaking alpha property is this complicated. --- .gitignore | 2 ++ .python-version | 1 + .venv/DONT_DELETE | 0 .vscode/launch.json | 9 +++++++ .vscode/settings.json | 4 +++ Makefile | 53 ++++++++++++++++++++++++++++++++++------ Pipfile | 9 +++++++ Pipfile.lock | 33 +++++++++++++++++++++++++ build.ps1 | 2 +- export_blender_models.py | 3 ++- nif.xml | 2 ++ setalpha.py | 34 ++++++++++++++++++++++++++ 12 files changed, 142 insertions(+), 10 deletions(-) create mode 100644 .python-version create mode 100644 .venv/DONT_DELETE create mode 100644 .vscode/settings.json create mode 100644 Pipfile create mode 100644 Pipfile.lock create mode 100644 setalpha.py diff --git a/.gitignore b/.gitignore index fb7b9b5..f8c1897 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ /build/ node_modules/ *.blend[0-9]* +.venv/* +!.venv/DONT_DELETE \ No newline at end of file diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..1606904 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.7.9 diff --git a/.venv/DONT_DELETE b/.venv/DONT_DELETE new file mode 100644 index 0000000..e69de29 diff --git a/.vscode/launch.json b/.vscode/launch.json index 1897174..c088bc9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,15 @@ // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "Python: Aktuelle Datei", + "type": "python", + "request": "launch", + "python": "${command:python.interpreterPath}", + "program": "${file}", + "args": ["--", "${workspaceFolder}/plugin/Data/Meshes/_EQ_ItemRoulette/roulette_container_final.nif"], + "console": "integratedTerminal" + }, { "type": "papyrus", "name": "Skyrim", diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3f72e61 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.pythonPath": "${workspaceFolder}/.venv/Scripts/python.exe", + "jupyter.jupyterServerType": "local" +} \ No newline at end of file diff --git a/Makefile b/Makefile index 944abf8..1e01ba6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/c/ProgramData/chocolatey/bin:$(SystemRoot)/System32/WindowsPowerShell/v1.0 +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/c/ProgramData/chocolatey/bin:$(SystemRoot)/System32:$(SystemRoot)/System32/WindowsPowerShell/v1.0:$(word 1,$(HOME) $(USERPROFILE))/.pyenv/pyenv-win/bin mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) current_dir := $(patsubst %/,%,$(dir $(mkfile_path))) @@ -40,17 +40,36 @@ plugin/Data/Scripts/%.pex: Source/Scripts/%.psc textures: $(textureFiles) +pipenv: .venv/pyvenv.cfg + plugin/Data/Textures/_EQ_ItemRoulette/%.dds: Source/Textures/_EQ_ItemRoulette/%.xcf export_gimp_textures.py GIMP=$$(powershell -Command '(Get-Item "$(ProgramW6432)/GIMP*/bin/gimp-console*.exe").FullName') "$$GIMP" -n -i --batch-interpreter python-fu-eval -b 'import export_gimp_textures ; export_gimp_textures.main("$<", "$@")' +.venv/lib/site-packages/pyffi/formats/kfm/kfmxml/kfm.xml: + mkdir -p "$(dir $@)" + powershell -Command 'Invoke-WebRequest -Uri "https://raw.githubusercontent.com/niftools/kfmxml/develop/kfm.xml" -OutFile "$@"' + +.venv/lib/site-packages/pyffi/formats/nif/nifxml/nif.xml: + mkdir -p "$(dir $@)" + powershell -Command 'Invoke-WebRequest -Uri "https://raw.githubusercontent.com/niftools/nifxml/959cb9c3dd59a319e60e819fc8a1402f821f3684/nif.xml" -OutFile "$@"' + +.PRECIOUS: .venv/pyvenv.cfg +.venv/pyvenv.cfg: Pipfile .venv/lib/site-packages/pyffi/formats/nif/nifxml/nif.xml .venv/lib/site-packages/pyffi/formats/kfm/kfmxml/kfm.xml + pyenv install $$(cat ".python-version") + pyenv exec pip install --user pipenv + pyenv exec python -m pipenv install + models: $(modelFiles) textures +.PRECIOUS: build/ChunkMerge/ChunkMerge.exe build/ChunkMerge/ChunkMerge.exe: build/chunkmerge.7z 7z x -y "-obuild" "$<" + touch -c "$@" +.PRECIOUS: build/chunkmerge.7z build/chunkmerge.7z: - powershell -Command 'Invoke-WebRequest -Uri "https://github.com/downloads/skyfox69/NifUtils/ChunkMerge0155.7z" -OutFile build/chunkmerge.7z' + powershell -Command 'Invoke-WebRequest -Uri "https://github.com/downloads/skyfox69/NifUtils/ChunkMerge0155.7z" -OutFile "$@"' build/ChunkMerge/ChunkMerge.xml: build/ChunkMerge/ChunkMerge.exe cat > "$@" <<'HERE' @@ -100,12 +119,30 @@ plugin/Data/Meshes/_EQ_ItemRoulette/%_final.nif: Source/Meshes/_EQ_ItemRoulette/ build/ChunkMerge/ChunkMerge.exe & powershell -Command '$$env:ChunkMerge_NifFile=Split-Path (Join-Path "$@" "."); $$env:ChunkMerge_CollisionFile=Split-Path (Join-Path "$(filter %_collision.nif,$^)" ".") ; $$env:ChunkMerge_TemplateFile="$(notdir $(filter %_template.nif,$^))" ; Start-Process -Wait -FilePath AutoHotKey -ArgumentList @("ChunkMerge.ahk") ; Stop-Process -Name ChunkMerge' +.PRECIOUS: build/blender-windows64/blender.exe +build/blender-windows64/blender.exe: build/blender.zip build/blender-windows64/2.93/scripts/addons/io_scene_niftools/__init__.py + 7z x -y "-obuild" "$<" + touch -c "$@" + +.PRECIOUS: build/blender-windows64/2.93/scripts/addons/io_scene_niftools/__init__.py +build/blender-windows64/2.93/scripts/addons/io_scene_niftools/__init__.py: build/blender-niftools.zip + 7z x -y "-o$$(dirname "$$(dirname "$@")")" "$<" + touch -c "$@" + +.PRECIOUS: build/blender-niftools.zip +build/blender-niftools.zip: + powershell -Command 'Invoke-WebRequest -Uri "https://github.com/niftools/blender_niftools_addon/releases/download/v0.0.6/blender_niftools_addon-v0.0.6-2021-04-24-fa4123d.zip" -OutFile "$@"' + +.PRECIOUS: build/blender.zip +build/blender.zip: + powershell -Command 'Invoke-WebRequest -Uri "https://mirror.clarkson.edu/blender/release/Blender2.93/blender-2.93.0-windows-x64.zip" -OutFile "$@"' + .PRECIOUS: plugin/Data/Meshes/_EQ_ItemRoulette/%_mesh.nif -plugin/Data/Meshes/_EQ_ItemRoulette/%_mesh.nif: Source/Meshes/_EQ_ItemRoulette/%_mesh.blend - BLENDER=$$(powershell -Command '(Get-Item "$(ProgramW6432)/Blender*/Blender*/blender.exe").FullName') - "$$BLENDER" --background --python "./export_blender_models.py" -- "$^" "$@" +plugin/Data/Meshes/_EQ_ItemRoulette/%_mesh.nif: Source/Meshes/_EQ_ItemRoulette/%_mesh.blend build/blender-windows64/blender.exe + BLENDER="$(word 2, $^)" + "$$BLENDER" --background --python "./export_blender_models.py" -- "$<" "$@" .PRECIOUS: plugin/Data/Meshes/_EQ_ItemRoulette/%_collision.nif -plugin/Data/Meshes/_EQ_ItemRoulette/%_collision.nif: Source/Meshes/_EQ_ItemRoulette/%_collision.blend - BLENDER=$$(powershell -Command '(Get-Item "$(ProgramW6432)/Blender*/Blender*/blender.exe").FullName') - "$$BLENDER" --background --python "./export_blender_models.py" -- "$^" "$@" \ No newline at end of file +plugin/Data/Meshes/_EQ_ItemRoulette/%_collision.nif: Source/Meshes/_EQ_ItemRoulette/%_collision.blend build/blender-windows64/blender.exe + BLENDER="$(word 2, $^)" + "$$BLENDER" --background --python "./export_blender_models.py" -- "$<" "$@" \ No newline at end of file diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..ee741ba --- /dev/null +++ b/Pipfile @@ -0,0 +1,9 @@ +[[source]] +url = "https://pypi.python.org/simple" + +[packages] +pyqt4 = {file = "https://download.lfd.uci.edu/pythonlibs/q4trcu4l/PyQt4-4.11.4-cp37-cp37m-win_amd64.whl"} +pyffi = {file = "https://github.com/amorilia/pyffi/archive/refs/tags/pyffi-2.2.2.zip"} + +[requires] +python_version = "3.7.9" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..5a5366a --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,33 @@ +{ + "_meta": { + "hash": { + "sha256": "bb61dfe357ea16e199e93ef79d83cabdc7fef8a99c5376ba3a5a6aa2428f4eeb" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7.9" + }, + "sources": [ + { + "url": "https://pypi.python.org/simple" + } + ] + }, + "default": { + "pyffi": { + "file": "https://github.com/amorilia/pyffi/archive/refs/tags/pyffi-2.2.2.zip", + "hashes": [ + "sha256:2ebdeb86e29e9b532b40fe61b6005e0d29973f2f7e966dbb9fc9c1f4680fa3ca" + ], + "version": "==2.2.2" + }, + "pyqt4": { + "file": "https://download.lfd.uci.edu/pythonlibs/q4trcu4l/PyQt4-4.11.4-cp37-cp37m-win_amd64.whl", + "hashes": [ + "sha256:3bd04c8576ffdc6db3b991642d1657fcee4df803c869a97d11a6eaab1445d59a" + ], + "version": "==4.11.4" + } + }, + "develop": {} +} diff --git a/build.ps1 b/build.ps1 index 6e2d563..968bc7e 100644 --- a/build.ps1 +++ b/build.ps1 @@ -63,7 +63,7 @@ if($InstallDependencies) { [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) - choco install blender gimp 7zip autohotkey make nodejs + choco install gimp 7zip autohotkey make nodejs pyenv-win return 0 } diff --git a/export_blender_models.py b/export_blender_models.py index 821dccf..7bba2a3 100644 --- a/export_blender_models.py +++ b/export_blender_models.py @@ -9,9 +9,10 @@ try: index = argv.index("--") + 1 except ValueError: index = len(argv) - argv = argv[index:] +bpy.ops.preferences.addon_enable(module='io_scene_niftools') + curdir = Path(__file__).parent blend_path = Path(argv[0]) nif_path = Path(argv[1]) diff --git a/nif.xml b/nif.xml index 686a3a9..bc427c2 100644 --- a/nif.xml +++ b/nif.xml @@ -111,9 +111,11 @@ A standard 32-bit floating point number. + A variable length string that ends with a newline character (0x0A). The string starts as follows depending on the version: diff --git a/setalpha.py b/setalpha.py new file mode 100644 index 0000000..fed6ae6 --- /dev/null +++ b/setalpha.py @@ -0,0 +1,34 @@ +from io import UnsupportedOperation +import pyffi +import pickle +from pyffi.formats.nif import NifFormat +import sys + +argv = sys.argv +try: + index = argv.index("--") + 1 +except ValueError: + index = len(argv) +argv = argv[index:] + +data = NifFormat.Data() +with open(argv[0], 'rb') as nif_stream: + data.inspect_version_only(nif_stream) + if data.version >= 0: + data.read(nif_stream) + elif data.version == -1: + raise UnsupportedOperation("Unsupported NIF version") + else: + raise UnsupportedOperation("Not a NIF") + +for child in data.get_global_iterator(): + if isinstance(child, NifFormat.NiTriShape): + alpha = NifFormat.NiAlphaProperty() + alpha.flags = 4845 + child.bs_properties.append(alpha) + child.bs_properties.update_size() + +with open('Z:/farts.nif', 'wb') as nif_out: + data.write(nif_out) + +print('frick') \ No newline at end of file