|
|
|
@@ -1,5 +1,6 @@ |
|
|
|
import bpy |
|
|
|
|
|
|
|
from bpy.props import StringProperty |
|
|
|
from bpy_extras.io_utils import ImportHelper |
|
|
|
from mathutils import Vector, Euler, Color, Matrix |
|
|
|
import json |
|
|
|
import pathlib |
|
|
|
@@ -7,6 +8,9 @@ import os |
|
|
|
from math import pi |
|
|
|
import random |
|
|
|
import bmesh |
|
|
|
import glob |
|
|
|
import zipfile |
|
|
|
import tempfile |
|
|
|
|
|
|
|
VIEW_DATA = { |
|
|
|
"FRONT": [0, 1, 2, "Front"], |
|
|
|
@@ -17,9 +21,22 @@ VIEW_DATA = { |
|
|
|
"BACK": [2, 1, 2, "Back"], |
|
|
|
"TOP": [0, 0, 1, "Top"], |
|
|
|
"BOTTOM": [0, 2, 1, "Bottom"], |
|
|
|
|
|
|
|
"BOTTOM_FLIPPED": [2, 2, 1, "Bottom Flipped"], |
|
|
|
} |
|
|
|
|
|
|
|
# Taken from https://blender.stackexchange.com/questions/127403/change-active-collection |
|
|
|
# This is the only way to get a LayerCollection. |
|
|
|
|
|
|
|
def recurLayerCollection(layerColl, collName): |
|
|
|
found = None |
|
|
|
if (layerColl.name == collName): |
|
|
|
return layerColl |
|
|
|
for layer in layerColl.children: |
|
|
|
found = recurLayerCollection(layer, collName) |
|
|
|
if found: |
|
|
|
return found |
|
|
|
|
|
|
|
def get_bounds(objects, camera_transform): |
|
|
|
xl = [] |
|
|
|
yl = [] |
|
|
|
@@ -468,8 +485,44 @@ class MVExport(bpy.types.Operator): |
|
|
|
|
|
|
|
return {'FINISHED'} |
|
|
|
|
|
|
|
class MVImportObj(bpy.types.Operator, ImportHelper): |
|
|
|
bl_idname = "mv.import_obj" |
|
|
|
bl_label = "Import from a directory of .zip files containing .obj files" |
|
|
|
filepath: StringProperty(subtype="FILE_PATH") |
|
|
|
filename_ext = "." |
|
|
|
use_filter_folder = True |
|
|
|
|
|
|
|
def execute(self, context: bpy.context): |
|
|
|
dir = pathlib.Path(self.filepath) |
|
|
|
glob_pattern = dir.joinpath("*.zip").__str__() |
|
|
|
for file in glob.glob(glob_pattern): |
|
|
|
zip = zipfile.ZipFile(file) |
|
|
|
tmpdir = pathlib.Path(tempfile.mkdtemp()) |
|
|
|
zip.extractall(tmpdir.__str__()) |
|
|
|
obj_glob_pattern = tmpdir.joinpath("*.obj").__str__() |
|
|
|
obj = glob.glob(obj_glob_pattern)[0] |
|
|
|
obj_path = pathlib.Path(obj) |
|
|
|
name = obj_path.with_suffix("").name |
|
|
|
|
|
|
|
if name in bpy.data.collections: |
|
|
|
continue |
|
|
|
|
|
|
|
c = bpy.data.collections.new(name) |
|
|
|
bpy.data.collections["Macrovision"].children.link(c) |
|
|
|
layer_collection = recurLayerCollection(bpy.context.view_layer.layer_collection, name) |
|
|
|
bpy.context.view_layer.active_layer_collection = layer_collection |
|
|
|
|
|
|
|
bpy.ops.import_scene.obj(filepath=obj_path.__str__()) |
|
|
|
|
|
|
|
return {'FINISHED'} |
|
|
|
|
|
|
|
def invoke(self, context, event): |
|
|
|
context.window_manager.fileselect_add(self) |
|
|
|
return {'RUNNING_MODAL'} |
|
|
|
|
|
|
|
clses = [ |
|
|
|
MVExport, |
|
|
|
MVAssignMaterials, |
|
|
|
MVConfigCollection |
|
|
|
MVConfigCollection, |
|
|
|
MVImportObj |
|
|
|
] |