Skip to content

Commit fc1ede0

Browse files
committed
Rename material channel properties to be more generic
1 parent 6a48040 commit fc1ede0

File tree

4 files changed

+83
-83
lines changed

4 files changed

+83
-83
lines changed

addons/4d/doc_classes/G4MFMaterialChannel4D.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
</method>
5555
</methods>
5656
<members>
57-
<member name="cell_colors_accessor_index" type="int" setter="set_cell_colors_accessor_index" getter="get_cell_colors_accessor_index" default="-1">
58-
The index of the [G4MFAccessor4D] in the [G4MFState4D]'s accessors array that contains the per-cell color data for this surface. These may be per-component multiplied with the [member single_color] to get the final color of the cells. If not defined, the surface does not have per-cell colors. If defined (set to a valid index), the amount of cell colors MUST match or exceed the amount of cells in the surface.
59-
</member>
6057
<member name="cell_texture_index" type="int" setter="set_cell_texture_index" getter="get_cell_texture_index" default="-1">
6158
The index of the [G4MFTexture4D] in the [G4MFState4D]'s textures array that contains the texture for this surface. This is per-component multiplied with the [member single_color] and the cell colors to get the final color of the cells. If not defined, the surface does not have a texture.
6259
[b]Note:[/b] This property is currently not used when generating a [Material4D] from a [G4MFMaterial4D].
@@ -65,13 +62,16 @@
6562
The index of the [G4MFAccessor4D] in the [G4MFState4D]'s accessors array that contains the per-cell texture map data for this surface, also known as a UV map or UVW map. This is used to map the texture to the surface cells. If not defined (set to a negative index), the surface does not have a texture map. If defined, the amount of texture map data MUST match or exceed the amount of cells in the surface.
6663
[b]Note:[/b] This property is currently not used when generating a [Material4D] from a [G4MFMaterial4D].
6764
</member>
68-
<member name="edge_colors_accessor_index" type="int" setter="set_edge_colors_accessor_index" getter="get_edge_colors_accessor_index" default="-1">
69-
The index of the [G4MFAccessor4D] in the [G4MFState4D]'s accessors array that contains the per-edge color data for this surface. These may be per-component multiplied with the [member single_color] to get the final color of the edges. If not defined, the surface does not have per-edge colors. If defined (set to a valid index), the amount of edge colors MUST match or exceed the amount of edges in the surface.
65+
<member name="factor" type="Color" setter="set_factor" getter="get_factor" default="Color(-1, -1, -1, -1)">
66+
The modulate factor of the surface, also known as the value or single base color. If non-negative, this is per-component multiplied with other properties to get the final color of the cells and edges, or if no other properties are defined, this is the only color used.
7067
</member>
71-
<member name="single_color" type="Color" setter="set_single_color" getter="get_single_color" default="Color(-1, -1, -1, -1)">
72-
The single color of the surface. If non-negative, this is per-component multiplied with other properties to get the final color of the cells and edges, or if no other properties are defined, this is the only color used.
68+
<member name="per_cell_accessor_index" type="int" setter="set_per_cell_accessor_index" getter="get_per_cell_accessor_index" default="-1">
69+
The index of the [G4MFAccessor4D] in the [G4MFState4D]'s accessors array that contains the per-cell color data for this surface. These may be per-component multiplied with the [member single_color] to get the final color of the cells. If not defined, the surface does not have per-cell colors. If defined (set to a valid index), the amount of cell colors MUST match or exceed the amount of cells in the surface.
70+
</member>
71+
<member name="per_edge_accessor_index" type="int" setter="set_edge_colors_accessor_index" getter="get_per_edge_accessor_index" default="-1">
72+
The index of the [G4MFAccessor4D] in the [G4MFState4D]'s accessors array that contains the per-edge color data for this surface. These may be per-component multiplied with the [member single_color] to get the final color of the edges. If not defined, the surface does not have per-edge colors. If defined (set to a valid index), the amount of edge colors MUST match or exceed the amount of edges in the surface.
7373
</member>
74-
<member name="vertex_colors_accessor_index" type="int" setter="set_vertex_colors_accessor_index" getter="get_vertex_colors_accessor_index" default="-1">
74+
<member name="per_vertex_accessor_index" type="int" setter="set_per_vertex_accessor_index" getter="get_per_vertex_accessor_index" default="-1">
7575
The index of the [G4MFAccessor4D] in the [G4MFState4D]'s accessors array that contains the per-vertex color data for this surface. These may be per-component multiplied with the [member single_color] to get the final color of the vertices. If not defined, the surface does not have per-vertex colors. If defined (set to a valid index), the amount of vertex colors MUST match or exceed the amount of vertices in the surface.
7676
[b]Note:[/b] This property is currently not used when generating a [Material4D] from a [G4MFMaterial4D].
7777
</member>

model/g4mf/structures/g4mf_material_4d.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Ref<TetraMaterial4D> G4MFMaterial4D::generate_tetra_material(const Ref<G4MFState
2929
tetra_material.instantiate();
3030
tetra_material->set_name(get_name());
3131
if (_base_color_channel.is_valid()) {
32-
const Color single_base_color = _base_color_channel->get_single_color();
32+
const Color single_base_color = _base_color_channel->get_factor();
3333
const bool has_single_base_color = single_base_color.r > -1 && !Color(1, 1, 1, 1).is_equal_approx(single_base_color);
3434
if (has_single_base_color) {
3535
tetra_material->set_albedo_color(single_base_color);
3636
}
37-
if (_base_color_channel->get_cell_colors_accessor_index() >= 0) {
37+
if (_base_color_channel->get_per_cell_accessor_index() >= 0) {
3838
tetra_material->set_albedo_color_array(_base_color_channel->load_cell_colors(p_g4mf_state));
3939
if (has_single_base_color) {
4040
tetra_material->set_albedo_source(TetraMaterial4D::TETRA_COLOR_SOURCE_PER_CELL_AND_SINGLE);
@@ -60,12 +60,12 @@ Ref<WireMaterial4D> G4MFMaterial4D::generate_wire_material(const Ref<G4MFState4D
6060
wire_material.instantiate();
6161
wire_material->set_name(get_name());
6262
if (_base_color_channel.is_valid()) {
63-
const Color single_base_color = _base_color_channel->get_single_color();
63+
const Color single_base_color = _base_color_channel->get_factor();
6464
const bool has_single_base_color = single_base_color.r > -1 && !Color(1, 1, 1, 1).is_equal_approx(single_base_color);
6565
if (has_single_base_color) {
6666
wire_material->set_albedo_color(single_base_color);
6767
}
68-
if (_base_color_channel->get_edge_colors_accessor_index() >= 0) {
68+
if (_base_color_channel->get_per_edge_accessor_index() >= 0) {
6969
wire_material->set_albedo_color_array(_base_color_channel->load_edge_colors(p_g4mf_state));
7070
if (has_single_base_color) {
7171
wire_material->set_albedo_source(WireMaterial4D::WIRE_COLOR_SOURCE_PER_EDGE_AND_SINGLE);
@@ -108,22 +108,22 @@ int G4MFMaterial4D::convert_material_into_state(Ref<G4MFState4D> p_g4mf_state, c
108108
Ref<G4MFMaterialChannel4D> base_color_channel;
109109
base_color_channel.instantiate();
110110
if (albedo_source_flags & Material4D::COLOR_SOURCE_FLAG_PER_CELL) {
111-
base_color_channel->set_cell_colors_accessor_index(base_color_accessor_index);
111+
base_color_channel->set_per_cell_accessor_index(base_color_accessor_index);
112112
} else if (albedo_source_flags & Material4D::COLOR_SOURCE_FLAG_PER_EDGE) {
113113
base_color_channel->set_edge_colors_accessor_index(base_color_accessor_index);
114114
} else {
115115
ERR_PRINT("G4MFMaterial4D.convert_material_into_state: Unhandled albedo source flag.");
116116
}
117117
if (albedo_source_flags & Material4D::COLOR_SOURCE_FLAG_SINGLE_COLOR) {
118-
base_color_channel->set_single_color(p_material->get_albedo_color());
118+
base_color_channel->set_factor(p_material->get_albedo_color());
119119
}
120120
g4mf_material->set_base_color_channel(base_color_channel);
121121
} else if (albedo_source_flags & Material4D::COLOR_SOURCE_FLAG_SINGLE_COLOR) {
122122
const Color base_color = p_material->get_albedo_color();
123123
if (!Color(1, 1, 1, 1).is_equal_approx(base_color)) {
124124
Ref<G4MFMaterialChannel4D> base_color_channel;
125125
base_color_channel.instantiate();
126-
base_color_channel->set_single_color(base_color);
126+
base_color_channel->set_factor(base_color);
127127
g4mf_material->set_base_color_channel(base_color_channel);
128128
}
129129
}

model/g4mf/structures/g4mf_material_channel_4d.cpp

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
#include "../g4mf_state_4d.h"
44

55
bool G4MFMaterialChannel4D::is_equal_exact(const Ref<G4MFMaterialChannel4D> &p_other) const {
6-
if (_single_color != p_other->get_single_color()) {
6+
if (_factor != p_other->get_factor()) {
77
return false;
88
}
9-
if (_cell_colors_accessor_index != p_other->get_cell_colors_accessor_index()) {
9+
if (_per_cell_accessor_index != p_other->get_per_cell_accessor_index()) {
1010
return false;
1111
}
12-
if (_edge_colors_accessor_index != p_other->get_edge_colors_accessor_index()) {
12+
if (_per_edge_accessor_index != p_other->get_per_edge_accessor_index()) {
1313
return false;
1414
}
15-
if (_vertex_colors_accessor_index != p_other->get_vertex_colors_accessor_index()) {
15+
if (_per_vertex_accessor_index != p_other->get_per_vertex_accessor_index()) {
1616
return false;
1717
}
1818
if (_cell_texture_map_accessor_index != p_other->get_cell_texture_map_accessor_index()) {
@@ -26,8 +26,8 @@ bool G4MFMaterialChannel4D::is_equal_exact(const Ref<G4MFMaterialChannel4D> &p_o
2626

2727
PackedColorArray G4MFMaterialChannel4D::load_cell_colors(const Ref<G4MFState4D> &p_g4mf_state) const {
2828
TypedArray<G4MFAccessor4D> state_accessors = p_g4mf_state->get_accessors();
29-
ERR_FAIL_INDEX_V(_cell_colors_accessor_index, state_accessors.size(), PackedColorArray());
30-
const Ref<G4MFAccessor4D> accessor = state_accessors[_cell_colors_accessor_index];
29+
ERR_FAIL_INDEX_V(_per_cell_accessor_index, state_accessors.size(), PackedColorArray());
30+
const Ref<G4MFAccessor4D> accessor = state_accessors[_per_cell_accessor_index];
3131
Array color_variants = accessor->decode_variants_from_bytes(p_g4mf_state, Variant::COLOR);
3232
const int color_variants_size = color_variants.size();
3333
PackedColorArray packed_colors;
@@ -40,8 +40,8 @@ PackedColorArray G4MFMaterialChannel4D::load_cell_colors(const Ref<G4MFState4D>
4040

4141
PackedColorArray G4MFMaterialChannel4D::load_edge_colors(const Ref<G4MFState4D> &p_g4mf_state) const {
4242
TypedArray<G4MFAccessor4D> state_accessors = p_g4mf_state->get_accessors();
43-
ERR_FAIL_INDEX_V(_edge_colors_accessor_index, state_accessors.size(), PackedColorArray());
44-
const Ref<G4MFAccessor4D> accessor = state_accessors[_edge_colors_accessor_index];
43+
ERR_FAIL_INDEX_V(_per_edge_accessor_index, state_accessors.size(), PackedColorArray());
44+
const Ref<G4MFAccessor4D> accessor = state_accessors[_per_edge_accessor_index];
4545
Array color_variants = accessor->decode_variants_from_bytes(p_g4mf_state, Variant::COLOR);
4646
const int color_variants_size = color_variants.size();
4747
PackedColorArray packed_colors;
@@ -54,8 +54,8 @@ PackedColorArray G4MFMaterialChannel4D::load_edge_colors(const Ref<G4MFState4D>
5454

5555
PackedColorArray G4MFMaterialChannel4D::load_vertex_colors(const Ref<G4MFState4D> &p_g4mf_state) const {
5656
TypedArray<G4MFAccessor4D> state_accessors = p_g4mf_state->get_accessors();
57-
ERR_FAIL_INDEX_V(_vertex_colors_accessor_index, state_accessors.size(), PackedColorArray());
58-
const Ref<G4MFAccessor4D> accessor = state_accessors[_vertex_colors_accessor_index];
57+
ERR_FAIL_INDEX_V(_per_vertex_accessor_index, state_accessors.size(), PackedColorArray());
58+
const Ref<G4MFAccessor4D> accessor = state_accessors[_per_vertex_accessor_index];
5959
Array color_variants = accessor->decode_variants_from_bytes(p_g4mf_state, Variant::COLOR);
6060
const int color_variants_size = color_variants.size();
6161
PackedColorArray packed_colors;
@@ -70,36 +70,36 @@ Ref<G4MFMaterialChannel4D> G4MFMaterialChannel4D::from_dictionary(const Dictiona
7070
Ref<G4MFMaterialChannel4D> material;
7171
material.instantiate();
7272
material->read_item_entries_from_dictionary(p_dict);
73-
if (p_dict.has("color")) {
74-
Array color_array = p_dict["color"];
75-
Color color;
76-
switch (color_array.size()) {
73+
if (p_dict.has("factor")) {
74+
Array factor_array = p_dict["factor"];
75+
Color factor_color;
76+
switch (factor_array.size()) {
7777
case 0: {
78-
color = Color(-1, -1, -1, -1);
78+
factor_color = Color(-1, -1, -1, -1);
7979
} break;
8080
case 1: {
81-
color = Color(color_array[0], color_array[0], color_array[0]);
81+
factor_color = Color(factor_array[0], factor_array[0], factor_array[0]);
8282
} break;
8383
case 2: {
84-
color = Color(color_array[0], color_array[1], 0.0, 1.0);
84+
factor_color = Color(factor_array[0], factor_array[1], 0.0, 1.0);
8585
} break;
8686
case 3: {
87-
color = Color(color_array[0], color_array[1], color_array[2], 1.0);
87+
factor_color = Color(factor_array[0], factor_array[1], factor_array[2], 1.0);
8888
} break;
8989
default: {
90-
color = Color(color_array[0], color_array[1], color_array[2], color_array[3]);
90+
factor_color = Color(factor_array[0], factor_array[1], factor_array[2], factor_array[3]);
9191
} break;
9292
}
93-
material->set_single_color(color);
93+
material->set_factor(factor_color);
9494
}
95-
if (p_dict.has("cellColors")) {
96-
material->set_cell_colors_accessor_index(p_dict["cellColors"]);
95+
if (p_dict.has("perCell")) {
96+
material->set_per_cell_accessor_index(p_dict["perCell"]);
9797
}
98-
if (p_dict.has("edgeColors")) {
99-
material->set_edge_colors_accessor_index(p_dict["edgeColors"]);
98+
if (p_dict.has("perEdge")) {
99+
material->set_edge_colors_accessor_index(p_dict["perEdge"]);
100100
}
101-
if (p_dict.has("vertexColors")) {
102-
material->set_vertex_colors_accessor_index(p_dict["vertexColors"]);
101+
if (p_dict.has("perVertex")) {
102+
material->set_per_vertex_accessor_index(p_dict["perVertex"]);
103103
}
104104
if (p_dict.has("cellTextureMap")) {
105105
material->set_cell_texture_map_accessor_index(p_dict["cellTextureMap"]);
@@ -112,30 +112,30 @@ Ref<G4MFMaterialChannel4D> G4MFMaterialChannel4D::from_dictionary(const Dictiona
112112

113113
Dictionary G4MFMaterialChannel4D::to_dictionary() const {
114114
Dictionary dict = write_item_entries_to_dictionary();
115-
if (_single_color.r > -1 && !Color(1, 1, 1, 1).is_equal_approx(_single_color)) {
116-
Array color_array;
117-
if (_single_color.a == 1.0) {
118-
color_array.resize(3);
119-
color_array[0] = _single_color.r;
120-
color_array[1] = _single_color.g;
121-
color_array[2] = _single_color.b;
115+
if (_factor.r > -1 && !Color(1, 1, 1, 1).is_equal_approx(_factor)) {
116+
Array factor_array;
117+
if (_factor.a == 1.0) {
118+
factor_array.resize(3);
119+
factor_array[0] = _factor.r;
120+
factor_array[1] = _factor.g;
121+
factor_array[2] = _factor.b;
122122
} else {
123-
color_array.resize(4);
124-
color_array[0] = _single_color.r;
125-
color_array[1] = _single_color.g;
126-
color_array[2] = _single_color.b;
127-
color_array[3] = _single_color.a;
123+
factor_array.resize(4);
124+
factor_array[0] = _factor.r;
125+
factor_array[1] = _factor.g;
126+
factor_array[2] = _factor.b;
127+
factor_array[3] = _factor.a;
128128
}
129-
dict["color"] = color_array;
129+
dict["factor"] = factor_array;
130130
}
131-
if (_cell_colors_accessor_index >= 0) {
132-
dict["cellColors"] = _cell_colors_accessor_index;
131+
if (_per_cell_accessor_index >= 0) {
132+
dict["perCell"] = _per_cell_accessor_index;
133133
}
134-
if (_edge_colors_accessor_index >= 0) {
135-
dict["edgeColors"] = _edge_colors_accessor_index;
134+
if (_per_edge_accessor_index >= 0) {
135+
dict["perEdge"] = _per_edge_accessor_index;
136136
}
137-
if (_vertex_colors_accessor_index >= 0) {
138-
dict["vertexColors"] = _vertex_colors_accessor_index;
137+
if (_per_vertex_accessor_index >= 0) {
138+
dict["perVertex"] = _per_vertex_accessor_index;
139139
}
140140
if (_cell_texture_map_accessor_index >= 0) {
141141
dict["cellTextureMap"] = _cell_texture_map_accessor_index;
@@ -147,14 +147,14 @@ Dictionary G4MFMaterialChannel4D::to_dictionary() const {
147147
}
148148

149149
void G4MFMaterialChannel4D::_bind_methods() {
150-
ClassDB::bind_method(D_METHOD("get_single_color"), &G4MFMaterialChannel4D::get_single_color);
151-
ClassDB::bind_method(D_METHOD("set_single_color", "single_color"), &G4MFMaterialChannel4D::set_single_color);
152-
ClassDB::bind_method(D_METHOD("get_cell_colors_accessor_index"), &G4MFMaterialChannel4D::get_cell_colors_accessor_index);
153-
ClassDB::bind_method(D_METHOD("set_cell_colors_accessor_index", "cell_colors_accessor_index"), &G4MFMaterialChannel4D::set_cell_colors_accessor_index);
154-
ClassDB::bind_method(D_METHOD("get_edge_colors_accessor_index"), &G4MFMaterialChannel4D::get_edge_colors_accessor_index);
150+
ClassDB::bind_method(D_METHOD("get_factor"), &G4MFMaterialChannel4D::get_factor);
151+
ClassDB::bind_method(D_METHOD("set_factor", "single_color"), &G4MFMaterialChannel4D::set_factor);
152+
ClassDB::bind_method(D_METHOD("get_per_cell_accessor_index"), &G4MFMaterialChannel4D::get_per_cell_accessor_index);
153+
ClassDB::bind_method(D_METHOD("set_per_cell_accessor_index", "cell_colors_accessor_index"), &G4MFMaterialChannel4D::set_per_cell_accessor_index);
154+
ClassDB::bind_method(D_METHOD("get_per_edge_accessor_index"), &G4MFMaterialChannel4D::get_per_edge_accessor_index);
155155
ClassDB::bind_method(D_METHOD("set_edge_colors_accessor_index", "edge_colors_accessor_index"), &G4MFMaterialChannel4D::set_edge_colors_accessor_index);
156-
ClassDB::bind_method(D_METHOD("get_vertex_colors_accessor_index"), &G4MFMaterialChannel4D::get_vertex_colors_accessor_index);
157-
ClassDB::bind_method(D_METHOD("set_vertex_colors_accessor_index", "vertex_colors_accessor_index"), &G4MFMaterialChannel4D::set_vertex_colors_accessor_index);
156+
ClassDB::bind_method(D_METHOD("get_per_vertex_accessor_index"), &G4MFMaterialChannel4D::get_per_vertex_accessor_index);
157+
ClassDB::bind_method(D_METHOD("set_per_vertex_accessor_index", "vertex_colors_accessor_index"), &G4MFMaterialChannel4D::set_per_vertex_accessor_index);
158158
ClassDB::bind_method(D_METHOD("get_cell_texture_map_accessor_index"), &G4MFMaterialChannel4D::get_cell_texture_map_accessor_index);
159159
ClassDB::bind_method(D_METHOD("set_cell_texture_map_accessor_index", "cell_texture_map_accessor_index"), &G4MFMaterialChannel4D::set_cell_texture_map_accessor_index);
160160
ClassDB::bind_method(D_METHOD("get_cell_texture_index"), &G4MFMaterialChannel4D::get_cell_texture_index);
@@ -168,10 +168,10 @@ void G4MFMaterialChannel4D::_bind_methods() {
168168
ClassDB::bind_static_method("G4MFMaterialChannel4D", D_METHOD("from_dictionary", "dict"), &G4MFMaterialChannel4D::from_dictionary);
169169
ClassDB::bind_method(D_METHOD("to_dictionary"), &G4MFMaterialChannel4D::to_dictionary);
170170

171-
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "single_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_single_color", "get_single_color");
172-
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_colors_accessor_index"), "set_cell_colors_accessor_index", "get_cell_colors_accessor_index");
173-
ADD_PROPERTY(PropertyInfo(Variant::INT, "edge_colors_accessor_index"), "set_edge_colors_accessor_index", "get_edge_colors_accessor_index");
174-
ADD_PROPERTY(PropertyInfo(Variant::INT, "vertex_colors_accessor_index"), "set_vertex_colors_accessor_index", "get_vertex_colors_accessor_index");
171+
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "factor", PROPERTY_HINT_COLOR_NO_ALPHA), "set_factor", "get_factor");
172+
ADD_PROPERTY(PropertyInfo(Variant::INT, "per_cell_accessor_index"), "set_per_cell_accessor_index", "get_per_cell_accessor_index");
173+
ADD_PROPERTY(PropertyInfo(Variant::INT, "per_edge_accessor_index"), "set_edge_colors_accessor_index", "get_per_edge_accessor_index");
174+
ADD_PROPERTY(PropertyInfo(Variant::INT, "per_vertex_accessor_index"), "set_per_vertex_accessor_index", "get_per_vertex_accessor_index");
175175
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_texture_map_accessor_index"), "set_cell_texture_map_accessor_index", "get_cell_texture_map_accessor_index");
176176
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_texture_index"), "set_cell_texture_index", "get_cell_texture_index");
177177
}

0 commit comments

Comments
 (0)