|
|
@@ -1,20 +1,22 @@ |
|
|
import bpy |
|
|
import bpy |
|
|
|
|
|
|
|
|
from mathutils import Vector, Euler, Color |
|
|
from mathutils import Vector, Euler, Color |
|
|
import json |
|
|
import json |
|
|
import pathlib |
|
|
import pathlib |
|
|
import os |
|
|
import os |
|
|
from math import pi |
|
|
from math import pi |
|
|
|
|
|
import random |
|
|
|
|
|
|
|
|
VIEW_DATA = { |
|
|
VIEW_DATA = { |
|
|
"Front": [0, 1, 2, "Front"], |
|
|
|
|
|
"Angled": [0.25, 1, 2, "Angled"], |
|
|
|
|
|
"Corner": [0.5, 1, 2, "Corner"], |
|
|
|
|
|
"Side": [1, 1, 2, "Side"], |
|
|
|
|
|
"Back Angled": [1.5, 1, 2, "Back Angled"], |
|
|
|
|
|
"Back": [2, 1, 2, "Back"], |
|
|
|
|
|
"Top": [0, 0, 1, "Top"], |
|
|
|
|
|
"Bottom": [0, 2, 1, "Bottom"], |
|
|
|
|
|
"Bottom Flipped": [2, 2, 1, "Bottom Flipped"], |
|
|
|
|
|
|
|
|
"FRONT": [0, 1, 2, "Front"], |
|
|
|
|
|
"ANGLED": [0.25, 1, 2, "Angled"], |
|
|
|
|
|
"CORNER": [0.5, 1, 2, "Corner"], |
|
|
|
|
|
"SIDE": [1, 1, 2, "Side"], |
|
|
|
|
|
"BACK_ANGLED": [1.5, 1, 2, "Back Angled"], |
|
|
|
|
|
"BACK": [2, 1, 2, "Back"], |
|
|
|
|
|
"TOP": [0, 0, 1, "Top"], |
|
|
|
|
|
"BOTTOM": [0, 2, 1, "Bottom"], |
|
|
|
|
|
"BOTTOM_FLIPPED": [2, 2, 1, "Bottom Flipped"], |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def get_bounds(objects): |
|
|
def get_bounds(objects): |
|
|
@@ -46,10 +48,6 @@ class MVConfigCollection(bpy.types.Operator): |
|
|
def execute(self, context: bpy.types.Context): |
|
|
def execute(self, context: bpy.types.Context): |
|
|
coll = context.scene.collection.children[0] |
|
|
coll = context.scene.collection.children[0] |
|
|
coll.name = "Macrovision" |
|
|
coll.name = "Macrovision" |
|
|
coll["MVName"] = "Name" |
|
|
|
|
|
coll["MVViews"] = "Front" |
|
|
|
|
|
coll["MVKind"] = "objects" |
|
|
|
|
|
coll["MVViewLabels"] = "Front: Front" |
|
|
|
|
|
|
|
|
|
|
|
mats = [ |
|
|
mats = [ |
|
|
("light", 0, 0, 1), |
|
|
("light", 0, 0, 1), |
|
|
@@ -109,18 +107,61 @@ class MVConfigCollection(bpy.types.Operator): |
|
|
|
|
|
|
|
|
bpy.ops.object.lineart_clear_all() |
|
|
bpy.ops.object.lineart_clear_all() |
|
|
|
|
|
|
|
|
return {"FINISHED"} |
|
|
|
|
|
|
|
|
return {'FINISHED'} |
|
|
|
|
|
|
|
|
|
|
|
class MVAssignMaterials(bpy.types.Operator): |
|
|
|
|
|
bl_idname = "mv.assign_materials" |
|
|
|
|
|
bl_label = "Assign Materials" |
|
|
|
|
|
|
|
|
|
|
|
def execute(self, context: bpy.types.Context): |
|
|
|
|
|
mv = bpy.data.collections["Macrovision"] |
|
|
|
|
|
collections = mv.children |
|
|
|
|
|
|
|
|
|
|
|
for coll in collections: |
|
|
|
|
|
for object in coll.objects: |
|
|
|
|
|
if object.type != "MESH": |
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
for index in range(len(object.material_slots)): |
|
|
|
|
|
if object.material_slots[index].material.name in ('light', 'medium', 'dark'): |
|
|
|
|
|
continue |
|
|
|
|
|
if context.scene.mv_material_mode == 'RANDOM': |
|
|
|
|
|
choices = [ |
|
|
|
|
|
bpy.data.materials['light'], |
|
|
|
|
|
bpy.data.materials['medium'], |
|
|
|
|
|
bpy.data.materials['dark'] |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
object.material_slots[index].material = random.choice(choices) |
|
|
|
|
|
|
|
|
|
|
|
if context.scene.mv_material_mode == 'NAMES': |
|
|
|
|
|
material = object.material_slots[index].material |
|
|
|
|
|
light_choices = context.scene.mv_material_names_light.split(",") |
|
|
|
|
|
medium_choices = context.scene.mv_material_names_medium.split(",") |
|
|
|
|
|
|
|
|
|
|
|
chosen = None |
|
|
|
|
|
|
|
|
|
|
|
for choice in light_choices: |
|
|
|
|
|
if choice in material.name or choice in object.name: |
|
|
|
|
|
chosen = bpy.data.materials['light'] |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
for choice in medium_choices: |
|
|
|
|
|
if choice in material.name or choice in object.name: |
|
|
|
|
|
chosen = bpy.data.materials['medium'] |
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
if chosen is None: |
|
|
|
|
|
chosen = bpy.data.materials['dark'] |
|
|
|
|
|
|
|
|
|
|
|
object.material_slots[index].material = chosen |
|
|
|
|
|
|
|
|
|
|
|
return {'FINISHED'} |
|
|
|
|
|
|
|
|
class MVExport(bpy.types.Operator): |
|
|
class MVExport(bpy.types.Operator): |
|
|
bl_idname = "mv.export" |
|
|
bl_idname = "mv.export" |
|
|
bl_label = "Export objects" |
|
|
bl_label = "Export objects" |
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
|
def poll(cls, context: bpy.types.Context): |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def execute(self, context: bpy.types.Context): |
|
|
def execute(self, context: bpy.types.Context): |
|
|
path_info = pathlib.Path(bpy.data.filepath).parent.joinpath("macrovision-directory.txt") |
|
|
path_info = pathlib.Path(bpy.data.filepath).parent.joinpath("macrovision-directory.txt") |
|
|
config_path = pathlib.Path(open(path_info).read().strip()) |
|
|
config_path = pathlib.Path(open(path_info).read().strip()) |
|
|
@@ -150,20 +191,21 @@ class MVExport(bpy.types.Operator): |
|
|
|
|
|
|
|
|
all_data = {} |
|
|
all_data = {} |
|
|
|
|
|
|
|
|
all_data["name"] = mv["MVName"] |
|
|
|
|
|
all_data["kind"] = mv["MVKind"] |
|
|
|
|
|
|
|
|
all_data["name"] = context.scene.mv_name |
|
|
|
|
|
all_data["kind"] = context.scene.mv_kind |
|
|
all_data["forms"] = [] |
|
|
all_data["forms"] = [] |
|
|
|
|
|
|
|
|
default_views = [] |
|
|
default_views = [] |
|
|
|
|
|
|
|
|
for view in mv["MVViews"].split(","): |
|
|
|
|
|
default_views.append(VIEW_DATA[view.strip()]) |
|
|
|
|
|
|
|
|
|
|
|
if "MVViewLabels" in mv: |
|
|
|
|
|
for pair in mv["MVViewLabels"].split(","): |
|
|
|
|
|
key, val = pair.split(":") |
|
|
|
|
|
VIEW_DATA[key.strip()][3] = val.strip() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for view in context.scene.mv_views: |
|
|
|
|
|
key = view.view |
|
|
|
|
|
default_views.append([ |
|
|
|
|
|
VIEW_DATA[key][0], |
|
|
|
|
|
VIEW_DATA[key][1], |
|
|
|
|
|
VIEW_DATA[key][2], |
|
|
|
|
|
view.name if view.name != "" else VIEW_DATA[key][3] |
|
|
|
|
|
]) |
|
|
|
|
|
print(default_views) |
|
|
|
|
|
|
|
|
workdir = pathlib.Path(parent_workdir).joinpath(all_data["name"]) |
|
|
workdir = pathlib.Path(parent_workdir).joinpath(all_data["name"]) |
|
|
|
|
|
|
|
|
@@ -212,15 +254,19 @@ class MVExport(bpy.types.Operator): |
|
|
c.location += Vector([0, 0, size * 2]) @ rot |
|
|
c.location += Vector([0, 0, size * 2]) @ rot |
|
|
c.data.clip_start = size / 4 |
|
|
c.data.clip_start = size / 4 |
|
|
c.data.clip_end = size * 8 |
|
|
c.data.clip_end = size * 8 |
|
|
|
|
|
|
|
|
|
|
|
scale_factor = (10 ** context.scene.mv_scale_factor) |
|
|
|
|
|
|
|
|
|
|
|
height = dimensions[angles[2]] * scale_factor |
|
|
data["views"].append({ |
|
|
data["views"].append({ |
|
|
"name": angles[3], |
|
|
"name": angles[3], |
|
|
"height": dimensions[angles[2]] |
|
|
|
|
|
|
|
|
"height": height |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
if "Volume" in coll: |
|
|
if "Volume" in coll: |
|
|
data["views"][-1]["volume"] = coll["Volume"] |
|
|
|
|
|
|
|
|
data["views"][-1]["volume"] = coll["Volume"] * (scale_factor ** 3) |
|
|
if "Mass" in coll: |
|
|
if "Mass" in coll: |
|
|
data["views"][-1]["mass"] = coll["Mass"] |
|
|
|
|
|
|
|
|
data["views"][-1]["mass"] = coll["Mass"] * (scale_factor ** 3) |
|
|
|
|
|
|
|
|
lineart.hide_render = False |
|
|
lineart.hide_render = False |
|
|
filename = f"{coll.name}-{angles[3]}.png" |
|
|
filename = f"{coll.name}-{angles[3]}.png" |
|
|
@@ -237,9 +283,10 @@ class MVExport(bpy.types.Operator): |
|
|
with open(workdir.joinpath("data.json"), "w") as file: |
|
|
with open(workdir.joinpath("data.json"), "w") as file: |
|
|
json.dump(all_data, file) |
|
|
json.dump(all_data, file) |
|
|
|
|
|
|
|
|
return {"FINISHED"} |
|
|
|
|
|
|
|
|
return {'FINISHED'} |
|
|
|
|
|
|
|
|
clses = [ |
|
|
clses = [ |
|
|
MVExport, |
|
|
MVExport, |
|
|
|
|
|
MVAssignMaterials, |
|
|
MVConfigCollection |
|
|
MVConfigCollection |
|
|
] |
|
|
] |