Now PropLights can be added into the mesher.

This commit is contained in:
Relintai 2021-08-11 18:20:29 +02:00
parent 00536c9596
commit 51ee053eed
2 changed files with 21 additions and 6 deletions

View File

@ -22,6 +22,7 @@ SOFTWARE.
#include "prop_mesher.h" #include "prop_mesher.h"
#include "lights/prop_light.h"
#include "modules/opensimplex/open_simplex_noise.h" #include "modules/opensimplex/open_simplex_noise.h"
const String PropMesher::BINDING_STRING_BUILD_FLAGS = "Use Lighting,Use AO,Use RAO,Bake Lights"; const String PropMesher::BINDING_STRING_BUILD_FLAGS = "Use Lighting,Use AO,Use RAO,Bake Lights";
@ -632,6 +633,13 @@ void PropMesher::_add_mesher(const Ref<PropMesher> &mesher) {
} }
} }
void PropMesher::add_light(const Ref<PropLight> &light) {
_lights.push_back(light);
}
void PropMesher::clear_lights() {
_lights.clear();
}
PoolVector<Vector3> PropMesher::build_collider() const { PoolVector<Vector3> PropMesher::build_collider() const {
PoolVector<Vector3> face_points; PoolVector<Vector3> face_points;
@ -666,7 +674,7 @@ void PropMesher::bake_colors() {
//if ((get_build_flags() & TerraChunkDefault::BUILD_FLAG_USE_LIGHTING) == 0) //if ((get_build_flags() & TerraChunkDefault::BUILD_FLAG_USE_LIGHTING) == 0)
// return; // return;
/* /*
if (_vertices.size() == 0) if (_vertices.size() == 0)
return; return;
@ -1090,12 +1098,15 @@ void PropMesher::_bind_methods() {
#endif #endif
ClassDB::bind_method(D_METHOD("generate_ao"), &PropMesher::generate_ao); ClassDB::bind_method(D_METHOD("generate_ao"), &PropMesher::generate_ao);
ClassDB::bind_method(D_METHOD("get_random_ao", "position"),&PropMesher::get_random_ao); ClassDB::bind_method(D_METHOD("get_random_ao", "position"), &PropMesher::get_random_ao);
BIND_VMETHOD(MethodInfo("_add_mesher", PropertyInfo(Variant::OBJECT, "mesher", PROPERTY_HINT_RESOURCE_TYPE, "PropMesher"))); BIND_VMETHOD(MethodInfo("_add_mesher", PropertyInfo(Variant::OBJECT, "mesher", PROPERTY_HINT_RESOURCE_TYPE, "PropMesher")));
ClassDB::bind_method(D_METHOD("add_mesher", "mesher"), &PropMesher::add_mesher); ClassDB::bind_method(D_METHOD("add_mesher", "mesher"), &PropMesher::add_mesher);
ClassDB::bind_method(D_METHOD("_add_mesher", "mesher"), &PropMesher::_add_mesher); ClassDB::bind_method(D_METHOD("_add_mesher", "mesher"), &PropMesher::_add_mesher);
ClassDB::bind_method(D_METHOD("add_light", "light"), &PropMesher::add_light);
ClassDB::bind_method(D_METHOD("clear_lights"), &PropMesher::clear_lights);
ClassDB::bind_method(D_METHOD("get_vertices"), &PropMesher::get_vertices); ClassDB::bind_method(D_METHOD("get_vertices"), &PropMesher::get_vertices);
ClassDB::bind_method(D_METHOD("set_vertices", "values"), &PropMesher::set_vertices); ClassDB::bind_method(D_METHOD("set_vertices", "values"), &PropMesher::set_vertices);
ClassDB::bind_method(D_METHOD("get_vertex_count"), &PropMesher::get_vertex_count); ClassDB::bind_method(D_METHOD("get_vertex_count"), &PropMesher::get_vertex_count);

View File

@ -39,9 +39,9 @@ using PoolVector = Vector<N>;
#else #else
#include "core/color.h" #include "core/color.h"
#include "core/pool_vector.h"
#include "core/reference.h" #include "core/reference.h"
#include "core/vector.h" #include "core/vector.h"
#include "core/pool_vector.h"
#include "scene/3d/mesh_instance.h" #include "scene/3d/mesh_instance.h"
#endif #endif
@ -61,6 +61,7 @@ using PoolVector = Vector<N>;
#endif #endif
class OpenSimplexNoise; class OpenSimplexNoise;
class PropLight;
class PropMesher : public Reference { class PropMesher : public Reference {
GDCLASS(PropMesher, Reference); GDCLASS(PropMesher, Reference);
@ -79,7 +80,6 @@ public:
}; };
struct Vertex { struct Vertex {
Vector3 vertex; Vector3 vertex;
Color color; Color color;
Vector3 normal; // normal, binormal, tangent Vector3 normal; // normal, binormal, tangent
@ -155,12 +155,15 @@ public:
void add_mesher(const Ref<PropMesher> &mesher); void add_mesher(const Ref<PropMesher> &mesher);
void _add_mesher(const Ref<PropMesher> &mesher); void _add_mesher(const Ref<PropMesher> &mesher);
void add_light(const Ref<PropLight> &light);
void clear_lights();
PoolVector<Vector3> build_collider() const; PoolVector<Vector3> build_collider() const;
void bake_colors(); void bake_colors();
#ifdef TERRAMAN_PRESENT #ifdef TERRAMAN_PRESENT
void bake_lights(MeshInstance *node, Vector<Ref<TerraLight> > &lights); void bake_lights(MeshInstance *node, Vector<Ref<TerraLight>> &lights);
#endif #endif
Array build_mesh(); Array build_mesh();
@ -221,6 +224,7 @@ protected:
PoolVector<Vertex> _vertices; PoolVector<Vertex> _vertices;
PoolVector<int> _indices; PoolVector<int> _indices;
Vector<Ref<PropLight>> _lights;
Color _last_color; Color _last_color;
Vector3 _last_normal; Vector3 _last_normal;