Blender V5.3
MOD_surface.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "BLI_math_vector_c.hh"
11#include "BLI_utildefines.hh"
12
13#include "BLT_translation.hh"
14
15#include "DNA_mesh_types.h"
16#include "DNA_modifier_types.h"
17#include "DNA_object_types.h"
18#include "DNA_screen_types.h"
19
20#include "BKE_bvh.hh"
21#include "BKE_lib_id.hh"
22#include "BKE_mesh.hh"
23
25#include "UI_resources.hh"
26
27#include "RNA_prototypes.hh"
28
29#include "DEG_depsgraph.hh"
31
32#include "MOD_modifiertypes.hh"
33#include "MOD_ui_common.hh"
34
35#include "MEM_guardedalloc.h"
36
37namespace blender {
38
39static void init_data(ModifierData *md)
40{
41 SurfaceModifierData *surmd = reinterpret_cast<SurfaceModifierData *>(md);
43}
44
45static void copy_data(const ModifierData *md_src, ModifierData *md_dst, const int flag)
46{
47 SurfaceModifierData *surmd_dst = reinterpret_cast<SurfaceModifierData *>(md_dst);
48
49 BKE_modifier_copydata_generic(md_src, md_dst, flag);
50
52}
53
54static void free_data(ModifierData *md)
55{
56 SurfaceModifierData *surmd = reinterpret_cast<SurfaceModifierData *>(md);
57
58 if (surmd) {
59 /* The tree is owned by the mesh's cache. */
60 surmd->runtime.bvhtree = nullptr;
61
62 if (surmd->runtime.mesh) {
63 BKE_id_free(nullptr, surmd->runtime.mesh);
64 surmd->runtime.mesh = nullptr;
65 }
66
67 MEM_SAFE_DELETE(surmd->runtime.vert_positions_prev);
68
69 MEM_SAFE_DELETE(surmd->runtime.vert_velocities);
70 }
71}
72
73static bool depends_on_time(Scene * /*scene*/, ModifierData * /*md*/)
74{
75 return true;
76}
77
78static void deform_verts(ModifierData *md,
79 const ModifierEvalContext *ctx,
80 Mesh *mesh,
81 MutableSpan<float3> positions)
82{
83 SurfaceModifierData *surmd = reinterpret_cast<SurfaceModifierData *>(md);
84 const int cfra = int(DEG_get_ctime(ctx->depsgraph));
85
86 /* Free mesh and BVH cache. */
87 surmd->runtime.bvhtree = nullptr;
88 if (surmd->runtime.mesh) {
89 BKE_id_free(nullptr, surmd->runtime.mesh);
90 surmd->runtime.mesh = nullptr;
91 }
92
93 if (mesh) {
95 }
96
97 if (!ctx->object->pd) {
98 printf("SurfaceModifier deform_verts: Should not happen!\n");
99 return;
100 }
101
102 if (surmd->runtime.mesh) {
103 uint mesh_verts_num = 0, i = 0;
104 int init = 0;
105
106 surmd->runtime.mesh->vert_positions_for_write().copy_from(positions);
107 surmd->runtime.mesh->tag_positions_changed();
108
109 mesh_verts_num = surmd->runtime.mesh->verts_num;
110
111 if ((mesh_verts_num != surmd->runtime.verts_num) ||
112 (surmd->runtime.vert_positions_prev == nullptr) ||
113 (surmd->runtime.vert_velocities == nullptr) || (cfra != surmd->runtime.cfra_prev + 1))
114 {
115
116 MEM_SAFE_DELETE(surmd->runtime.vert_positions_prev);
117 MEM_SAFE_DELETE(surmd->runtime.vert_velocities);
118
120 __func__);
121 surmd->runtime.vert_velocities = MEM_new_array_zeroed<float[3]>(mesh_verts_num, __func__);
122
123 surmd->runtime.verts_num = mesh_verts_num;
124
125 init = 1;
126 }
127
128 /* convert to global coordinates and calculate velocity */
129 MutableSpan<float3> positions = surmd->runtime.mesh->vert_positions_for_write();
130 for (i = 0; i < mesh_verts_num; i++) {
131 float *vec = positions[i];
132 mul_m4_v3(ctx->object->object_to_world().ptr(), vec);
133
134 if (init) {
136 }
137 else {
139 }
140
141 copy_v3_v3(surmd->runtime.vert_positions_prev[i], vec);
142 }
143
144 surmd->runtime.cfra_prev = cfra;
145
146 const bool has_face = surmd->runtime.mesh->faces_num > 0;
147 const bool has_edge = surmd->runtime.mesh->edges_num > 0;
148 if (has_face) {
149 surmd->runtime.bvhtree = &surmd->runtime.mesh->bvh_tris();
150 }
151 else if (has_edge) {
152 surmd->runtime.bvhtree = &surmd->runtime.mesh->bvh_edges();
153 }
154 }
155}
156
157static void panel_draw(const bContext * /*C*/, Panel *panel)
158{
159 ui::Layout &layout = *panel->layout;
160
162
163 layout.label(RPT_("Settings are inside the Physics tab"), ICON_NONE);
164
165 modifier_error_message_draw(layout, ptr);
166}
167
168static void panel_register(ARegionType *region_type)
169{
171}
172
173static void blend_read(BlendDataReader * /*reader*/, ModifierData *md)
174{
175 SurfaceModifierData *surmd = reinterpret_cast<SurfaceModifierData *>(md);
176
178}
179
181 /*idname*/ "Surface",
182 /*name*/ N_("Surface"),
183 /*struct_name*/ "SurfaceModifierData",
184 /*struct_size*/ sizeof(SurfaceModifierData),
185 /*srna*/ &RNA_SurfaceModifier,
189 /*icon*/ ICON_MOD_PHYSICS,
190
191 /*copy_data*/ copy_data,
192
193 /*deform_verts*/ deform_verts,
194 /*deform_matrices*/ nullptr,
195 /*deform_verts_EM*/ nullptr,
196 /*deform_matrices_EM*/ nullptr,
197 /*modify_mesh*/ nullptr,
198 /*modify_geometry_set*/ nullptr,
199
200 /*init_data*/ init_data,
201 /*required_data_mask*/ nullptr,
202 /*free_data*/ free_data,
203 /*is_disabled*/ nullptr,
204 /*update_depsgraph*/ nullptr,
205 /*depends_on_time*/ depends_on_time,
206 /*depends_on_normals*/ nullptr,
207 /*foreach_ID_link*/ nullptr,
208 /*foreach_tex_link*/ nullptr,
209 /*free_runtime_data*/ nullptr,
210 /*panel_register*/ panel_register,
211 /*blend_write*/ nullptr,
212 /*blend_read*/ blend_read,
213 /*foreach_cache*/ nullptr,
214 /*foreach_working_space_color*/ nullptr,
215};
216
217} // namespace blender
#define RPT_(msgid)
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
BMesh Iterators.
static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
static bool depends_on_time(Scene *, ModifierData *)
Definition MOD_build.cc:46
static void init_data(ModifierData *md)
ModifierTypeInfo modifierType_Surface
void mul_m4_v3(const float M[4][4], float r[3])
void modifier_error_message_draw(ui::Layout &layout, PointerRNA *ptr)
static void free_data(ModifierData *md)
static void panel_register(ARegionType *region_type)
MINLINE void zero_v3(float r[3])
void BKE_id_free(Main *bmain, void *idv)
@ eModifierTypeFlag_NoUserAdd
@ eModifierTypeFlag_AcceptsCVs
@ eModifierTypeFlag_AcceptsMesh
static void blend_read(BlendDataReader *, ModifierData *md)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
static void panel_draw(const bContext *, Panel *panel)
static void deform_verts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions)
float DEG_get_ctime(const Depsgraph *graph)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BKE_modifier_copydata_generic(const ModifierData *md, ModifierData *md_dst, int flag)
struct PartDeflect * pd
ui::Layout * layout
SurfaceModifierData_Runtime runtime
void label(StringRef name, int icon)
#define N_(msgid)