From 59e5481b5765c1176e9c72667525804f31f6f468 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 4 Apr 2023 17:28:34 -0400 Subject: [PATCH] Fix incorrect pretends-to-be-a semantics from #367. This fixes review comments left on #367 that were caused by missing pretends-to-be-a semantics. `BMeshObject` is intended to provide pass-through access to `bpy.types.Object`'s attributes. --- korman/exporter/utils.py | 12 ++++++++++++ korman/operators/op_mesh.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/korman/exporter/utils.py b/korman/exporter/utils.py index 188c490..fa180ee 100644 --- a/korman/exporter/utils.py +++ b/korman/exporter/utils.py @@ -85,6 +85,18 @@ class BMeshObject: def __getattr__(self, name: str) -> Any: return getattr(self._obj, name) + def __setattr__(self, name: str, value: Any) -> None: + # NOTE: Calling `hasattr()` will trigger infinite recursion in __getattr__(), so + # check the object dict itself for anything that we want on this instance. + d = self.__dict__ + if name not in d: + obj = d.get("_obj") + if obj is not None: + if hasattr(obj, name): + setattr(obj, name, value) + return + super().__setattr__(name, value) + @property def object(self) -> bpy.types.Object: return self._obj diff --git a/korman/operators/op_mesh.py b/korman/operators/op_mesh.py index 3db0ab8..0917589 100644 --- a/korman/operators/op_mesh.py +++ b/korman/operators/op_mesh.py @@ -103,7 +103,7 @@ class PlasmaAddFlareOperator(PlasmaMeshOperator, bpy.types.Operator): flare_plane = utils.BMeshObject(f"{self.name_stem}_Visible", managed=False) flare_plane.hide_render = True flare_plane.plasma_object.enabled = True - bpyscene.objects.active = flare_plane + bpyscene.objects.active = flare_plane.object with flare_plane as bm: # Make the actual plane mesh, facing away from the empty bmesh.ops.create_grid(bm, size=(0.5 + self.flare_distance * 0.5), matrix=mathutils.Matrix.Rotation(math.radians(180.0), 4, 'X'))