Blender V5.3
MOD_ocean.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_color_types.hh"
10#include "BLI_math_base_c.hh"
11#include "BLI_task_c.hh"
12#include "BLI_utildefines.hh"
13
14#include "BLT_translation.hh"
15
17#include "DNA_mesh_types.h"
18#include "DNA_meshdata_types.h"
19#include "DNA_modifier_types.h"
20#include "DNA_object_types.h"
21#include "DNA_screen_types.h"
22
23#include "BKE_attribute.h"
24#include "BKE_attribute.hh"
25#include "BKE_lib_id.hh"
26#include "BKE_mesh.hh"
27#include "BKE_modifier.hh"
28#include "BKE_ocean.h"
29
31#include "UI_resources.hh"
32
33#include "RNA_access.hh"
34#include "RNA_prototypes.hh"
35
36#include "WM_types.hh" /* For UI free bake operator. */
37
39
40#include "MOD_ui_common.hh"
41
42namespace blender {
43
44#ifdef WITH_OCEANSIM
45static void init_cache_data(Object *ob, OceanModifierData *omd, const int resolution)
46{
47 const char *relbase = BKE_modifier_path_relbase_from_global(ob);
48
49 omd->oceancache = BKE_ocean_init_cache(omd->cachepath,
50 relbase,
51 omd->bakestart,
52 omd->bakeend,
53 omd->wave_scale,
54 omd->chop_amount,
55 omd->foam_coverage,
56 omd->foam_fade,
57 resolution);
58}
59
60static void simulate_ocean_modifier(OceanModifierData *omd)
61{
62 BKE_ocean_simulate(omd->ocean, omd->time, omd->wave_scale, omd->chop_amount);
63}
64#endif /* WITH_OCEANSIM */
65
66/* Modifier Code */
67
68static void init_data(ModifierData *md)
69{
70#ifdef WITH_OCEANSIM
73
74 BKE_modifier_path_init(omd->cachepath, sizeof(omd->cachepath), "cache_ocean");
75
76 omd->ocean = BKE_ocean_add();
78 simulate_ocean_modifier(omd);
79 }
80#else /* WITH_OCEANSIM */
81 UNUSED_VARS(md);
82#endif /* WITH_OCEANSIM */
83}
84
85static void free_data(ModifierData *md)
86{
87#ifdef WITH_OCEANSIM
89
91 if (omd->oceancache) {
93 }
94#else /* WITH_OCEANSIM */
95 /* unused */
96 (void)md;
97#endif /* WITH_OCEANSIM */
98}
99
100static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
101{
102#ifdef WITH_OCEANSIM
103# if 0
104 const OceanModifierData *omd = (const OceanModifierData *)md;
105# endif
106 OceanModifierData *tomd = (OceanModifierData *)target;
107
108 BKE_modifier_copydata_generic(md, target, flag);
109
110 /* The oceancache object will be recreated for this copy
111 * automatically when cached=true */
112 tomd->oceancache = nullptr;
113
114 tomd->ocean = BKE_ocean_add();
116 simulate_ocean_modifier(tomd);
117 }
118#else /* WITH_OCEANSIM */
119 /* unused */
120 (void)md;
121 (void)target;
122 (void)flag;
123#endif /* WITH_OCEANSIM */
124}
125
126#ifdef WITH_OCEANSIM
127static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
128{
129 OceanModifierData *omd = (OceanModifierData *)md;
130
131 if (omd->flag & MOD_OCEAN_GENERATE_FOAM) {
132 r_cddata_masks->fmask |= CD_MASK_MCOL; /* XXX Should be loop cddata I guess? */
133 }
134}
135#else /* WITH_OCEANSIM */
136static void required_data_mask(ModifierData * /*md*/, CustomData_MeshMasks * /*r_cddata_masks*/) {}
137#endif /* WITH_OCEANSIM */
138
139#ifdef WITH_OCEANSIM
140
141struct GenerateOceanGeometryData {
142 MutableSpan<float3> vert_positions;
143 MutableSpan<int> face_offsets;
144 MutableSpan<int> corner_verts;
145 MutableSpan<float2> uv_map;
146
147 int res_x, res_y;
148 int rx, ry;
149 float ox, oy;
150 float sx, sy;
151 float ix, iy;
152};
153
154static void generate_ocean_geometry_verts(void *__restrict userdata,
155 const int y,
156 const TaskParallelTLS *__restrict /*tls*/)
157{
158 GenerateOceanGeometryData *gogd = static_cast<GenerateOceanGeometryData *>(userdata);
159 int x;
160
161 for (x = 0; x <= gogd->res_x; x++) {
162 const int i = y * (gogd->res_x + 1) + x;
163 float *co = gogd->vert_positions[i];
164 co[0] = gogd->ox + (x * gogd->sx);
165 co[1] = gogd->oy + (y * gogd->sy);
166 co[2] = 0.0f;
167 }
168}
169
170static void generate_ocean_geometry_faces(void *__restrict userdata,
171 const int y,
172 const TaskParallelTLS *__restrict /*tls*/)
173{
174 GenerateOceanGeometryData *gogd = static_cast<GenerateOceanGeometryData *>(userdata);
175 int x;
176
177 for (x = 0; x < gogd->res_x; x++) {
178 const int fi = y * gogd->res_x + x;
179 const int vi = y * (gogd->res_x + 1) + x;
180
181 gogd->corner_verts[fi * 4 + 0] = vi;
182 gogd->corner_verts[fi * 4 + 1] = vi + 1;
183 gogd->corner_verts[fi * 4 + 2] = vi + 1 + gogd->res_x + 1;
184 gogd->corner_verts[fi * 4 + 3] = vi + gogd->res_x + 1;
185
186 gogd->face_offsets[fi] = fi * 4;
187 }
188}
189
190static void generate_ocean_geometry_uvs(void *__restrict userdata,
191 const int y,
192 const TaskParallelTLS *__restrict /*tls*/)
193{
194 GenerateOceanGeometryData *gogd = static_cast<GenerateOceanGeometryData *>(userdata);
195 int x;
196
197 for (x = 0; x < gogd->res_x; x++) {
198 const int i = y * gogd->res_x + x;
199 float2 *luv = &gogd->uv_map[i * 4];
200
201 (*luv)[0] = x * gogd->ix;
202 (*luv)[1] = y * gogd->iy;
203 luv++;
204
205 (*luv)[0] = (x + 1) * gogd->ix;
206 (*luv)[1] = y * gogd->iy;
207 luv++;
208
209 (*luv)[0] = (x + 1) * gogd->ix;
210 (*luv)[1] = (y + 1) * gogd->iy;
211 luv++;
212
213 (*luv)[0] = x * gogd->ix;
214 (*luv)[1] = (y + 1) * gogd->iy;
215 luv++;
216 }
217}
218
219static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig, const int resolution)
220{
221 Mesh *result;
222
223 GenerateOceanGeometryData gogd;
224
225 int verts_num;
226 int faces_num;
227
228 const bool use_threading = resolution > 4;
229
230 gogd.rx = resolution * resolution;
231 gogd.ry = resolution * resolution;
232 gogd.res_x = gogd.rx * omd->repeat_x;
233 gogd.res_y = gogd.ry * omd->repeat_y;
234
235 verts_num = (gogd.res_x + 1) * (gogd.res_y + 1);
236 faces_num = gogd.res_x * gogd.res_y;
237
238 gogd.sx = omd->size * omd->spatial_size;
239 gogd.sy = omd->size * omd->spatial_size;
240 gogd.ox = -gogd.sx / 2.0f;
241 gogd.oy = -gogd.sy / 2.0f;
242
243 gogd.sx /= gogd.rx;
244 gogd.sy /= gogd.ry;
245
246 result = BKE_mesh_new_nomain(verts_num, 0, faces_num, faces_num * 4);
248
249 gogd.vert_positions = result->vert_positions_for_write();
250 gogd.face_offsets = result->face_offsets_for_write();
251 gogd.corner_verts = result->corner_verts_for_write();
252
253 TaskParallelSettings settings;
255 settings.use_threading = use_threading;
256
257 /* create vertices */
258 BLI_task_parallel_range(0, gogd.res_y + 1, &gogd, generate_ocean_geometry_verts, &settings);
259
260 /* create faces */
261 BLI_task_parallel_range(0, gogd.res_y, &gogd, generate_ocean_geometry_faces, &settings);
262
263 bke::mesh_calc_edges(*result, false, false);
264
265 /* add uvs */
266 if (result->uv_map_names().size() < MAX_MTFACE) {
267 bke::MutableAttributeAccessor attributes = result->attributes_for_write();
269 "UVMap");
270 bke::SpanAttributeWriter<float2> uv_map = attributes.lookup_or_add_for_write_span<float2>(
272
273 if (uv_map) { /* unlikely to fail */
274 gogd.uv_map = uv_map.span;
275 gogd.ix = 1.0 / gogd.rx;
276 gogd.iy = 1.0 / gogd.ry;
277
278 BLI_task_parallel_range(0, gogd.res_y, &gogd, generate_ocean_geometry_uvs, &settings);
279 }
280
281 uv_map.finish();
282 }
283
284 return result;
285}
286
287static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
288{
290 if (omd->ocean && !BKE_ocean_is_valid(omd->ocean)) {
291 BKE_modifier_set_error(ctx->object, md, "Failed to allocate memory");
292 return mesh;
293 }
294 int cfra_scene = int(DEG_get_ctime(ctx->depsgraph));
295 Object *ob = ctx->object;
296 bool allocated_ocean = false;
297
298 Mesh *result = nullptr;
299 OceanResult ocr;
300
301 const int resolution = (ctx->flag & MOD_APPLY_RENDER) ? omd->resolution :
302 omd->viewport_resolution;
303
304 int cfra_for_cache;
305 int i, j;
306
307 /* Use cached & inverted value for speed expanded this would read:
308 * `(axis / (omd->size * omd->spatial_size)) + 0.5f`. */
309# define OCEAN_CO(_size_co_inv, _v) ((_v * _size_co_inv) + 0.5f)
310
311 const float size_co_inv = 1.0f / (omd->size * omd->spatial_size);
312
313 /* can happen in when size is small, avoid bad array lookups later and quit now */
314 if (!isfinite(size_co_inv)) {
315 return mesh;
316 }
317
318 /* do ocean simulation */
319 if (omd->cached) {
320 if (!omd->oceancache) {
321 init_cache_data(ob, omd, resolution);
322 }
323 BKE_ocean_simulate_cache(omd->oceancache, cfra_scene);
324 }
325 else {
326 /* omd->ocean is nullptr on an original object (in contrast to an evaluated one).
327 * We can create a new one, but we have to free it as well once we're done.
328 * This function is only called on an original object when applying the modifier
329 * using the 'Apply Modifier' button, and thus it is not called frequently for
330 * simulation. */
331 allocated_ocean |= BKE_ocean_ensure(omd, resolution);
332 simulate_ocean_modifier(omd);
333 }
334
335 if (omd->geometry_mode == MOD_OCEAN_GEOM_GENERATE) {
336 result = generate_ocean_geometry(omd, mesh, resolution);
337 }
338 else if (omd->geometry_mode == MOD_OCEAN_GEOM_DISPLACE) {
339 result = (Mesh *)BKE_id_copy_ex(nullptr, &mesh->id, nullptr, LIB_ID_COPY_LOCALIZE);
340 }
341
342 cfra_for_cache = cfra_scene;
343 CLAMP(cfra_for_cache, omd->bakestart, omd->bakeend);
344 cfra_for_cache -= omd->bakestart; /* shift to 0 based */
345
346 MutableSpan<float3> positions = result->vert_positions_for_write();
347 const OffsetIndices faces = result->faces();
348
349 /* Add vertex-colors before displacement: allows lookup based on position. */
350
351 if (omd->flag & MOD_OCEAN_GENERATE_FOAM) {
353 bke::MutableAttributeAccessor attributes = result->attributes_for_write();
354 const Span<int> corner_verts = result->corner_verts();
355 bke::SpanAttributeWriter mloopcols = attributes.lookup_or_add_for_write_span<ColorGeometry4b>(
356 BKE_attribute_calc_unique_name(owner, omd->foamlayername), bke::AttrDomain::Corner);
357
359 if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) {
360 mloopcols_spray = attributes.lookup_or_add_for_write_span<ColorGeometry4b>(
361 BKE_attribute_calc_unique_name(owner, omd->spraylayername), bke::AttrDomain::Corner);
362 }
363
364 if (mloopcols) { /* unlikely to fail */
365
366 for (const int i : faces.index_range()) {
367 const IndexRange face = faces[i];
368 const int *corner_vert = &corner_verts[face.start()];
369 ColorGeometry4b *mlcol = &mloopcols.span[face.start()];
370
371 ColorGeometry4b *mlcolspray = nullptr;
372 if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) {
373 mlcolspray = &mloopcols_spray.span[face.start()];
374 }
375
376 for (j = face.size(); j--; corner_vert++, mlcol++) {
377 const float *vco = positions[*corner_vert];
378 const float u = OCEAN_CO(size_co_inv, vco[0]);
379 const float v = OCEAN_CO(size_co_inv, vco[1]);
380 float foam;
381
382 if (omd->oceancache && omd->cached) {
383 BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v);
384 foam = ocr.foam;
385 CLAMP(foam, 0.0f, 1.0f);
386 }
387 else {
388 BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
389 foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage);
390 }
391
392 mlcol->r = mlcol->g = mlcol->b = char(foam * 255);
393 /* This needs to be set (render engine uses) */
394 mlcol->a = 255;
395
396 if (omd->flag & MOD_OCEAN_GENERATE_SPRAY) {
397 if (omd->flag & MOD_OCEAN_INVERT_SPRAY) {
398 mlcolspray->r = ocr.Eminus[0] * 255;
399 }
400 else {
401 mlcolspray->r = ocr.Eplus[0] * 255;
402 }
403 mlcolspray->g = 0;
404 if (omd->flag & MOD_OCEAN_INVERT_SPRAY) {
405 mlcolspray->b = ocr.Eminus[2] * 255;
406 }
407 else {
408 mlcolspray->b = ocr.Eplus[2] * 255;
409 }
410 mlcolspray->a = 255;
411 }
412 }
413 }
414 }
415
416 mloopcols.finish();
417 mloopcols_spray.finish();
418 }
419
420 /* displace the geometry */
421
422 /* NOTE: tried to parallelized that one and previous foam loop,
423 * but gives 20% slower results... odd. */
424 {
425 const int verts_num = result->verts_num;
426
427 for (i = 0; i < verts_num; i++) {
428 float *vco = positions[i];
429 const float u = OCEAN_CO(size_co_inv, vco[0]);
430 const float v = OCEAN_CO(size_co_inv, vco[1]);
431
432 if (omd->oceancache && omd->cached) {
433 BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra_for_cache, u, v);
434 }
435 else {
436 BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
437 }
438
439 vco[2] += ocr.disp[1];
440
441 if (omd->chop_amount > 0.0f) {
442 vco[0] += ocr.disp[0];
443 vco[1] += ocr.disp[2];
444 }
445 }
446 }
447
448 result->tag_positions_changed();
449
450 if (allocated_ocean) {
451 BKE_ocean_free(omd->ocean);
452 omd->ocean = nullptr;
453 }
454
455# undef OCEAN_CO
456
457 return result;
458}
459#else /* WITH_OCEANSIM */
460static Mesh *doOcean(ModifierData * /*md*/, const ModifierEvalContext * /*ctx*/, Mesh *mesh)
461{
462 return mesh;
463}
464#endif /* WITH_OCEANSIM */
465
467{
468 return doOcean(md, ctx, mesh);
469}
470// #define WITH_OCEANSIM
471static void panel_draw(const bContext * /*C*/, Panel *panel)
472{
473 ui::Layout &layout = *panel->layout;
474#ifdef WITH_OCEANSIM
475
476 PointerRNA ob_ptr;
478
479 layout.use_property_split_set(true);
480
481 ui::Layout &col = layout.column(false);
482 col.prop(ptr, "geometry_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
483 if (RNA_enum_get(ptr, "geometry_mode") == MOD_OCEAN_GEOM_GENERATE) {
484 ui::Layout &sub = col.column(true);
485 sub.prop(ptr, "repeat_x", UI_ITEM_NONE, IFACE_("Repeat X"), ICON_NONE);
486 sub.prop(ptr, "repeat_y", UI_ITEM_NONE, IFACE_("Y"), ICON_NONE);
487 }
488
489 ui::Layout &sub = col.column(true);
490 sub.prop(ptr, "viewport_resolution", UI_ITEM_NONE, IFACE_("Resolution Viewport"), ICON_NONE);
491 sub.prop(ptr, "resolution", UI_ITEM_NONE, IFACE_("Render"), ICON_NONE);
492
493 col.prop(ptr, "time", UI_ITEM_NONE, std::nullopt, ICON_NONE);
494
495 col.prop(ptr, "depth", UI_ITEM_NONE, std::nullopt, ICON_NONE);
496 col.prop(ptr, "size", UI_ITEM_NONE, std::nullopt, ICON_NONE);
497 col.prop(ptr, "spatial_size", UI_ITEM_NONE, std::nullopt, ICON_NONE);
498
499 col.prop(ptr, "random_seed", UI_ITEM_NONE, std::nullopt, ICON_NONE);
500
501 col.prop(ptr, "use_normals", UI_ITEM_NONE, std::nullopt, ICON_NONE);
502
503 modifier_error_message_draw(layout, ptr);
504
505#else /* WITH_OCEANSIM */
506 layout.label(RPT_("Built without Ocean modifier"), ICON_NONE);
507#endif /* WITH_OCEANSIM */
508}
509
510#ifdef WITH_OCEANSIM
511static void waves_panel_draw(const bContext * /*C*/, Panel *panel)
512{
513 ui::Layout &layout = *panel->layout;
514
515 PointerRNA *ptr = modifier_panel_get_property_pointers(panel, nullptr);
516
517 layout.use_property_split_set(true);
518
519 ui::Layout *col = &layout.column(false);
520 col->prop(ptr, "wave_scale", UI_ITEM_NONE, IFACE_("Scale"), ICON_NONE);
521 col->prop(ptr, "wave_scale_min", UI_ITEM_NONE, std::nullopt, ICON_NONE);
522 col->prop(ptr, "choppiness", UI_ITEM_NONE, std::nullopt, ICON_NONE);
523 col->prop(ptr, "wind_velocity", UI_ITEM_NONE, std::nullopt, ICON_NONE);
524
525 layout.separator();
526
527 col = &layout.column(false);
528 col->prop(ptr, "wave_alignment", ui::ITEM_R_SLIDER, IFACE_("Alignment"), ICON_NONE);
529 ui::Layout &sub = col->column(false);
530 sub.active_set(RNA_float_get(ptr, "wave_alignment") > 0.0f);
531 sub.prop(ptr, "wave_direction", UI_ITEM_NONE, IFACE_("Direction"), ICON_NONE);
532 sub.prop(ptr, "damping", UI_ITEM_NONE, std::nullopt, ICON_NONE);
533}
534
535static void foam_panel_draw_header(const bContext * /*C*/, Panel *panel)
536{
537 ui::Layout &layout = *panel->layout;
538
540
541 layout.prop(ptr, "use_foam", UI_ITEM_NONE, IFACE_("Foam"), ICON_NONE);
542}
543
544static void foam_panel_draw(const bContext * /*C*/, Panel *panel)
545{
546 ui::Layout &layout = *panel->layout;
547
549
550 bool use_foam = RNA_boolean_get(ptr, "use_foam");
551
552 layout.use_property_split_set(true);
553
554 ui::Layout &col = layout.column(false);
555 col.active_set(use_foam);
556 col.prop(ptr, "foam_layer_name", UI_ITEM_NONE, IFACE_("Data Layer"), ICON_NONE);
557 col.prop(ptr, "foam_coverage", UI_ITEM_NONE, IFACE_("Coverage"), ICON_NONE);
558}
559
560static void spray_panel_draw_header(const bContext * /*C*/, Panel *panel)
561{
562 ui::Layout &layout = *panel->layout;
563
565
566 bool use_foam = RNA_boolean_get(ptr, "use_foam");
567
568 ui::Layout &row = layout.row(false);
569 row.active_set(use_foam);
570 row.prop(
571 ptr, "use_spray", UI_ITEM_NONE, CTX_IFACE_(BLT_I18NCONTEXT_ID_MESH, "Spray"), ICON_NONE);
572}
573
574static void spray_panel_draw(const bContext * /*C*/, Panel *panel)
575{
576 ui::Layout &layout = *panel->layout;
577
579
580 bool use_foam = RNA_boolean_get(ptr, "use_foam");
581 bool use_spray = RNA_boolean_get(ptr, "use_spray");
582
583 layout.use_property_split_set(true);
584
585 ui::Layout &col = layout.column(false);
586 col.active_set(use_foam && use_spray);
587 col.prop(ptr, "spray_layer_name", UI_ITEM_NONE, IFACE_("Data Layer"), ICON_NONE);
588 col.prop(ptr, "invert_spray", UI_ITEM_NONE, IFACE_("Invert"), ICON_NONE);
589}
590
591static void spectrum_panel_draw(const bContext * /*C*/, Panel *panel)
592{
593 ui::Layout &layout = *panel->layout;
594
596
597 int spectrum = RNA_enum_get(ptr, "spectrum");
598
599 layout.use_property_split_set(true);
600
601 ui::Layout &col = layout.column(false);
602 col.prop(ptr, "spectrum", UI_ITEM_NONE, std::nullopt, ICON_NONE);
604 col.prop(ptr, "sharpen_peak_jonswap", ui::ITEM_R_SLIDER, std::nullopt, ICON_NONE);
605 col.prop(ptr, "fetch_jonswap", UI_ITEM_NONE, std::nullopt, ICON_NONE);
606 }
607}
608
609static void bake_panel_draw(const bContext * /*C*/, Panel *panel)
610{
611 ui::Layout &layout = *panel->layout;
612
614
615 layout.use_property_split_set(true);
616
617 bool is_cached = RNA_boolean_get(ptr, "is_cached");
618 bool use_foam = RNA_boolean_get(ptr, "use_foam");
619
620 if (is_cached) {
621 PointerRNA op_ptr = layout.op("OBJECT_OT_ocean_bake",
622 IFACE_("Delete Bake"),
623 ICON_NONE,
626 RNA_boolean_set(&op_ptr, "free", true);
627 }
628 else {
629 PointerRNA op_ptr = layout.op("OBJECT_OT_ocean_bake",
630 IFACE_("Bake"),
631 ICON_NONE,
634 RNA_boolean_set(&op_ptr, "free", false);
635 }
636
637 layout.prop(ptr, "filepath", UI_ITEM_NONE, std::nullopt, ICON_NONE);
638
639 ui::Layout *col = &layout.column(true);
640 col->enabled_set(!is_cached);
641 col->prop(ptr, "frame_start", UI_ITEM_NONE, IFACE_("Frame Start"), ICON_NONE);
642 col->prop(ptr, "frame_end", UI_ITEM_NONE, IFACE_("End"), ICON_NONE);
643
644 col = &layout.column(false);
645 col->active_set(use_foam);
646 col->prop(ptr, "bake_foam_fade", UI_ITEM_NONE, std::nullopt, ICON_NONE);
647}
648#endif /* WITH_OCEANSIM */
649
650static void panel_register(ARegionType *region_type)
651{
653#ifdef WITH_OCEANSIM
654 modifier_subpanel_register(region_type, "waves", "Waves", nullptr, waves_panel_draw, panel_type);
656 region_type, "foam", "", foam_panel_draw_header, foam_panel_draw, panel_type);
658 region_type, "spray", "", spray_panel_draw_header, spray_panel_draw, foam_panel);
660 region_type, "spectrum", "Spectrum", nullptr, spectrum_panel_draw, panel_type);
661 modifier_subpanel_register(region_type, "bake", "Bake", nullptr, bake_panel_draw, panel_type);
662#else
663 UNUSED_VARS(panel_type);
664#endif /* WITH_OCEANSIM */
665}
666
667static void blend_read(BlendDataReader * /*reader*/, ModifierData *md)
668{
669 OceanModifierData *omd = reinterpret_cast<OceanModifierData *>(md);
670 omd->oceancache = nullptr;
671 omd->ocean = nullptr;
672}
673
675 /*idname*/ "Ocean",
676 /*name*/ N_("Ocean"),
677 /*struct_name*/ "OceanModifierData",
678 /*struct_size*/ sizeof(OceanModifierData),
679 /*srna*/ &RNA_OceanModifier,
683 /*icon*/ ICON_MOD_OCEAN,
684
685 /*copy_data*/ copy_data,
686 /*deform_verts*/ nullptr,
687
688 /*deform_matrices*/ nullptr,
689 /*deform_verts_EM*/ nullptr,
690 /*deform_matrices_EM*/ nullptr,
691 /*modify_mesh*/ modify_mesh,
692 /*modify_geometry_set*/ nullptr,
693
694 /*init_data*/ init_data,
695 /*required_data_mask*/ required_data_mask,
696 /*free_data*/ free_data,
697 /*is_disabled*/ nullptr,
698 /*update_depsgraph*/ nullptr,
699 /*depends_on_time*/ nullptr,
700 /*depends_on_normals*/ nullptr,
701 /*foreach_ID_link*/ nullptr,
702 /*foreach_tex_link*/ nullptr,
703 /*free_runtime_data*/ nullptr,
704 /*panel_register*/ panel_register,
705 /*blend_write*/ nullptr,
706 /*blend_read*/ blend_read,
707 /*foreach_cache*/ nullptr,
708 /*foreach_working_space_color*/ nullptr,
709};
710
711} // namespace blender
Generic geometry attributes built on CustomData.
#define RPT_(msgid)
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_ID_MESH
Object is a sort of wrapper for general info.
#define UI_ITEM_NONE
#define CLAMP(a, b, c)
#define UNUSED_VARS(...)
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define ELEM(...)
#define CD_MASK_MCOL
#define MAX_MTFACE
static AttributeOwner from_id(ID *id)
void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges)
BMesh Iterators.
static void copy_data(const ModifierData *md, ModifierData *target, const int flag)
@ MOD_OCEAN_SPECTRUM_TEXEL_MARSEN_ARSLOE
int RNA_enum_get(PointerRNA *ptr, const char *name)
void BKE_modifier_set_error(const Object *ob, ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
float BKE_ocean_jminus_to_foam(float jminus, float coverage)
Definition ocean.cc:1565
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float v)
Definition ocean.cc:1570
static void init_data(ModifierData *md)
void BKE_ocean_free(struct Ocean *oc)
Definition ocean.cc:1618
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static Mesh * doOcean(ModifierData *, const ModifierEvalContext *, Mesh *mesh)
Definition MOD_ocean.cc:460
std::string BKE_attribute_calc_unique_name(const AttributeOwner &owner, StringRef name)
@ LIB_ID_COPY_LOCALIZE
struct OceanCache * BKE_ocean_init_cache(const char *bakepath, const char *relbase, int start, int end, float wave_scale, float chop_amount, float foam_coverage, float foam_fade, int resolution)
Definition ocean.cc:1647
static void required_data_mask(ModifierData *, CustomData_MeshMasks *)
Definition MOD_ocean.cc:136
static void required_data_mask(ModifierData *, CustomData_MeshMasks *r_cddata_masks)
void modifier_error_message_draw(ui::Layout &layout, PointerRNA *ptr)
void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
VecBase< float, 2 > float2
static void free_data(ModifierData *md)
Definition MOD_ocean.cc:85
static void bake_panel_draw(const bContext *, Panel *panel)
static void panel_register(ARegionType *region_type)
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static Mesh * modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
Definition MOD_array.cc:873
@ eModifierTypeFlag_EnableInEditmode
@ eModifierTypeFlag_SupportsEditmode
@ eModifierTypeFlag_AcceptsMesh
bool BKE_ocean_init_from_modifier(struct Ocean *ocean, struct OceanModifierData const *omd, int resolution)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void BKE_ocean_cache_eval_uv(struct OceanCache *och, struct OceanResult *ocr, int f, float u, float v)
Definition ocean.cc:1637
static void blend_read(BlendDataReader *, ModifierData *md)
bool BKE_ocean_is_valid(const struct Ocean *o)
void BKE_ocean_free_cache(struct OceanCache *och)
Definition ocean.cc:1628
void BKE_ocean_simulate_cache(struct OceanCache *och, int frame)
Definition ocean.cc:1662
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
static void panel_draw(const bContext *, Panel *panel)
PanelType * modifier_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:851
const char * BKE_modifier_path_relbase_from_global(Object *ob)
ModifierTypeInfo modifierType_Ocean
Definition MOD_ocean.cc:674
float DEG_get_ctime(const Depsgraph *graph)
void BKE_modifier_path_init(char *path, int path_maxncpy, const char *name)
bool BKE_ocean_ensure(struct OceanModifierData *omd, int resolution)
float RNA_float_get(PointerRNA *ptr, const char *name)
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
void BKE_ocean_simulate(struct Ocean *o, float t, float scale, float chop_amount)
Definition ocean.cc:1581
struct Ocean * BKE_ocean_add()
Definition ocean.cc:1583
void BKE_modifier_copydata_generic(const ModifierData *md, ModifierData *md_dst, int flag)
ui::Layout * layout
void enabled_set(bool enabled)
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void active_set(bool active)
Layout & column(bool align)
Layout & row(bool align)
#define N_(msgid)