Skip to content

Commit

Permalink
update document
Browse files Browse the repository at this point in the history
  • Loading branch information
matyalatte committed Oct 13, 2022
1 parent 4011d84 commit 2b28ed7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 55 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ You can download zip files from [the release page](https://github.com/matyalatte

If you want to use the addon on other platforms, you need to build [Texconv](https://github.com/matyalatte/Texconv-Custom-DLL) by yourself.

## Getting Started
[Getting Started · matyalatte/Blender-DDS-Addon Wiki](https://github.com/matyalatte/Blender-DDS-Addon/wiki/Getting-Started)

## Supported Formats
The addon supports most of the 2D formats.
(Cube maps and 3D textures are unsupported.)

Here is a list of supported formats.
Here is a list of supported formats.

<details>
<summary>Supported DXGI Formats</summary>

Expand Down Expand Up @@ -90,7 +94,7 @@ Here is a list of supported formats.
[Texconv](https://github.com/microsoft/DirectXTex/wiki/Texconv)
is a texture converter developed by Microsoft.
It's the best DDS converter as far as I know.
And [Texconv-Custom-DLL](https://github.com/matyalatte/Texconv-Custom-DLL) is a cross-platform implementation for [Texconv](https://github.com/microsoft/DirectXTex/wiki/Texconv).
And [Texconv-Custom-DLL](https://github.com/matyalatte/Texconv-Custom-DLL) is a cross-platform implementation I made.
The official Texconv only supports Windows but you can use it on Unix systems.

## License
Expand Down
4 changes: 2 additions & 2 deletions addons/blender_dds_addon/dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def get_dds_format(fmt):
for pxlfmt, dxgi in DDS_PIXELFORMAT_TO_DXGI:
if fmt in pxlfmt:
return dxgi
print("Failed to detect dxgi format. It'll be loaded as a DXT1 texture.")
return DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM
print("Failed to detect dxgi format. It'll be loaded as a B8G8R8A8 texture.")
return DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM


def is_hdr(name):
Expand Down
56 changes: 29 additions & 27 deletions addons/blender_dds_addon/export_dds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""UI panel and operator to export .uasset files."""
"""UI panel and operator to export DDS files."""

import os
import time
Expand All @@ -19,12 +19,15 @@


def save_dds(tex, file, dds_fmt, invert_normals=False, no_mip=False,
allow_slow_codec=False, no_err=False, texconv=None):
"""Export a texture form .uasset file.
allow_slow_codec=False, texconv=None):
"""Export a texture as DDS.
Args:
file (string): file path to .uasset file
invert_normals (bool): Flip y axis if the texture is normal map.
file (string): file path to .dds file
dds_fmt (string): DXGI format (e.g. BC1_UNORM)
invert_normals (bool): Flip y axis for BC5 textures.
no_mip (bool): Disable mipmap generation.
allow_slow_codec: Allow CPU codec for BC6 and BC7.
texconv (Texconv): Texture converter for dds.
Returns:
Expand All @@ -33,34 +36,33 @@ def save_dds(tex, file, dds_fmt, invert_normals=False, no_mip=False,
file_format = tex.file_format
filepath_raw = tex.filepath_raw

with tempfile.TemporaryDirectory() as temp_dir:
if is_hdr(dds_fmt):
temp = os.path.join(temp_dir, 'temp.hdr')
tex.file_format = 'HDR'
else:
temp = os.path.join(temp_dir, 'temp.tga')
tex.file_format = 'TARGA_RAW'
tex.filepath_raw = temp
tex.save()

if texconv is None:
texconv = Texconv()
try:
try:
with tempfile.TemporaryDirectory() as temp_dir:
if is_hdr(dds_fmt):
temp = os.path.join(temp_dir, 'temp.hdr')
tex.file_format = 'HDR'
else:
temp = os.path.join(temp_dir, 'temp.tga')
tex.file_format = 'TARGA_RAW'
tex.filepath_raw = temp
tex.save()

if texconv is None:
texconv = Texconv()

temp_dds = texconv.convert_to_dds(temp, dds_fmt, out=temp_dir,
invert_normals=invert_normals, no_mip=no_mip,
allow_slow_codec=allow_slow_codec)
if temp_dds is None: # if texconv doesn't exist
invert_normals=invert_normals, no_mip=no_mip,
allow_slow_codec=allow_slow_codec)
if temp_dds is None:
raise RuntimeError('Failed to convert texture.')
shutil.copyfile(temp_dds, file)
tex.file_format = file_format
tex.filepath_raw = filepath_raw

except Exception as e:
if not no_err:
raise e
print(f'Failed to load {file}')
tex = None

except Exception as e:
tex.file_format = file_format
tex.filepath_raw = filepath_raw
raise e

return tex

Expand Down
28 changes: 15 additions & 13 deletions addons/blender_dds_addon/import_dds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""UI panel and operator to import .uasset files."""
"""UI panel and operator to import DDS files."""

import os
import time
Expand Down Expand Up @@ -33,7 +33,7 @@ def load_tga(file, name, color_space='Non-Color'):
return tex


def load_dds(file, invert_normals=False, no_err=False, texconv=None):
def load_dds(file, invert_normals=False, texconv=None):
"""Import a texture form .uasset file.
Args:
Expand All @@ -46,21 +46,23 @@ def load_dds(file, invert_normals=False, no_err=False, texconv=None):
"""
texture_name = os.path.basename(file)[:-4]

with tempfile.TemporaryDirectory() as temp_dir:
temp = os.path.join(temp_dir, "temp.dds")
shutil.copyfile(file, temp)
if texconv is None:
texconv = Texconv()
try:

try:
with tempfile.TemporaryDirectory() as temp_dir:
temp = os.path.join(temp_dir, "temp.dds")
shutil.copyfile(file, temp)
if texconv is None:
texconv = Texconv()

temp_tga = texconv.convert_to_tga(temp, out=temp_dir, invert_normals=invert_normals)
if temp_tga is None: # if texconv doesn't exist
raise RuntimeError('Failed to convert texture.')
tex = load_tga(temp_tga, name=texture_name)
except Exception as e:
if not no_err:
raise e
print(f'Failed to load {file}')
tex = None

except Exception as e:
if tex is not None:
bpy.data.images.remove(tex)
raise e

return tex

Expand Down
14 changes: 7 additions & 7 deletions for_dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ There are some python scripts to test the addon.
[Flake8](https://flake8.pycqa.org/en/latest/) is a tool for style guide enforcement.<br>
It will check if you are following [PEP8](https://peps.python.org/pep-0008/).<br>
Install it with `pip install flake8`.<br>
Then, type `flake8` in `./Blender-Uasset-Addon`.<br>
Then, type `flake8` in `./Blender-DDS-Addon`.<br>
You should get no messages from flake8.

## Pylint
[Pylint](https://pylint.pycqa.org/en/latest/) is a static code analyser.<br>
It can rate your scripts.<br>
Install it with `pip install pylint`.<br>
Then, type `python for_dev\lint.py --path=addons\blender_uasset_addon` in `./Blender-Uasset-Addon`.<br>
Then, type `python for_dev\lint.py --path=addons\blender_dds_addon` in `./Blender-DDS-Addon`.<br>
You will get results like `PyLint Passed | Score:...`.<br>
The score should be more than 7.<br>

Expand All @@ -27,32 +27,32 @@ You can use bpy with pytest.<br>
First, install requirements in your python environment like this.<br>

```
pip install pytest pytest-blender pytest-cov
pip install pytest pytest-blender
```

Then, install pytest and pytest-cov in Blender's python environment like this.<br>
Then, install pytest in Blender's python environment like this.<br>
```
REM This is for Windows. See pytest-blender's document for linux and mac.
set BLENDER=C:\Program Files\Blender Foundation\Blender 3.0
set PYTHON_PATH=%BLENDER%\3.0\python\bin\python.exe
set SITE_PACK=%BLENDER%\3.0\python\lib\site-packages
"%PYTHON_PATH%" -m ensurepip
"%PYTHON_PATH%" -m pip install pytest pytest-cov -t "%SITE_PACK%" --upgrade
"%PYTHON_PATH%" -m pip install pytest -t "%SITE_PACK%" --upgrade
```

And then, you can use pytest with bpy.
```
set BLENDER_EXE=C:\Program Files\Blender Foundation\Blender 3.0\blender.exe
pytest tests\ -svv --blender-executable "%BLENDER_EXE%" --cov-report html --cov-report term:skip-covered
pytest tests\ -svv --blender-executable "%BLENDER_EXE%"
```

## Github Actions
[Github Actions](https://docs.github.com/en/actions) is an automation tool for development workflows.<br>
You can run scripts on remote servers for your repositories.<br>
There are 2 workflows for the addon.

- CI: Run flake8, pylint, and pytest to check your codes.
- Test: Run flake8, pylint, and pytest to check your codes.
- Build: Build Texconv and zip it with python scripts.

See here if you want to use the workflows.<br>
Expand Down
2 changes: 1 addition & 1 deletion for_dev/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Notes:
Install pylint with "pip install pylint"
Then, run "python for_dev/lint.py --path=blender_uasset_addon"
Then, run "python for_dev/lint.py --path=blender_dds_addon"
You should get no errors.
"""
import argparse
Expand Down
6 changes: 3 additions & 3 deletions for_dev/regist_without_installing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Notes:
Registration
1. Make a new folder and rename it to 'modules'
2. Unzip blender_uasset_addon*.zip
3. Put blender_uasset_addon (not a zip!) in the modules folder
2. Unzip blender_dds_addon*.zip
3. Put blender_dds_addon (not a zip!) in the modules folder
4. Launch Blender
5. Uninstall blender uasset addon if you installed
5. Uninstall blender dds addon if you installed
6. Go to Edit->Preferences->File Paths->Data->Scripts
7. Type the directory has the modules folder
8. Close the preferences window
Expand Down

0 comments on commit 2b28ed7

Please sign in to comment.