Skip to content

Commit

Permalink
Don't clutter editor inspector with unused properties per format
Browse files Browse the repository at this point in the history
Also added visual noise normalmap generation screenshot in README.

3.1.beta.Xrayez.006f31b
  • Loading branch information
Xrayez committed Mar 4, 2019
1 parent 139024f commit 5baf9ca
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ branches and/or releases for compatible versions.
* make custom modular noise as components from base nodes.

![Visual Accidental Noise Workbench](examples/images/visual_noise.png)
![Visual Accidental Noise Normalmap](examples/images/visual_noise_normalmap.png)

See [wiki](https://github.com/Xrayez/godot-anl/wiki#visual-noise) on how to get started
creating noise with visual nodes.
Expand Down
Binary file added examples/images/visual_noise_normalmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions noise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void AccidentalNoise::set_format(Format p_format) {

format = p_format;
emit_changed();
_change_notify();
}

AccidentalNoise::Format AccidentalNoise::get_format() const {
Expand Down Expand Up @@ -1042,6 +1043,19 @@ Vector<Ref<Image> > AccidentalNoise::_map_to_image_3d(int p_width, int p_height,
return noise;
}

void AccidentalNoise::_validate_property(PropertyInfo &property) const {

if (property.name.begins_with("normalmap") && format != FORMAT_NORMALMAP) {
property.usage = PROPERTY_USAGE_NOEDITOR;
}
if (property.name.begins_with("bumpmap") && format != FORMAT_BUMPMAP) {
property.usage = PROPERTY_USAGE_NOEDITOR;
}
if (property.name == "function" || property.name == "last_function") {
property.usage = PROPERTY_USAGE_NOEDITOR;
}
}

void AccidentalNoise::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_mode", "mode"), &AccidentalNoise::set_mode);
Expand All @@ -1061,6 +1075,7 @@ void AccidentalNoise::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::AABB, "ranges"), "set_ranges", "get_ranges");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "expression", PROPERTY_HINT_MULTILINE_TEXT), "set_expression", "get_expression");

// Normalmap / Bumpmap -----------------------------------------------------
ClassDB::bind_method(D_METHOD("set_normalmap_spacing", "normalmap_spacing"), &AccidentalNoise::set_normalmap_spacing);
ClassDB::bind_method(D_METHOD("get_normalmap_spacing"), &AccidentalNoise::get_normalmap_spacing);

Expand Down Expand Up @@ -1088,6 +1103,7 @@ void AccidentalNoise::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "bumpmap_spacing"), "set_bumpmap_spacing", "get_bumpmap_spacing");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bumpmap_wrapped"), "set_bumpmap_wrapped", "is_bumpmap_wrapped");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "bumpmap_light"), "set_bumpmap_light", "get_bumpmap_light");
//--------------------------------------------------------------------------

BIND_ENUM_CONSTANT(FORMAT_HEIGHTMAP);
BIND_ENUM_CONSTANT(FORMAT_NORMALMAP);
Expand Down
10 changes: 6 additions & 4 deletions noise.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AccidentalNoise : public Resource {

protected:
static void _bind_methods();
virtual void _validate_property(PropertyInfo &property) const;

public:
enum Format {
Expand All @@ -39,7 +40,7 @@ class AccidentalNoise : public Resource {
String get_expression() const;

//------------------------------------------------------------------------------
// Normal/bump map
// Normal/bump map according to format
//------------------------------------------------------------------------------
void set_normalmap_spacing(double p_spacing);
double get_normalmap_spacing() const;
Expand Down Expand Up @@ -280,6 +281,10 @@ class AccidentalNoise : public Resource {
anl::CNoiseExecutor vm;
anl::CExpressionBuilder eb;

Ref<Image> _map_to_image(int p_width, int p_height, Index p_index, anl::EMappingModes p_mode, Format p_format, const AABB &p_ranges);
Vector<Ref<Image> > _map_to_image_3d(int p_width, int p_height, int p_depth, Index p_index, anl::EMappingModes p_mode, Format p_format, const AABB &p_ranges);

protected:
Index function;
Index prev_function;

Expand All @@ -295,9 +300,6 @@ class AccidentalNoise : public Resource {
double bumpmap_spacing;
bool bumpmap_wrapped;
Vector3 bumpmap_light;

Ref<Image> _map_to_image(int p_width, int p_height, Index p_index, anl::EMappingModes p_mode, Format p_format, const AABB &p_ranges);
Vector<Ref<Image> > _map_to_image_3d(int p_width, int p_height, int p_depth, Index p_index, anl::EMappingModes p_mode, Format p_format, const AABB &p_ranges);
};

VARIANT_ENUM_CAST(anl::InterpolationTypes);
Expand Down
12 changes: 12 additions & 0 deletions visual_noise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,18 @@ double VisualAccidentalNoise::get_clamp_high() const {
return clamp_high;
}

void VisualAccidentalNoise::_validate_property(PropertyInfo &property) const {

AccidentalNoise::_validate_property(property);

if (format == FORMAT_TEXTURE) {
if (property.name.begins_with("clamp")) {
// This will spoil color texture into grayscale, disallow it in editor at least
property.usage = PROPERTY_USAGE_NOEDITOR;
}
}
}

void VisualAccidentalNoise::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_clamping_enabled", "enabled"), &VisualAccidentalNoise::set_clamping_enabled);
Expand Down
1 change: 1 addition & 0 deletions visual_noise.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class VisualAccidentalNoise : public AccidentalNoise {

protected:
static void _bind_methods();
virtual void _validate_property(PropertyInfo &property) const;

public:
void set_clamping_enabled(bool p_enable);
Expand Down

0 comments on commit 5baf9ca

Please sign in to comment.