Tiled Wall support for PropInstance and PropinstanceMerger. Also fixed a double transform multiplication with MeshDataResources in PropInstanceMerger.

This commit is contained in:
Relintai 2021-08-18 18:48:13 +02:00
parent f2d1383ba8
commit 51e3254bfc
5 changed files with 117 additions and 3 deletions

View File

@ -24,7 +24,9 @@ SOFTWARE.
#include "../../props/props/prop_data.h"
#include "../../props/props/prop_data_prop.h"
#include "../../props/props/prop_data_tiled_wall.h"
#include "../singleton/prop_cache.h"
#include "../tiled_wall/tiled_wall_data.h"
#if MESH_DATA_RESOURCE_PRESENT
#define PROPS_PRESENT 1
@ -196,9 +198,24 @@ void PropMaterialCache::prop_add_textures(const Ref<PropData> &prop) {
continue;
texture_add(tex);
continue;
}
#endif
Ref<PropDataTiledWall> pdtw = prop->get_prop(i);
if (pdtw.is_valid()) {
Ref<TiledWallData> twd = pdtw->get_data();
if (!twd.is_valid())
continue;
twd->setup_cache(Ref<PropMaterialCache>(this));
continue;
}
Ref<PropDataProp> pdp = prop->get_prop(i);
if (pdp.is_valid()) {
@ -225,6 +242,33 @@ void PropMaterialCache::prop_remove_textures(const Ref<PropData> &prop) {
}
#endif
Ref<PropDataTiledWall> pdtw = prop->get_prop(i);
if (pdtw.is_valid()) {
Ref<TiledWallData> twd = pdtw->get_data();
if (!twd.is_valid())
continue;
for (int j = 0; j < twd->get_texture_count(); ++j) {
const Ref<Texture> &tex = twd->get_texture(j);
if (tex.is_valid()) {
texture_remove(tex);
}
}
for (int j = 0; j < twd->get_flavour_texture_count(); ++j) {
const Ref<Texture> &tex = twd->get_flavour_texture(j);
if (tex.is_valid()) {
texture_remove(tex);
}
}
continue;
}
Ref<PropDataProp> pdp = prop->get_prop(i);
if (pdp.is_valid()) {

View File

@ -23,6 +23,10 @@
#include "./props/prop_data_light.h"
#include "./props/prop_data_prop.h"
#include "./props/prop_data_scene.h"
#include "./props/prop_data_tiled_wall.h"
#include "tiled_wall/tiled_wall.h"
#include "tiled_wall/tiled_wall_data.h"
Ref<PropData> PropInstance::get_prop_data() {
return _prop_data;
@ -127,6 +131,23 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref<PropData> &pr
continue;
}
Ref<PropDataTiledWall> tiled_wall_data = e;
if (tiled_wall_data.is_valid()) {
TiledWall *twn = memnew(TiledWall);
twn->set_width(tiled_wall_data->get_width());
twn->set_heigth(tiled_wall_data->get_heigth());
twn->set_data(tiled_wall_data->get_data());
twn->set_collision(tiled_wall_data->get_collision());
twn->set_transform(t);
add_child(twn);
continue;
}
Ref<PropDataScene> scene_data = e;
if (scene_data.is_valid()) {
@ -185,7 +206,6 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref<PropData> &pr
if (spmat.is_valid()) {
spmat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture);
} else {
Ref<ShaderMaterial> shmat = mat;
if (shmat.is_valid()) {

View File

@ -61,6 +61,10 @@ typedef class RenderingServer VS;
#include "../thread_pool/thread_pool.h"
#endif
#include "./props/prop_data_tiled_wall.h"
#include "tiled_wall/tiled_wall_data.h"
const float PropInstanceMerger::LOD_CHECK_INTERVAL = 2;
bool PropInstanceMerger::get_building() {
@ -522,6 +526,7 @@ void PropInstanceMerger::_build() {
Ref<PropMaterialCache> cache = PropCache::get_singleton()->material_cache_get(_prop_data);
//note: this should be moved to the job
if (!cache->get_initialized()) {
cache->mutex_lock();
@ -590,6 +595,15 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Ref<PropDat
continue;
}
Ref<PropDataTiledWall> tiled_wall_data = e;
if (tiled_wall_data.is_valid()) {
_job->add_tiled_wall(tiled_wall_data, t);
continue;
}
Ref<PropDataScene> scene_data = e;
if (scene_data.is_valid()) {

View File

@ -59,6 +59,9 @@ SOFTWARE.
#undef PROPS_PRESENT
#endif
#include "tiled_wall/tiled_wall_data.h"
#include "props/prop_data_tiled_wall.h"
Ref<PropMaterialCache> PropInstancePropJob::get_material_cache() {
return _material_cache;
}
@ -132,6 +135,18 @@ void PropInstancePropJob::clear_meshes() {
}
#endif
void PropInstancePropJob::add_tiled_wall(const Ref<PropDataTiledWall> &data, const Transform &base_transform) {
PTWEntry e;
e.data = data;
e.base_transform = base_transform;
_prop_tiled_wall_datas.push_back(e);
}
void PropInstancePropJob::clear_tiled_walls() {
_prop_tiled_wall_datas.clear();
}
void PropInstancePropJob::add_light(const Ref<PropLight> &light) {
_prop_mesher->add_light(light);
}
@ -209,7 +224,6 @@ void PropInstancePropJob::phase_prop() {
Ref<MeshDataResource> mesh = pmd->get_mesh();
Ref<Texture> tex = pmd->get_texture();
Transform t = pmd->get_transform();
t *= e.base_transform;
Rect2 uvr = _material_cache->texture_get_uv_rect(tex);
@ -217,6 +231,15 @@ void PropInstancePropJob::phase_prop() {
}
#endif
for (int i = 0; i < _prop_tiled_wall_datas.size(); ++i) {
PTWEntry &e = _prop_tiled_wall_datas.write[i];
Ref<PropDataTiledWall> pdtw = e.data;
Transform t = pdtw->get_transform();
_prop_mesher->add_tiled_wall_simple(pdtw->get_width(), pdtw->get_heigth(), t, pdtw->get_data(), _material_cache);
}
if (_prop_mesher->get_vertex_count() == 0) {
//reset_meshes();
@ -293,6 +316,8 @@ void PropInstancePropJob::_reset() {
_prop_mesher->reset();
}
_prop_tiled_wall_datas.clear();
_prop_mesh_datas.clear();
clear_collision_shapes();

View File

@ -32,6 +32,7 @@ class PropMesherJobStep;
class PropMaterialCache;
class Shape;
class PropLight;
class PropDataTiledWall;
#if MESH_DATA_RESOURCE_PRESENT
class PropDataMeshData;
@ -65,6 +66,9 @@ public:
void clear_meshes();
#endif
void add_tiled_wall(const Ref<PropDataTiledWall> &data, const Transform &base_transform);
void clear_tiled_walls();
void add_light(const Ref<PropLight> &light);
void clear_lights();
@ -103,6 +107,11 @@ protected:
};
#endif
struct PTWEntry {
Ref<PropDataTiledWall> data;
Transform base_transform;
};
struct CollisionShapeEntry {
Ref<Shape> shape;
Transform transform;
@ -123,6 +132,8 @@ protected:
Vector<CollisionShapeEntry> _collision_shapes;
Vector<PTWEntry> _prop_tiled_wall_datas;
Array temp_mesh_arr;
};