Improved MeshDataInstance, and PropDataMeshData will create a material in _processor_get_node_for.

This commit is contained in:
Relintai 2020-07-05 23:09:23 +02:00
parent ac6e09939d
commit 85417ebee9
3 changed files with 26 additions and 10 deletions

View File

@ -30,8 +30,12 @@ void MeshDataInstance::set_mesh_data(const Ref<MeshDataResource> &mesh) {
_mesh = mesh;
if (_mesh.is_valid() && is_inside_tree()) {
setup_mesh();
if (_mesh.is_valid()) {
if (is_inside_tree()) {
setup_mesh();
} else {
_dirty = true;
}
}
}
@ -118,6 +122,7 @@ void MeshDataInstance::setup_material_texture() {
}
MeshDataInstance::MeshDataInstance() {
_dirty = false;
_snap_to_mesh = false;
_snap_axis = Vector3(0, -1, 0);
}
@ -125,16 +130,21 @@ MeshDataInstance::~MeshDataInstance() {
_mesh.unref();
_texture.unref();
}
/*
void MeshDataInstance::notification(int p_what) {
void MeshDataInstance::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (get_parent() == NULL)
return;
if (_dirty) {
_dirty = false;
if (_mesh.is_valid()) {
setup_mesh();
}
}
}
}
}
*/
void MeshDataInstance::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_snap_to_mesh"), &MeshDataInstance::get_snap_to_mesh);
ClassDB::bind_method(D_METHOD("set_snap_to_mesh", "value"), &MeshDataInstance::set_snap_to_mesh);

View File

@ -67,10 +67,11 @@ public:
~MeshDataInstance();
protected:
//void notification(int p_what);
void _notification(int p_what);
static void _bind_methods();
private:
bool _dirty;
bool _snap_to_mesh;
Vector3 _snap_axis;
Ref<MeshDataResource> _mesh;

View File

@ -25,6 +25,7 @@ SOFTWARE.
#if PROPS_PRESENT
#include "../nodes/mesh_data_instance.h"
#include "scene/resources/material.h"
Ref<MeshDataResource> PropDataMeshData::get_mesh() const {
return _mesh;
@ -84,9 +85,13 @@ void PropDataMeshData::_processor_process(Ref<PropData> prop_data, Node *node, c
Node *PropDataMeshData::_processor_get_node_for(const Transform &transform) {
MeshDataInstance *i = memnew(MeshDataInstance);
i->set_mesh_data(get_mesh());
Ref<SpatialMaterial> m;
m.instance();
i->set_material(m);
i->set_texture(get_texture());
i->set_transform(transform * get_transform());
i->set_mesh_data(get_mesh());
i->set_transform(get_transform());
return i;
}