Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-07-23 03:27:58 +0300
committerHans Goudey <h.goudey@me.com>2022-07-23 03:27:58 +0300
commit97a43c5452d50643143a39bc6e08a3550dc4f8d3 (patch)
tree7240af940b10c419f4f2c8a18a28cc816a7ed3fc /source/blender/blenkernel/intern/crazyspace.c
parent00d2f493d1bb1314d41f6642637a9128f2ab81d9 (diff)
Squashed commit of the following:
commit 33f9897ebe5848b6437e95fb934b6dbda8d58e3b Merge: fcb6a57b8df 80b2fc59d11 Author: Hans Goudey <h.goudey@me.com> Date: Fri Jul 22 19:13:57 2022 -0500 Merge branch 'master' into refactor-mesh-hide-generic commit 80b2fc59d11d5814afe7e219c535525a8d494c17 Author: Hans Goudey <h.goudey@me.com> Date: Fri Jul 22 15:49:53 2022 -0500 Fix T99873: Use evaluated vertex groups in armature modifier Geometry nodes has added the ability to modify mesh vertex groups during evaluation (see 3b6ee8cee7080af2). However, the armature modifier always uses the vertex groups from the original object. This is wrong for the modifier stack, where each modifier is meant to use the output of the previous. This commit makes the armature modifier use the evaluated vertex groups if they are available. Otherwise it uses the originals like before. Differential Revision: https://developer.blender.org/D15515 commit 7d8b651268df74157f89858eda9ddce9fd452138 Author: Clément Foucault <foucault.clem@gmail.com> Date: Fri Jul 22 21:03:06 2022 +0200 EEVEE-Next: Add exposure awareness to denoising This uses the exposure to get a better approximation of the perceptual brighness of a sample before accumulating it. Note that we do not modify exposure of the image. Only the samples weights are computed differently. commit 676a2f690c3e3fffe2e515208d4d308e0a96e8e6 Author: Clément Foucault <foucault.clem@gmail.com> Date: Fri Jul 22 20:32:17 2022 +0200 EEVEE-Next: Fix render not working The swaps during accumulation were ignored because of the way the `SwapChain<>` implementation works. Using external references and updating them fixes the issue. commit 35843ddcd80e5957656b157650da950f228d2808 Author: Hans Goudey <h.goudey@me.com> Date: Fri Jul 22 11:36:55 2022 -0500 Fix T99835: Incorrect title case for two node names commit 98395e0bdfc849e2d2770052c6e8651a42500608 Author: Hans Goudey <h.goudey@me.com> Date: Fri Jul 22 10:49:09 2022 -0500 Cleanup: Use r_ prefix for boolean return parameters Also rearrange some lines to simplify logic. commit c40971d79a887820d621705b29f65f833d9b9f52 Author: Hans Goudey <h.goudey@me.com> Date: Fri Jul 22 10:31:10 2022 -0500 Fix T99873: Store named attribute node cannot write to vertex groups Since fd5e5dac8946b13599, the node would remove the attribute before adding it again, which lost the vertex group status of an attribute, meaning they were written as arbitrary attributes. Now, the node first tries to write to attributes with the same domain and data-type, which covers the vertex group case. Then it falls back to removing the attribute and adding it again. Even that can fail though, so I added an error message to make that a bit clearer. Differential Revision: https://developer.blender.org/D15514 commit e4eaf424b9ce4800e64d35ddfebe28f986b14647 Author: Germano Cavalcante <germano.costa@ig.com.br> Date: Fri Jul 22 12:17:22 2022 -0300 Fix nodes not transforming Error in {rB98bf714b37c1} commit 6bcda04d1f1cc396dcc188678997105b09231bde Author: Hans Goudey <h.goudey@me.com> Date: Fri Jul 22 09:59:28 2022 -0500 Geometry Nodes: Port sample curves node to new data-block Use the newer more generic sampling and interpolation functions developed recently (ab444a80a280) instead of the `CurveEval` type. Functions are split up a bit more internally, to allow a separate mode for supplying the curve index directly in the future (T92474). In one basic test, the performance seems mostly unchanged from 3.1. Differential Revision: https://developer.blender.org/D14621 commit 1f94b56d774440d08eb92f2a7a47b9a6a7aa7b84 Author: Jacques Lucke <jacques@blender.org> Date: Fri Jul 22 15:39:41 2022 +0200 Curves: support sculpting on deformed curves Previously, curves sculpt tools only worked on original data. This was very limiting, because one could effectively only sculpt the curves when all procedural effects were turned off. This patch adds support for curves sculpting while looking the result of procedural effects (like deformation based on the surface mesh). This functionality is also known as "crazy space" support in Blender. For more details see D15407. Differential Revision: https://developer.blender.org/D15407 commit 98bf714b37c1f1b05a162b6ffdaca367b312de1f Author: Germano Cavalcante <mano-wii> Date: Thu Jul 21 23:44:39 2022 -0300 Refactor: arrange transform convert functions in 'TransConvertTypeInfo' Simplify the transform code by bundling the TransData creation, Data recalculation, and special updates into a single struct. So similar functions and parameters can be accessed without special type checks. Differential Revision: https://developer.blender.org/D15494 commit 185eeeaaac01bf24930f7e8b25c96f9fa9503073 Author: Campbell Barton <campbell@blender.org> Date: Fri Jul 22 22:13:10 2022 +1000 GHOST/Wayland: Fix mouse wheel events for Sway Compositor (use seat v5) Bump the requested seat version to v5, use discreet scroll callback. Tested with gnome, river & sway. commit 003dfae270781bfa642a2c5804fa190edd4dfca4 Author: Xavier Hallade <xavier.hallade@intel.com> Date: Fri Jul 22 13:00:46 2022 +0200 Cycles: enable oneAPI in Linux release builds 0f50ae131f54d51f778424d4c9655128cafbbefc didn't do it reliably since it was deactivated explicitly a bit above. commit e0d4aede4da8a1f670f53fe597140111b9726234 Author: Campbell Barton <campbell@blender.org> Date: Fri Jul 22 16:49:37 2022 +1000 BMesh: move bmesh_mesh to C++ This allows parts of the code to be threaded more easily. commit 95e60b4ffd6c325d2658f318d05ab52d712ca953 Author: Jacques Lucke <jacques@blender.org> Date: Fri Jul 22 12:33:08 2022 +0200 Cleanup: move crazyspace.c to c++ Doing this in preparation for D15407. commit 087f27a52f7857887e90754d87a7a73715ebc3fb Author: Campbell Barton <campbell@blender.org> Date: Fri Jul 22 13:57:04 2022 +1000 Fix T87779: Asymmetric vertex positions in circles primitives Add sin_cos_from_fraction which ensures each quadrant has matching values when their sign is flipped. commit 08c5d99e88ee3e9f807dfe69c188660eae347f31 Author: Campbell Barton <campbell@blender.org> Date: Fri Jul 22 13:05:26 2022 +1000 Cleanup: add BKE_image_find_nearest_tile_with_offset Every caller BKE_image_find_nearest_tile was calculating the tile offset so add a version of this function that returns the offset too. commit 72e249974aa7f6a3bd6d5c35c5d5e59cd1c3bded Author: Campbell Barton <campbell@blender.org> Date: Fri Jul 22 12:25:10 2022 +1000 Fix crash loading factory settings in image paint mode Loading factory settings left the region NULL, causing the brushes poll function to crash. commit d3db38cfb1f223b81ab89c38bae0652a0d40c03e Author: Campbell Barton <campbell@blender.org> Date: Fri Jul 22 12:23:33 2022 +1000 Cleanup: quiet nonull-compare warnings with GCC commit 77257405437336dbd91a481926013f8c747cacae Author: Siddhartha Jejurkar <f20180617@goa.bits-pilani.ac.in> Date: Fri Jul 22 10:47:28 2022 +1000 UV: Edge support for select shortest path operator Calculating shortest path selection in UV edge mode was done using vertex path logic. Since the UV editor now supports proper edge selection [0], this approach can sometimes give incorrect results. This problem is now fixed by adding separate logic to calculate the shortest path in UV edge mode. Resolves T99344. [0]: ffaaa0bcbf477c30cf3665b9330bbbb767397169 Reviewed By: campbellbarton Ref D15511. commit aa1ffc093c4711a40932c854670730944008118b Author: Hans Goudey <h.goudey@me.com> Date: Thu Jul 21 19:44:06 2022 -0500 Fix T99884: Crash when converting to old curve type The conversion from Curves to CurveEval used an incorrect type for one of the builtin attributes. Also, an incorrect default was used for reading the nurbs_weight attribute. commit fcb6a57b8dfdc9d18cb370f71f82d6f82f8d917d Author: Hans Goudey <h.goudey@me.com> Date: Thu Jul 21 19:11:50 2022 -0500 Fix BMesh conversion commit d07a18e49b64d475f02b9edf24e3808adfbf4cfb Author: Hans Goudey <h.goudey@me.com> Date: Thu Jul 21 19:09:34 2022 -0500 Remove bad assert commit 520cc7073a9ac8fd25425e7112f6c7d4dea6a43d Author: Hans Goudey <h.goudey@me.com> Date: Thu Jul 21 19:09:23 2022 -0500 Don't create layers when unnecessary commit d39fde3662c792800945270a19612f81a4b8e8fd Author: Hans Goudey <h.goudey@me.com> Date: Thu Jul 21 18:35:16 2022 -0500 Parallelize flag copying commit 76bdacec1bf299de6b36dbc6e45d7922ca15d969 Author: Hans Goudey <h.goudey@me.com> Date: Thu Jul 21 18:19:46 2022 -0500 Cleanup variables names, add "finish" calls commit e91eff347a9f855d3c0e757a94962078cd2e8d60 Author: Hans Goudey <h.goudey@me.com> Date: Thu Jul 21 18:12:35 2022 -0500 Remove "new" in comment
Diffstat (limited to 'source/blender/blenkernel/intern/crazyspace.c')
-rw-r--r--source/blender/blenkernel/intern/crazyspace.c585
1 files changed, 0 insertions, 585 deletions
diff --git a/source/blender/blenkernel/intern/crazyspace.c b/source/blender/blenkernel/intern/crazyspace.c
deleted file mode 100644
index 606d3128804..00000000000
--- a/source/blender/blenkernel/intern/crazyspace.c
+++ /dev/null
@@ -1,585 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later
- * Copyright 2005 Blender Foundation. All rights reserved. */
-
-/** \file
- * \ingroup bke
- */
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-
-#include "BLI_bitmap.h"
-#include "BLI_linklist.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_DerivedMesh.h"
-#include "BKE_crazyspace.h"
-#include "BKE_editmesh.h"
-#include "BKE_lib_id.h"
-#include "BKE_mesh.h"
-#include "BKE_mesh_wrapper.h"
-#include "BKE_modifier.h"
-#include "BKE_multires.h"
-#include "BKE_report.h"
-
-#include "DEG_depsgraph_query.h"
-
-BLI_INLINE void tan_calc_quat_v3(float r_quat[4],
- const float co_1[3],
- const float co_2[3],
- const float co_3[3])
-{
- float vec_u[3], vec_v[3];
- float nor[3];
-
- sub_v3_v3v3(vec_u, co_1, co_2);
- sub_v3_v3v3(vec_v, co_1, co_3);
-
- cross_v3_v3v3(nor, vec_u, vec_v);
-
- if (normalize_v3(nor) > FLT_EPSILON) {
- const float zero_vec[3] = {0.0f};
- tri_to_quat_ex(r_quat, zero_vec, vec_u, vec_v, nor);
- }
- else {
- unit_qt(r_quat);
- }
-}
-
-static void set_crazy_vertex_quat(float r_quat[4],
- const float co_1[3],
- const float co_2[3],
- const float co_3[3],
- const float vd_1[3],
- const float vd_2[3],
- const float vd_3[3])
-{
- float q1[4], q2[4];
-
- tan_calc_quat_v3(q1, co_1, co_2, co_3);
- tan_calc_quat_v3(q2, vd_1, vd_2, vd_3);
-
- sub_qt_qtqt(r_quat, q2, q1);
-}
-
-static bool modifiers_disable_subsurf_temporary(struct Scene *scene, Object *ob)
-{
- bool disabled = false;
- int cageIndex = BKE_modifiers_get_cage_index(scene, ob, NULL, 1);
-
- ModifierData *md = ob->modifiers.first;
- for (int i = 0; md && i <= cageIndex; i++, md = md->next) {
- if (md->type == eModifierType_Subsurf) {
- md->mode ^= eModifierMode_DisableTemporary;
- disabled = true;
- }
- }
-
- return disabled;
-}
-
-float (*BKE_crazyspace_get_mapped_editverts(struct Depsgraph *depsgraph, Object *obedit))[3]
-{
- Scene *scene = DEG_get_input_scene(depsgraph);
- Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
- Object *obedit_eval = DEG_get_evaluated_object(depsgraph, obedit);
- Mesh *mesh_eval = obedit_eval->data;
- BMEditMesh *editmesh_eval = mesh_eval->edit_mesh;
-
- /* disable subsurf temporal, get mapped cos, and enable it */
- if (modifiers_disable_subsurf_temporary(scene_eval, obedit_eval)) {
- /* need to make new derivemesh */
- makeDerivedMesh(depsgraph, scene_eval, obedit_eval, &CD_MASK_BAREMESH);
- }
-
- /* now get the cage */
- Mesh *mesh_eval_cage = editbmesh_get_eval_cage_from_orig(
- depsgraph, scene, obedit, &CD_MASK_BAREMESH);
-
- const int nverts = editmesh_eval->bm->totvert;
- float(*vertexcos)[3] = MEM_mallocN(sizeof(*vertexcos) * nverts, "vertexcos map");
- mesh_get_mapped_verts_coords(mesh_eval_cage, vertexcos, nverts);
-
- /* set back the flag, no new cage needs to be built, transform does it */
- modifiers_disable_subsurf_temporary(scene_eval, obedit_eval);
-
- return vertexcos;
-}
-
-void BKE_crazyspace_set_quats_editmesh(BMEditMesh *em,
- float (*origcos)[3],
- float (*mappedcos)[3],
- float (*quats)[4],
- const bool use_select)
-{
- BMFace *f;
- BMIter iter;
- int index;
-
- {
- BMVert *v;
- BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, index) {
- BM_elem_flag_disable(v, BM_ELEM_TAG);
- BM_elem_index_set(v, index); /* set_inline */
- }
- em->bm->elem_index_dirty &= ~BM_VERT;
- }
-
- BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) {
- BMLoop *l_iter, *l_first;
-
- l_iter = l_first = BM_FACE_FIRST_LOOP(f);
- do {
- if (BM_elem_flag_test(l_iter->v, BM_ELEM_HIDDEN) ||
- BM_elem_flag_test(l_iter->v, BM_ELEM_TAG) ||
- (use_select && !BM_elem_flag_test(l_iter->v, BM_ELEM_SELECT))) {
- continue;
- }
-
- if (!BM_elem_flag_test(l_iter->v, BM_ELEM_TAG)) {
- const float *co_prev, *co_curr, *co_next; /* orig */
- const float *vd_prev, *vd_curr, *vd_next; /* deform */
-
- const int i_prev = BM_elem_index_get(l_iter->prev->v);
- const int i_curr = BM_elem_index_get(l_iter->v);
- const int i_next = BM_elem_index_get(l_iter->next->v);
-
- /* retrieve mapped coordinates */
- vd_prev = mappedcos[i_prev];
- vd_curr = mappedcos[i_curr];
- vd_next = mappedcos[i_next];
-
- if (origcos) {
- co_prev = origcos[i_prev];
- co_curr = origcos[i_curr];
- co_next = origcos[i_next];
- }
- else {
- co_prev = l_iter->prev->v->co;
- co_curr = l_iter->v->co;
- co_next = l_iter->next->v->co;
- }
-
- set_crazy_vertex_quat(quats[i_curr], co_curr, co_next, co_prev, vd_curr, vd_next, vd_prev);
-
- BM_elem_flag_enable(l_iter->v, BM_ELEM_TAG);
- }
- } while ((l_iter = l_iter->next) != l_first);
- }
-}
-
-void BKE_crazyspace_set_quats_mesh(Mesh *me,
- float (*origcos)[3],
- float (*mappedcos)[3],
- float (*quats)[4])
-{
- BLI_bitmap *vert_tag = BLI_BITMAP_NEW(me->totvert, __func__);
-
- /* first store two sets of tangent vectors in vertices, we derive it just from the face-edges */
- const MVert *vertices = BKE_mesh_vertices(me);
- const MPoly *polygons = BKE_mesh_polygons(me);
- const MLoop *loops = BKE_mesh_loops(me);
-
- for (int i = 0; i < me->totpoly; i++) {
- const MPoly *poly = &polygons[i];
- const MLoop *ml_next = &loops[poly->loopstart];
- const MLoop *ml_curr = &ml_next[poly->totloop - 1];
- const MLoop *ml_prev = &ml_next[poly->totloop - 2];
-
- for (int j = 0; j < poly->totloop; j++) {
- if (!BLI_BITMAP_TEST(vert_tag, ml_curr->v)) {
- const float *co_prev, *co_curr, *co_next; /* orig */
- const float *vd_prev, *vd_curr, *vd_next; /* deform */
-
- /* retrieve mapped coordinates */
- vd_prev = mappedcos[ml_prev->v];
- vd_curr = mappedcos[ml_curr->v];
- vd_next = mappedcos[ml_next->v];
-
- if (origcos) {
- co_prev = origcos[ml_prev->v];
- co_curr = origcos[ml_curr->v];
- co_next = origcos[ml_next->v];
- }
- else {
- co_prev = vertices[ml_prev->v].co;
- co_curr = vertices[ml_curr->v].co;
- co_next = vertices[ml_next->v].co;
- }
-
- set_crazy_vertex_quat(
- quats[ml_curr->v], co_curr, co_next, co_prev, vd_curr, vd_next, vd_prev);
-
- BLI_BITMAP_ENABLE(vert_tag, ml_curr->v);
- }
-
- ml_prev = ml_curr;
- ml_curr = ml_next;
- ml_next++;
- }
- }
-
- MEM_freeN(vert_tag);
-}
-
-int BKE_crazyspace_get_first_deform_matrices_editbmesh(struct Depsgraph *depsgraph,
- Scene *scene,
- Object *ob,
- BMEditMesh *em,
- float (**deformmats)[3][3],
- float (**deformcos)[3])
-{
- ModifierData *md;
- Mesh *me_input = ob->data;
- Mesh *me = NULL;
- int i, a, modifiers_left_num = 0, verts_num = 0;
- int cageIndex = BKE_modifiers_get_cage_index(scene, ob, NULL, 1);
- float(*defmats)[3][3] = NULL, (*deformedVerts)[3] = NULL;
- VirtualModifierData virtualModifierData;
- ModifierEvalContext mectx = {depsgraph, ob, 0};
-
- BKE_modifiers_clear_errors(ob);
-
- md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
-
- /* compute the deformation matrices and coordinates for the first
- * modifiers with on cage editing that are enabled and support computing
- * deform matrices */
- for (i = 0; md && i <= cageIndex; i++, md = md->next) {
- const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
-
- if (!editbmesh_modifier_is_enabled(scene, ob, md, me != NULL)) {
- continue;
- }
-
- if (mti->type == eModifierTypeType_OnlyDeform && mti->deformMatricesEM) {
- if (!defmats) {
- const int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
- CustomData_MeshMasks cd_mask_extra = CD_MASK_BAREMESH;
- CDMaskLink *datamasks = BKE_modifier_calc_data_masks(
- scene, ob, md, &cd_mask_extra, required_mode, NULL, NULL);
- cd_mask_extra = datamasks->mask;
- BLI_linklist_free((LinkNode *)datamasks, NULL);
-
- me = BKE_mesh_wrapper_from_editmesh_with_coords(em, &cd_mask_extra, NULL, me_input);
- deformedVerts = editbmesh_vert_coords_alloc(em, &verts_num);
- defmats = MEM_mallocN(sizeof(*defmats) * verts_num, "defmats");
-
- for (a = 0; a < verts_num; a++) {
- unit_m3(defmats[a]);
- }
- }
- mti->deformMatricesEM(md, &mectx, em, me, deformedVerts, defmats, verts_num);
- }
- else {
- break;
- }
- }
-
- for (; md && i <= cageIndex; md = md->next, i++) {
- if (editbmesh_modifier_is_enabled(scene, ob, md, me != NULL) &&
- BKE_modifier_is_correctable_deformed(md)) {
- modifiers_left_num++;
- }
- }
-
- if (me) {
- BKE_id_free(NULL, me);
- }
-
- *deformmats = defmats;
- *deformcos = deformedVerts;
-
- return modifiers_left_num;
-}
-
-/**
- * Crazy-space evaluation needs to have an object which has all the fields
- * evaluated, but the mesh data being at undeformed state. This way it can
- * re-apply modifiers and also have proper pointers to key data blocks.
- *
- * Similar to #BKE_object_eval_reset(), but does not modify the actual evaluated object.
- */
-static void crazyspace_init_object_for_eval(struct Depsgraph *depsgraph,
- Object *object,
- Object *object_crazy)
-{
- Object *object_eval = DEG_get_evaluated_object(depsgraph, object);
- *object_crazy = *object_eval;
- if (object_crazy->runtime.data_orig != NULL) {
- object_crazy->data = object_crazy->runtime.data_orig;
- }
-}
-
-static void crazyspace_init_verts_and_matrices(const Mesh *mesh,
- float (**deformmats)[3][3],
- float (**deformcos)[3])
-{
- int verts_num;
- *deformcos = BKE_mesh_vert_coords_alloc(mesh, &verts_num);
- *deformmats = MEM_callocN(sizeof(**deformmats) * verts_num, "defmats");
- for (int a = 0; a < verts_num; a++) {
- unit_m3((*deformmats)[a]);
- }
- BLI_assert(verts_num == mesh->totvert);
-}
-
-static bool crazyspace_modifier_supports_deform_matrices(ModifierData *md)
-{
- if (ELEM(md->type, eModifierType_Subsurf, eModifierType_Multires)) {
- return true;
- }
- const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
- return (mti->type == eModifierTypeType_OnlyDeform);
-}
-
-static bool crazyspace_modifier_supports_deform(ModifierData *md)
-{
- const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
- return (mti->type == eModifierTypeType_OnlyDeform);
-}
-
-int BKE_sculpt_get_first_deform_matrices(struct Depsgraph *depsgraph,
- Scene *scene,
- Object *object,
- float (**deformmats)[3][3],
- float (**deformcos)[3])
-{
- ModifierData *md;
- Mesh *me_eval = NULL;
- float(*defmats)[3][3] = NULL, (*deformedVerts)[3] = NULL;
- int modifiers_left_num = 0;
- VirtualModifierData virtualModifierData;
- Object object_eval;
- crazyspace_init_object_for_eval(depsgraph, object, &object_eval);
- MultiresModifierData *mmd = get_multires_modifier(scene, &object_eval, 0);
- const bool is_sculpt_mode = (object->mode & OB_MODE_SCULPT) != 0;
- const bool has_multires = mmd != NULL && mmd->sculptlvl > 0;
- const ModifierEvalContext mectx = {depsgraph, &object_eval, 0};
-
- if (is_sculpt_mode && has_multires) {
- *deformmats = NULL;
- *deformcos = NULL;
- return modifiers_left_num;
- }
-
- md = BKE_modifiers_get_virtual_modifierlist(&object_eval, &virtualModifierData);
-
- for (; md; md = md->next) {
- if (!BKE_modifier_is_enabled(scene, md, eModifierMode_Realtime)) {
- continue;
- }
-
- if (crazyspace_modifier_supports_deform_matrices(md)) {
- const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
- if (defmats == NULL) {
- /* NOTE: Evaluated object is re-set to its original un-deformed state. */
- Mesh *me = object_eval.data;
- me_eval = BKE_mesh_copy_for_eval(me, true);
- crazyspace_init_verts_and_matrices(me_eval, &defmats, &deformedVerts);
- }
-
- if (mti->deformMatrices) {
- mti->deformMatrices(md, &mectx, me_eval, deformedVerts, defmats, me_eval->totvert);
- }
- else {
- /* More complex handling will continue in BKE_crazyspace_build_sculpt.
- * Exiting the loop on a non-deform modifier causes issues - T71213. */
- BLI_assert(crazyspace_modifier_supports_deform(md));
- break;
- }
- }
- }
-
- for (; md; md = md->next) {
- if (!BKE_modifier_is_enabled(scene, md, eModifierMode_Realtime)) {
- continue;
- }
-
- if (crazyspace_modifier_supports_deform(md)) {
- modifiers_left_num++;
- }
- }
-
- if (me_eval != NULL) {
- BKE_id_free(NULL, me_eval);
- }
-
- *deformmats = defmats;
- *deformcos = deformedVerts;
-
- return modifiers_left_num;
-}
-
-void BKE_crazyspace_build_sculpt(struct Depsgraph *depsgraph,
- Scene *scene,
- Object *object,
- float (**deformmats)[3][3],
- float (**deformcos)[3])
-{
- int totleft = BKE_sculpt_get_first_deform_matrices(
- depsgraph, scene, object, deformmats, deformcos);
-
- if (totleft) {
- /* There are deformation modifier which doesn't support deformation matrices calculation.
- * Need additional crazy-space correction. */
-
- Mesh *mesh = (Mesh *)object->data;
- Mesh *mesh_eval = NULL;
-
- if (*deformcos == NULL) {
- crazyspace_init_verts_and_matrices(mesh, deformmats, deformcos);
- }
-
- float(*deformedVerts)[3] = *deformcos;
- float(*origVerts)[3] = MEM_dupallocN(deformedVerts);
- float(*quats)[4];
- int i, deformed = 0;
- VirtualModifierData virtualModifierData;
- Object object_eval;
- crazyspace_init_object_for_eval(depsgraph, object, &object_eval);
- ModifierData *md = BKE_modifiers_get_virtual_modifierlist(&object_eval, &virtualModifierData);
- const ModifierEvalContext mectx = {depsgraph, &object_eval, 0};
-
- for (; md; md = md->next) {
- if (!BKE_modifier_is_enabled(scene, md, eModifierMode_Realtime)) {
- continue;
- }
-
- if (crazyspace_modifier_supports_deform(md)) {
- const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
-
- /* skip leading modifiers which have been already
- * handled in sculpt_get_first_deform_matrices */
- if (mti->deformMatrices && !deformed) {
- continue;
- }
-
- if (mesh_eval == NULL) {
- mesh_eval = BKE_mesh_copy_for_eval(mesh, true);
- }
-
- mti->deformVerts(md, &mectx, mesh_eval, deformedVerts, mesh_eval->totvert);
- deformed = 1;
- }
- }
-
- quats = MEM_mallocN(mesh->totvert * sizeof(*quats), "crazy quats");
-
- BKE_crazyspace_set_quats_mesh(mesh, origVerts, deformedVerts, quats);
-
- for (i = 0; i < mesh->totvert; i++) {
- float qmat[3][3], tmat[3][3];
-
- quat_to_mat3(qmat, quats[i]);
- mul_m3_m3m3(tmat, qmat, (*deformmats)[i]);
- copy_m3_m3((*deformmats)[i], tmat);
- }
-
- MEM_freeN(origVerts);
- MEM_freeN(quats);
-
- if (mesh_eval != NULL) {
- BKE_id_free(NULL, mesh_eval);
- }
- }
-
- if (*deformmats == NULL) {
- int a, verts_num;
- Mesh *mesh = (Mesh *)object->data;
-
- *deformcos = BKE_mesh_vert_coords_alloc(mesh, &verts_num);
- *deformmats = MEM_callocN(sizeof(*(*deformmats)) * verts_num, "defmats");
-
- for (a = 0; a < verts_num; a++) {
- unit_m3((*deformmats)[a]);
- }
- }
-}
-
-/* -------------------------------------------------------------------- */
-/** \name Crazyspace API
- * \{ */
-
-void BKE_crazyspace_api_eval(Depsgraph *depsgraph,
- Scene *scene,
- Object *object,
- struct ReportList *reports)
-{
- if (object->runtime.crazyspace_deform_imats != NULL ||
- object->runtime.crazyspace_deform_cos != NULL) {
- return;
- }
-
- if (object->type != OB_MESH) {
- BKE_report(reports,
- RPT_ERROR,
- "Crazyspace transformation is only available for Mesh type of objects");
- return;
- }
-
- const Mesh *mesh = (const Mesh *)object->data;
- object->runtime.crazyspace_verts_num = mesh->totvert;
- BKE_crazyspace_build_sculpt(depsgraph,
- scene,
- object,
- &object->runtime.crazyspace_deform_imats,
- &object->runtime.crazyspace_deform_cos);
-}
-
-void BKE_crazyspace_api_displacement_to_deformed(struct Object *object,
- struct ReportList *reports,
- int vertex_index,
- float displacement[3],
- float r_displacement_deformed[3])
-{
- if (vertex_index < 0 || vertex_index >= object->runtime.crazyspace_verts_num) {
- BKE_reportf(reports,
- RPT_ERROR,
- "Invalid vertex index %d (expected to be within 0 to %d range)",
- vertex_index,
- object->runtime.crazyspace_verts_num);
- return;
- }
-
- mul_v3_m3v3(r_displacement_deformed,
- object->runtime.crazyspace_deform_imats[vertex_index],
- displacement);
-}
-
-void BKE_crazyspace_api_displacement_to_original(struct Object *object,
- struct ReportList *reports,
- int vertex_index,
- float displacement_deformed[3],
- float r_displacement[3])
-{
- if (vertex_index < 0 || vertex_index >= object->runtime.crazyspace_verts_num) {
- BKE_reportf(reports,
- RPT_ERROR,
- "Invalid vertex index %d (expected to be within 0 to %d range))",
- vertex_index,
- object->runtime.crazyspace_verts_num);
- return;
- }
-
- float mat[3][3];
- if (!invert_m3_m3(mat, object->runtime.crazyspace_deform_imats[vertex_index])) {
- copy_v3_v3(r_displacement, displacement_deformed);
- return;
- }
-
- mul_v3_m3v3(r_displacement, mat, displacement_deformed);
-}
-
-void BKE_crazyspace_api_eval_clear(Object *object)
-{
- MEM_SAFE_FREE(object->runtime.crazyspace_deform_imats);
- MEM_SAFE_FREE(object->runtime.crazyspace_deform_cos);
-}
-
-/** \} */