From 0a24173addaf7c17d4b9fd85bb24b19a429398a7 Mon Sep 17 00:00:00 2001 From: Alexey Taranov Date: Sat, 21 May 2022 14:59:10 +0300 Subject: [PATCH] Unity Blender Decimate --- Decimate.py | 21 ++++++ Decimate.py.meta | 7 ++ UnityBlenderDecimate.cs | 128 +++++++++++++++++++++++++++++++++++ UnityBlenderDecimate.cs.meta | 14 ++++ UnityToBlender.uxml | 16 +++++ UnityToBlender.uxml.meta | 10 +++ 6 files changed, 196 insertions(+) create mode 100644 Decimate.py create mode 100644 Decimate.py.meta create mode 100644 UnityBlenderDecimate.cs create mode 100644 UnityBlenderDecimate.cs.meta create mode 100644 UnityToBlender.uxml create mode 100644 UnityToBlender.uxml.meta diff --git a/Decimate.py b/Decimate.py new file mode 100644 index 0000000..ab713f8 --- /dev/null +++ b/Decimate.py @@ -0,0 +1,21 @@ +import bpy +import sys + +argv = sys.argv +#Get only our arguments +argv = argv[argv.index("--") + 1:] +print(argv) +objPath = argv[0] +decimateValue = argv[1] + +#Delete default objects:cube,camera,light +bpy.ops.object.select_all(action='SELECT') +bpy.ops.object.delete(use_global=False) + +imported_object = bpy.ops.import_scene.obj(filepath=objPath) +obj_object = bpy.context.selected_objects[0] +decimate = obj_object.modifiers.new(name="Decimate", type = 'DECIMATE') +decimate.ratio = float(decimateValue) + +#Export as obj +bpy.ops.export_scene.obj(filepath=objPath) \ No newline at end of file diff --git a/Decimate.py.meta b/Decimate.py.meta new file mode 100644 index 0000000..55232a0 --- /dev/null +++ b/Decimate.py.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 80b44aaee10ec47c98d74f3399696eed +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityBlenderDecimate.cs b/UnityBlenderDecimate.cs new file mode 100644 index 0000000..d933fbc --- /dev/null +++ b/UnityBlenderDecimate.cs @@ -0,0 +1,128 @@ +using System; +using System.Diagnostics; +using System.IO; +using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine; +using UnityEngine.UIElements; +using Object = UnityEngine.Object; + +namespace Editor.UnityBlenderDecimate +{ + public class UnityBlenderDecimate : EditorWindow + { + [MenuItem("Tools/Unity To Blender")] + public static void ShowExample() + { + UnityBlenderDecimate window = GetWindow(); + window.titleContent = new GUIContent("Unity Blender Decimate"); + } + + [SerializeField] private VisualTreeAsset visualTreeAsset; + [SerializeField] private string blenderPath; + private Button BlenderPathSelectButton => rootVisualElement.Q