Example #1
0
    def execute(self, context):
        sourcelist = []
        targetlist = []
        processed = set()
        links = [obj.name for obj in bpy.context.selected_objects if obj.phobostype == 'link']
        t = datetime.now()
        objdict = {obj.name: obj for obj in bpy.data.objects if obj.phobostype in ['visual', 'collision']
                   and obj.parent.name in links}
        # gather all name bases of objects for which both visual and collision are present
        for obj in objdict.keys():
            basename = obj.replace(objdict[obj].phobostype + '_', '')
            if 'visual_' + basename in objdict.keys() and 'collision_' + basename in objdict.keys():
                processed.add(basename)
        # fill source and target lists for syncing
        for basename in processed:
            if self.synctype == "vtc":
                sourcelist.append('visual_' + basename)
                targetlist.append('collision_' + basename)
            elif self.synctype == "ctv":
                targetlist.append('visual_' + basename)
                sourcelist.append('collision_' + basename)
            else:  # latest to oldest
                try:
                    tv = generalUtils.datetimeFromIso(objdict['visual_' + basename]['masschanged'])
                    tc = generalUtils.datetimeFromIso(objdict['collision_' + basename]['masschanged'])
                    if tc < tv:  # if collision information is older than visual information
                        sourcelist.append('visual_' + basename)
                        targetlist.append('collision_' + basename)
                    else:
                        targetlist.append('visual_' + basename)
                        sourcelist.append('collision_' + basename)
                except KeyError:
                    print(basename, "has insufficient data for time-based synchronisation of masses.")
        # sync the mass values
        for i in range(len(sourcelist)):
            try:
                objdict[targetlist[i]]['mass'] = objdict[sourcelist[i]]['mass']
            except KeyError:
                print("No mass information in object", targetlist[i])
            if self.synctype != "vtc" and self.synctype != "ctv":
                objdict[targetlist[i]]['masschanged'] = objdict[sourcelist[i]]['masschanged']

        for linkname in links:
            masssum = 0.0
            link = bpy.data.objects[linkname]
            viscols = inertia.getInertiaRelevantObjects(link)
            for obj in viscols:
                masssum += obj['mass']
            link['mass'] = masssum
            link['masschanged'] = t.isoformat()
            if self.updateinertial:
                inertia.createInertials(link)
        return {'FINISHED'}
Example #2
0
 def execute(self, context):
     links = [obj for obj in bpy.context.selected_objects if obj.phobostype == 'link']
     show_progress = bpy.app.version[0] * 100 + bpy.app.version[1] >= 269
     if show_progress:
         wm = bpy.context.window_manager
         total = float(len(links))
         wm.progress_begin(0, total)
         i = 1
     for link in links:
         inertia.createInertials(link, not self.auto_compute, self.preserve_children)
         if show_progress:
             wm.progress_update(i)
             i += 1
     if show_progress:
         wm.progress_end()
     return {'FINISHED'}