mirror of
https://github.com/Relintai/props.git
synced 2024-11-12 10:15:25 +01:00
Material support for the Propinstance.
This commit is contained in:
parent
446b526f57
commit
40201207f5
@ -36,6 +36,13 @@ void PropInstance::set_prop_data(const Ref<PropData> &data) {
|
||||
queue_build();
|
||||
}
|
||||
|
||||
Ref<Material> PropInstance::get_material() {
|
||||
return _material;
|
||||
}
|
||||
void PropInstance::set_material(const Ref<Material> &material) {
|
||||
_material = material;
|
||||
}
|
||||
|
||||
void PropInstance::init_materials() {
|
||||
call("_init_materials");
|
||||
}
|
||||
@ -158,7 +165,32 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref<PropData> &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<Material> mat = _material->duplicate();
|
||||
|
||||
Ref<Texture> texture = mdi->get_texture();
|
||||
|
||||
if (texture.is_valid()) {
|
||||
//texture is valid, try to set it into the material
|
||||
Ref<SpatialMaterial> spmat = mat;
|
||||
|
||||
if (spmat.is_valid()) {
|
||||
spmat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture);
|
||||
} else {
|
||||
|
||||
Ref<ShaderMaterial> 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")));
|
||||
|
@ -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<PropData> get_prop_data();
|
||||
void set_prop_data(const Ref<PropData> &data);
|
||||
|
||||
Ref<Material> get_material();
|
||||
void set_material(const Ref<Material> &material);
|
||||
|
||||
void init_materials();
|
||||
virtual void _init_materials();
|
||||
|
||||
@ -66,6 +71,7 @@ protected:
|
||||
|
||||
protected:
|
||||
Ref<PropData> _prop_data;
|
||||
Ref<Material> _material;
|
||||
|
||||
bool _build_queued;
|
||||
bool _building;
|
||||
|
Loading…
Reference in New Issue
Block a user