Skip to content

Commit

Permalink
Fix defer geo no armature case
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter-Noble committed Mar 24, 2017
1 parent 34ca011 commit beeb605
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
14 changes: 10 additions & 4 deletions cm_generation/cm_templates.py
Expand Up @@ -113,6 +113,10 @@ class GeoTemplateGROUP(GeoTemplate):
def build(self, pos, rot, scale, group, deferGeo):
dat = bpy.data

gp = [o for o in dat.groups[self.settings["inputGroup"]].objects]
group_objects = [o.copy() for o in gp]
zaxis = lambda x: x.location[2]

if deferGeo:
for obj in dat.groups[self.settings["inputGroup"]].objects:
if obj.type == 'ARMATURE':
Expand All @@ -125,9 +129,12 @@ def build(self, pos, rot, scale, group, deferGeo):
newObj["cm_deferGroup"] = {"group": self.settings["inputGroup"],
"aName": obj.name}
return newObj

gp = [o for o in dat.groups[self.settings["inputGroup"]].objects]
group_objects = [o.copy() for o in gp]
bpy.ops.object.add(type='EMPTY',
location=min(group_objects, key=zaxis).location)
e = bpy.context.object
group.objects.link(e)
e["cm_deferGroup"] = {"group": self.settings["inputGroup"]}
return e

topObj = None

Expand Down Expand Up @@ -155,7 +162,6 @@ def build(self, pos, rot, scale, group, deferGeo):
topObj = obj

if topObj is None: # For if there is no armature object in the group
zaxis = lambda x: x.location[2]
bpy.ops.object.add(type='EMPTY',
location=min(group_objects, key=zaxis).location)
e = bpy.context.object
Expand Down
57 changes: 36 additions & 21 deletions cm_utilities.py
Expand Up @@ -377,28 +377,43 @@ def execute(self, context):
elif "cm_deferGroup" in obj:
df = obj["cm_deferGroup"]
originalGroup = df["group"]
aName = df["aName"]

newObjs = []
gp = list(groups[originalGroup].objects)
for groupObj in gp:
if groupObj.name != aName:
if "aName" in df:
aName = df["aName"]

newObjs = []
gp = list(groups[originalGroup].objects)
for groupObj in gp:
if groupObj.name != aName:
newObjs.append(groupObj.copy())
else:
newObjs.append(context.scene.objects[agent.name])

for nObj in newObjs:
if nObj.name == agent.name:
continue
if nObj.parent in gp:
nObj.parent = newObjs[gp.index(nObj.parent)]

groups[agent.geoGroup].objects.link(nObj)
bpy.context.scene.objects.link(nObj)
if nObj.type == 'MESH' and len(nObj.modifiers) > 0:
for mod in nObj.modifiers:
if mod.type == "ARMATURE":
mod.object = objects[agent.name]
else:
newObjs = []
gp = list(groups[originalGroup].objects)
for groupObj in gp:
newObjs.append(groupObj.copy())
else:
newObjs.append(context.scene.objects[agent.name])

for nObj in newObjs:
if nObj.name == agent.name:
continue
if nObj.parent in gp:
nObj.parent = newObjs[gp.index(nObj.parent)]

groups[agent.geoGroup].objects.link(nObj)
bpy.context.scene.objects.link(nObj)
if nObj.type == 'MESH' and len(nObj.modifiers) > 0:
for mod in nObj.modifiers:
if mod.type == "ARMATURE":
mod.object = objects[agent.name]

for nObj in newObjs:
if nObj.parent in gp:
nObj.parent = newObjs[gp.index(nObj.parent)]
elif nObj.parent is None:
nObj.parent = obj

groups[agent.geoGroup].objects.link(nObj)
bpy.context.scene.objects.link(nObj)

if preferences.show_node_hud:
newhudText = "Done Placing Deferred Geometry!"
Expand Down

0 comments on commit beeb605

Please sign in to comment.