[Bf-blender-cvs] [945e1e98baa] hair_guides_grooming: Move bind data from bundle to region.
Lukas Tönne
noreply at git.blender.org
Mon Jun 4 15:05:29 CEST 2018
Commit: 945e1e98baa734f443640238c59c6ff093320bbb
Author: Lukas Tönne
Date: Mon Jun 4 14:02:12 2018 +0100
Branches: hair_guides_grooming
https://developer.blender.org/rB945e1e98baa734f443640238c59c6ff093320bbb
Move bind data from bundle to region.
===================================================================
M release/scripts/startup/bl_ui/properties_data_groom.py
M source/blender/blenkernel/BKE_groom.h
M source/blender/blenkernel/intern/groom.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/draw/intern/draw_cache_impl_groom.c
M source/blender/editors/groom/editgroom.c
M source/blender/editors/groom/editgroom_region.c
M source/blender/editors/space_view3d/view3d_iterators.c
M source/blender/editors/transform/transform_conversions.c
M source/blender/makesdna/DNA_groom_types.h
M source/blender/makesrna/intern/rna_groom.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_groom.py b/release/scripts/startup/bl_ui/properties_data_groom.py
index a31f0ac3f76..f5ff9302fe1 100644
--- a/release/scripts/startup/bl_ui/properties_data_groom.py
+++ b/release/scripts/startup/bl_ui/properties_data_groom.py
@@ -26,13 +26,12 @@ class GROOM_UL_regions(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
groom = data
region = item
- bundle = region.bundle
if self.layout_type in {'DEFAULT', 'COMPACT'}:
row = layout.row(align=True)
- if not bundle.is_bound:
+ if not region.is_bound:
row.label(icon='ERROR')
- row.label(bundle.scalp_facemap)
+ row.label(region.scalp_facemap)
elif self.layout_type == 'GRID':
layout.alignment = 'CENTER'
@@ -98,15 +97,13 @@ class DATA_PT_groom_regions(DataButtonsPanel, Panel):
groom, "regions",
groom.regions, "active_index")
if region:
- bundle = region.bundle
-
col = layout.column()
if groom.scalp_object:
- col.prop_search(bundle, "scalp_facemap", groom.scalp_object, "face_maps", text="")
+ col.prop_search(region, "scalp_facemap", groom.scalp_object, "face_maps", text="")
else:
- col.prop(bundle, "scalp_facemap", text="")
+ col.prop(region, "scalp_facemap", text="")
- col.prop(bundle, "guides_count")
+ col.prop(region.bundle, "guides_count")
class DATA_PT_groom_hair(DataButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/BKE_groom.h b/source/blender/blenkernel/BKE_groom.h
index a23a8f540bb..ef9be249897 100644
--- a/source/blender/blenkernel/BKE_groom.h
+++ b/source/blender/blenkernel/BKE_groom.h
@@ -36,6 +36,7 @@ struct BoundBox;
struct Depsgraph;
struct Groom;
struct GroomBundle;
+struct GroomRegion;
struct Main;
struct Mesh;
struct Object;
@@ -68,8 +69,8 @@ void BKE_groom_curve_cache_clear(struct Groom *groom);
/* Try to bind bundles to their scalp regions */
void BKE_groom_bind_scalp_regions(struct Groom *groom, bool force_rebind);
-bool BKE_groom_bundle_bind(struct Groom *groom, struct GroomBundle *bundle, bool force_rebind);
-void BKE_groom_bundle_unbind(struct GroomBundle *bundle);
+bool BKE_groom_region_bind(struct Groom *groom, struct GroomRegion *region, bool force_rebind);
+void BKE_groom_region_unbind(struct GroomRegion *region);
/* === Constraints === */
diff --git a/source/blender/blenkernel/intern/groom.c b/source/blender/blenkernel/intern/groom.c
index b608268cad2..61060de42b9 100644
--- a/source/blender/blenkernel/intern/groom.c
+++ b/source/blender/blenkernel/intern/groom.c
@@ -106,6 +106,11 @@ static void groom_regions_free(ListBase *regions)
{
for (GroomRegion *region = regions->first; region; region = region->next)
{
+ if (region->scalp_samples)
+ {
+ MEM_freeN(region->scalp_samples);
+ }
+
GroomBundle *bundle = ®ion->bundle;
BKE_groom_bundle_curve_cache_clear(bundle);
@@ -118,10 +123,6 @@ static void groom_regions_free(ListBase *regions)
{
MEM_freeN(bundle->verts);
}
- if (bundle->scalp_region)
- {
- MEM_freeN(bundle->scalp_region);
- }
if (bundle->guides)
{
MEM_freeN(bundle->guides);
@@ -182,6 +183,11 @@ void BKE_groom_copy_data(Main *UNUSED(bmain), Groom *groom_dst, const Groom *gro
BLI_duplicatelist(&groom_dst->regions, &groom_src->regions);
for (GroomRegion *region = groom_dst->regions.first; region; region = region->next)
{
+ if (region->scalp_samples)
+ {
+ region->scalp_samples = MEM_dupallocN(region->scalp_samples);
+ }
+
GroomBundle *bundle = ®ion->bundle;
if (bundle->curvecache)
{
@@ -195,10 +201,6 @@ void BKE_groom_copy_data(Main *UNUSED(bmain), Groom *groom_dst, const Groom *gro
{
bundle->verts = MEM_dupallocN(bundle->verts);
}
- if (bundle->scalp_region)
- {
- bundle->scalp_region = MEM_dupallocN(bundle->scalp_region);
- }
if (bundle->guides)
{
bundle->guides = MEM_dupallocN(bundle->guides);
@@ -244,7 +246,7 @@ bool BKE_groom_minmax(Groom *groom, float min[3], float max[3])
GroomBundle *bundle = ®ion->bundle;
if (bundle->curvecache)
{
- const int totcurvecache = (bundle->numshapeverts + 1) * bundle->curvesize;
+ const int totcurvecache = (region->numverts + 1) * bundle->curvesize;
GroomCurveCache *cc = bundle->curvecache;
for (int i = 0; i < totcurvecache; ++i, ++cc)
{
@@ -299,29 +301,29 @@ void BKE_groom_bind_scalp_regions(Groom *groom, bool force_rebind)
{
for (GroomRegion *region = groom->editgroom->regions.first; region; region = region->next)
{
- BKE_groom_bundle_bind(groom, ®ion->bundle, force_rebind);
+ BKE_groom_region_bind(groom, region, force_rebind);
}
}
else
{
for (GroomRegion *region = groom->regions.first; region; region = region->next)
{
- BKE_groom_bundle_bind(groom, ®ion->bundle, force_rebind);
+ BKE_groom_region_bind(groom, region, force_rebind);
}
}
}
/* Returns the transform at the root of the bundle */
-static bool groom_get_bundle_transform_on_scalp(const GroomBundle *bundle, const Mesh *scalp, float r_loc[3], float r_rot[3][3])
+static bool groom_get_region_transform_on_scalp(const GroomRegion *region, const Mesh *scalp, float r_loc[3], float r_rot[3][3])
{
- const int numshapeverts = bundle->numshapeverts;
- if (numshapeverts == 0 || bundle->scalp_region == NULL)
+ const int numverts = region->numverts;
+ if (numverts == 0 || region->scalp_samples == NULL)
{
return false;
}
/* last sample is the center position */
- const MeshSample *center_sample = &bundle->scalp_region[numshapeverts];
+ const MeshSample *center_sample = ®ion->scalp_samples[numverts];
if (BKE_mesh_sample_eval(scalp, center_sample, r_loc, r_rot[2], r_rot[1]))
{
@@ -336,11 +338,12 @@ static bool groom_get_bundle_transform_on_scalp(const GroomBundle *bundle, const
}
}
-static bool groom_shape_rebuild(GroomBundle *bundle, Object *scalp_ob)
+static bool groom_shape_rebuild(GroomRegion *region, Object *scalp_ob)
{
- BLI_assert(bundle->scalp_region != NULL);
+ GroomBundle *bundle = ®ion->bundle;
+ BLI_assert(region->scalp_samples != NULL);
BLI_assert(scalp_ob->type == OB_MESH);
- const int numshapeverts = bundle->numshapeverts;
+ const int numshapeverts = region->numverts;
bool result = true;
float (*shape)[2] = MEM_mallocN(sizeof(*shape) * numshapeverts, "groom section shape");
@@ -349,13 +352,13 @@ static bool groom_shape_rebuild(GroomBundle *bundle, Object *scalp_ob)
float center_loc[3];
float center_mat[3][3];
- if (!groom_get_bundle_transform_on_scalp(bundle, me, center_loc, center_mat))
+ if (!groom_get_region_transform_on_scalp(region, me, center_loc, center_mat))
{
result = false;
goto cleanup;
}
- MeshSample *sample = bundle->scalp_region;
+ MeshSample *sample = region->scalp_samples;
GroomSectionVertex *vert0 = bundle->verts;
for (int i = 0; i < numshapeverts; ++i, ++sample, ++vert0)
{
@@ -409,14 +412,14 @@ static BMesh *groom_create_scalp_bmesh(Mesh *me)
return bm;
}
-static bool groom_bundle_region_from_mesh_fmap(GroomBundle *bundle, Object *scalp_ob)
+static bool groom_region_from_mesh_fmap(GroomRegion *region, Object *scalp_ob)
{
BLI_assert(scalp_ob->type == OB_MESH);
- BKE_groom_bundle_curve_cache_clear(bundle);
+ BKE_groom_bundle_curve_cache_clear(®ion->bundle);
Mesh *me = scalp_ob->data;
- const int scalp_fmap_nr = BKE_object_facemap_name_index(scalp_ob, bundle->scalp_facemap_name);
+ const int scalp_fmap_nr = BKE_object_facemap_name_index(scalp_ob, region->scalp_facemap_name);
const int cd_fmap_offset = CustomData_get_offset(&me->pdata, CD_FACEMAP);
if (scalp_fmap_nr < 0 || cd_fmap_offset < 0)
{
@@ -448,14 +451,14 @@ static bool groom_bundle_region_from_mesh_fmap(GroomBundle *bundle, Object *scal
goto finalize;
}
- const int numshapeverts = bundle->numshapeverts = BMO_slot_buffer_count(op.slots_out, "boundary");
- bundle->scalp_region = MEM_callocN(sizeof(*bundle->scalp_region) * (numshapeverts + 1), "groom bundle scalp region");
+ const int numverts = region->numverts = BMO_slot_buffer_count(op.slots_out, "boundary");
+ region->scalp_samples = MEM_callocN(sizeof(*region->scalp_samples) * (numverts + 1), "groom bundle scalp region");
float center_co[3]; /* average vertex location for placing the center */
{
BMLoop *l;
BMOIter oiter;
- MeshSample *sample = bundle->scalp_region;
+ MeshSample *sample = region->scalp_samples;
zero_v3(center_co);
BMO_ITER (l, &oiter, op.slots_out, "boundary", BM_LOOP)
{
@@ -469,9 +472,9 @@ static bool groom_bundle_region_from_mesh_fmap(GroomBundle *bundle, Object *scal
++sample;
}
- if (numshapeverts > 0)
+ if (numverts > 0)
{
- mul_v3_fl(center_co, 1.0f / (float)(numshapeverts));
+ mul_v3_fl(center_co, 1.0f / (float)(numverts));
}
}
@@ -488,7 +491,7 @@ static bool groom_bundle_region_from_mesh_fmap(GroomBundle *bundle, Object *scal
if (nearest.index >= 0)
{
/* last sample is the center position */
- MeshSample *center_sample = &bundle->scalp_region[numshapeverts];
+ MeshSample *center_sample = ®ion->scalp_samples[numverts];
BKE_mesh_sample_weights_from_loc(center_sample, me, nearest.index, nearest.co);
BLI_assert(BKE_mesh_sample_is_valid(center_sample));
}
@@ -504,14 +507,14 @@ static bool groom_bundle_region_from_mesh_fmap(GroomBundle *bundle, Object *scal
finalize:
if (result == true)
{
- groom_shape_rebuild(bundle, scalp_ob);
+ groom_shape_rebuild(region, scalp_ob);
}
else
{
- if (bundle->scalp_region)
+ if (region->scalp_samples)
{
- MEM_freeN(bundle->scalp_region);
- bundle->scalp_region = NULL;
+ MEM_freeN(region->scalp_samples);
+ region->scalp_samples = NULL;
}
}
@@ -521,37 +524,37 @@ finalize:
return result;
}
-bool BKE_groom_bundle_bind(Groom *groom, GroomBundle *bundle, bool force_rebind)
+bool BKE_groom_region_bind(Groom *groom, GroomRegion
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list