[Bf-blender-cvs] [839c682ba5e] derived: Fix bug.
Brecht Van Lommel
noreply at git.blender.org
Thu Mar 28 02:28:55 CET 2019
Commit: 839c682ba5e9ae2c35a8cb9c568b2ab23fea9f9e
Author: Brecht Van Lommel
Date: Thu Mar 28 02:17:30 2019 +0100
Branches: derived
https://developer.blender.org/rB839c682ba5e9ae2c35a8cb9c568b2ab23fea9f9e
Fix bug.
===================================================================
M source/blender/blenkernel/intern/DerivedMesh.c
M source/blender/blenkernel/intern/object_dupli.c
===================================================================
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 2496ccb047e..a6b564d36f3 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1148,10 +1148,12 @@ static void mesh_modifiers_eval(
/* We need mesh even for deform-only part of the stack, in cases where some modifier needs
* e.g. access to updated normals. See T62633 for an example. */
- Mesh *me = NULL;
-
+ Mesh *me = BKE_mesh_copy_for_eval(ob->data, true);
+ ASSERT_IS_VALID_MESH(me);
+ bool isDeformedOnly = true;
float (*deformedVerts)[3] = NULL;
bool isPrevDeform = false;
+
if (useDeform) {
/* Apply all leading deforming modifiers */
for (; md; md = md->next, curr = curr->next) {
@@ -1177,10 +1179,6 @@ static void mesh_modifiers_eval(
}
if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
- if (me == NULL) {
- me = BKE_mesh_copy_for_eval(ob->data, true);
- ASSERT_IS_VALID_MESH(me);
- }
BKE_mesh_apply_vert_coords(me, deformedVerts);
}
@@ -1227,7 +1225,7 @@ static void mesh_modifiers_eval(
continue;
}
- if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && me) {
+ if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && !isDeformedOnly) {
modifier_setError(md, "Modifier requires original data, bad stack position");
continue;
}
@@ -1253,7 +1251,7 @@ static void mesh_modifiers_eval(
mti->requiredDataMask(ob, md, &mask);
}
- if (me && (mask.vmask & CD_MASK_ORCO)) {
+ if (mask.vmask & CD_MASK_ORCO) {
add_orco_mesh(ob, NULL, me, me_orco, CD_ORCO);
}
@@ -1265,25 +1263,18 @@ static void mesh_modifiers_eval(
if (mti->type == eModifierTypeType_OnlyDeform) {
/* No existing verts to deform, need to build them. */
if (!deformedVerts) {
- if (me) {
- /* Deforming a mesh, read the vertex locations
- * out of the mesh and deform them. Once done with this
- * run of deformers verts will be written back.
- */
- deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
- }
- else {
- deformedVerts = BKE_mesh_vertexCos_get(ob->data, &numVerts);
- }
+ /* Deforming a mesh, read the vertex locations
+ * out of the mesh and deform them. Once done with this
+ * run of deformers verts will be written back.
+ */
+ deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
}
/* if this is not the last modifier in the stack then recalculate the normals
* to avoid giving bogus normals to the next modifier see: [#23673] */
if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
/* XXX, this covers bug #23673, but we may need normal calc for other types */
- if (me) {
- BKE_mesh_apply_vert_coords(me, deformedVerts);
- }
+ BKE_mesh_apply_vert_coords(me, deformedVerts);
}
modwrap_deformVerts(md, &mectx_deform, me, deformedVerts, numVerts);
@@ -1297,19 +1288,11 @@ static void mesh_modifiers_eval(
nextmask = *dataMask;
/* apply vertex coordinates or build a Mesh as necessary */
- if (me) {
- if (deformedVerts) {
- BKE_mesh_apply_vert_coords(me, deformedVerts);
- }
+ if (deformedVerts) {
+ BKE_mesh_apply_vert_coords(me, deformedVerts);
}
- else {
- me = BKE_mesh_copy_for_eval(ob->data, true);
- ASSERT_IS_VALID_MESH(me);
-
- if (deformedVerts) {
- BKE_mesh_apply_vert_coords(me, deformedVerts);
- }
+ if (isDeformedOnly) {
/* Constructive modifiers need to have an origindex
* otherwise they wont have anywhere to copy the data from.
*
@@ -1317,7 +1300,8 @@ static void mesh_modifiers_eval(
* requests it, this way Mirror, Solidify etc will keep ORIGINDEX
* data by using generic DM_copy_vert_data() functions.
*/
- if (need_mapping || ((nextmask.vmask | nextmask.emask | nextmask.pmask) & CD_MASK_ORIGINDEX)) {
+ /*if (need_mapping || ((nextmask.vmask | nextmask.emask | nextmask.pmask) & CD_MASK_ORIGINDEX))*/ {
+ printf("go!\n");
/* calc */
CustomData_add_layer(&me->vdata, CD_ORIGINDEX, CD_CALLOC, NULL, me->totvert);
CustomData_add_layer(&me->edata, CD_ORIGINDEX, CD_CALLOC, NULL, me->totedge);
@@ -1361,7 +1345,7 @@ static void mesh_modifiers_eval(
if (me_next) {
/* if the modifier returned a new mesh, release the old one */
- if (me && me != me_next) {
+ if (me != me_next) {
BLI_assert(me != ob->data);
BKE_id_free(NULL, me);
}
@@ -1399,7 +1383,7 @@ static void mesh_modifiers_eval(
if (me_next) {
/* if the modifier returned a new mesh, release the old one */
- if (me_orco && me_orco != me_next) {
+ if (me_orco != me_next) {
BLI_assert(me_orco != ob->data);
BKE_id_free(NULL, me_orco);
}
@@ -1425,7 +1409,7 @@ static void mesh_modifiers_eval(
if (me_next) {
/* if the modifier returned a new mesh, release the old one */
- if (me_orco_cloth && me_orco_cloth != me_next) {
+ if (me_orco_cloth != me_next) {
BLI_assert(me_orco != ob->data);
BKE_id_free(NULL, me_orco_cloth);
}
@@ -1441,6 +1425,7 @@ static void mesh_modifiers_eval(
}
me->runtime.deformed_only = false;
+ isDeformedOnly = false;
}
isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform);
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 1f3680eb850..51212ffb0a7 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -316,26 +316,19 @@ typedef struct VertexDupliData {
float child_imat[4][4];
} VertexDupliData;
-static void get_duplivert_transform(const float co[3], const float nor_f[3], const short nor_s[3],
+static void get_duplivert_transform(const float co[3], const short no[3],
bool use_rotation, short axis, short upflag, float mat[4][4])
{
float quat[4];
const float size[3] = {1.0f, 1.0f, 1.0f};
if (use_rotation) {
- float nor[3];
/* construct rotation matrix from normals */
- if (nor_f) {
- nor[0] = -nor_f[0];
- nor[1] = -nor_f[1];
- nor[2] = -nor_f[2];
- }
- else if (nor_s) {
- nor[0] = (float)-nor_s[0];
- nor[1] = (float)-nor_s[1];
- nor[2] = (float)-nor_s[2];
- }
- vec_to_quat(quat, nor, axis, upflag);
+ float nor_f[3];
+ nor_f[0] = (float)-no[0];
+ nor_f[1] = (float)-no[1];
+ nor_f[2] = (float)-no[2];
+ vec_to_quat(quat, nor_f, axis, upflag);
}
else
unit_qt(quat);
@@ -343,16 +336,14 @@ static void get_duplivert_transform(const float co[3], const float nor_f[3], con
loc_quat_size_to_mat4(mat, co, quat, size);
}
-static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
- const float nor_f[3], const short nor_s[3])
+static void vertex_dupli(const VertexDupliData *vdd, int index, const float co[3], const short no[3])
{
- const VertexDupliData *vdd = userData;
Object *inst_ob = vdd->inst_ob;
DupliObject *dob;
float obmat[4][4], space_mat[4][4];
/* obmat is transform to vertex */
- get_duplivert_transform(co, nor_f, nor_s, vdd->use_rotation, inst_ob->trackflag, inst_ob->upflag, obmat);
+ get_duplivert_transform(co, no, vdd->use_rotation, inst_ob->trackflag, inst_ob->upflag, obmat);
/* make offset relative to inst_ob using relative child transform */
mul_mat3_m4_v3((float (*)[4])vdd->child_imat, obmat[3]);
/* apply obmat _after_ the local vertex transform */
@@ -382,8 +373,14 @@ static void make_child_duplis_verts(const DupliContext *ctx, void *userdata, Obj
/* relative transform from parent to child space */
mul_m4_m4m4(vdd->child_imat, child->imat, ctx->object->obmat);
- BKE_mesh_foreach_mapped_vert(me_eval, vertex_dupli__mapFunc, vdd,
- vdd->use_rotation ? MESH_FOREACH_USE_NORMAL : 0);
+ const MVert *mvert = me_eval->mvert;
+ const int *index = CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX);
+
+ for (int i = 0, j = 0; i < me_eval->totvert; i++, mvert++) {
+ if (index == NULL || *index != ORIGINDEX_NONE) {
+ vertex_dupli(vdd, j++, mvert->co, mvert->no);
+ }
+ }
}
static void make_duplis_verts(const DupliContext *ctx)
More information about the Bf-blender-cvs
mailing list