|
@@ -18,6 +18,7 @@
|
|
|
|
|
|
import os
|
|
|
import json
|
|
|
+import logging
|
|
|
|
|
|
import bpy
|
|
|
from bpy_extras.io_utils import ExportHelper
|
|
@@ -31,6 +32,10 @@ from bpy.props import (
|
|
|
|
|
|
from . import constants
|
|
|
|
|
|
+logging.basicConfig(
|
|
|
+ format='%(levelname)s:THREE:%(message)s',
|
|
|
+ level=logging.DEBUG)
|
|
|
+
|
|
|
bl_info = {
|
|
|
'name': "Three.js Format",
|
|
|
'author': "repsac, mrdoob, yomotsu, mpk, jpweeks, rkusa",
|
|
@@ -250,6 +255,160 @@ class ThreeObject(bpy.types.Panel):
|
|
|
row = layout.row()
|
|
|
row.prop(obj, 'THREE_export', text='Export')
|
|
|
|
|
|
+class ThreeExportSettings(bpy.types.Operator):
|
|
|
+ """Save the current export settings (gets saved in .blend)"""
|
|
|
+ bl_label = "Save Settings"
|
|
|
+ bl_idname = "scene.three_export_settings_set"
|
|
|
+
|
|
|
+ def execute(self, context):
|
|
|
+ cycles = context.scene.cycles
|
|
|
+ cycles.use_samples_final = True
|
|
|
+
|
|
|
+ context.scene[constants.EXPORT_SETTINGS_KEY] = set_settings(context.active_operator.properties)
|
|
|
+
|
|
|
+ self.report({"INFO"}, "Three Export Settings Saved")
|
|
|
+
|
|
|
+ return {"FINISHED"}
|
|
|
+
|
|
|
+def restore_export_settings(properties, settings):
|
|
|
+ """Restore the settings
|
|
|
+
|
|
|
+ :param properties:
|
|
|
+
|
|
|
+ """
|
|
|
+
|
|
|
+ ## Geometry {
|
|
|
+ properties.option_vertices = settings.get(
|
|
|
+ constants.VERTICES,
|
|
|
+ constants.EXPORT_OPTIONS[constants.VERTICES])
|
|
|
+
|
|
|
+ properties.option_faces = settings.get(
|
|
|
+ constants.FACES,
|
|
|
+ constants.EXPORT_OPTIONS[constants.FACES])
|
|
|
+ properties.option_normals = settings.get(
|
|
|
+ constants.NORMALS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.NORMALS])
|
|
|
+
|
|
|
+ properties.option_skinning = settings.get(
|
|
|
+ constants.SKINNING,
|
|
|
+ constants.EXPORT_OPTIONS[constants.SKINNING])
|
|
|
+
|
|
|
+ properties.option_bones = settings.get(
|
|
|
+ constants.BONES,
|
|
|
+ constants.EXPORT_OPTIONS[constants.BONES])
|
|
|
+
|
|
|
+ properties.option_influences = settings.get(
|
|
|
+ constants.INFLUENCES_PER_VERTEX,
|
|
|
+ constants.EXPORT_OPTIONS[constants.INFLUENCES_PER_VERTEX])
|
|
|
+
|
|
|
+ properties.option_geometry_type = settings.get(
|
|
|
+ constants.GEOMETRY_TYPE,
|
|
|
+ constants.EXPORT_OPTIONS[constants.GEOMETRY_TYPE])
|
|
|
+ ## }
|
|
|
+
|
|
|
+ ## Materials {
|
|
|
+ properties.option_materials = settings.get(
|
|
|
+ constants.MATERIALS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.MATERIALS])
|
|
|
+
|
|
|
+ properties.option_uv_coords = settings.get(
|
|
|
+ constants.UVS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.UVS])
|
|
|
+
|
|
|
+ properties.option_face_materials = settings.get(
|
|
|
+ constants.FACE_MATERIALS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.FACE_MATERIALS])
|
|
|
+
|
|
|
+ properties.option_maps = settings.get(
|
|
|
+ constants.MAPS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.MAPS])
|
|
|
+
|
|
|
+ properties.option_colors = settings.get(
|
|
|
+ constants.COLORS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.COLORS])
|
|
|
+
|
|
|
+ properties.option_mix_colors = settings.get(
|
|
|
+ constants.MIX_COLORS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.MIX_COLORS])
|
|
|
+ ## }
|
|
|
+
|
|
|
+ ## Settings {
|
|
|
+ properties.option_scale = settings.get(
|
|
|
+ constants.SCALE,
|
|
|
+ constants.EXPORT_OPTIONS[constants.SCALE])
|
|
|
+
|
|
|
+ properties.option_round_off = settings.get(
|
|
|
+ constants.ENABLE_PRECISION,
|
|
|
+ constants.EXPORT_OPTIONS[constants.ENABLE_PRECISION])
|
|
|
+
|
|
|
+ properties.option_round_value = settings.get(
|
|
|
+ constants.PRECISION,
|
|
|
+ constants.EXPORT_OPTIONS[constants.PRECISION])
|
|
|
+
|
|
|
+ properties.option_logging = settings.get(
|
|
|
+ constants.LOGGING,
|
|
|
+ constants.EXPORT_OPTIONS[constants.LOGGING])
|
|
|
+
|
|
|
+ properties.option_compression = settings.get(
|
|
|
+ constants.COMPRESSION,
|
|
|
+ constants.NONE)
|
|
|
+
|
|
|
+ properties.option_indent = settings.get(
|
|
|
+ constants.INDENT,
|
|
|
+ constants.EXPORT_OPTIONS[constants.INDENT])
|
|
|
+
|
|
|
+ properties.option_copy_textures = settings.get(
|
|
|
+ constants.COPY_TEXTURES,
|
|
|
+ constants.EXPORT_OPTIONS[constants.COPY_TEXTURES])
|
|
|
+
|
|
|
+ properties.option_texture_folder = settings.get(
|
|
|
+ constants.TEXTURE_FOLDER,
|
|
|
+ constants.EXPORT_OPTIONS[constants.TEXTURE_FOLDER])
|
|
|
+
|
|
|
+ properties.option_embed_animation = settings.get(
|
|
|
+ constants.EMBED_ANIMATION,
|
|
|
+ constants.EXPORT_OPTIONS[constants.EMBED_ANIMATION])
|
|
|
+ ## }
|
|
|
+
|
|
|
+ ## Scene {
|
|
|
+ properties.option_export_scene = settings.get(
|
|
|
+ constants.SCENE,
|
|
|
+ constants.EXPORT_OPTIONS[constants.SCENE])
|
|
|
+
|
|
|
+ #properties.option_embed_geometry = settings.get(
|
|
|
+ # constants.EMBED_GEOMETRY,
|
|
|
+ # constants.EXPORT_OPTIONS[constants.EMBED_GEOMETRY])
|
|
|
+
|
|
|
+ properties.option_lights = settings.get(
|
|
|
+ constants.LIGHTS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.LIGHTS])
|
|
|
+
|
|
|
+ properties.option_cameras = settings.get(
|
|
|
+ constants.CAMERAS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.CAMERAS])
|
|
|
+
|
|
|
+ properties.option_hierarchy = settings.get(
|
|
|
+ constants.HIERARCHY,
|
|
|
+ constants.EXPORT_OPTIONS[constants.HIERARCHY])
|
|
|
+ ## }
|
|
|
+
|
|
|
+ ## Animation {
|
|
|
+ properties.option_animation_morph = settings.get(
|
|
|
+ constants.MORPH_TARGETS,
|
|
|
+ constants.EXPORT_OPTIONS[constants.MORPH_TARGETS])
|
|
|
+
|
|
|
+ properties.option_animation_skeletal = settings.get(
|
|
|
+ constants.ANIMATION,
|
|
|
+ constants.EXPORT_OPTIONS[constants.ANIMATION])
|
|
|
+
|
|
|
+ properties.option_frame_step = settings.get(
|
|
|
+ constants.FRAME_STEP,
|
|
|
+ constants.EXPORT_OPTIONS[constants.FRAME_STEP])
|
|
|
+
|
|
|
+ properties.option_frame_index_as_time = settings.get(
|
|
|
+ constants.FRAME_INDEX_AS_TIME,
|
|
|
+ constants.EXPORT_OPTIONS[constants.FRAME_INDEX_AS_TIME])
|
|
|
+ ## }
|
|
|
|
|
|
def set_settings(properties):
|
|
|
"""Set the export settings to the correct keys.
|
|
@@ -522,6 +681,17 @@ class ExportThree(bpy.types.Operator, ExportHelper):
|
|
|
default=2)
|
|
|
|
|
|
def invoke(self, context, event):
|
|
|
+ settings = context.scene.get(constants.EXPORT_SETTINGS_KEY)
|
|
|
+ if settings:
|
|
|
+ try:
|
|
|
+ restore_export_settings(self.properties, settings)
|
|
|
+ except AttributeError as e:
|
|
|
+ logging.error("Loading export settings failed:")
|
|
|
+ logging.exception(e)
|
|
|
+ logging.debug("Removed corrupted settings")
|
|
|
+
|
|
|
+ del context.scene[constants.EXPORT_SETTINGS_KEY]
|
|
|
+
|
|
|
return ExportHelper.invoke(self, context, event)
|
|
|
|
|
|
@classmethod
|
|
@@ -694,6 +864,15 @@ class ExportThree(bpy.types.Operator, ExportHelper):
|
|
|
row.prop(self.properties, 'option_indent')
|
|
|
## }
|
|
|
|
|
|
+ ## Operators {
|
|
|
+ has_settings = context.scene.get(constants.EXPORT_SETTINGS_KEY, False)
|
|
|
+ row = layout.row()
|
|
|
+ row.operator(
|
|
|
+ ThreeExportSettings.bl_idname,
|
|
|
+ ThreeExportSettings.bl_label,
|
|
|
+ icon="%s" % "PINNED" if has_settings else "UNPINNED")
|
|
|
+ ## }
|
|
|
+
|
|
|
|
|
|
|
|
|
def menu_func_export(self, context):
|