Browse Source

iterated on environment, and exporter. Cleaning up evironment variables

akal 9 years ago
parent
commit
d845210897

+ 22 - 23
tools/anki_scene_exporter/__init__.py

@@ -1,8 +1,5 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 bl_info = {
 bl_info = {
@@ -47,7 +44,6 @@ class SCENE_anki_scene_exporter(AddonPreferences):
 	# when defining this in a submodule of a python package.
 	# when defining this in a submodule of a python package.
 	bl_idname = __name__
 	bl_idname = __name__
 
 
-
 	anki_environment = StringProperty(
 	anki_environment = StringProperty(
 			name="Anki Environment",
 			name="Anki Environment",
 			default=ENV.ENVIRO,
 			default=ENV.ENVIRO,
@@ -56,10 +52,18 @@ class SCENE_anki_scene_exporter(AddonPreferences):
 		name="Project Path",
 		name="Project Path",
 		subtype='FILE_PATH',
 		subtype='FILE_PATH',
 		)
 		)
-	export_path = StringProperty(
+	export_map_path = StringProperty(
+			name="Map Path",
+			default="Map Path",
+			)
+	export_source_path = StringProperty(
 			name="Source Path",
 			name="Source Path",
 			default="Source Path:",
 			default="Source Path:",
 			)
 			)
+	export_texture_path = StringProperty(
+			name="Texture Path",
+			default="Texture Path",
+			)
 	im_convert = StringProperty(
 	im_convert = StringProperty(
 			name="ImageMagick Convert Path",
 			name="ImageMagick Convert Path",
 			default="/usr/bin/convert",
 			default="/usr/bin/convert",
@@ -72,19 +76,14 @@ class SCENE_anki_scene_exporter(AddonPreferences):
 			)
 			)
 	tools_path = StringProperty(
 	tools_path = StringProperty(
 			name="Tools Path",
 			name="Tools Path",
-			default="Tools Path:",
-			)
-	map_path = StringProperty(
-			name="Map Path",
-			default="Map Path:",
-			)
-	texture_path = StringProperty(
-			name="Texture Path",
-			default="Texture Path:{}",
+			default="Tools Path",
 			)
 			)
 	temp_dea = StringProperty(
 	temp_dea = StringProperty(
 			name="Temp Dea Path",
 			name="Temp Dea Path",
 			)
 			)
+	tool_py_texture = StringProperty(
+			name="Texture Tool",
+			)
 	# Try to get/set the environment variables
 	# Try to get/set the environment variables
 	path_list = os.getenv(ENV.ENVIRO)
 	path_list = os.getenv(ENV.ENVIRO)
 	environment_root = None
 	environment_root = None
@@ -94,7 +93,7 @@ class SCENE_anki_scene_exporter(AddonPreferences):
 		anki_project_path[1]['default'] = environment_root
 		anki_project_path[1]['default'] = environment_root
 
 
 		env_dct, export_dct, tools_dct = ENV.get_environment()
 		env_dct, export_dct, tools_dct = ENV.get_environment()
-		# ENV.set_environment(env_dct, tools_dct)
+		ENV.set_environment(env_dct, tools_dct)
 
 
 		# check converter if does not exit remove default path
 		# check converter if does not exit remove default path
 		if not os.path.exists(im_convert[1]['default']):
 		if not os.path.exists(im_convert[1]['default']):
@@ -107,10 +106,11 @@ class SCENE_anki_scene_exporter(AddonPreferences):
 
 
 		# Set the gui
 		# Set the gui
 		tools_path[1]['default'] = tools_dct['tools_path']
 		tools_path[1]['default'] = tools_dct['tools_path']
-		export_path[1]['default'] = export_dct['export_src_data']
-		map_path[1]['default'] = export_dct['export_map_path']
-		texture_path[1]['default'] = export_dct['export_texture_path']
+		export_source_path[1]['default'] = export_dct['export_src_data']
+		export_map_path[1]['default'] = export_dct['export_map_path']
 		temp_dea[1]['default'] = export_dct['export_temp_dea']
 		temp_dea[1]['default'] = export_dct['export_temp_dea']
+		export_texture_path[1]['default'] = export_dct['export_texture_path']
+		tool_py_texture[1]['default'] = "{0}/convert_image.py".format(tools_dct['tools_texture_path'])
 
 
 	def draw(self, context):
 	def draw(self, context):
 		layout = self.layout
 		layout = self.layout
@@ -128,14 +128,13 @@ class SCENE_anki_scene_exporter(AddonPreferences):
 		col.label(text='Tools Path:')
 		col.label(text='Tools Path:')
 
 
 		col = split.column()
 		col = split.column()
-		col.label(text=self.export_path)
-		col.label(text=self.map_path)
-		col.label(text=self.texture_path)
+		col.label(text=self.export_source_path)
+		col.label(text=self.export_map_path)
+		col.label(text=self.export_texture_path)
 		col.label(text=self.tools_path)
 		col.label(text=self.tools_path)
 
 
 		layout.operator("scene.anki_preference_set", text="Set Preferences")
 		layout.operator("scene.anki_preference_set", text="Set Preferences")
 
 
-
 def register():
 def register():
 	bpy.utils.register_module(__name__)
 	bpy.utils.register_module(__name__)
 
 

+ 24 - 16
tools/anki_scene_exporter/lib/environment.py

@@ -1,12 +1,10 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 # system imports
 # system imports
 import os
 import os
+import sys
 
 
 bl_info = {"author": "A. A. Kalugin Jr."}
 bl_info = {"author": "A. A. Kalugin Jr."}
 
 
@@ -41,8 +39,8 @@ def get_environment():
 	# Tools Environment
 	# Tools Environment
 	tool_etcpack_path     = "{0}/thirdparty/bin".format(environment_root)
 	tool_etcpack_path     = "{0}/thirdparty/bin".format(environment_root)
 	tools_path            = "{0}/tools".format(anki_build_path)
 	tools_path            = "{0}/tools".format(anki_build_path)
-	tools_scene_path      = "{0}/scene".format(tools_path)
-	tools_texture_path    = "{0}/texture".format(tools_path)
+	tools_scene_path      = "{0}/tools/scene".format(environment_root)
+	tools_texture_path    = "{0}/tools/texture".format(environment_root)
 
 
 	# Make the Export Paths
 	# Make the Export Paths
 	for _path in [export_src_data, export_map_path, export_texture_path]:
 	for _path in [export_src_data, export_map_path, export_texture_path]:
@@ -50,19 +48,15 @@ def get_environment():
 			print ("Making directory:", _path)
 			print ("Making directory:", _path)
 			os.makedirs(_path)
 			os.makedirs(_path)
 
 
+	# anki checked out path dictionary
 	env_dct = {
 	env_dct = {
-					'environment_root':environment_root+'/',
+					'anki_root_path':environment_root+'/',
 					'anki_build_path':anki_build_path,
 					'anki_build_path':anki_build_path,
 					'anki_engine_data_path':anki_engine_data_path,
 					'anki_engine_data_path':anki_engine_data_path,
 					'anki_shaders_path':anki_shaders_path,
 					'anki_shaders_path':anki_shaders_path,
 					}
 					}
-	tools_dct = {
-					'tool_etcpack_path':tool_etcpack_path,
-					'tools_path':tools_path,
-					'tools_scene_path':tools_scene_path,
-					'tools_texture_path':tools_texture_path,
-					}
 
 
+	# export path dictionary
 	export_dct = {
 	export_dct = {
 					'export_src_data':export_src_data,
 					'export_src_data':export_src_data,
 					'export_map_path':export_map_path,
 					'export_map_path':export_map_path,
@@ -70,14 +64,28 @@ def get_environment():
 					'export_temp_dea':export_temp_dea,
 					'export_temp_dea':export_temp_dea,
 					}
 					}
 
 
+	# tools path dictionary
+	tools_dct = {
+					'tool_etcpack_path':tool_etcpack_path,
+					'tools_path':tools_path,
+					'tools_scene_path':tools_scene_path,
+					'tools_texture_path':tools_texture_path,
+					}
 	return env_dct, export_dct, tools_dct
 	return env_dct, export_dct, tools_dct
 
 
 def set_environment(anki_env_dct, tools_dct):
 def set_environment(anki_env_dct, tools_dct):
 	"""
 	"""
 	Sets the environment variable.
 	Sets the environment variable.
 	"""
 	"""
-	environment_path = ':'.join(anki_env_dct.values())
-	os.environ[ENVIRO]=environment_path
-	environment_path = ':'.join(tools_dct.values())
+	# Set the environment variable for anki
+	environment_path = os.pathsep.join(anki_env_dct.values())
 	os.environ[ENVIRO]=environment_path
 	os.environ[ENVIRO]=environment_path
 
 
+	# Append the tools path to the $PATH
+	tools_path = os.pathsep.join(tools_dct.values())
+
+	# Create a clean PATH environment varaible
+	os.environ["PATH"] += os.pathsep + tools_path
+	path_l = os.getenv("PATH").split(os.pathsep)
+	new_path = os.pathsep.join(set(path_l))
+	os.environ["PATH"] = new_path

+ 1 - 4
tools/anki_scene_exporter/lib/gui.py

@@ -1,8 +1,5 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 # blender imports
 # blender imports

+ 3 - 6
tools/anki_scene_exporter/lib/material.py

@@ -1,8 +1,5 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 # blender imports
 # blender imports
@@ -10,7 +7,7 @@ import bpy
 
 
 bl_info = {"author": "A. A. Kalugin Jr."}
 bl_info = {"author": "A. A. Kalugin Jr."}
 
 
-def get_blender_images():
+def get_texture_images_nodes():
 	"""
 	"""
 	Gets the blender images using the materials
 	Gets the blender images using the materials
 	"""
 	"""
@@ -20,6 +17,6 @@ def get_blender_images():
 		for slot in mat.texture_slots:
 		for slot in mat.texture_slots:
 			if slot:
 			if slot:
 				if (slot.texture.image != None):
 				if (slot.texture.image != None):
-					bl_images.append(slot.texture.image.file_format)
+					bl_images.append(slot.texture.image)
 	return bl_images
 	return bl_images
 
 

+ 2 - 5
tools/anki_scene_exporter/lib/objects.py

@@ -1,8 +1,5 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 # blender imports
 # blender imports
@@ -23,4 +20,4 @@ def get_camera():
 	cam = getter()
 	cam = getter()
 	if cam == None:
 	if cam == None:
 		bpy.ops.object.camera_add()
 		bpy.ops.object.camera_add()
-	return getter()
+	return getter()

+ 2 - 5
tools/anki_scene_exporter/lib/preferences.py

@@ -1,8 +1,5 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 bl_info = {"author": "A. A. Kalugin Jr."}
 bl_info = {"author": "A. A. Kalugin Jr."}
@@ -12,4 +9,4 @@ def get_anki_exporter_preferences(context):
 	Gets the scene preferences.
 	Gets the scene preferences.
 	"""
 	"""
 	user_preferences = context.user_preferences
 	user_preferences = context.user_preferences
-	return user_preferences.addons['anki_scene_exporter'].preferences
+	return user_preferences.addons['anki_scene_exporter'].preferences

+ 2 - 4
tools/anki_scene_exporter/ops/environment.py

@@ -1,8 +1,5 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 # blender imports
 # blender imports
@@ -28,6 +25,7 @@ class OBJECT_OT_anki_preference_set(Operator):
 		addon_prefs = PREF.get_anki_exporter_preferences(context)
 		addon_prefs = PREF.get_anki_exporter_preferences(context)
 		ENV.ENVIRO = addon_prefs.anki_environment
 		ENV.ENVIRO = addon_prefs.anki_environment
 		env_dct, export_dct, tools_dct = ENV.get_environment()
 		env_dct, export_dct, tools_dct = ENV.get_environment()
+		ENV.set_environment(env_dct, tools_dct)
 
 
 		# Set project paths
 		# Set project paths
 		addon_prefs.tools_path = tools_dct['tools_path']
 		addon_prefs.tools_path = tools_dct['tools_path']

+ 74 - 18
tools/anki_scene_exporter/ops/export.py

@@ -1,14 +1,11 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 # system imports
 # system imports
-import subprocess
 import os
 import os
-
+import subprocess
+from subprocess import Popen
 # blender imports
 # blender imports
 import bpy
 import bpy
 from bpy.types import Operator
 from bpy.types import Operator
@@ -16,15 +13,67 @@ import mathutils
 
 
 # local imports
 # local imports
 from ..lib import gui as GUI
 from ..lib import gui as GUI
-from ..lib import preferences as PREF
 from ..lib import objects as OBJ
 from ..lib import objects as OBJ
+from ..lib import material as MAT
+from ..lib import math as MTH
+from ..lib import preferences as PREF
 
 
 bl_info = {"author": "A. A. Kalugin Jr."}
 bl_info = {"author": "A. A. Kalugin Jr."}
 
 
-class OBJECT_OT_anki_export(Operator):
+class OBJECT_OT_anki_export_material(Operator):
+		"""Export anki scene textures"""
+		bl_idname = "scene.anki_export_textures"
+		bl_label = "Export Textures"
+		bl_options = {'REGISTER'}
+		def execute(self, context):
+			scn                = context.scene
+			exported_log       = []
+			error_log          = []
+			commands           = []
+			addon_prefs        = PREF.get_anki_exporter_preferences(context)
+			py_image_converter = addon_prefs.tool_py_texture
+			export_path        = addon_prefs.export_texture_path
+			textures           = MAT.get_texture_images_nodes()
+
+			# Process the blender texture slot nodes.
+			for texture in textures:
+				src_path = texture.filepath
+				src_file_name = os.path.basename(src_path)
+
+				# Check if the resolution of the image is power of twos
+				res_x = (texture.size[0])
+				res_y = (texture.size[1])
+				if not MTH.is_power_of_two(res_x) and not MTH.is_power_of_two(res_y):
+					msg = "Image {0} resolution not power of 2. x {1} y {2}"
+					error = msg.format(texture.filepath, res_x, res_y)
+					error_log.append(error)
+					continue
+
+				# Set up the command for texture export.
+				dst_path = ("{0}/{1}.ankitex".format(export_path, os.path.splitext(src_file_name)[0] ))
+				cmd = "{0} -i {1} -o {2}".format(py_image_converter, texture.filepath, dst_path)
+				Popen(cmd, shell=True)
+				src_time = os.path.getatime(src_path)
+				dst_time = os.path.getatime(dst_path)
+				if src_time > dst_time:
+					export = "Running command: {0}".format(cmd)
+					exported_log.append(export)
+					commands.append(cmd)
+
+			# Process the commands
+			if len(commands) > 0:
+				for cmd in commands:
+					print ("Running command: {0}".format(cmd))
+					Popen(cmd, shell=True)
+			else:
+				print("No commands to to process.")
+
+			return {'FINISHED'}
+
+class OBJECT_OT_anki_export_scene(Operator):
 		"""Export anki scene"""
 		"""Export anki scene"""
-		bl_idname = "scene.anki_export"
-		bl_label = "Anki Export"
+		bl_idname = "scene.anki_export_scene"
+		bl_label = "Export Scene"
 		bl_options = {'REGISTER'}
 		bl_options = {'REGISTER'}
 
 
 		def execute(self, context):
 		def execute(self, context):
@@ -72,8 +121,8 @@ class OBJECT_OT_anki_export(Operator):
 													deform_bones_only=False,
 													deform_bones_only=False,
 													active_uv_only=False,
 													active_uv_only=False,
 													include_uv_textures=False,
 													include_uv_textures=False,
-													include_material_textures=False,
-													use_texture_copies=True,
+													include_material_textures=True,
+													use_texture_copies=False,
 													triangulate=True,
 													triangulate=True,
 													use_object_instantiation=True,
 													use_object_instantiation=True,
 													sort_by_name=False,
 													sort_by_name=False,
@@ -87,14 +136,21 @@ class OBJECT_OT_anki_export(Operator):
 						cam.matrix_world = view_mtx
 						cam.matrix_world = view_mtx
 						print ("Restored camera to original projection matrix.")
 						print ("Restored camera to original projection matrix.")
 
 
-				# Convert the exported collada
-				relative_path = (addon_prefs.map_path.replace(addon_prefs.anki_project_path + os.sep, ""))
-				cmd  = "ankisceneimp {0} {1} -rpath {2}  -flipyz".format(temp_dea, addon_prefs.map_path, relative_path)
+				# Format the command and convert the exported collada
+				rel_map_path = (addon_prefs.export_map_path.replace(addon_prefs.anki_project_path, ""))
+				rel_texture_path = (addon_prefs.export_texture_path.replace(addon_prefs.anki_project_path, ""))
+				cmd_str = "ankisceneimp {0} {1} -rpath {2} -texrpath {3} -flipyz"
+				cmd  = cmd_str.format(temp_dea,
+									  addon_prefs.export_map_path,
+									  rel_map_path,
+									  rel_texture_path)
+
 				subprocess.call(cmd, shell=True)
 				subprocess.call(cmd, shell=True)
-				print (cmd)
+
 				# Run the level in the game
 				# Run the level in the game
-				test_app = ("{0}/build/bled/bled".format(addon_prefs.anki_project_path))
+				bled_app = ("{0}/build/bled/bled".format(addon_prefs.anki_project_path))
 
 
-				subprocess.call(test_app, shell=True)
+				subprocess.call(bled_app, shell=True)
 
 
 				return {'FINISHED'}
 				return {'FINISHED'}
+

+ 2 - 5
tools/anki_scene_exporter/props/export_props.py

@@ -1,8 +1,5 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 # blender imports
 # blender imports
@@ -24,4 +21,4 @@ bpy.types.Scene.ExportAllTextures = BoolProperty(
 bpy.types.Scene.UpdateTextures = BoolProperty(
 bpy.types.Scene.UpdateTextures = BoolProperty(
 	name = "Update Textures",
 	name = "Update Textures",
 	description = "True or False?",
 	description = "True or False?",
-	default= True)
+	default= True)

+ 10 - 6
tools/anki_scene_exporter/ui/gui.py

@@ -1,8 +1,5 @@
-# Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
-# All rights reserved.
 # Code licensed under the BSD License.
 # Code licensed under the BSD License.
-# http://www.anki3d.org/LICENSE
-
+# http://www.anki3d.org/LICENSE Panagiotis Christopoulos Charitos and contributors
 # keep methods in alphabetical order
 # keep methods in alphabetical order
 
 
 """
 """
@@ -50,6 +47,13 @@ class VIEW3D_PT_tools_anki(AnkiPanel, Panel):
 
 
 		split = layout.split()
 		split = layout.split()
 		col = split.column()
 		col = split.column()
-		col.prop(scn, 'UseViewport')
+		col.prop(scn, "UseViewport", text="Viewport")
 		col = split.column()
 		col = split.column()
-		col.operator("scene.anki_export", icon='PLAY')
+		col.operator("scene.anki_export_scene", icon='PLAY')
+		col = layout.column(align=True)
+
+		col.separator()
+
+		col.label(text="Texture Export:")
+		row = col.row(align=True)
+		row.operator("scene.anki_export_textures", icon='IMAGE_COL')