WIP: Experiment: Geometry Nodes: support baking individual simulations #112179

Closed
Jacques Lucke wants to merge 51 commits from JacquesLucke/blender:simulation-bake-individual into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
15 changed files with 721 additions and 570 deletions
Showing only changes of commit 2d50946075 - Show all commits

View File

@ -16,6 +16,8 @@
#include "kernel/sample/lcg.h"
#include "kernel/sample/mapping.h"
#include "kernel/util/color.h"
#include "kernel/closure/bsdf_microfacet.h"
#include <iostream>
@ -39,7 +41,6 @@ static float precompute_ggx_E(float rough, float mu, float3 rand)
float pdf = 0.0f, sampled_eta;
float2 sampled_roughness;
bsdf_microfacet_ggx_sample((ShaderClosure *)&bsdf,
0,
make_float3(0.0f, 0.0f, 1.0f),
make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
rand,
@ -71,7 +72,6 @@ static float precompute_ggx_glass_E(float rough, float mu, float eta, float3 ran
float pdf = 0.0f, sampled_eta;
float2 sampled_roughness;
bsdf_microfacet_ggx_sample((ShaderClosure *)&bsdf,
0,
make_float3(0.0f, 0.0f, 1.0f),
make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
rand,
@ -114,7 +114,6 @@ static float precompute_ggx_gen_schlick_s(
float pdf = 0.0f, sampled_eta;
float2 sampled_roughness;
bsdf_microfacet_ggx_sample((ShaderClosure *)&bsdf,
0,
make_float3(0.0f, 0.0f, 1.0f),
make_float3(sqrtf(1.0f - sqr(mu)), 0.0f, mu),
rand,

View File

@ -157,13 +157,13 @@ ccl_device_inline int bsdf_sample(KernelGlobals kg,
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
label = bsdf_microfacet_ggx_sample(
sc, path_flag, Ng, sd->wi, rand, eval, wo, pdf, sampled_roughness, eta);
sc, Ng, sd->wi, rand, eval, wo, pdf, sampled_roughness, eta);
break;
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID:
label = bsdf_microfacet_beckmann_sample(
sc, path_flag, Ng, sd->wi, rand, eval, wo, pdf, sampled_roughness, eta);
sc, Ng, sd->wi, rand, eval, wo, pdf, sampled_roughness, eta);
break;
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
label = bsdf_ashikhmin_shirley_sample(

View File

@ -576,7 +576,6 @@ ccl_device Spectrum bsdf_microfacet_eval(ccl_private const ShaderClosure *sc,
template<MicrofacetType m_type>
ccl_device int bsdf_microfacet_sample(ccl_private const ShaderClosure *sc,
const int path_flag,
float3 Ng,
float3 wi,
const float3 rand,
@ -915,7 +914,6 @@ ccl_device Spectrum bsdf_microfacet_ggx_eval(ccl_private const ShaderClosure *sc
}
ccl_device int bsdf_microfacet_ggx_sample(ccl_private const ShaderClosure *sc,
const int path_flag,
float3 Ng,
float3 wi,
const float3 rand,
@ -927,7 +925,7 @@ ccl_device int bsdf_microfacet_ggx_sample(ccl_private const ShaderClosure *sc,
{
int label = bsdf_microfacet_sample<MicrofacetType::GGX>(
sc, path_flag, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
sc, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
*eval *= ((ccl_private const MicrofacetBsdf *)sc)->energy_scale;
return label;
}
@ -980,7 +978,6 @@ ccl_device Spectrum bsdf_microfacet_beckmann_eval(ccl_private const ShaderClosur
}
ccl_device int bsdf_microfacet_beckmann_sample(ccl_private const ShaderClosure *sc,
const int path_flag,
float3 Ng,
float3 wi,
const float3 rand,
@ -991,7 +988,7 @@ ccl_device int bsdf_microfacet_beckmann_sample(ccl_private const ShaderClosure *
ccl_private float *eta)
{
return bsdf_microfacet_sample<MicrofacetType::BECKMANN>(
sc, path_flag, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
sc, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
}
CCL_NAMESPACE_END

View File

@ -4584,6 +4584,9 @@ def km_grease_pencil_edit(params):
# Dissolve
("grease_pencil.dissolve", {"type": 'X', "value": 'PRESS', "ctrl": True}, None),
("grease_pencil.dissolve", {"type": 'DEL', "value": 'PRESS', "ctrl": True}, None),
# Delete all active frames
("grease_pencil.delete_frame", {"type": 'DEL', "value": 'PRESS', "shift": True},
{"properties": [("type", "ALL_FRAMES")]}),
])
return keymap

View File

@ -3446,6 +3446,9 @@ class WM_MT_region_toggle_pie(Menu):
# Use to access the labels.
enum_items = bpy.types.Region.bl_rna.properties["type"].enum_items_static_ui
# Remove empty items.
items[:] = [item for item in items if item != []]
for region_type_list in (items + items_overflow):
if not region_type_list:
pie.separator()

View File

@ -4863,6 +4863,10 @@ class VIEW3D_MT_edit_greasepencil_delete(Menu):
layout = self.layout
layout.operator_enum("grease_pencil.dissolve", "type")
layout.operator("grease_pencil.delete_frame", text="Delete Active Keyframe (Active Layer)").type = 'ACTIVE_FRAME'
layout.operator("grease_pencil.delete_frame", text="Delete Active Keyframes (All Layers)").type = 'ALL_FRAMES'
# Edit Curve
# draw_curve is used by VIEW3D_MT_edit_curve and VIEW3D_MT_edit_surface

View File

@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdlib>
@ -873,20 +874,6 @@ void BKE_curvemapping_premultiply(CurveMapping *cumap, bool restore)
}
}
static int sort_curvepoints(const void *a1, const void *a2)
{
const CurveMapPoint *x1 = static_cast<const CurveMapPoint *>(a1),
*x2 = static_cast<const CurveMapPoint *>(a2);
if (x1->x > x2->x) {
return 1;
}
if (x1->x < x2->x) {
return -1;
}
return 0;
}
/* ************************ more CurveMapping calls *************** */
void BKE_curvemapping_changed(CurveMapping *cumap, const bool rem_doubles)
@ -936,7 +923,9 @@ void BKE_curvemapping_changed(CurveMapping *cumap, const bool rem_doubles)
}
}
qsort(cmp, cuma->totpoint, sizeof(CurveMapPoint), sort_curvepoints);
std::stable_sort(cuma->curve,
cuma->curve + cuma->totpoint,
[](const CurveMapPoint &a, const CurveMapPoint &b) { return a.x < b.x; });
/* remove doubles, threshold set on 1% of default range */
if (rem_doubles && cuma->totpoint > 2) {

View File

@ -712,6 +712,91 @@ static void GREASE_PENCIL_OT_dissolve(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Delete Frame Operator
* \{ */
enum class DeleteFrameMode : int8_t {
/* Delete the active frame for the current layer. */
ACTIVE_FRAME,
/* Delete the active frames for all layers. */
ALL_FRAMES,
};
static const EnumPropertyItem prop_greasepencil_deleteframe_types[] = {
{int(DeleteFrameMode::ACTIVE_FRAME),
"ACTIVE_FRAME",
0,
"Active Frame",
"Deletes current frame in the active layer"},
{int(DeleteFrameMode::ALL_FRAMES),
"ALL_FRAMES",
0,
"All Active Frames",
"Delete active frames for all layers"},
{0, nullptr, 0, nullptr, nullptr},
};
static int grease_pencil_delete_frame_exec(bContext *C, wmOperator *op)
{
using namespace blender;
const Scene *scene = CTX_data_scene(C);
Object *object = CTX_data_active_object(C);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(object->data);
const int current_frame = scene->r.cfra;
const DeleteFrameMode mode = DeleteFrameMode(RNA_enum_get(op->ptr, "type"));
bool changed = false;
if (mode == DeleteFrameMode::ACTIVE_FRAME && grease_pencil.has_active_layer()) {
bke::greasepencil::Layer &layer = *grease_pencil.get_active_layer_for_write();
if (layer.is_editable()) {
changed |= grease_pencil.remove_frames(layer, {layer.frame_key_at(current_frame)});
}
}
else if (mode == DeleteFrameMode::ALL_FRAMES) {
for (bke::greasepencil::Layer *layer : grease_pencil.layers_for_write()) {
if (layer->is_editable()) {
changed |= grease_pencil.remove_frames(*layer, {layer->frame_key_at(current_frame)});
}
}
}
if (changed) {
DEG_id_tag_update(&grease_pencil.id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA | NA_EDITED, &grease_pencil);
}
return OPERATOR_FINISHED;
}
static void GREASE_PENCIL_OT_delete_frame(wmOperatorType *ot)
{
PropertyRNA *prop;
/* Identifiers. */
ot->name = "Delete Frame";
ot->idname = "GREASE_PENCIL_OT_delete_frame";
ot->description = "Delete Grease Pencil Frame(s)";
/* Callbacks. */
ot->invoke = WM_menu_invoke;
ot->exec = grease_pencil_delete_frame_exec;
ot->poll = editable_grease_pencil_poll;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
ot->prop = prop = RNA_def_enum(ot->srna,
"type",
prop_greasepencil_deleteframe_types,
0,
"Type",
"Method used for deleting Grease Pencil frames");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/** \} */
} // namespace blender::ed::greasepencil
void ED_operatortypes_grease_pencil_edit()
@ -720,6 +805,7 @@ void ED_operatortypes_grease_pencil_edit()
WM_operatortype_append(GREASE_PENCIL_OT_stroke_smooth);
WM_operatortype_append(GREASE_PENCIL_OT_stroke_simplify);
WM_operatortype_append(GREASE_PENCIL_OT_dissolve);
WM_operatortype_append(GREASE_PENCIL_OT_delete_frame);
}
void ED_keymap_grease_pencil(wmKeyConfig *keyconf)

View File

@ -27,6 +27,16 @@
namespace blender::ed::greasepencil {
void set_selected_frames_type(bke::greasepencil::Layer &layer,
const eBezTriple_KeyframeType key_type)
{
for (GreasePencilFrame &frame : layer.frames_for_write().values()) {
if (frame.is_selected()) {
frame.type = key_type;
}
}
}
bool remove_all_selected_frames(GreasePencil &grease_pencil, bke::greasepencil::Layer &layer)
{
Vector<int> frames_to_remove;

View File

@ -47,6 +47,9 @@ eAttrDomain ED_grease_pencil_selection_domain_get(bContext *C);
namespace blender::ed::greasepencil {
void set_selected_frames_type(bke::greasepencil::Layer &layer,
const eBezTriple_KeyframeType key_type);
bool remove_all_selected_frames(GreasePencil &grease_pencil, bke::greasepencil::Layer &layer);
void select_layer_channel(GreasePencil &grease_pencil, bke::greasepencil::Layer *layer);

View File

@ -348,9 +348,9 @@ std::string NodeSocketDropTarget::drop_tooltip(const DragInfo &drag_info) const
case DropLocation::Into:
return "";
case DropLocation::Before:
return N_("Insert before socket");
return TIP_("Insert before socket");
case DropLocation::After:
return N_("Insert after socket");
return TIP_("Insert after socket");
}
return "";
}
@ -430,11 +430,11 @@ std::string NodePanelDropTarget::drop_tooltip(const DragInfo &drag_info) const
{
switch (drag_info.drop_location) {
case DropLocation::Into:
return "Insert into panel";
return TIP_("Insert into panel");
case DropLocation::Before:
return N_("Insert before panel");
return TIP_("Insert before panel");
case DropLocation::After:
return N_("Insert after panel");
return TIP_("Insert after panel");
}
return "";
}

View File

@ -1662,7 +1662,10 @@ static void setkeytype_action_keys(bAnimContext *ac, short mode)
break;
case ANIMTYPE_GREASE_PENCIL_LAYER:
/* GPv3: To be implemented. */
blender::ed::greasepencil::set_selected_frames_type(
static_cast<GreasePencilLayer *>(ale->data)->wrap(),
static_cast<eBezTriple_KeyframeType>(mode));
ale->update |= ANIM_UPDATE_DEPS;
break;
case ANIMTYPE_FCURVE:

View File

@ -435,6 +435,14 @@ void draw_seq_strip_thumbnail(View2D *v2d,
float pixelx,
float pixely)
{
SpaceSeq *sseq = CTX_wm_space_seq(C);
if ((sseq->flag & SEQ_SHOW_OVERLAY) == 0 ||
(sseq->timeline_overlay.flag & SEQ_TIMELINE_SHOW_THUMBNAILS) == 0 ||
!ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_IMAGE))
{
return;
}
bool clipped = false;
float image_height, image_width, thumb_width;
rcti crop;

View File

@ -195,10 +195,10 @@ class CurveStartPointInput final : public bke::CurvesFieldInput {
}
GVArray get_varray_for_context(const bke::CurvesGeometry &curves,
const eAttrDomain /*domain*/,
const eAttrDomain domain,
const IndexMask & /*mask*/) const final
{
return VArray<int>::ForSpan(curves.offsets());
return curves.adapt_domain(VArray<int>::ForSpan(curves.offsets()), ATTR_DOMAIN_CURVE, domain);
}
uint64_t hash() const final