Beispiel #1
0
def blob_group_assign(context, blobob, test=False):
    settings = _settings.get(context)
    blob_group = settings.blob_group(context)

    if test and blobob in blob_group.objects.values():
        return

    blob_group.objects.link(blobob)
    # NOTE: unsetting the type is important, otherwise gathering templates
    # a second time will include deleted objects!
    blobob.meadow.type = 'NONE'
Beispiel #2
0
def blob_group_assign(context, blobob, test=False):
    settings = _settings.get(context)
    blob_group = settings.blob_group(context)
    
    if test and blobob in blob_group.objects.values():
        return
    
    blob_group.objects.link(blobob)
    # NOTE: unsetting the type is important, otherwise gathering templates
    # a second time will include deleted objects!
    blobob.meadow.type = 'NONE'
Beispiel #3
0
    def execute(self, context):
        scene = context.scene
        settings = _settings.get(context)

        groundob = find_meadow_object(context, 'GROUND')

        with OperatorCallContext():
            progress_default()
            meadow.delete_blobs(context, groundob)

        return {'FINISHED'}
Beispiel #4
0
 def execute(self, context):
     scene = context.scene
     settings = _settings.get(context)
     
     groundob = find_meadow_object(context, 'GROUND')
     
     with OperatorCallContext():
         progress_default()
         meadow.delete_blobs(context, groundob)
     
     return {'FINISHED'}
Beispiel #5
0
def make_samples(context, gridob, groundob):
    settings = _settings.get(context)
    
    mat = groundob.matrix_world
    bbmin = mat * Vector(tuple(min(p[i] for p in groundob.bound_box) for i in range(3)))
    bbmax = mat * Vector(tuple(max(p[i] for p in groundob.bound_box) for i in range(3)))
    
    # get a sample generator implementation
    #gen = best_candidate_gen(groundob.meadow.sample_distance, bbmin[0], bbmax[0], bbmin[1], bbmax[1])
    gen = hierarchical_dart_throw_gen(groundob.meadow.sample_distance, groundob.meadow.sampling_levels, bbmin[0], bbmax[0], bbmin[1], bbmax[1])
    
    loc2D = [p[0:2] for p in gen(groundob.meadow.seed, groundob.meadow.max_samples)]
    
    return loc2D
Beispiel #6
0
def bake_all(context):
    context_override = context.copy(
    )  # context override for the 'point_cache' argument
    scene = context.scene
    settings = _settings.get(context)

    patches = patch.patch_objects(context)
    nonpatches = set(scene.objects) - set(patches)

    # XXX this could disable necessary external influences,
    # so for now rely on the user to disable unnecessary stuff
    # should not be a big issue in practice ...
    """
    # disable all non-patch objects to avoid possible simulation overhead
    for ob in nonpatches:
        for md in ob.modifiers:
            if md.type in sim_modifier_types:
                md.show_viewport = False
                md.show_render = False
    """

    for ob in patches:
        for md, ptcache in object_sims(ob):
            # convenience feature: copy the frame range from the scene to the patch objects
            # the per-cache frame range will probably be dropped anyway at some point
            ptcache.frame_start = scene.frame_start
            ptcache.frame_end = scene.frame_end

            # reset unbaked cache data just to be sure (depsgraph is not reliable enough ...)
            object_mod_clear_cache(md)

    # walk through frames, this creates (unbaked) cache frames
    totframes = scene.frame_end - scene.frame_start + 1  # note: +1 because the end frame is included
    with progress.ProgressContext("Calculate Physics", scene.frame_start,
                                  scene.frame_end):
        for cfra in range(scene.frame_start, scene.frame_end + 1):
            progress.progress_set(cfra)
            scene.frame_set(cfra)
            scene.update()

    # make cached data "baked" so it doesn't get destroyed
    for ob in patches:
        for md, ptcache in object_sims(ob):
            if not ptcache.is_baked:
                select_single_object(ob)
                context_override["point_cache"] = ptcache
                bpy.ops.ptcache.bake_from_cache(context_override)
Beispiel #7
0
def bake_all(context):
    context_override = context.copy() # context override for the 'point_cache' argument
    scene = context.scene
    settings = _settings.get(context)

    patches = patch.patch_objects(context)
    nonpatches = set(scene.objects) - set(patches)
    
    # XXX this could disable necessary external influences,
    # so for now rely on the user to disable unnecessary stuff
    # should not be a big issue in practice ...
    """
    # disable all non-patch objects to avoid possible simulation overhead
    for ob in nonpatches:
        for md in ob.modifiers:
            if md.type in sim_modifier_types:
                md.show_viewport = False
                md.show_render = False
    """
    
    for ob in patches:
        for md, ptcache in object_sims(ob):
            # convenience feature: copy the frame range from the scene to the patch objects
            # the per-cache frame range will probably be dropped anyway at some point
            ptcache.frame_start = scene.frame_start
            ptcache.frame_end = scene.frame_end

            # reset unbaked cache data just to be sure (depsgraph is not reliable enough ...)
            object_mod_clear_cache(md)

    # walk through frames, this creates (unbaked) cache frames
    totframes = scene.frame_end - scene.frame_start + 1 # note: +1 because the end frame is included
    with progress.ProgressContext("Calculate Physics", scene.frame_start, scene.frame_end):
        for cfra in range(scene.frame_start, scene.frame_end+1):
            progress.progress_set(cfra)
            scene.frame_set(cfra)
            scene.update()

    # make cached data "baked" so it doesn't get destroyed
    for ob in patches:
        for md, ptcache in object_sims(ob):
            if not ptcache.is_baked:
                select_single_object(ob)
                context_override["point_cache"] = ptcache
                bpy.ops.ptcache.bake_from_cache(context_override)
Beispiel #8
0
def make_samples(context, gridob, groundob):
    settings = _settings.get(context)

    mat = groundob.matrix_world
    bbmin = mat * Vector(
        tuple(min(p[i] for p in groundob.bound_box) for i in range(3)))
    bbmax = mat * Vector(
        tuple(max(p[i] for p in groundob.bound_box) for i in range(3)))

    # get a sample generator implementation
    #gen = best_candidate_gen(groundob.meadow.sample_distance, bbmin[0], bbmax[0], bbmin[1], bbmax[1])
    gen = hierarchical_dart_throw_gen(groundob.meadow.sample_distance,
                                      groundob.meadow.sampling_levels,
                                      bbmin[0], bbmax[0], bbmin[1], bbmax[1])

    loc2D = [
        p[0:2] for p in gen(groundob.meadow.seed, groundob.meadow.max_samples)
    ]

    return loc2D
Beispiel #9
0
def make_blob_object(context, index, loc, samples, display_radius):
    settings = _settings.get(context)
    
    obmat = Matrix.Translation(loc)
    
    mesh = duplimesh.make_dupli_mesh(_blob_object_name, obmat, samples, display_radius)
    mesh.materials.append(get_blob_material(context))
    
    ob = object_utils.object_data_add(bpy.context, mesh, operator=None).object
    # assign the index for mapping
    ob.meadow.blob_index = index
    # objects get put at the cursor location by object_utils
    ob.matrix_world = obmat
    
    blob_apply_settings(ob, settings)
    
    # assign color and material settings
    ob.color = select_color(index)
    ob.show_wire_color = True # XXX this is debatable, could make it an option
    
    return ob
Beispiel #10
0
def make_blob_object(context, index, loc, samples, display_radius):
    settings = _settings.get(context)

    obmat = Matrix.Translation(loc)

    mesh = duplimesh.make_dupli_mesh(_blob_object_name, obmat, samples,
                                     display_radius)
    mesh.materials.append(get_blob_material(context))

    ob = object_utils.object_data_add(bpy.context, mesh, operator=None).object
    # assign the index for mapping
    ob.meadow.blob_index = index
    # objects get put at the cursor location by object_utils
    ob.matrix_world = obmat

    blob_apply_settings(ob, settings)

    # assign color and material settings
    ob.color = select_color(index)
    ob.show_wire_color = True  # XXX this is debatable, could make it an option

    return ob
Beispiel #11
0
 def execute(self, context):
     scene = context.scene
     settings = _settings.get(context)
     
     if not settings.patch_group(context):
         bpy.data.groups.new(settings.patch_groupname)
     if not settings.blob_group(context):
         bpy.data.groups.new(settings.blob_groupname)
     
     groundob = find_meadow_object(context, 'GROUND')
     if not groundob:
         self.report({'ERROR'}, "Could not find meadow Ground object")
         return {'CANCELLED'}
     blobgridob = find_meadow_object(context, 'BLOBGRID')
     if not blobgridob:
         self.report({'ERROR'}, "Could not find meadow Blob Grid object")
         return {'CANCELLED'}
     
     with OperatorCallContext():
         progress_default()
         meadow.make_patches(context, blobgridob, groundob)
     
     return {'FINISHED'}
Beispiel #12
0
    def execute(self, context):
        scene = context.scene
        settings = _settings.get(context)

        if not settings.patch_group(context):
            bpy.data.groups.new(settings.patch_groupname)
        if not settings.blob_group(context):
            bpy.data.groups.new(settings.blob_groupname)

        groundob = find_meadow_object(context, 'GROUND')
        if not groundob:
            self.report({'ERROR'}, "Could not find meadow Ground object")
            return {'CANCELLED'}
        blobgridob = find_meadow_object(context, 'BLOBGRID')
        if not blobgridob:
            self.report({'ERROR'}, "Could not find meadow Blob Grid object")
            return {'CANCELLED'}

        with OperatorCallContext():
            progress_default()
            meadow.make_patches(context, blobgridob, groundob)

        return {'FINISHED'}
Beispiel #13
0
    def draw(self, context):
        settings = _settings.get(context)
        groundob = find_meadow_object(context, 'GROUND')
        has_samples = blob.object_has_blob_data(groundob) if groundob else False
        ob = context.object
        meadow = ob.meadow
        layout = self.layout
        
        layout.prop(meadow, "type", expand=True)
        
        layout.separator()
        
        if meadow.type == 'TEMPLATE':
            row = layout.row()
            if groundob:
                row.prop_search(meadow, "density_vgroup_name", groundob, "vertex_groups", text="Density Vertex Group")
            else:
                row.active = False
                row.prop(meadow, "density_vgroup_name", text="Density Vertex Group")
            
            row = layout.row()
            row.prop(meadow, "use_as_dupli")
            sub = row.row()
            sub.enabled = meadow.use_as_dupli
            sub.prop(meadow, "use_centered")
            row = layout.row()
            row.prop(meadow, "hide")
        
        elif meadow.type == 'GROUND':
            box = layout.box()
            
            sub = box.column()
            # this politely prevents users from changing settings unwantedly,
            # they have to delete the samples first
            sub.enabled = not has_samples
            sub.prop(meadow, "seed")
            col = sub.column(align=True)
            col.prop(meadow, "sample_distance")
            sub2 = col.row(align=True)
            sub2.prop(meadow, "max_samples")
            sub2.operator("meadow.estimate_max_samples", text="Estimate")
            sub.prop(meadow, "sampling_levels")
            
            if has_samples:
                box.operator("meadow.delete_blobs", icon='X', text="Delete Samples")
            else:
                box.operator("meadow.make_blobs", icon='STICKY_UVS_DISABLE', text="Create Samples")
        
        layout.separator()
        
        col = layout.column()
        col.enabled = has_samples

        box = col.box()
        box.prop(meadow, "slope_rotation")
        box.operator("meadow.make_patches", icon='PARTICLE_PATH', text="Update Patches")
        
        row = col.row()
        row.operator("meadow.bake_physics", icon='MOD_PHYSICS')
        row.operator("meadow.free_physics", icon='X')

        if groundob:
            row = layout.row()
            row.prop(groundob.meadow, "use_layers")
            sub = row.row()
            if groundob.meadow.use_layers:
                sub.template_layers(groundob.meadow, "layers", groundob.meadow, "used_layers", -1)
            else:
                sub.enabled = False
                sub.template_layers(groundob, "layers", groundob.meadow, "used_layers", -1)
Beispiel #14
0
def patch_group_clear(context):
    settings = _settings.get(context)
    patch_group = settings.patch_group(context)
    
    if patch_group:
        delete_objects(context, patch_group.objects)
Beispiel #15
0
    def draw(self, context):
        settings = _settings.get(context)
        groundob = find_meadow_object(context, 'GROUND')
        has_samples = blob.object_has_blob_data(
            groundob) if groundob else False
        ob = context.object
        meadow = ob.meadow
        layout = self.layout

        layout.prop(meadow, "type", expand=True)

        layout.separator()

        if meadow.type == 'TEMPLATE':
            row = layout.row()
            if groundob:
                row.prop_search(meadow,
                                "density_vgroup_name",
                                groundob,
                                "vertex_groups",
                                text="Density Vertex Group")
            else:
                row.active = False
                row.prop(meadow,
                         "density_vgroup_name",
                         text="Density Vertex Group")

            row = layout.row()
            row.prop(meadow, "use_as_dupli")
            sub = row.row()
            sub.enabled = meadow.use_as_dupli
            sub.prop(meadow, "use_centered")
            row = layout.row()
            row.prop(meadow, "hide")

        elif meadow.type == 'GROUND':
            box = layout.box()

            sub = box.column()
            # this politely prevents users from changing settings unwantedly,
            # they have to delete the samples first
            sub.enabled = not has_samples
            sub.prop(meadow, "seed")
            col = sub.column(align=True)
            col.prop(meadow, "sample_distance")
            sub2 = col.row(align=True)
            sub2.prop(meadow, "max_samples")
            sub2.operator("meadow.estimate_max_samples", text="Estimate")
            sub.prop(meadow, "sampling_levels")

            if has_samples:
                box.operator("meadow.delete_blobs",
                             icon='X',
                             text="Delete Samples")
            else:
                box.operator("meadow.make_blobs",
                             icon='STICKY_UVS_DISABLE',
                             text="Create Samples")

        layout.separator()

        col = layout.column()
        col.enabled = has_samples

        box = col.box()
        box.prop(meadow, "slope_rotation")
        box.operator("meadow.make_patches",
                     icon='PARTICLE_PATH',
                     text="Update Patches")

        row = col.row()
        row.operator("meadow.bake_physics", icon='MOD_PHYSICS')
        row.operator("meadow.free_physics", icon='X')

        if groundob:
            row = layout.row()
            row.prop(groundob.meadow, "use_layers")
            sub = row.row()
            if groundob.meadow.use_layers:
                sub.template_layers(groundob.meadow, "layers", groundob.meadow,
                                    "used_layers", -1)
            else:
                sub.enabled = False
                sub.template_layers(groundob, "layers", groundob.meadow,
                                    "used_layers", -1)
Beispiel #16
0
def patch_group_remove(context, patchob):
    settings = _settings.get(context)
    patch_group = settings.patch_group(context)
    
    patch_group.objects.unlink(patchob)
Beispiel #17
0
def blob_group_remove(context, blobob):
    settings = _settings.get(context)
    blob_group = settings.blob_group(context)
    
    blob_group.objects.unlink(blobob)
Beispiel #18
0
def blob_group_clear(context):
    settings = _settings.get(context)
    blob_group = settings.blob_group(context)
    
    if blob_group:
        delete_objects(context, blob_group.objects)
Beispiel #19
0
def blob_objects(context):
    settings = _settings.get(context)
    blob_group = settings.blob_group(context)
    # ignore objects with invalid blob index
    return [ob for ob in blob_group.objects if ob.meadow.blob_index >= 0]
Beispiel #20
0
def blob_objects(context):
    settings = _settings.get(context)
    blob_group = settings.blob_group(context)
    # ignore objects with invalid blob index
    return [ob for ob in blob_group.objects if ob.meadow.blob_index >= 0]
Beispiel #21
0
def blob_group_clear(context):
    settings = _settings.get(context)
    blob_group = settings.blob_group(context)

    if blob_group:
        delete_objects(context, blob_group.objects)
Beispiel #22
0
def blob_group_remove(context, blobob):
    settings = _settings.get(context)
    blob_group = settings.blob_group(context)

    blob_group.objects.unlink(blobob)