Skip to content

Commit

Permalink
Update based on PR review (part 1).
Browse files Browse the repository at this point in the history
  • Loading branch information
Candoran2 committed Oct 28, 2023
1 parent 8c71f71 commit eb25fbb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version v0.1.01
Version v0.1.1
===============

- #591 Expansion of DisplayList processing and small fixes.
Expand All @@ -24,7 +24,7 @@ Version v0.1.01
- #592 Update to documentation
- #593 Supported export for Sid Meier's Pirates!.

Version v0.1.00
Version v0.1.0
===============

- #576 Updates to documentation, changelog and makezip.bat (copies over generated folder from cobra-tools).
Expand Down
37 changes: 17 additions & 20 deletions io_scene_niftools/modules/nif_import/armature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
# ***** END LICENSE BLOCK *****

import os
import numpy as np

import bpy
from bpy_extras.io_utils import orientation_helper
Expand Down Expand Up @@ -141,33 +142,29 @@ def store_bind_matrices(self, n_armature):
if isinstance(geom, NifClasses.BSTriShape):
vertex_data = geom.get_vertex_data()
if isinstance(geom, NifClasses.BSDynamicTriShape):
# BSDynamicTriShape uses Vector4 to store vertices with a 0 W component, which would
# nullify translation when multiplied by a Matrix44. Hence, first conversion to Vector3
# and assign the position values back later.
vertices = [NifClasses.Vector3.from_value((vertex.x, vertex.y, vertex.z)) for vertex in geom.vertices]
vertices = geom.vertices
else:
vertices = [vert_data.vertex for vert_data in vertex_data]

normals = [vert_data.normal for vert_data in vertex_data]
else:
vertices = geom.data.vertices
normals = geom.data.normals
for vert in vertices:
newvert = vert * diff
vert.x = newvert.x
vert.y = newvert.y
vert.z = newvert.z
diff33 = diff.get_matrix_33()
for norm in normals:
newnorm = norm * diff33
norm.x = newnorm.x
norm.y = newnorm.y
norm.z = newnorm.z
if isinstance(geom, NifClasses.BSDynamicTriShape):
for vertex, t_vertex in zip(geom.vertices, vertices):
vertex.x = t_vertex.x
vertex.y = t_vertex.y
vertex.z = t_vertex.z
# BSDynamicTriShape uses Vector4 to store vertices with a 0 W component, which would
# nullify translation when multiplied by a Matrix44. Hence, first conversion to three-component
# vector
np_vertices = np.array(vertices, dtype=float)[:,:3]
np_vertices = np.concatenate((np_vertices, np.ones((len(np_vertices), 1), dtype=float)), axis=1)
np_diff = np.array(diff.as_list())
np_vertices = np_vertices @ np_diff
np_normals = np.array(normals, dtype=float)
np_diff33 = np.array(diff.get_matrix_33().as_list())
np_normals = np_normals @ np_diff33
# assign the transformed values back
for vertex, t_vertex in zip(vertices, np_vertices[:, :3]):
vertex.x, vertex.y, vertex.z = t_vertex
for normal, t_normal in zip(normals, np_normals):
normal.x, normal.y, normal.z = t_normal
break
# store bind pose
for bonenode, bonedata in self.bones_iter(skininst):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#
# ***** END LICENSE BLOCK *****

import numpy as np

from nifgen.formats.nif import classes as NifClasses
from nifgen.formats.nif.nimesh.structs.DisplayList import DisplayList

Expand Down Expand Up @@ -127,8 +129,7 @@ def import_mesh(self, n_block, b_obj):
normals = None
else:
# for some reason, normals can be four-component structs instead of 3, discard the 4th.
if len(normals[0]) > 3:
normals = [(n[0], n[1], n[2]) for n in normals]
normals = np.array(normals)[:, :3]
elif isinstance(n_block, NifClasses.NiTriBasedGeom):

# shortcut for mesh geometry data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
#
# ***** END LICENSE BLOCK *****

from io_scene_niftools.utils.singleton import NifOp
import numpy as np

from io_scene_niftools.utils.singleton import NifOp


class Vertex:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ def get_bone_weights(ni_block):
for w, b_i in zip(vertex_weights, bone_indices):
if w > 0:
group_name = bone_names[b_i]
# conversion from numpy.uint16 to int necessary because Blender doesn't accept them
bone_weights_map[group_name].append((vert, w))
return bone_weights_map

Expand All @@ -268,6 +267,7 @@ def set_bone_weights(bone_weights, b_obj):
else:
v_group = b_obj.vertex_groups[bone_name]
for (v_index, weight) in index_weights:
# conversion from numpy.uint16 to int necessary because Blender doesn't accept them
v_group.add([int(v_index)], weight, 'REPLACE')

@staticmethod
Expand Down

0 comments on commit eb25fbb

Please sign in to comment.