|
|
@ -14,6 +14,7 @@ |
|
|
|
# along with Korman. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
# along with Korman. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
|
|
|
import bpy |
|
|
|
import bpy |
|
|
|
|
|
|
|
from contextlib import ExitStack |
|
|
|
import itertools |
|
|
|
import itertools |
|
|
|
from PyHSPlasma import * |
|
|
|
from PyHSPlasma import * |
|
|
|
from math import fabs |
|
|
|
from math import fabs |
|
|
@ -163,6 +164,7 @@ class _GeoData: |
|
|
|
|
|
|
|
|
|
|
|
class _MeshManager: |
|
|
|
class _MeshManager: |
|
|
|
def __init__(self, report=None): |
|
|
|
def __init__(self, report=None): |
|
|
|
|
|
|
|
self.context_stack = ExitStack() |
|
|
|
if report is not None: |
|
|
|
if report is not None: |
|
|
|
self._report = report |
|
|
|
self._report = report |
|
|
|
self._overrides = {} |
|
|
|
self._overrides = {} |
|
|
@ -181,6 +183,8 @@ class _MeshManager: |
|
|
|
return props |
|
|
|
return props |
|
|
|
|
|
|
|
|
|
|
|
def __enter__(self): |
|
|
|
def __enter__(self): |
|
|
|
|
|
|
|
self.context_stack.__enter__() |
|
|
|
|
|
|
|
|
|
|
|
scene = bpy.context.scene |
|
|
|
scene = bpy.context.scene |
|
|
|
self._report.progress_advance() |
|
|
|
self._report.progress_advance() |
|
|
|
self._report.progress_range = len(scene.objects) |
|
|
|
self._report.progress_range = len(scene.objects) |
|
|
@ -207,23 +211,26 @@ class _MeshManager: |
|
|
|
self._report.progress_increment() |
|
|
|
self._report.progress_increment() |
|
|
|
return self |
|
|
|
return self |
|
|
|
|
|
|
|
|
|
|
|
def __exit__(self, type, value, traceback): |
|
|
|
def __exit__(self, *exc_info): |
|
|
|
data_bos, data_meshes = bpy.data.objects, bpy.data.meshes |
|
|
|
try: |
|
|
|
for obj_name, override in self._overrides.items(): |
|
|
|
self.context_stack.__exit__(*exc_info) |
|
|
|
bo = data_bos.get(obj_name) |
|
|
|
finally: |
|
|
|
|
|
|
|
data_bos, data_meshes = bpy.data.objects, bpy.data.meshes |
|
|
|
# Reapply the old mesh |
|
|
|
for obj_name, override in self._overrides.items(): |
|
|
|
trash_mesh, bo.data = bo.data, data_meshes.get(override["mesh"]) |
|
|
|
bo = data_bos.get(obj_name) |
|
|
|
data_meshes.remove(trash_mesh) |
|
|
|
|
|
|
|
|
|
|
|
# Reapply the old mesh |
|
|
|
# If modifiers were removed, reapply them now unless they're read-only. |
|
|
|
trash_mesh, bo.data = bo.data, data_meshes.get(override["mesh"]) |
|
|
|
readonly_attributes = {("DECIMATE", "face_count"),} |
|
|
|
data_meshes.remove(trash_mesh) |
|
|
|
for cached_mod in override["modifiers"]: |
|
|
|
|
|
|
|
mod = bo.modifiers.new(cached_mod["name"], cached_mod["type"]) |
|
|
|
# If modifiers were removed, reapply them now unless they're read-only. |
|
|
|
for key, value in cached_mod.items(): |
|
|
|
readonly_attributes = {("DECIMATE", "face_count"),} |
|
|
|
if key in {"name", "type"} or (cached_mod["type"], key) in readonly_attributes: |
|
|
|
for cached_mod in override["modifiers"]: |
|
|
|
continue |
|
|
|
mod = bo.modifiers.new(cached_mod["name"], cached_mod["type"]) |
|
|
|
setattr(mod, key, value) |
|
|
|
for key, value in cached_mod.items(): |
|
|
|
|
|
|
|
if key in {"name", "type"} or (cached_mod["type"], key) in readonly_attributes: |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
setattr(mod, key, value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MeshConverter(_MeshManager): |
|
|
|
class MeshConverter(_MeshManager): |
|
|
|