Skip to content

Commit 34dff52

Browse files
committed
Release - 2.4.1
1 parent b4dd465 commit 34dff52

8 files changed

Lines changed: 228 additions & 154 deletions

File tree

addon/io_scs_tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"name": "SCS Tools",
2323
"description": "Setup models, Import-Export SCS data format",
2424
"author": "Simon Lusenc (50keda), Milos Zajic (4museman)",
25-
"version": (2, 4, "1909305e"),
25+
"version": (2, 4, "aeadde03"),
2626
"blender": (3, 2, 0),
2727
"location": "File > Import-Export",
2828
"doc_url": "http://modding.scssoft.com/wiki/Documentation/Tools/SCS_Blender_Tools",

addon/io_scs_tools/exp/pim/piece.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __calc_vertex_hash(index, normal, uvs, rgba, tangent):
7474
:return: calculated vertex hash
7575
:rtype: str
7676
"""
77-
fprec = 10 * 4
77+
fprec = 10 ** 4
7878

7979
if tangent:
8080
vertex_hash = (index,

addon/io_scs_tools/internals/containers/parsers/sii.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def parse_token(self):
108108

109109
else:
110110

111-
lprint("W No included SII file found, ignoring include: %r\n\t from: %r",
111+
lprint("D No included SII file found, ignoring include: %r\n\t from: %r",
112112
(match.group(1), self.filepath))
113113

114114
new_array = self.input[:self.current_line]

addon/io_scs_tools/operators/mesh.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,15 @@ def initialize(self, context):
416416
vcolor = mesh.color_attributes.new(name=layer_name, type='FLOAT_COLOR', domain='CORNER')
417417

418418
buffer = None
419+
color = list(Color((0.5,) * 3).from_srgb_to_scene_linear()) + [1.0, ] # our default is 0.5, even for alpha where 0.5 is also max
419420
if layer_name == _VCT_consts.ColoringLayersTypes.Color:
420-
buffer = numpy.array([0.5] * (len(mesh.loops) * 4))
421+
buffer = numpy.array(color * len(mesh.loops))
421422
elif layer_name == _VCT_consts.ColoringLayersTypes.Decal:
422-
buffer = numpy.array([1.0] * (len(mesh.loops) * 4))
423+
buffer = numpy.array(color * len(mesh.loops))
423424
elif layer_name == _VCT_consts.ColoringLayersTypes.AO:
424-
buffer = numpy.array([0.5] * (len(mesh.loops) * 4))
425+
buffer = numpy.array(color * len(mesh.loops))
425426
elif layer_name == _VCT_consts.ColoringLayersTypes.AO2:
426-
buffer = numpy.array([0.5] * (len(mesh.loops) * 4))
427+
buffer = numpy.array(color * len(mesh.loops))
427428

428429
if buffer is not None:
429430
vcolor.data.foreach_set("color", buffer)
@@ -534,6 +535,19 @@ def execute(self, context):
534535
if VertexColorTools.SCS_TOOLS_OT_StartVColoring.__static_is_active:
535536
return {'CANCELLED'}
536537

538+
# ensure our output layers definition
539+
#
540+
# NOTE: here is the deal: when switching to vertex paint mode
541+
# blender creates first color attribute if none is present.
542+
# As it happens it's name is the same as we use, so to ensure it creates proper
543+
# color type and domain we rather create our output layers beforehand.
544+
mesh_vcolors = context.active_object.data.color_attributes
545+
if _MESH_consts.default_vcol not in mesh_vcolors:
546+
mesh_vcolors.new(name=_MESH_consts.default_vcol, type='FLOAT_COLOR', domain='CORNER')
547+
548+
if _MESH_consts.default_vcol + _MESH_consts.vcol_a_suffix not in mesh_vcolors:
549+
mesh_vcolors.new(name=_MESH_consts.default_vcol + _MESH_consts.vcol_a_suffix, type='FLOAT_COLOR', domain='CORNER')
550+
537551
bpy.ops.object.mode_set(mode="VERTEX_PAINT")
538552

539553
# NOTE: We have to push undo event otherwise undo was just
@@ -629,7 +643,8 @@ def execute(self, context):
629643
lprint(message)
630644
self.report({'INFO'}, message[2:])
631645

632-
_view3d_utils.tag_redraw_all_view3d() # trigger view update to see rebaked colors
646+
# trigger view update to see rebaked colors, with fake reassignment.
647+
mesh.color_attributes.active_color = mesh.color_attributes.active_color
633648

634649
else:
635650

addon/io_scs_tools/operators/scene.py

Lines changed: 143 additions & 108 deletions
Large diffs are not rendered by default.

addon/io_scs_tools/properties/object.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717
# ##### END GPL LICENSE BLOCK #####
1818

19-
# Copyright (C) 2013-2021: SCS Software
19+
# Copyright (C) 2013-2022: SCS Software
2020

2121
import bpy
2222
from bpy.props import (StringProperty,
@@ -293,6 +293,10 @@ def update_empty_object_type(self, context):
293293
obj.empty_display_size = 5.0
294294
obj.empty_display_type = "ARROWS"
295295
obj.show_name = True
296+
297+
# ensure default part
298+
part_inventory = obj.scs_object_part_inventory
299+
_inventory.add_item(part_inventory, _PART_consts.default_name, conditional=True)
296300
else:
297301
obj.empty_display_size = 1.0
298302
obj.empty_display_type = "PLAIN_AXES"

addon/io_scs_tools/utils/convert.py

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
#
1717
# ##### END GPL LICENSE BLOCK #####
1818

19-
# Copyright (C) 2013-2021: SCS Software
19+
# Copyright (C) 2013-2022: SCS Software
2020

2121
import struct
2222
import math
2323
import re
24+
from numpy import vectorize
2425
from mathutils import Matrix, Quaternion, Vector, Color
2526
from io_scs_tools.consts import Colors as _COL_consts
2627
from io_scs_tools.utils.printout import lprint
@@ -32,9 +33,44 @@
3233
_BYTE_STRUCT = struct.Struct(">I")
3334

3435

36+
def __linear_to_srgb(x):
37+
"""Converts value from linear to srgb
38+
NOTE: taken from game and blender code
39+
40+
:param x: value to convert
41+
:type x: float
42+
"""
43+
44+
if x <= 0.0031308:
45+
return 12.92 * x
46+
else:
47+
return (x ** (1.0 / 2.4)) * 1.055 - 0.055
48+
49+
50+
def __srgb_to_linear(x):
51+
"""Converts value from linear to srgb
52+
NOTE: taken from game and blender code
53+
54+
:param x: value to convert
55+
:type x: float
56+
"""
57+
58+
if x <= 0.04045:
59+
return x / 12.92
60+
else:
61+
return ((x + 0.055) / 1.055) ** 2.4
62+
63+
64+
np_linear_to_srgb = vectorize(__linear_to_srgb)
65+
"""Vectorizes linear to srgb function to be used with numpy arrays."""
66+
67+
68+
np_srgb_to_linear = vectorize(__srgb_to_linear)
69+
"""Vectorizes srgb to linear function to be used with numpy arrays."""
70+
71+
3572
def linear_to_srgb(value):
3673
"""Converts linear color to srgb colorspace. Function can convert single float or list of floats.
37-
NOTE: taken from game code
3874
3975
:param value: list of floats or float
4076
:type value: float | collections.Iterable[float]
@@ -44,26 +80,13 @@ def linear_to_srgb(value):
4480

4581
is_float = isinstance(value, float)
4682
if is_float:
47-
vals = [value]
48-
else:
49-
vals = list(value)
50-
51-
for i, v in enumerate(vals):
52-
if v <= 0.0031308:
53-
vals[i] = 12.92 * v
54-
else:
55-
a = 0.055
56-
vals[i] = (v ** (1.0 / 2.4) * (1.0 + a)) - a
57-
58-
if is_float:
59-
return vals[0]
83+
return __linear_to_srgb(value)
6084
else:
61-
return vals
85+
return [__linear_to_srgb(v) for v in list(value)]
6286

6387

6488
def srgb_to_linear(value):
6589
"""Converts srgb color to linear colorspace. Function can convert single float or list of floats.
66-
NOTE: taken from game code
6790
6891
:param value: list of floats or float
6992
:type value: float | collections.Iterable[float]
@@ -73,22 +96,9 @@ def srgb_to_linear(value):
7396

7497
is_float = isinstance(value, float)
7598
if is_float:
76-
vals = [value]
77-
else:
78-
vals = list(value)
79-
80-
for i, v in enumerate(vals):
81-
82-
if v <= 0.04045:
83-
vals[i] = v / 12.92
84-
else:
85-
a = 0.055
86-
vals[i] = ((v + a) / (1.0 + a)) ** 2.4
87-
88-
if is_float:
89-
return vals[0]
99+
return __srgb_to_linear(value)
90100
else:
91-
return vals
101+
return [__srgb_to_linear(v) for v in list(value)]
92102

93103

94104
def pre_gamma_corrected_col(color):

addon/io_scs_tools/utils/mesh.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717
# ##### END GPL LICENSE BLOCK #####
1818

19-
# Copyright (C) 2013-2019: SCS Software
19+
# Copyright (C) 2013-2022: SCS Software
2020

2121
import bpy
2222
import bmesh
@@ -386,13 +386,14 @@ def vcoloring_rebake(mesh, vcolor_arrays, old_array_hash):
386386
mesh_vcolors.new(name=_MESH_consts.default_vcol + _MESH_consts.vcol_a_suffix, type='FLOAT_COLOR', domain='CORNER')
387387

388388
# get vertex color data for hash calculation
389-
if mesh_vcolors.active.name == _VCT_consts.ColoringLayersTypes.Color:
389+
active_color_name = mesh_vcolors.active_color.name
390+
if active_color_name == _VCT_consts.ColoringLayersTypes.Color:
390391
color_loops.foreach_get("color", vcolor_arrays[0])
391-
elif mesh_vcolors.active.name == _VCT_consts.ColoringLayersTypes.Decal:
392+
elif active_color_name == _VCT_consts.ColoringLayersTypes.Decal:
392393
decal_loops.foreach_get("color", vcolor_arrays[0])
393-
elif mesh_vcolors.active.name == _VCT_consts.ColoringLayersTypes.AO:
394+
elif active_color_name == _VCT_consts.ColoringLayersTypes.AO:
394395
ao_loops.foreach_get("color", vcolor_arrays[0])
395-
elif mesh_vcolors.active.name == _VCT_consts.ColoringLayersTypes.AO2:
396+
elif active_color_name == _VCT_consts.ColoringLayersTypes.AO2:
396397
ao2_loops.foreach_get("color", vcolor_arrays[0])
397398

398399
new_array_hash = hash(vcolor_arrays[0].tobytes())
@@ -406,7 +407,16 @@ def vcoloring_rebake(mesh, vcolor_arrays, old_array_hash):
406407
ao_loops.foreach_get("color", vcolor_arrays[2])
407408
ao2_loops.foreach_get("color", vcolor_arrays[3])
408409

410+
# convert to srgb
411+
for i in (0, 2, 3):
412+
vcolor_arrays[i] = _convert.np_linear_to_srgb(vcolor_arrays[i])
413+
414+
# combine
409415
vcolor_arrays[0] = vcolor_arrays[0] * vcolor_arrays[2] * vcolor_arrays[3] * 4.0
416+
417+
# convert back to scene linear
418+
vcolor_arrays[0] = _convert.np_srgb_to_linear(vcolor_arrays[0])
419+
410420
# alpha is donated only by decal layer color, thus we just comment it out
411421
# vcolor_arrays[1] = vcolor_arrays[1]
412422

0 commit comments

Comments
 (0)