Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
5 changes: 3 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Blender PKG Add-On
Version 1.02
March 11th 2022
Version 1.03

31st July 2023

Created by Dummiesman

Expand Down
2 changes: 1 addition & 1 deletion io_scene_pkg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
bl_info = {
"name": "Angel Studios PKG Format",
"author": "Dummiesman",
"version": (1, 0, 0),
"version": (1, 0, 3),
"blender": (2, 83, 0),
"location": "File > Import-Export",
"description": "Import-Export PKG files",
Expand Down
12 changes: 6 additions & 6 deletions io_scene_pkg/binary_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# READ #
########
def read_angel_string(file):
str_len = struct.unpack('B', file.read(1))[0]
str_len = struct.unpack('<B', file.read(1))[0]
if str_len == 0:
return ''
else:
Expand Down Expand Up @@ -52,7 +52,7 @@ def read_color4f(file):


def read_color4d(file):
c4d = struct.unpack('BBBB', file.read(4))
c4d = struct.unpack('<BBBB', file.read(4))
return [c4d[0]/255, c4d[1]/255, c4d[2]/255, c4d[3]/255]


Expand Down Expand Up @@ -108,11 +108,11 @@ def write_matrix3x4(file, matrix):

def write_angel_string(file, strng):
if strng is not None and len(strng) > 0:
file.write(struct.pack('B', len(strng)+1))
file.write(struct.pack('<B', len(strng)+1))
file.write(bytes(strng, 'UTF-8'))
file.write(bytes('\x00', 'UTF-8'))
else:
file.write(struct.pack('B', 0))
file.write(struct.pack('<B', 0))


def write_float2(file, data):
Expand All @@ -128,7 +128,7 @@ def write_color4d(file, color, alpha=1):
g = min(255, int(color[1] * 255))
b = min(255, int(color[2] * 255))
a = min(255, int(alpha * 255))
file.write(struct.pack('BBBB', r, g, b, a))
file.write(struct.pack('<BBBB', r, g, b, a))


def write_color4f(file, color, alpha=1):
Expand All @@ -138,4 +138,4 @@ def write_color4f(file, color, alpha=1):
def write_file_header(file, name, length=0):
file.write(bytes('FILE', 'utf-8'))
write_angel_string(file, name)
file.write(struct.pack('L', length))
file.write(struct.pack('<L', length))
60 changes: 40 additions & 20 deletions io_scene_pkg/common_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,49 @@ def make_placeholder_texture(name):
im.pixels = pixels[:]
im.update()
return im


def find_file_with_game_fallback(file, search_path, subfolder = None, ignore_subdir_on_search_path = False):
# first search the search_path
find_path = (path.abspath(path.join(search_path, file))
if (subfolder is None or ignore_subdir_on_search_path)
else path.abspath(path.join(search_path, subfolder, file)))

#print("find_path initial:" + find_path)
if path.isfile(find_path):
return find_path
# quick'n'dirty case-insensitive file finder
def find_file_case_insensitive(directory_to_search, file_to_find):
directory_listing = os.listdir(path.abspath(directory_to_search))

for file in directory_listing:
if file.lower() == file_to_find.lower():
return file

return None


def find_file(directory, filename):
real_file = find_file_case_insensitive(directory, filename)

if real_file is not None:
find_path = path.abspath(path.join(directory, real_file))

# then search game dir
preferences = bpy.context.preferences
addon_prefs = preferences.addons[__package__].preferences
if addon_prefs.use_gamepath:
find_path = (path.abspath(path.join(addon_prefs.gamepath, subfolder, file))
if subfolder is not None
else path.abspath(path.join(addon_prefs.gamepath, file)))
#print("find_path game:" + find_path)
if path.isfile(find_path):
return find_path

# wasn't found in game dir or search_path
return None


def find_file_with_game_fallback(file, search_path, subfolder = None, ignore_subdir_on_search_path = False):
preferences = bpy.context.preferences
addon_prefs = preferences.addons[__package__].preferences

if addon_prefs.use_gamepath is True and addon_prefs.gamepath != "":
search_path = addon_prefs.gamepath

normalised_search_path = (search_path
if (subfolder is None or ignore_subdir_on_search_path)
else path.join(search_path, subfolder)
)

found_file = find_file(normalised_search_path, file)

if found_file is not None:
return found_file

# exhausted our search, return nothing
return None


Expand All @@ -79,7 +99,7 @@ def load_texture_from_path(file_path, use_placeholder_if_missing=True):
else:
img = bpy.data.images.load(file_path)
return img

return None


Expand Down Expand Up @@ -152,4 +172,4 @@ def convert_vecspace_to_blender(vtx):
return (vtx[0] * -1, vtx[2], vtx[1])

def convert_vecspace_to_mm2(vtx):
return (vtx[0] * -1, vtx[2], vtx[1])
return (vtx[0] * -1, vtx[2], vtx[1])
8 changes: 4 additions & 4 deletions io_scene_pkg/export_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ def bounds(obj):

def write_matrix_standard(object, file):
bnds = bounds(object)
file.write(struct.pack('fff', *helper.convert_vecspace_to_mm2((bnds.x.min * -1, bnds.y.min, bnds.z.min)))) # have to do * -1 for some reason
file.write(struct.pack('fff', *helper.convert_vecspace_to_mm2((bnds.x.max * -1, bnds.y.max, bnds.z.max)))) # have to do * -1 for some reason
file.write(struct.pack('fff', *helper.convert_vecspace_to_mm2(object.location))) # write this twice. one is pivot and one is origin
file.write(struct.pack('fff', *helper.convert_vecspace_to_mm2(object.location)))
file.write(struct.pack('<fff', *helper.convert_vecspace_to_mm2((bnds.x.min * -1, bnds.y.min, bnds.z.min)))) # have to do * -1 for some reason
file.write(struct.pack('<fff', *helper.convert_vecspace_to_mm2((bnds.x.max * -1, bnds.y.max, bnds.z.max)))) # have to do * -1 for some reason
file.write(struct.pack('<fff', *helper.convert_vecspace_to_mm2(object.location))) # write this twice. one is pivot and one is origin
file.write(struct.pack('<fff', *helper.convert_vecspace_to_mm2(object.location)))


def write_matrix(meshname, object, pkg_path):
Expand Down
Loading