Pārlūkot izejas kodu

support enabling godot beta features

Jason0214 6 gadi atpakaļ
vecāks
revīzija
37268bcc18
2 mainītis faili ar 48 papildinājumiem un 0 dzēšanām
  1. 10 0
      io_scene_godot/__init__.py
  2. 38 0
      io_scene_godot/export_godot.py

+ 10 - 0
io_scene_godot/__init__.py

@@ -116,6 +116,16 @@ class ExportGodot(bpy.types.Operator, ExportHelper):
                     "animation and place into AnimationPlayer",
         default=True,
     )
+    use_export_material = BoolProperty(
+        name="Export Materinal",
+        description="Export all the material associated with mesh surfaces",
+        default=True,
+    )
+    use_beta_features = BoolProperty(
+        name="Use Beta Features",
+        description="Export using new features coming in Godot beta versions",
+        default=True,
+    )
     generate_external_material = BoolProperty(
         name="Generate External Material",
         description="If turned on, materials in the exported scene would "

+ 38 - 0
io_scene_godot/export_godot.py

@@ -62,6 +62,7 @@ def find_godot_project_dir(export_path):
 class ExporterLogHandler(logging.Handler):
     """Custom handler for exporter, would report logging message
     to GUI"""
+
     def __init__(self, operator):
         super().__init__()
         self.setLevel(logging.WARNING)
@@ -203,6 +204,38 @@ class GodotExporter:
                 # recursive exporting on root object
                 self.export_object(obj, root_gd_node)
 
+    def load_supported_features(self):
+        """According to `project.godot`, determine all new feature supported
+        by that godot version"""
+        project_dir = ""
+        try:
+            project_dir = self.config["project_path_func"]()
+        except structures.ValidationError:
+            project_dir = False
+            logging.warning(
+                "Not export to Godot project dir, disable all beta features.")
+
+        # minimal supported version
+        conf_versiton = 3
+        if project_dir:
+            project_file_path = os.path.join(project_dir, "project.godot")
+            with open(project_file_path, "r") as proj_f:
+                for line in proj_f:
+                    if not line.startswith("config_version"):
+                        continue
+
+                    _, version_str = tuple(line.split("="))
+                    conf_versiton = int(version_str)
+                    break
+
+        if conf_versiton < 2:
+            logging.error(
+                "Godot version smaller than 3.0, not supported by this addon")
+
+        if conf_versiton >= 4:
+            # godot >=3.1
+            self.config["feature_bezier_track"] = True
+
     def export(self):
         """Begin the export"""
         self.escn_file = structures.ESCNFile(structures.FileEntry(
@@ -236,6 +269,11 @@ class GodotExporter:
         # to be exported
         self.exporting_objects = set()
 
+        # optional features
+        self.config["feature_bezier_track"] = False
+        if self.config["use_beta_features"]:
+            self.load_supported_features()
+
         self.escn_file = None
 
     def __enter__(self):