mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
Made material texture setup scriptable.
This commit is contained in:
parent
6d8ded844c
commit
2b369f5be8
@ -64,6 +64,11 @@ void VoxelmanLibrary::clear_liquid_surfaces() {
|
||||
void VoxelmanLibrary::refresh_rects() {
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::setup_material_albedo(int material_index, Ref<Texture> texture) {
|
||||
if (has_method("_setup_material_albedo"))
|
||||
call("_setup_material_albedo", material_index, texture);
|
||||
}
|
||||
|
||||
VoxelmanLibrary::VoxelmanLibrary() {
|
||||
}
|
||||
|
||||
@ -75,6 +80,8 @@ VoxelmanLibrary::~VoxelmanLibrary() {
|
||||
}
|
||||
|
||||
void VoxelmanLibrary::_bind_methods() {
|
||||
BIND_VMETHOD(MethodInfo("_setup_material_albedo", PropertyInfo(Variant::INT, "material_index"), PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_material"), &VoxelmanLibrary::get_material);
|
||||
ClassDB::bind_method(D_METHOD("set_material", "value"), &VoxelmanLibrary::set_material);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material", "get_material");
|
||||
@ -104,4 +111,11 @@ void VoxelmanLibrary::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("clear_liquid_surfaces"), &VoxelmanLibrary::clear_liquid_surfaces);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("refresh_rects"), &VoxelmanLibrary::refresh_rects);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("setup_material_albedo", "material_index", "texture"), &VoxelmanLibrary::setup_material_albedo);
|
||||
|
||||
BIND_CONSTANT(MATERIAL_INDEX_VOXELS);
|
||||
BIND_CONSTANT(MATERIAL_INDEX_PROP);
|
||||
BIND_CONSTANT(MATERIAL_INDEX_LIQUID);
|
||||
BIND_CONSTANT(MATERIAL_INDEX_CLUTTER);
|
||||
}
|
||||
|
@ -13,6 +13,14 @@ class VoxelMesher;
|
||||
class VoxelmanLibrary : public Resource {
|
||||
GDCLASS(VoxelmanLibrary, Resource)
|
||||
|
||||
public:
|
||||
enum {
|
||||
MATERIAL_INDEX_VOXELS = 0,
|
||||
MATERIAL_INDEX_PROP = 1,
|
||||
MATERIAL_INDEX_LIQUID = 2,
|
||||
MATERIAL_INDEX_CLUTTER = 3,
|
||||
};
|
||||
|
||||
public:
|
||||
Ref<Material> get_material() const;
|
||||
void set_material(Ref<Material> mat);
|
||||
@ -42,6 +50,8 @@ public:
|
||||
|
||||
virtual void refresh_rects();
|
||||
|
||||
void setup_material_albedo(int material_index, Ref<Texture> texture);
|
||||
|
||||
VoxelmanLibrary();
|
||||
~VoxelmanLibrary();
|
||||
|
||||
|
@ -256,11 +256,7 @@ void VoxelmanLibraryMerger::refresh_rects() {
|
||||
|
||||
Ref<Texture> tex = _packer->get_generated_texture(0);
|
||||
|
||||
Ref<SpatialMaterial> mat = get_material();
|
||||
|
||||
if (mat.is_valid()) {
|
||||
mat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, tex);
|
||||
}
|
||||
setup_material_albedo(MATERIAL_INDEX_VOXELS, tex);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _voxel_surfaces.size(); i++) {
|
||||
@ -280,6 +276,37 @@ void VoxelmanLibraryMerger::refresh_rects() {
|
||||
}
|
||||
}
|
||||
|
||||
void VoxelmanLibraryMerger::_setup_material_albedo(int material_index, Ref<Texture> texture) {
|
||||
Ref<SpatialMaterial> mat;
|
||||
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_VOXELS:
|
||||
mat = get_material();
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
mat = get_prop_material();
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
mat = get_liquid_material();
|
||||
break;
|
||||
case MATERIAL_INDEX_CLUTTER:
|
||||
mat = get_clutter_material();
|
||||
break;
|
||||
}
|
||||
|
||||
Ref<SpatialMaterial> spmat;
|
||||
|
||||
if (spmat.is_valid()) {
|
||||
spmat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture);
|
||||
}
|
||||
|
||||
Ref<ShaderMaterial> shmat = get_material();
|
||||
|
||||
if (shmat.is_valid()) {
|
||||
shmat->set_shader_param("texture_albedo", texture);
|
||||
}
|
||||
}
|
||||
|
||||
VoxelmanLibraryMerger::VoxelmanLibraryMerger() {
|
||||
_packer.instance();
|
||||
_packer->set_texture_flags(Texture::FLAG_MIPMAPS | Texture::FLAG_FILTER);
|
||||
@ -341,4 +368,6 @@ void VoxelmanLibraryMerger::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_liquid_voxel_surfaces"), &VoxelmanLibraryMerger::get_liquid_voxel_surfaces);
|
||||
ClassDB::bind_method(D_METHOD("set_liquid_voxel_surfaces"), &VoxelmanLibraryMerger::set_liquid_voxel_surfaces);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "liquid_voxel_surfaces", PROPERTY_HINT_NONE, "17/17:VoxelSurfaceMerger", PROPERTY_USAGE_DEFAULT, "VoxelSurfaceMerger"), "set_liquid_voxel_surfaces", "get_liquid_voxel_surfaces");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_setup_material_albedo", "material_index", "texture"), &VoxelmanLibraryMerger::_setup_material_albedo);
|
||||
}
|
||||
|
@ -53,6 +53,8 @@ public:
|
||||
|
||||
void refresh_rects();
|
||||
|
||||
void _setup_material_albedo(int material_index, Ref<Texture> texture);
|
||||
|
||||
VoxelmanLibraryMerger();
|
||||
~VoxelmanLibraryMerger();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user