Skip to content

Commit

Permalink
Merge pull request #19 from SWTOR-Slicers/Blender-4.2-support
Browse files Browse the repository at this point in the history
Multiple UV map objects import bugfix
  • Loading branch information
ZeroGravitasIndeed authored Sep 22, 2024
2 parents 1914996 + c6c848b commit 8e20c5d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

---

- [SWTOR Granny2 (.gr2) Import/Export Add-on for Blender 2.8 to 4.0](#swtor-granny2-gr2-importexport-add-on-for-blender-28-to-40)
- [WARNING: not yet compatible with Blender 4.1.x and higher. We are working on that.](#warning-not-yet-compatible-with-blender-41x-and-higher-we-are-working-on-that)
- [SWTOR Granny2 (.gr2) Import/Export Add-on for Blender 2.8 to 4.2](#swtor-granny2-gr2-importexport-add-on-for-blender-28-to-42)
- [WE ARE FINALLY BLENDER 4.1/4.2-COMPATIBLE!!! 🙂](#we-are-finally-blender-4142-compatible-)
- [New version with new features:](#new-version-with-new-features)
- **[Download](#download)**
- [Download](#download)
- [Installation](#installation)
- [Description](#description)
- [Import/export tools:](#importexport-tools)
Expand All @@ -30,8 +30,6 @@
- [Available Operators.](#available-operators)
- [Custom Scene Property with feedback about the calls' results.](#custom-scene-property-with-feedback-about-the-calls-results)
- [Current state of the project.](#current-state-of-the-project)
- [The Blender 4.1 showstopper.](#the-blender-41-showstopper)
- [Other than that.](#other-than-that)

### New version with new features:
* **Up to Blender 4.2 compatibility**.
Expand Down
Binary file modified io_scene_gr2.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion io_scene_gr2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
bl_info = {
"name": "Star Wars: The Old Republic (.gr2)",
"author": "Darth Atroxa, SWTOR Slicers",
"version": (4, 0, 2),
"version": (4, 0, 3),
"blender": (2, 82, 0),
"location": "File > Import-Export",
"description": "Import-Export SWTOR skeleton, or model with bone weights, UV's and materials",
Expand Down
20 changes: 13 additions & 7 deletions io_scene_gr2/ops/import_gr2.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,23 +582,26 @@ def build(gr2,
if mesh.bit_flag2 & 2: # 0x02
# NOTE: We store 'temp' normals in loops, since validate() may alter final mesh,
# we can only set custom loop normals *after* calling it.

# We use a custom attribute to store them because we can't use
# the "normal" attribute: blend_mesh.loops[loop_index].normal is
# read-only in 4.1 and higher.
temp_custom_normals = blend_mesh.attributes.new(
name="temp_custom_normals",
type='FLOAT_VECTOR',
domain='CORNER'
).data


# UV stuff
blend_mesh.uv_layers.new(do_init=False)
if mesh.bit_flag2 & 64: # 0x40
blend_mesh.uv_layers.new(do_init=False)
if mesh.bit_flag2 & 128: # 0x80
blend_mesh.uv_layers.new(do_init=False)

# For some reason, the creation of extra UV map layers for
# multiUvExtraction objects blitzes the temp normals custom attribute,
# so, we are creating it AFTER the creation of UV layers.
temp_custom_normals = blend_mesh.attributes.new(
name="temp_custom_normals",
type='FLOAT_VECTOR',
domain='CORNER'
).data


for j, polygon in enumerate(blend_mesh.polygons):
loop_indices = polygon.loop_indices
Expand All @@ -610,6 +613,9 @@ def build(gr2,
# doesn't normalize them for free the way mesh.loops[loop_index].normal used to.
# As we are using for the normals data the mathutils' Vector type,
# we use its normalized() method (instead of normalize() which might be slower?).
# blend_mesh.loops[loop_index].normal = [v.normals.x, v.normals.y, v.normals.z]

# temp_custom_normals[loop_index].vector = v.normals.xyz.normalized()
temp_custom_normals[loop_index].vector = v.normals.xyz.normalized()

# UV stuff
Expand Down

0 comments on commit 8e20c5d

Please sign in to comment.