Skip to content

Commit 1c06432

Browse files
committed
feat: implement unit scaling for SoulWorker models and update related file import processes
1 parent 6609335 commit 1c06432

5 files changed

Lines changed: 27 additions & 11 deletions

File tree

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,3 @@ Press N *(keyboard button)* -> SoulWorker *(tab)*:
6060

6161
- Some models use materials that are not in the root folder.
6262
Please unpack the game resources **keeping the original structure**.
63-
- The scale of the models in the game is **very large**. If you can't see anything but the object appears in the **Outliner**, increase the draw distance.
64-
65-
Press N *(keyboard)* -> View *(tab)* -> End *(input)*.
66-
67-
I set it to **30_000 m**.

io_soulworker/chunks/vmsh_chunk.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from io_soulworker.core.binary_reader import BinaryReader
44
from io_soulworker.core.binary_writer import BinaryWriter
55
from io_soulworker.core.data_exchange import DataExchange_cl
6+
from io_soulworker.unit_scale import BLENDER_TO_GAME, GAME_TO_BLENDER
67
from io_soulworker.core.utility import indices_to_face
78
from io_soulworker.core.vis_chunk_id import VisChunkId
89
from io_soulworker.core.vis_index_format import VisIndexFormat
@@ -126,7 +127,13 @@ def read(self, reader: BinaryReader) -> None:
126127
reader.seek(t + off)
127128

128129
pos = reader.read_vector3()
129-
self.vertices.append([pos.x, pos.y, pos.z])
130+
self.vertices.append(
131+
[
132+
pos.x * GAME_TO_BLENDER,
133+
pos.y * GAME_TO_BLENDER,
134+
pos.z * GAME_TO_BLENDER,
135+
]
136+
)
130137

131138
if self.descriptor.has_component(self.descriptor.normal_offset):
132139

@@ -279,7 +286,14 @@ def __write_vertices(self, writer: BinaryWriter, vertex_count: int) -> None:
279286

280287
off = self.descriptor.offset_of(self.descriptor.pos_offset)
281288
x, y, z = self.__vector3_at(self.vertices, index)
282-
pack_into("<fff", raw, off, x, y, z)
289+
pack_into(
290+
"<fff",
291+
raw,
292+
off,
293+
x * BLENDER_TO_GAME,
294+
y * BLENDER_TO_GAME,
295+
z * BLENDER_TO_GAME,
296+
)
283297

284298
if self.descriptor.has_component(self.descriptor.normal_offset):
285299

io_soulworker/file_import/animation/file_reader.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from io_soulworker.chunks.skel_chunk import VisSkeletonChunk_cl
1414
from io_soulworker.file_import.animation.action_builder import group_keyframes_by_bone
1515
from io_soulworker.file_import.animation.chunk_reader import AnimationFileChunkReader
16+
from io_soulworker.unit_scale import GAME_TO_BLENDER
1617

1718

1819
@dataclass(frozen=True)
@@ -236,7 +237,7 @@ def _add_transform_curves(
236237
pose_bone.rotation_mode = 'QUATERNION'
237238
positions_by_bone[bone_name] = {
238239
frame: self._remap_translation(
239-
position,
240+
position * GAME_TO_BLENDER,
240241
source_ref,
241242
target_ref
242243
)
@@ -315,6 +316,9 @@ def _add_transform_curves(
315316
4,
316317
)
317318

319+
action.frame_start = int(key_frames[0])
320+
action.frame_end = int(key_frames[-1])
321+
318322
def _source_skeleton_refs(self, fallback_bone_names: list[str]) -> list[SkeletonBoneRef]:
319323
skeleton = self._skeleton_at_index(self.skeleton_index)
320324

@@ -339,7 +343,7 @@ def _bone_refs_from_chunk(chunk: VisSkeletonChunk_cl) -> list[SkeletonBoneRef]:
339343
SkeletonBoneRef(
340344
name=bone.name,
341345
parent_name=bone_names_by_id.get(bone.parent_id),
342-
local_position=bone.local_space_position.copy(),
346+
local_position=bone.local_space_position * GAME_TO_BLENDER,
343347
local_orientation=bone.local_space_orientation.copy(),
344348
)
345349
for bone in chunk.bones

io_soulworker/file_import/armature_builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from io_soulworker.chunks.skel_chunk import VisSkeletalBone_cl
88
from io_soulworker.chunks.skel_chunk import VisSkeletonChunk_cl
99
from io_soulworker.file_import.model.skeleton_builder import build_bone_transforms
10+
from io_soulworker.unit_scale import GAME_TO_BLENDER
1011

1112

1213
class NameHelper:
@@ -99,7 +100,7 @@ def build_armature_from_skeleton(
99100

100101
def bone_local_matrix(bone):
101102
matrix = bone.local_space_orientation.to_matrix().to_4x4()
102-
matrix.translation = bone.local_space_position
103+
matrix.translation = bone.local_space_position * GAME_TO_BLENDER
103104

104105
return matrix
105106

@@ -132,7 +133,7 @@ def bone_local_matrix(bone):
132133
{
133134
"name": bone.name,
134135
"parent_id": bone.parent_id,
135-
"local_position": _vector_to_list(bone.local_space_position),
136+
"local_position": _vector_to_list(bone.local_space_position * GAME_TO_BLENDER),
136137
"local_orientation": _quaternion_to_list(bone.local_space_orientation),
137138
}
138139
for bone in chunk.bones

io_soulworker/unit_scale.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GAME_TO_BLENDER = 0.01
2+
BLENDER_TO_GAME = 100.0

0 commit comments

Comments
 (0)