Skip to content

Commit

Permalink
Beta - 0.4.1
Browse files Browse the repository at this point in the history
Changelog:
- revisited handling of export paths, "Global Export Path" removed
and "Default Export Path" used instead
- improved reporting of successfully exported SCS Game Objects
- added extra warning buttons for export paths with guidance how to solve
the problem
- improved saving of blend file, Blender files should now be up to 8 times
smaller
  • Loading branch information
simon50keda committed Feb 24, 2015
1 parent 4ba0069 commit 11df243
Show file tree
Hide file tree
Showing 43 changed files with 400 additions and 631 deletions.
62 changes: 38 additions & 24 deletions addon/io_scs_tools/exp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@

# Copyright (C) 2013-2014: SCS Software

import bpy
import os

from io_scs_tools.exp import pia
from io_scs_tools.exp import pic
from io_scs_tools.exp import pip
from io_scs_tools.exp import pis
from io_scs_tools.exp import pix

from io_scs_tools.utils import object as _object
from io_scs_tools.utils import path as _path
from io_scs_tools.utils import get_scs_globals as _get_scs_globals
from io_scs_tools.utils.printout import lprint

Expand All @@ -50,57 +52,69 @@ def batch_export(operator_instance, init_obj_list, exclude_switched_off=True, me
game_objects_dict = _object.exclude_switched_off(game_objects_dict)

if game_objects_dict:
scs_game_objects_exported = 0
scs_game_objects_exported = []

# GET GLOBAL FILE PATH
global_export_filepath = _get_scs_globals().global_export_filepath
global_filepath = _path.get_blenderfilewise_abs_filepath(global_export_filepath)
scs_project_path = _get_scs_globals().scs_project_path
is_blend_file_within_base = bpy.data.filepath != "" and bpy.data.filepath.startswith(scs_project_path)
default_export_path = bpy.context.scene.scs_props.default_export_filepath
# if not set try to use Blender filepath
if default_export_path == "" and is_blend_file_within_base:
global_filepath = os.path.dirname(bpy.data.filepath)
else:
global_filepath = os.path.join(scs_project_path, default_export_path.strip(os.sep * 2))

for root_object in game_objects_dict:
game_object_list = game_objects_dict[root_object]

# GET CUSTOM FILE PATH
scs_root_object_export_filepath = root_object.scs_props.scs_root_object_export_filepath
# print(' scs_root_object_export_filepath:\n%r' % str(scs_root_object_export_filepath))
custom_filepath = _path.get_blenderfilewise_abs_filepath(scs_root_object_export_filepath, data_type="'SCS Game Object' custom export")
# print(' custom_filepath (%r):\n%r' % (root_object.name, str(custom_filepath)))
custom_filepath = None
if root_object.scs_props.scs_root_object_allow_custom_path:
scs_root_export_path = root_object.scs_props.scs_root_object_export_filepath
# if not set try to use Blender filepath
if scs_root_export_path == "" and is_blend_file_within_base:
custom_filepath = os.path.dirname(bpy.data.filepath)
print("Custom filepath for Blend file!")
else:
custom_filepath = os.path.join(scs_project_path, scs_root_export_path.strip(os.sep * 2))
print("Custom filepath:", custom_filepath)

# MAKE FINAL FILEPATH
filepath = None
if menu_filepath:
filepath = menu_filepath
elif scs_root_object_export_filepath and custom_filepath and root_object.scs_props.scs_root_object_allow_custom_path:
filepath_message = "Export path selected in file browser:\n\t \"" + filepath + "\""
elif custom_filepath:
filepath = custom_filepath
elif global_filepath:
filepath_message = "Custom export path used for \"" + root_object.name + "\" is:\n\t \"" + filepath + "\""
else:
filepath = global_filepath
filepath_message = "Default export path used for \"" + root_object.name + "\":\n\t \"" + filepath + "\""

# print(' filepath (%r):\n%r' % (root_object.name, str(filepath)))
scs_project_path = _get_scs_globals().scs_project_path
if filepath and filepath.startswith(scs_project_path) and scs_project_path != "":
if os.path.isdir(filepath) and filepath.startswith(scs_project_path) and scs_project_path != "":
pix.export(filepath, root_object, game_object_list)
scs_game_objects_exported += 1
scs_game_objects_exported.append("> \"" + root_object.name + "\" exported to: '" + filepath + "'")
# if result != {'FINISHED'}: return {'CANCELLED'}
else:
if filepath:
message = (
"No valid export inside SCS Project Base Path found!\n\t "
"Make sure that SCS Project Base Path is properly set and\n\t " +
"that you are exporting somewhere inside that path!\n\t " +
"No valid export path found!\n\t " +
"Export path does not exists or it's not inside SCS Project Base Path.\n\t " +
"SCS Project Base Path:\n\t \"" + scs_project_path + "\"\n\t " +
"SCS Game Object export path:\n\t \"" + filepath + "\""
filepath_message
)
else:
message = "No valid export path found! Please check the export path."
message = "No valid export path found! Please check \"SCS Project Base Path\" first."
lprint('E ' + message)
operator_instance.report({'ERROR'}, message.replace("\t", "").replace(" ", ""))
return {'CANCELLED'}

if scs_game_objects_exported > 0:
if scs_game_objects_exported == 1:
message = "Single 'SCS Game Object' exported."
else:
message = "%i 'SCS Game Objects' exported." % scs_game_objects_exported
lprint('I ' + message)
lprint("\nI Export procces completed, summaries are printed below!", report_errors=True, report_warnings=True)
if len(scs_game_objects_exported) > 0:
print("\n\nEXPORTED GAME OBJECTS:\n" + "=" * 22)
for scs_game_object_export_message in scs_game_objects_exported:
print(scs_game_object_export_message)
else:
message = "Nothing to export! Please set at least one 'SCS Root Object'."
lprint('E ' + message)
Expand Down
5 changes: 3 additions & 2 deletions addon/io_scs_tools/exp/pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _get_texture_path_from_material(material, texture_type, export_path):
texture_abs_filepath = _path_utils.get_abs_path(texture_raw_path)

# TOBJ PATH
scs_project_path = _get_scs_globals().scs_project_path
scs_project_path = _get_scs_globals().scs_project_path.rstrip("\\").rstrip("/")
if os.path.isfile(scs_project_path + os.sep + texture_raw_path): # relative within base

tobj_rel_filepath = os.path.splitext(texture_raw_path)[0][1:]
Expand Down Expand Up @@ -191,7 +191,8 @@ def _get_texture_path_from_material(material, texture_type, export_path):
# export tobj only if file of texture exists
if os.path.isfile(texture_abs_filepath):
settings = getattr(material.scs_props, "shader_" + texture_type + "_settings", set())
_tobj.export(tobj_abs_filepath, os.path.split(texture_raw_path)[1], settings)
texture_name = os.path.basename(_path_utils.strip_sep(texture_raw_path))
_tobj.export(tobj_abs_filepath, texture_name, settings)
else:
lprint("E Texture file %r from material %r doesn't exists, TOBJ can not be exported!",
(texture_raw_path, material.name))
Expand Down
4 changes: 1 addition & 3 deletions addon/io_scs_tools/exp/pix.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def export(dirpath, root_object, game_object_list):
# FINAL FEEDBACK
context.window.cursor_modal_restore()
if export_success:
lprint('\nI Export compleeted in %.3f sec. Files were saved to folder:\n\t %r\n', (time.time() - t, dirpath),
report_errors=True,
report_warnings=True)
lprint('\nI Export compleeted in %.3f sec. Files were saved to folder:\n\t %r\n', (time.time() - t, dirpath))
else:
lprint("E Nothing to export! Please set a 'SCS Root Object'...", report_errors=True)

Expand Down
6 changes: 5 additions & 1 deletion addon/io_scs_tools/internals/callbacks/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def enable():
bpy.app.handlers.load_post.append(_persistent_init.initialise_scs_dict)

bpy.app.handlers.scene_update_post.append(_persistent_loop.object_data_check)

bpy.app.handlers.save_pre.append(_persistent_file_save.pre_save)
bpy.app.handlers.save_post.append(_persistent_file_save.post_save)


def disable():
Expand All @@ -48,4 +50,6 @@ def disable():
if _persistent_loop.object_data_check in bpy.app.handlers.scene_update_post:
bpy.app.handlers.scene_update_post.remove(_persistent_loop.object_data_check)
if _persistent_file_save.pre_save in bpy.app.handlers.save_pre:
bpy.app.handlers.save_pre.remove(_persistent_file_save.pre_save)
bpy.app.handlers.save_pre.remove(_persistent_file_save.pre_save)
if _persistent_file_save.post_save in bpy.app.handlers.save_pre:
bpy.app.handlers.save_pre.remove(_persistent_file_save.post_save)
24 changes: 13 additions & 11 deletions addon/io_scs_tools/internals/containers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ def update_shader_presets_path(scs_shader_presets_inventory, shader_presets_file
new_shader_preset = scs_shader_presets_inventory.add()
new_shader_preset.name = preset_name
else:
lprint('\nW The file path "%s" is not valid!', shader_presets_abs_path)
lprint('\nW The file path "%s" is not valid!', (shader_presets_abs_path,))

update_item_in_file('Paths.ShaderPresetsFilePath', shader_presets_filepath)


def update_sign_library_rel_path(scs_sign_model_inventory, sign_library_rel_path):
def update_sign_library_rel_path(scs_sign_model_inventory, sign_library_rel_path, readonly=False):
"""The function deletes and populates again a list of Sign names in inventory. It also updates corresponding record in config file.
:param sign_library_rel_path: Relative path to the directory with Sign files
Expand Down Expand Up @@ -164,12 +164,12 @@ def update_sign_library_rel_path(scs_sign_model_inventory, sign_library_rel_path

else:
print(' sign_library_rel_path: "%s"' % str(sign_library_rel_path))
# print(' sign_library_filepath:\n%s' % str(sign_library_filepath))

if not readonly:
update_item_in_file('Paths.SignRelFilePath', sign_library_rel_path)


def update_tsem_library_rel_path(scs_tsem_profile_inventory, tsem_library_rel_path):
def update_tsem_library_rel_path(scs_tsem_profile_inventory, tsem_library_rel_path, readonly=False):
"""The function deletes and populates again a list of Traffic Semaphore Profile names in inventory. It also updates corresponding record in
config file.
Expand Down Expand Up @@ -203,10 +203,11 @@ def update_tsem_library_rel_path(scs_tsem_profile_inventory, tsem_library_rel_pa
else:
print(' tsem_library_rel_path: "%s"' % str(tsem_library_rel_path))

if not readonly:
update_item_in_file('Paths.TSemProfileRelFilePath', tsem_library_rel_path)


def update_traffic_rules_library_rel_path(scs_traffic_rules_inventory, traffic_rules_library_rel_path):
def update_traffic_rules_library_rel_path(scs_traffic_rules_inventory, traffic_rules_library_rel_path, readonly=False):
"""The function deletes and populates again a list of Traffic Rules names in inventory. It also updates corresponding record in config file.
:param traffic_rules_library_rel_path: Relative path to the directory with Traffic Rules files
Expand Down Expand Up @@ -237,10 +238,11 @@ def update_traffic_rules_library_rel_path(scs_traffic_rules_inventory, traffic_r
else:
print(' traffic_rules_library_rel_path: "%s"' % str(traffic_rules_library_rel_path))

if not readonly:
update_item_in_file('Paths.TrafficRulesRelFilePath', traffic_rules_library_rel_path)


def update_hookup_library_rel_path(scs_hookup_inventory, hookup_library_rel_path):
def update_hookup_library_rel_path(scs_hookup_inventory, hookup_library_rel_path, readonly=False):
"""The function deletes and populates again a list of Hookup names in inventory. It also updates corresponding record in config file.
:param hookup_library_rel_path: Relative path to the directory with Hookup files
Expand Down Expand Up @@ -291,10 +293,11 @@ def update_hookup_library_rel_path(scs_hookup_inventory, hookup_library_rel_path
if '.svn' in dirs:
dirs.remove('.svn') # ignore SVN

update_item_in_file('Paths.HookupRelDirPath', hookup_library_rel_path)
if not readonly:
update_item_in_file('Paths.HookupRelDirPath', hookup_library_rel_path)


def update_matsubs_inventory(scs_matsubs_inventory, matsubs_library_rel_path):
def update_matsubs_inventory(scs_matsubs_inventory, matsubs_library_rel_path, readonly=False):
"""The function deletes and populates again a list of Material Substance names in inventory. It also updates corresponding record in config file.
:param matsubs_library_rel_path: Relative path to the directory with Material Substance files
Expand Down Expand Up @@ -330,6 +333,7 @@ def update_matsubs_inventory(scs_matsubs_inventory, matsubs_library_rel_path):
else:
print(' matsubs_library_rel_path: "%s"' % str(matsubs_library_rel_path))

if not readonly:
update_item_in_file('Paths.MatSubsRelFilePath', matsubs_library_rel_path)


Expand All @@ -341,9 +345,7 @@ def fill_header_section():
section = _SectionData("Header")
section.props.append(("FormatVersion", 1))
blender_version, blender_build = _info.get_blender_version()
section.props.append(("Source", "Blender " + blender_version + blender_build + ", SCS Blender Tools " + str(_info.get_tools_version(

))))
section.props.append(("Source", "Blender " + blender_version + blender_build + ", SCS Blender Tools " + str(_info.get_tools_version())))
section.props.append(("Type", "Configuration"))
section.props.append(("Note", "User settings of SCS Blender Tools"))
author = bpy.context.user_preferences.system.author
Expand Down
44 changes: 43 additions & 1 deletion addon/io_scs_tools/internals/persistent/file_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import bpy
from bpy.app.handlers import persistent
from io_scs_tools.internals.containers import config as _config_container
from io_scs_tools.consts import Icons as _ICONS_consts
from io_scs_tools.utils import get_scs_globals as _get_scs_globals


@persistent
Expand All @@ -33,4 +35,44 @@ def pre_save(scene):
img.use_fake_user = False
img.user_clear()

bpy.data.images.remove(img)
bpy.data.images.remove(img)

# clear all not needed inventories
scs_globals = _get_scs_globals()
scs_globals.scs_hookup_inventory.clear()
scs_globals.scs_matsubs_inventory.clear()
scs_globals.scs_sign_model_inventory.clear()
scs_globals.scs_traffic_rules_inventory.clear()
scs_globals.scs_tsem_profile_inventory.clear()


@persistent
def post_save(scene):
# reaload inventories
readonly = True
scs_globals = _get_scs_globals()
_config_container.update_hookup_library_rel_path(
scs_globals.scs_hookup_inventory,
scs_globals.hookup_library_rel_path,
readonly
)
_config_container.update_matsubs_inventory(
scs_globals.scs_matsubs_inventory,
scs_globals.matsubs_library_rel_path,
readonly
)
_config_container.update_traffic_rules_library_rel_path(
scs_globals.scs_traffic_rules_inventory,
scs_globals.traffic_rules_library_rel_path,
readonly
)
_config_container.update_tsem_library_rel_path(
scs_globals.scs_tsem_profile_inventory,
scs_globals.tsem_library_rel_path,
readonly
)
_config_container.update_sign_library_rel_path(
scs_globals.scs_sign_model_inventory,
scs_globals.sign_library_rel_path,
readonly
)
12 changes: 12 additions & 0 deletions addon/io_scs_tools/internals/persistent/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from io_scs_tools.internals.containers import config as _config_container
from io_scs_tools.internals.connections.wrappers import group as _connections_group_wrapper
from io_scs_tools.internals.icons import wrapper as _icons_wrapper
from io_scs_tools.utils import path as _path_utils
from io_scs_tools.utils import get_scs_globals as _get_scs_globals
from io_scs_tools.utils.printout import lprint

Expand Down Expand Up @@ -78,6 +79,17 @@ def initialise_scs_dict(scene):
lprint("\nW The Project Path %r is NOT VALID!\n\tPLEASE SELECT A VALID PATH TO THE PROJECT BASE FOLDER.\n",
(_get_scs_globals().scs_project_path,))

# FIX PLATFORM RELATED PATHS
for obj in bpy.data.objects:
if obj.scs_props.empty_object_type == "SCS_Root":
_path_utils.fix_sep_by_platform(obj.scs_props, "scs_root_object_export_filepath")

for material in bpy.data.materials:
for prop in material.scs_props.get_shader_texture_types():
_path_utils.fix_sep_by_platform(material.scs_props, prop)

_path_utils.fix_sep_by_platform(bpy.context.scene.scs_props, "default_export_filepath")

# CREATE PREVIEW MODEL LIBRARY
_preview_models.init()

Expand Down
3 changes: 2 additions & 1 deletion addon/io_scs_tools/operators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@

from io_scs_tools.operators import object
from io_scs_tools.operators import scene
from io_scs_tools.operators import material
from io_scs_tools.operators import material
from io_scs_tools.operators import wm
Loading

0 comments on commit 11df243

Please sign in to comment.