Skip to content

Commit

Permalink
Fix showing J3D preview resulting in changes to the original J3D mode…
Browse files Browse the repository at this point in the history
…l being saved to RAM
  • Loading branch information
LagoLunatic committed Dec 27, 2024
1 parent 74bdd12 commit 0bc5cb5
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions gcft_ui/j3d_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
from io import BytesIO
import time
import copy
from PySide6.QtGui import *
from PySide6.QtCore import *
from PySide6.QtWidgets import *
Expand Down Expand Up @@ -373,11 +374,10 @@ def guesstimate_model_bbox(self, j3d_model: J3D) -> tuple[np.ndarray, np.ndarray
def get_preview_compatible_j3d(self, orig_j3d: J3D) -> J3D:
# return orig_j3d

# We have to save the original J3D for the changes to its chunks to be reflected properly.
# Simply copying orig_j3d.data is not sufficient on its own.
orig_j3d.save()
# TODO: implement copying just the instance, without having to serialize and deserialize it here.
hack_j3d = J3D(fs.make_copy_data(orig_j3d.data))
# Making a copy of the orig_j3d's data bytes or its instance wouldn't be enough for the changes
# to its chunks to be reflected properly. So we make a deepcopy of it instead.
# Then we modify that copy with some hacks and save that, then use those bytes for the preview.
hack_j3d = copy.deepcopy(orig_j3d)
chunks_modified = set()

# Wind Waker has a hardcoded system where the textures that control toon shading are dynamically
Expand Down Expand Up @@ -423,11 +423,8 @@ def get_preview_compatible_j3d(self, orig_j3d: J3D) -> J3D:
# del hack_j3d.mat3.materials[mat_index]
chunks_modified.add("MAT3")

if chunks_modified:
hack_j3d.save(only_chunks=chunks_modified)
return hack_j3d
else:
return orig_j3d
hack_j3d.save()
return hack_j3d

#region Animation

Expand Down

0 comments on commit 0bc5cb5

Please sign in to comment.