diff --git a/prop_instance.cpp b/prop_instance.cpp index 02b7225..301560c 100644 --- a/prop_instance.cpp +++ b/prop_instance.cpp @@ -36,6 +36,13 @@ void PropInstance::set_prop_data(const Ref &data) { queue_build(); } +Ref PropInstance::get_material() { + return _material; +} +void PropInstance::set_material(const Ref &material) { + _material = material; +} + void PropInstance::init_materials() { call("_init_materials"); } @@ -158,7 +165,32 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref &pr MeshDataInstance *mdi = memnew(MeshDataInstance); add_child(mdi); mdi->set_transform(t); - //mdi->set_material(); + + if (_material.is_valid()) { + //duplicate the material, so that textures will work + Ref mat = _material->duplicate(); + + Ref texture = mdi->get_texture(); + + if (texture.is_valid()) { + //texture is valid, try to set it into the material + Ref spmat = mat; + + if (spmat.is_valid()) { + spmat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture); + } else { + + Ref shmat = mat; + + if (shmat.is_valid()) { + shmat->set_shader_param("texture_albedo", texture); + } + } + } + + mdi->set_material(mat); + } + mdi->set_mesh_data(mdr); continue; @@ -193,6 +225,10 @@ void PropInstance::_bind_methods() { ClassDB::bind_method(D_METHOD("set_prop_data", "value"), &PropInstance::set_prop_data); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_data", PROPERTY_HINT_RESOURCE_TYPE, "PropData"), "set_prop_data", "get_prop_data"); + ClassDB::bind_method(D_METHOD("get_material"), &PropInstance::get_material); + ClassDB::bind_method(D_METHOD("set_material", "material"), &PropInstance::set_material); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_material", "get_material"); + BIND_VMETHOD(MethodInfo("_prop_preprocess", PropertyInfo(Variant::TRANSFORM, "tarnsform"), PropertyInfo(Variant::OBJECT, "prop_data", PROPERTY_HINT_RESOURCE_TYPE, "PropData"))); diff --git a/prop_instance.h b/prop_instance.h index d7b00ce..f75b238 100644 --- a/prop_instance.h +++ b/prop_instance.h @@ -33,6 +33,8 @@ SOFTWARE. #define Spatial Node3D #endif +#include "scene/resources/material.h" + #include "core/math/vector3.h" #include "props/prop_data.h" @@ -44,6 +46,9 @@ public: Ref get_prop_data(); void set_prop_data(const Ref &data); + Ref get_material(); + void set_material(const Ref &material); + void init_materials(); virtual void _init_materials(); @@ -66,6 +71,7 @@ protected: protected: Ref _prop_data; + Ref _material; bool _build_queued; bool _building;