Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for 'tsnmapcalc' Flavor #4

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
.vs/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
4 changes: 2 additions & 2 deletions addon/io_scs_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
bl_info = {
"name": "SCS Tools",
"description": "Setup models, Import-Export SCS data format",
"author": "Simon Lusenc (50keda), Milos Zajic (4museman)",
"version": (2, 4, "aeadde03"),
"author": "Simon Lusenc (50keda), Milos Zajic (4museman), Michal (Michaleczeq)",
"version": (2, 4, "aeadde03", 2),
"blender": (3, 2, 0),
"location": "File > Import-Export",
"doc_url": "http://modding.scssoft.com/wiki/Documentation/Tools/SCS_Blender_Tools",
Expand Down
52 changes: 52 additions & 0 deletions addon/io_scs_tools/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ class TrafficLightTypes(Enum):
Yellow = 1
Green = 2

class InteriorWindowTools:
"""Constants related to interior window tools
"""

class GlassReflection(Enum):
"""Defined states of glass reflection.
"""
Enable = 0
Disable = 1

class VertexColorTools:
"""Constants related to vertex color tools
Expand Down Expand Up @@ -444,6 +453,49 @@ class PIF:
TYPE_END = 0x00020000
TYPE_CROSS_SHARP = 0x00040000

class PSPCF:
"""Constants represetning spawn point custom flags.
"""
# Depot Types
DEPOT_TYPE_MASK = 0x00000004
DEPOT_TYPE_UNLOAD = 0x00000000
DEPOT_TYPE_LOAD = 0x00000004

# Difficulties
DIFFICULTY_MASK = 0x00000003
DIFFICULTY_NONE = 0x00000000
DIFFICULTY_EASY = 0x00000001
DIFFICULTY_MEDIUM = 0x00000002
DIFFICULTY_HARD = 0x00000003

# Lenght
LENGHT_MASK = 0x000000F0
LENGHT_14 = 0x00000000
LENGHT_15 = 0x00000010
LENGHT_16 = 0x00000020
LENGHT_17 = 0x00000030
LENGHT_18 = 0x00000040
LENGHT_19 = 0x00000050
LENGHT_20 = 0x00000060
LENGHT_21 = 0x00000070
LENGHT_22 = 0x00000080
LENGHT_23 = 0x00000090
LENGHT_24 = 0x000000A0
LENGHT_25 = 0x000000B0
LENGHT_26 = 0x000000C0
LENGHT_27 = 0x000000D0
LENGHT_28 = 0x000000E0
UNLIMITED = 0x000000F0

# Rule
TRAILER_MASK = 0x000F0000
TRAILER_ANY = 0x00000000
TRAILER_BOX = 0x00010000
TRAILER_TANK = 0x00020000
TRAILER_DUMP_BULK = 0x00030000
TRAILER_PLATFORM_LOG_CONT = 0x00040000
TRAILER_LIVESTOCK = 0x00050000
TRAILER_LOG = 0x00060000

class Bones:
init_scale_key = "scs_init_scale"
Expand Down
20 changes: 20 additions & 0 deletions addon/io_scs_tools/exp/pim/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ def __init__(self, index, alias, effect, blend_mat):

self.__used_textures_without_uv_count += 1

if blend_mat and "scs_shader_attributes" in blend_mat and "mappings" in blend_mat["scs_shader_attributes"]:
for tex_entry in blend_mat["scs_shader_attributes"]["mappings"].values():
self.__used_textures_count += 1
if "Tag" in tex_entry:
tex_type = tex_entry["Tag"]
mappings = getattr(blend_mat.scs_props, "shader_mapping_" + tex_type, [])

for uv_map_i, uv_map in enumerate(mappings):
if uv_map.value != "": # filter out none specified mappings

tex_coord_map[uv_map.tex_coord] = uv_map.value

elif uv_map.tex_coord != -1: # if tex coord is -1 texture doesn't use uvs
lprint("W Mapping type '%s' on material '%s' is missing UV mapping value, expect problems in game!",
(tex_type, blend_mat.name))

else: # if texture doesn't have mappings it means uv is not required for it

self.__used_textures_without_uv_count += 1

# create uv layer map with used tex_coord on it (this tex_coords now represents aliases for given uv layers)
# It also uses ordered dictionary because order of keys now defines actually physical order for uvs in PIM file
self.__uvs_map_by_name = OrderedDict()
Expand Down
2 changes: 2 additions & 0 deletions addon/io_scs_tools/exp/pip/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ def execute(dirpath, filename, name_suffix, prefab_locator_list, offset_matrix,

spawn_point.set_type(int(locator_scs_props.locator_prefab_spawn_type))

spawn_point.set_flags(locator_scs_props)

pip_spawn_points.append(spawn_point)

# semaphores creation
Expand Down
24 changes: 24 additions & 0 deletions addon/io_scs_tools/exp/pip/spawn_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, name):
self.__position = (0.,) * 3
self.__rotation = (1.,) + (0.,) * 3
self.__type = 0 # NONE
self.__flags = 0 # NONE

SpawnPoint.__global_spawn_point_counter += 1

Expand Down Expand Up @@ -74,6 +75,28 @@ def set_type(self, sp_type):
"""
self.__type = sp_type

def set_flags(self, sp_flags):
"""Set flags of spawn point.

NOTE: there is no safety check if value is valid,
make sure that prefab locator properties are synced with PSPCF_* consts.

:param sp_flags: integer flags of spawn point
:type sp_flags: int
"""

# depot type
self.__flags |= int(sp_flags.locator_prefab_custom_depot_type)

# parking difficulty
self.__flags |= int(sp_flags.locator_prefab_custom_parking_difficulty)

# lenght
self.__flags |= int(sp_flags.locator_prefab_custom_lenght)

# rule
self.__flags |= int(sp_flags.locator_prefab_custom_rule)

def get_as_section(self):
"""Get spawn point information represented with SectionData structure class.

Expand All @@ -86,5 +109,6 @@ def get_as_section(self):
section.props.append(("Position", ["&&", tuple(self.__position)]))
section.props.append(("Rotation", ["&&", tuple(self.__rotation)]))
section.props.append(("Type", self.__type))
section.props.append(("Flags", self.__flags))

return section
27 changes: 23 additions & 4 deletions addon/io_scs_tools/imp/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _get_sign_properties(section):
def _get_spawn_properties(section):
"""Receives a Spawn section and returns its properties in its own variables.
For any item that fails to be found, it returns None."""
spawn_name = spawn_position = spawn_rotation = spawn_type = None
spawn_name = spawn_position = spawn_rotation = spawn_type = spawn_flags = None
for prop in section.props:
if prop[0] in ("", "#"):
pass
Expand All @@ -219,9 +219,11 @@ def _get_spawn_properties(section):
spawn_rotation = prop[1]
elif prop[0] == "Type":
spawn_type = prop[1]
elif prop[0] == "Flags":
spawn_flags = prop[1]
else:
lprint('\nW Unknown property in "Spawn" data: "%s"!', prop[0])
return spawn_name, spawn_position, spawn_rotation, spawn_type
return spawn_name, spawn_position, spawn_rotation, spawn_type, spawn_flags


def _get_t_light_properties(section):
Expand Down Expand Up @@ -450,12 +452,23 @@ def _create_spawn_locator(
spawn_name,
spawn_position,
spawn_rotation,
spawn_type
spawn_type,
spawn_flags
):
locator = _object_utils.create_locator_empty(spawn_name, spawn_position, spawn_rotation, (1, 1, 1), 0.1, 'Prefab')
if locator:
locator.scs_props.locator_prefab_type = 'Spawn Point'
locator.scs_props.locator_prefab_spawn_type = str(spawn_type)

# flags for custom spawn type

# check if Spawn Type = Custom (9)
if locator.scs_props.locator_prefab_spawn_type == str(_PL_consts.PSP.CUSTOM):
locator.scs_props.locator_prefab_custom_depot_type = str(spawn_flags & _PL_consts.PSPCF.DEPOT_TYPE_MASK)
locator.scs_props.locator_prefab_custom_parking_difficulty = str(spawn_flags & _PL_consts.PSPCF.DIFFICULTY_MASK)
locator.scs_props.locator_prefab_custom_lenght = str(spawn_flags & _PL_consts.PSPCF.LENGHT_MASK)
locator.scs_props.locator_prefab_custom_rule = str(spawn_flags & _PL_consts.PSPCF.TRAILER_MASK)

return locator


Expand Down Expand Up @@ -732,18 +745,23 @@ def load(filepath, terrain_points_trans):
(spawn_name,
spawn_position,
spawn_rotation,
spawn_type) = _get_spawn_properties(section)
spawn_type,
spawn_flags) = _get_spawn_properties(section)

if spawn_name is None:
spawn_name = str('Sign_Locator_' + str(spawn_index))
else:
spawn_name = _name_utils.get_unique(spawn_name, spawn_points_data.keys())

if spawn_flags is None:
spawn_flags = int(0)

spawn_points_data[spawn_name] = (
spawn_index,
spawn_position,
spawn_rotation,
spawn_type,
spawn_flags,
)
spawn_index += 1
elif section.type == 'Semaphore': # former "TrafficLight"
Expand Down Expand Up @@ -915,6 +933,7 @@ def load(filepath, terrain_points_trans):
spawn_points_data[name][1],
spawn_points_data[name][2],
spawn_points_data[name][3],
spawn_points_data[name][4], # sp_flags
)
if loc:
_print_locator_result(loc, "Spawn Point", name)
Expand Down
7 changes: 7 additions & 0 deletions addon/io_scs_tools/imp/pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ def _get_look(section):
mat_effect = mat_effect.replace(".night", ".day")
lprint("W Night version of building shader detected in material %r, switching it to day!", (mat_alias,))

# If day/night version of "window" shader is detected, switch it to "lit".
if mat_effect.startswith("eut2.window") and mat_effect.endswith((".day", ".night")):

mat_effect = mat_effect.replace(".day", ".lit").replace(".night", ".lit")

lprint("W Outdated Day or Night version of window shader detected in material %r, switching it to lit!", (mat_alias,))

look_mat_settings[mat_alias] = (mat_effect, mat_flags, attributes, textures, sec)

return look_name, look_mat_settings
Expand Down
28 changes: 13 additions & 15 deletions addon/io_scs_tools/internals/open_gl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import bpy
import blf
import bgl
import gpu
from mathutils import Vector
from gpu_extras.presets import draw_texture_2d
from io_scs_tools.consts import Operators as _OP_consts
Expand Down Expand Up @@ -139,15 +139,14 @@ def _draw_3dview_report(window, area, region):
# draw BT banner
(bindcode, width, height) = _Show3DViewReport.get_scs_banner_img_data(window)

bgl.glEnable(bgl.GL_BLEND)
bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
gpu.state.blend_set("ALPHA")
draw_texture_2d(bindcode, (pos_x - 5, pos_y), width, height)
bgl.glDisable(bgl.GL_BLEND)
gpu.state.blend_set("NONE")

# draw control buttons, if controls are enabled
if _Show3DViewReport.has_controls(window):

blf.size(0, 20, 72)
blf.size(0, 20)
blf.color(0, .8, .8, .8, 1)

# set x and y offsets to report operator, so that area calculations for buttons can be calculated properly
Expand Down Expand Up @@ -187,7 +186,7 @@ def _draw_3dview_report(window, area, region):
# draw scroll controls
if _Show3DViewReport.is_scrolled() and _Show3DViewReport.is_shown():

blf.size(0, 16, 72)
blf.size(0, 16)

# draw scroll up button
scroll_up_pos = (
Expand Down Expand Up @@ -243,7 +242,7 @@ def _draw_3dview_report(window, area, region):

# draw version string
pos_y -= 12
blf.size(0, 11, 72)
blf.size(0, 11)
blf.color(0, 0.909803921568627, .631372549019608, .0627450980392157, 1)
blf.shadow(0, 0, 0, 0, 0, 1)
blf.position(0, pos_x, pos_y, 0)
Expand All @@ -253,7 +252,7 @@ def _draw_3dview_report(window, area, region):
# draw actual operator title and message if shown
if _Show3DViewReport.is_shown():

blf.size(0, 12, 72)
blf.size(0, 12)
blf.color(0, 1, 1, 1, 1)
blf.shadow(0, 0, 0, 0, 0, 1)

Expand Down Expand Up @@ -322,7 +321,7 @@ def _draw_3dview_immediate_report(region):
)

# set size of the immidete text
blf.size(0, 18, 72)
blf.size(0, 18)
blf.color(0, .952, .635, .062, 1)

# draw on center of the region
Expand Down Expand Up @@ -457,16 +456,15 @@ def draw_custom_3d_elements(mode):
return

if mode == "Normal":
bgl.glEnable(bgl.GL_DEPTH_TEST)
bgl.glEnable(bgl.GL_BLEND)
bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
gpu.state.depth_test_set("LESS")
gpu.state.blend_set("ALPHA")

# draw buffers
_primitive.draw_buffers(bpy.context.space_data)

if mode == "Normal":
bgl.glDisable(bgl.GL_DEPTH_TEST)
bgl.glDisable(bgl.GL_BLEND)
gpu.state.depth_test_set("NONE")
gpu.state.blend_set("NONE")


def draw_custom_2d_elements():
Expand Down Expand Up @@ -495,7 +493,7 @@ def draw_custom_2d_elements():
return

font_id = 0 # default font
blf.size(font_id, 12, 72)
blf.size(font_id, 12)
blf.color(font_id, scs_globals.info_text_color[0], scs_globals.info_text_color[1], scs_globals.info_text_color[2], 1.0)
blf.word_wrap(font_id, 999)
blf.enable(font_id, blf.WORD_WRAP)
Expand Down
Loading