Use StringName for voxel names
This commit is contained in:
parent
f9e2d9cc12
commit
fd9122a0de
@ -449,6 +449,7 @@ void Voxel::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("set_collision_aabbs", "aabbs"), &Voxel::_b_set_collision_aabbs);
|
ClassDB::bind_method(D_METHOD("set_collision_aabbs", "aabbs"), &Voxel::_b_set_collision_aabbs);
|
||||||
ClassDB::bind_method(D_METHOD("get_collision_aabbs"), &Voxel::_b_get_collision_aabbs);
|
ClassDB::bind_method(D_METHOD("get_collision_aabbs"), &Voxel::_b_get_collision_aabbs);
|
||||||
|
|
||||||
|
// TODO Update to StringName in Godot 4
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "voxel_name"), "set_voxel_name", "get_voxel_name");
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "voxel_name"), "set_voxel_name", "get_voxel_name");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent"), "set_transparent", "is_transparent");
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent"), "set_transparent", "is_transparent");
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
// Properties
|
// Properties
|
||||||
|
|
||||||
Ref<Voxel> set_voxel_name(String name);
|
Ref<Voxel> set_voxel_name(String name);
|
||||||
_FORCE_INLINE_ String get_voxel_name() const { return _name; }
|
_FORCE_INLINE_ StringName get_voxel_name() const { return _name; }
|
||||||
|
|
||||||
Ref<Voxel> set_id(int id);
|
Ref<Voxel> set_id(int id);
|
||||||
_FORCE_INLINE_ int get_id() const { return _id; }
|
_FORCE_INLINE_ int get_id() const { return _id; }
|
||||||
@ -98,7 +98,6 @@ private:
|
|||||||
|
|
||||||
void clear_geometry();
|
void clear_geometry();
|
||||||
Ref<Voxel> set_cube_geometry(float sy = 1);
|
Ref<Voxel> set_cube_geometry(float sy = 1);
|
||||||
//Ref<Voxel> set_xquad_geometry(Vector2 atlas_pos);
|
|
||||||
|
|
||||||
Array _b_get_collision_aabbs() const;
|
Array _b_get_collision_aabbs() const;
|
||||||
void _b_set_collision_aabbs(Array array);
|
void _b_set_collision_aabbs(Array array);
|
||||||
@ -108,7 +107,7 @@ private:
|
|||||||
|
|
||||||
// Identifiers
|
// Identifiers
|
||||||
int _id;
|
int _id;
|
||||||
String _name; // TODO StringName?
|
StringName _name;
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
int _material_id;
|
int _material_id;
|
||||||
|
@ -30,6 +30,16 @@ void VoxelLibrary::set_voxel_count(unsigned int type_count) {
|
|||||||
_change_notify();
|
_change_notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int VoxelLibrary::get_voxel_index_from_name(StringName name) const {
|
||||||
|
for (size_t i = 0; i < _voxel_types.size(); ++i) {
|
||||||
|
const Ref<Voxel> &v = _voxel_types[i];
|
||||||
|
if (v->get_name() == name) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void VoxelLibrary::load_default() {
|
void VoxelLibrary::load_default() {
|
||||||
set_voxel_count(2);
|
set_voxel_count(2);
|
||||||
create_voxel(0, "air")->set_transparent(true);
|
create_voxel(0, "air")->set_transparent(true);
|
||||||
@ -382,6 +392,9 @@ void VoxelLibrary::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("set_voxel_count", "count"), &VoxelLibrary::set_voxel_count);
|
ClassDB::bind_method(D_METHOD("set_voxel_count", "count"), &VoxelLibrary::set_voxel_count);
|
||||||
ClassDB::bind_method(D_METHOD("get_voxel_count"), &VoxelLibrary::get_voxel_count);
|
ClassDB::bind_method(D_METHOD("get_voxel_count"), &VoxelLibrary::get_voxel_count);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_voxel_index_from_name", "name"), &VoxelLibrary::get_voxel_index_from_name);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_voxel_by_name", "name"), &VoxelLibrary::_b_get_voxel_by_name);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("bake"), &VoxelLibrary::bake);
|
ClassDB::bind_method(D_METHOD("bake"), &VoxelLibrary::bake);
|
||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "atlas_size"), "set_atlas_size", "get_atlas_size");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "atlas_size"), "set_atlas_size", "get_atlas_size");
|
||||||
@ -394,3 +407,9 @@ Ref<Voxel> VoxelLibrary::_b_get_voxel(unsigned int id) {
|
|||||||
ERR_FAIL_COND_V(id >= _voxel_types.size(), Ref<Voxel>());
|
ERR_FAIL_COND_V(id >= _voxel_types.size(), Ref<Voxel>());
|
||||||
return _voxel_types[id];
|
return _voxel_types[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ref<Voxel> VoxelLibrary::_b_get_voxel_by_name(StringName name) {
|
||||||
|
int id = get_voxel_index_from_name(name);
|
||||||
|
ERR_FAIL_COND_V(id == -1, Ref<Voxel>());
|
||||||
|
return _voxel_types[id];
|
||||||
|
}
|
||||||
|
@ -41,6 +41,8 @@ public:
|
|||||||
|
|
||||||
bool get_side_pattern_occlusion(unsigned int pattern_a, unsigned int pattern_b) const;
|
bool get_side_pattern_occlusion(unsigned int pattern_a, unsigned int pattern_b) const;
|
||||||
|
|
||||||
|
int get_voxel_index_from_name(StringName name) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generate_side_culling_matrix();
|
void generate_side_culling_matrix();
|
||||||
|
|
||||||
@ -51,6 +53,7 @@ private:
|
|||||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||||
|
|
||||||
Ref<Voxel> _b_get_voxel(unsigned int id);
|
Ref<Voxel> _b_get_voxel(unsigned int id);
|
||||||
|
Ref<Voxel> _b_get_voxel_by_name(StringName name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Ref<Voxel> > _voxel_types;
|
std::vector<Ref<Voxel> > _voxel_types;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user