Added option to center image when loading particle emission mask

This commit is contained in:
Brecht Kuppens 2023-06-22 21:41:50 +02:00
parent 46424488ed
commit 86117f8cba
4 changed files with 29 additions and 7 deletions

View file

@ -217,11 +217,16 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() {
}
{
Vector2 offset;
if (emission_mask_centered->is_pressed()) {
offset = Vector2(-s.width * 0.5, -s.height * 0.5);
}
PackedVector2Array points;
points.resize(valid_positions.size());
Vector2 *pointsw = points.ptrw();
for (int i = 0; i < valid_positions.size(); i += 1) {
pointsw[i] = valid_positions[i];
pointsw[i] = valid_positions[i] + offset;
}
particles->set_emission_points(points);
}
@ -281,9 +286,14 @@ CPUParticles2DEditorPlugin::CPUParticles2DEditorPlugin() {
emission_mask_mode->add_item(TTR("Solid Pixels"), EMISSION_MODE_SOLID);
emission_mask_mode->add_item(TTR("Border Pixels"), EMISSION_MODE_BORDER);
emission_mask_mode->add_item(TTR("Directed Border Pixels"), EMISSION_MODE_BORDER_DIRECTED);
VBoxContainer *optionsvb = memnew(VBoxContainer);
emvb->add_margin_child(TTR("Options"), optionsvb);
emission_mask_centered = memnew(CheckBox);
emission_mask_centered->set_text(TTR("Centered"));
optionsvb->add_child(emission_mask_centered);
emission_colors = memnew(CheckBox);
emission_colors->set_text(TTR("Capture from Pixel"));
emvb->add_margin_child(TTR("Emission Colors"), emission_colors);
emission_colors->set_text(TTR("Capture Colors from Pixel"));
optionsvb->add_child(emission_colors);
toolbar->add_child(emission_mask);

View file

@ -69,6 +69,7 @@ class CPUParticles2DEditorPlugin : public EditorPlugin {
ConfirmationDialog *emission_mask = nullptr;
OptionButton *emission_mask_mode = nullptr;
CheckBox *emission_mask_centered = nullptr;
CheckBox *emission_colors = nullptr;
String source_emission_file;

View file

@ -292,11 +292,16 @@ void GPUParticles2DEditorPlugin::_generate_emission_mask() {
texdata.resize(w * h * 2 * sizeof(float));
{
Vector2 offset;
if (emission_mask_centered->is_pressed()) {
offset = Vector2(-s.width * 0.5, -s.height * 0.5);
}
uint8_t *tw = texdata.ptrw();
float *twf = reinterpret_cast<float *>(tw);
for (int i = 0; i < vpc; i++) {
twf[i * 2 + 0] = valid_positions[i].x;
twf[i * 2 + 1] = valid_positions[i].y;
twf[i * 2 + 0] = valid_positions[i].x + offset.x;
twf[i * 2 + 1] = valid_positions[i].y + offset.y;
}
}
@ -417,9 +422,14 @@ GPUParticles2DEditorPlugin::GPUParticles2DEditorPlugin() {
emission_mask_mode->add_item(TTR("Solid Pixels"), EMISSION_MODE_SOLID);
emission_mask_mode->add_item(TTR("Border Pixels"), EMISSION_MODE_BORDER);
emission_mask_mode->add_item(TTR("Directed Border Pixels"), EMISSION_MODE_BORDER_DIRECTED);
VBoxContainer *optionsvb = memnew(VBoxContainer);
emvb->add_margin_child(TTR("Options"), optionsvb);
emission_mask_centered = memnew(CheckBox);
emission_mask_centered->set_text(TTR("Centered"));
optionsvb->add_child(emission_mask_centered);
emission_colors = memnew(CheckBox);
emission_colors->set_text(TTR("Capture from Pixel"));
emvb->add_margin_child(TTR("Emission Colors"), emission_colors);
emission_colors->set_text(TTR("Capture Colors from Pixel"));
optionsvb->add_child(emission_colors);
toolbar->add_child(emission_mask);

View file

@ -75,6 +75,7 @@ class GPUParticles2DEditorPlugin : public EditorPlugin {
ConfirmationDialog *emission_mask = nullptr;
OptionButton *emission_mask_mode = nullptr;
CheckBox *emission_mask_centered = nullptr;
CheckBox *emission_colors = nullptr;
String source_emission_file;