mirror of
https://github.com/Relintai/props.git
synced 2024-11-12 10:15:25 +01:00
Cleaned up prop instance job and prop instance merger. All the necessary logic (for the time being) is there. It still needs some fixes though.
This commit is contained in:
parent
688499cca0
commit
0eee4dba90
@ -19,6 +19,8 @@
|
||||
#include "servers/rendering_server.h"
|
||||
typedef class RenderingServer VS;
|
||||
|
||||
#define GET_WORLD get_world_3d
|
||||
|
||||
#else
|
||||
#include "core/engine.h"
|
||||
|
||||
@ -31,14 +33,16 @@ typedef class RenderingServer VS;
|
||||
|
||||
#include "servers/visual_server.h"
|
||||
|
||||
#define GET_WORLD get_world
|
||||
|
||||
#endif
|
||||
|
||||
#if MESH_DATA_RESOURCE_PRESENT
|
||||
//define PROPS_PRESENT, so things compile. That module's scsub will define this too while compiling,
|
||||
//define PROPS_PRESENT, so things compile. That module's scsub will define this too while compiling,
|
||||
//but not when included from here.
|
||||
#define PROPS_PRESENT 1
|
||||
#include "../mesh_data_resource/props/prop_data_mesh_data.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "./props/prop_data_entry.h"
|
||||
#include "./props/prop_data_light.h"
|
||||
@ -109,25 +113,66 @@ void PropInstanceMerger::materials_set(const Vector<Variant> &materials) {
|
||||
RID PropInstanceMerger::mesh_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _meshes.size(), RID());
|
||||
|
||||
return _meshes[index];
|
||||
return _meshes[index].mesh;
|
||||
}
|
||||
|
||||
void PropInstanceMerger::mesh_add(const RID value) {
|
||||
_meshes.push_back(value);
|
||||
RID PropInstanceMerger::mesh_instance_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _meshes.size(), RID());
|
||||
|
||||
return _meshes[index].mesh_instance;
|
||||
}
|
||||
|
||||
void PropInstanceMerger::mesh_add(const RID mesh_instance, const RID mesh) {
|
||||
MeshEntry e;
|
||||
e.mesh = mesh;
|
||||
e.mesh_instance = mesh_instance;
|
||||
|
||||
_meshes.push_back(e);
|
||||
}
|
||||
|
||||
int PropInstanceMerger::mesh_get_num() const {
|
||||
return _meshes.size();
|
||||
}
|
||||
|
||||
void PropInstanceMerger::meshs_clear() {
|
||||
void PropInstanceMerger::meshes_clear() {
|
||||
_meshes.clear();
|
||||
}
|
||||
|
||||
void PropInstanceMerger::meshes_create(const int num) {
|
||||
free_meshes();
|
||||
|
||||
for (int i = 0; i < num; ++i) {
|
||||
RID mesh_instance_rid = VS::get_singleton()->instance_create();
|
||||
|
||||
if (GET_WORLD().is_valid())
|
||||
VS::get_singleton()->instance_set_scenario(mesh_instance_rid, GET_WORLD()->get_scenario());
|
||||
|
||||
RID mesh_rid = VS::get_singleton()->mesh_create();
|
||||
|
||||
VS::get_singleton()->instance_set_base(mesh_instance_rid, mesh_rid);
|
||||
|
||||
VS::get_singleton()->instance_set_transform(mesh_instance_rid, get_transform());
|
||||
|
||||
if (i != 0)
|
||||
VS::get_singleton()->instance_set_visible(mesh_instance_rid, false);
|
||||
|
||||
MeshEntry e;
|
||||
e.mesh = mesh_rid;
|
||||
e.mesh_instance = mesh_instance_rid;
|
||||
|
||||
_meshes.push_back(e);
|
||||
}
|
||||
}
|
||||
|
||||
Vector<Variant> PropInstanceMerger::meshes_get() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _meshes.size(); i++) {
|
||||
r.push_back(_meshes[i]);
|
||||
Array a;
|
||||
|
||||
a.push_back(_meshes[i].mesh);
|
||||
a.push_back(_meshes[i].mesh_instance);
|
||||
|
||||
r.push_back(a);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@ -136,21 +181,58 @@ void PropInstanceMerger::meshes_set(const Vector<Variant> &meshs) {
|
||||
_meshes.clear();
|
||||
|
||||
for (int i = 0; i < _meshes.size(); i++) {
|
||||
RID mesh = RID(meshs[i]);
|
||||
Array arr = Array(meshs[i]);
|
||||
|
||||
_meshes.push_back(mesh);
|
||||
ERR_CONTINUE(arr.size() != 2);
|
||||
|
||||
MeshEntry e;
|
||||
e.mesh = RID(arr[0]);
|
||||
e.mesh_instance = RID(arr[1]);
|
||||
|
||||
_meshes.push_back(e);
|
||||
}
|
||||
}
|
||||
|
||||
//Collider
|
||||
RID PropInstanceMerger::collider_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _colliders.size(), RID());
|
||||
|
||||
return _colliders[index];
|
||||
Transform PropInstanceMerger::collider_local_transform_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _colliders.size(), Transform());
|
||||
|
||||
return _colliders[index].transform;
|
||||
}
|
||||
|
||||
void PropInstanceMerger::collider_add(const RID value) {
|
||||
_colliders.push_back(value);
|
||||
RID PropInstanceMerger::collider_body_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _colliders.size(), RID());
|
||||
|
||||
return _colliders[index].body;
|
||||
}
|
||||
|
||||
Ref<Shape> PropInstanceMerger::collider_shape_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _colliders.size(), Ref<Shape>());
|
||||
|
||||
return _colliders[index].shape;
|
||||
}
|
||||
|
||||
RID PropInstanceMerger::collider_shape_rid_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _colliders.size(), RID());
|
||||
|
||||
return _colliders[index].shape_rid;
|
||||
}
|
||||
|
||||
int PropInstanceMerger::collider_add(const Transform &local_transform, const Ref<Shape> &shape, const RID &shape_rid, const RID &body) {
|
||||
ERR_FAIL_COND_V(!shape.is_valid() && shape_rid == RID(), 0);
|
||||
|
||||
int index = _colliders.size();
|
||||
|
||||
ColliderBody e;
|
||||
e.transform = local_transform;
|
||||
e.body = body;
|
||||
e.shape = shape;
|
||||
e.shape_rid = shape_rid;
|
||||
|
||||
_colliders.push_back(e);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
int PropInstanceMerger::collider_get_num() const {
|
||||
@ -164,7 +246,7 @@ void PropInstanceMerger::colliders_clear() {
|
||||
Vector<Variant> PropInstanceMerger::colliders_get() {
|
||||
Vector<Variant> r;
|
||||
for (int i = 0; i < _colliders.size(); i++) {
|
||||
r.push_back(_colliders[i]);
|
||||
r.push_back(_colliders[i].body);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
@ -175,7 +257,92 @@ void PropInstanceMerger::colliders_set(const Vector<Variant> &colliders) {
|
||||
for (int i = 0; i < colliders.size(); i++) {
|
||||
RID collider = (colliders[i]);
|
||||
|
||||
_colliders.push_back(collider);
|
||||
ColliderBody c;
|
||||
c.body = collider;
|
||||
|
||||
_colliders.push_back(c);
|
||||
}
|
||||
}
|
||||
|
||||
void PropInstanceMerger::debug_mesh_allocate() {
|
||||
if (_debug_mesh_rid == RID()) {
|
||||
_debug_mesh_rid = VisualServer::get_singleton()->mesh_create();
|
||||
}
|
||||
|
||||
if (_debug_mesh_instance == RID()) {
|
||||
_debug_mesh_instance = VisualServer::get_singleton()->instance_create();
|
||||
|
||||
if (GET_WORLD().is_valid())
|
||||
VS::get_singleton()->instance_set_scenario(_debug_mesh_instance, GET_WORLD()->get_scenario());
|
||||
|
||||
VS::get_singleton()->instance_set_base(_debug_mesh_instance, _debug_mesh_rid);
|
||||
VS::get_singleton()->instance_set_transform(_debug_mesh_instance, get_transform());
|
||||
VS::get_singleton()->instance_set_visible(_debug_mesh_instance, true);
|
||||
}
|
||||
}
|
||||
void PropInstanceMerger::debug_mesh_free() {
|
||||
if (_debug_mesh_instance != RID()) {
|
||||
VisualServer::get_singleton()->free(_debug_mesh_instance);
|
||||
}
|
||||
|
||||
if (_debug_mesh_rid != RID()) {
|
||||
VisualServer::get_singleton()->free(_debug_mesh_rid);
|
||||
}
|
||||
}
|
||||
bool PropInstanceMerger::debug_mesh_has() {
|
||||
return _debug_mesh_rid != RID();
|
||||
}
|
||||
void PropInstanceMerger::debug_mesh_clear() {
|
||||
if (_debug_mesh_rid != RID()) {
|
||||
VisualServer::get_singleton()->mesh_clear(_debug_mesh_rid);
|
||||
}
|
||||
}
|
||||
void PropInstanceMerger::debug_mesh_array_clear() {
|
||||
_debug_mesh_array.resize(0);
|
||||
}
|
||||
void PropInstanceMerger::debug_mesh_add_vertices_to(const PoolVector3Array &arr) {
|
||||
_debug_mesh_array.append_array(arr);
|
||||
|
||||
if (_debug_mesh_array.size() % 2 == 1) {
|
||||
_debug_mesh_array.append(_debug_mesh_array[_debug_mesh_array.size() - 1]);
|
||||
}
|
||||
}
|
||||
void PropInstanceMerger::debug_mesh_send() {
|
||||
debug_mesh_allocate();
|
||||
debug_mesh_clear();
|
||||
|
||||
if (_debug_mesh_array.size() == 0)
|
||||
return;
|
||||
|
||||
SceneTree *st = SceneTree::get_singleton();
|
||||
|
||||
Array arr;
|
||||
arr.resize(VisualServer::ARRAY_MAX);
|
||||
arr[VisualServer::ARRAY_VERTEX] = _debug_mesh_array;
|
||||
|
||||
VisualServer::get_singleton()->mesh_add_surface_from_arrays(_debug_mesh_rid, VisualServer::PRIMITIVE_LINES, arr);
|
||||
|
||||
if (st) {
|
||||
VisualServer::get_singleton()->mesh_surface_set_material(_debug_mesh_rid, 0, SceneTree::get_singleton()->get_debug_collision_material()->get_rid());
|
||||
}
|
||||
|
||||
debug_mesh_array_clear();
|
||||
}
|
||||
|
||||
void PropInstanceMerger::draw_debug_mdr_colliders() {
|
||||
if (!debug_mesh_has()) {
|
||||
debug_mesh_allocate();
|
||||
}
|
||||
|
||||
for (int i = 0; i < collider_get_num(); ++i) {
|
||||
Ref<Shape> shape = collider_shape_get(i);
|
||||
|
||||
if (!shape.is_valid())
|
||||
continue;
|
||||
|
||||
Transform t = collider_local_transform_get(i);
|
||||
|
||||
shape->add_vertices_to_array(_debug_mesh_array, t);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,8 +361,30 @@ void PropInstanceMerger::set_lod_reduction_distance_squared(const float dist) {
|
||||
}
|
||||
|
||||
void PropInstanceMerger::free_meshes() {
|
||||
RID rid;
|
||||
|
||||
for (int i = 0; i < _meshes.size(); ++i) {
|
||||
MeshEntry &e = _meshes.write[i];
|
||||
|
||||
if (e.mesh_instance != rid) {
|
||||
VS::get_singleton()->free(e.mesh_instance);
|
||||
}
|
||||
|
||||
if (e.mesh != rid) {
|
||||
VS::get_singleton()->free(e.mesh);
|
||||
}
|
||||
|
||||
e.mesh_instance = rid;
|
||||
e.mesh = rid;
|
||||
}
|
||||
}
|
||||
|
||||
void PropInstanceMerger::free_colliders() {
|
||||
for (int i = 0; i < _colliders.size(); ++i) {
|
||||
PhysicsServer::get_singleton()->free(_colliders[i].body);
|
||||
|
||||
_colliders.write[i].body = RID();
|
||||
}
|
||||
}
|
||||
|
||||
void PropInstanceMerger::_init_materials() {
|
||||
@ -233,7 +422,6 @@ void PropInstanceMerger::_build() {
|
||||
_job->set_texture_packer(packer);
|
||||
#endif
|
||||
|
||||
|
||||
for (int i = 0; i < get_child_count(); ++i) {
|
||||
Node *n = get_child(i);
|
||||
|
||||
@ -366,6 +554,11 @@ void PropInstanceMerger::_notification(int p_what) {
|
||||
if (_prop_data.is_valid()) {
|
||||
build();
|
||||
}
|
||||
|
||||
set_physics_process_internal(true);
|
||||
set_process_internal(true);
|
||||
|
||||
break;
|
||||
}
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
if (_job.is_valid()) {
|
||||
@ -374,6 +567,29 @@ void PropInstanceMerger::_notification(int p_what) {
|
||||
|
||||
free_meshes();
|
||||
free_colliders();
|
||||
break;
|
||||
}
|
||||
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
||||
//todo turn this on and off properly
|
||||
|
||||
if (_building) {
|
||||
if (_job->get_build_phase_type() == PropInstanceJob::BUILD_PHASE_TYPE_PHYSICS_PROCESS) {
|
||||
_job->physics_process(get_physics_process_delta_time());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case NOTIFICATION_INTERNAL_PROCESS: {
|
||||
//todo turn this on and off properly
|
||||
|
||||
if (_building) {
|
||||
if (_job->get_build_phase_type() == PropInstanceJob::BUILD_PHASE_TYPE_PROCESS) {
|
||||
_job->process(get_process_delta_time());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -401,23 +617,34 @@ void PropInstanceMerger::_bind_methods() {
|
||||
|
||||
//Meshes
|
||||
ClassDB::bind_method(D_METHOD("mesh_get", "index"), &PropInstanceMerger::mesh_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_add", "value"), &PropInstanceMerger::mesh_add);
|
||||
ClassDB::bind_method(D_METHOD("mesh_instance_get", "index"), &PropInstanceMerger::mesh_instance_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_add", "mesh_instance", "mesh"), &PropInstanceMerger::mesh_add);
|
||||
ClassDB::bind_method(D_METHOD("mesh_get_num"), &PropInstanceMerger::mesh_get_num);
|
||||
ClassDB::bind_method(D_METHOD("meshs_clear"), &PropInstanceMerger::meshs_clear);
|
||||
ClassDB::bind_method(D_METHOD("meshes_clear"), &PropInstanceMerger::meshes_clear);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("meshes_get"), &PropInstanceMerger::meshes_get);
|
||||
ClassDB::bind_method(D_METHOD("meshes_set"), &PropInstanceMerger::meshes_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "meshes", PROPERTY_HINT_NONE, "", 0), "meshes_set", "meshes_get");
|
||||
|
||||
//Colliders
|
||||
ClassDB::bind_method(D_METHOD("collider_get", "index"), &PropInstanceMerger::collider_get);
|
||||
ClassDB::bind_method(D_METHOD("collider_add", "value"), &PropInstanceMerger::collider_add);
|
||||
ClassDB::bind_method(D_METHOD("collider_local_transform_get", "index"), &PropInstanceMerger::collider_local_transform_get);
|
||||
ClassDB::bind_method(D_METHOD("collider_body_get", "index"), &PropInstanceMerger::collider_body_get);
|
||||
ClassDB::bind_method(D_METHOD("collider_shape_get", "index"), &PropInstanceMerger::collider_shape_get);
|
||||
ClassDB::bind_method(D_METHOD("collider_shape_rid_get", "index"), &PropInstanceMerger::collider_shape_rid_get);
|
||||
ClassDB::bind_method(D_METHOD("collider_add", "local_transform", "shape", "shape_rid", "body"), &PropInstanceMerger::collider_add);
|
||||
ClassDB::bind_method(D_METHOD("collider_get_num"), &PropInstanceMerger::collider_get_num);
|
||||
ClassDB::bind_method(D_METHOD("colliders_clear"), &PropInstanceMerger::colliders_clear);
|
||||
ClassDB::bind_method(D_METHOD("meshes_create", "num"), &PropInstanceMerger::meshes_create);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("colliders_get"), &PropInstanceMerger::colliders_get);
|
||||
ClassDB::bind_method(D_METHOD("colliders_set"), &PropInstanceMerger::colliders_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "colliders", PROPERTY_HINT_NONE, "", 0), "colliders_set", "colliders_get");
|
||||
//Colliders
|
||||
ClassDB::bind_method(D_METHOD("debug_mesh_allocate"), &PropInstanceMerger::debug_mesh_allocate);
|
||||
ClassDB::bind_method(D_METHOD("debug_mesh_free"), &PropInstanceMerger::debug_mesh_free);
|
||||
ClassDB::bind_method(D_METHOD("debug_mesh_has"), &PropInstanceMerger::debug_mesh_has);
|
||||
ClassDB::bind_method(D_METHOD("debug_mesh_clear"), &PropInstanceMerger::debug_mesh_clear);
|
||||
ClassDB::bind_method(D_METHOD("debug_mesh_array_clear"), &PropInstanceMerger::debug_mesh_array_clear);
|
||||
ClassDB::bind_method(D_METHOD("debug_mesh_add_vertices_to", "arr"), &PropInstanceMerger::debug_mesh_add_vertices_to);
|
||||
ClassDB::bind_method(D_METHOD("debug_mesh_send"), &PropInstanceMerger::debug_mesh_send);
|
||||
ClassDB::bind_method(D_METHOD("draw_debug_mdr_colliders"), &PropInstanceMerger::draw_debug_mdr_colliders);
|
||||
|
||||
//---
|
||||
ClassDB::bind_method(D_METHOD("get_first_lod_distance_squared"), &PropInstanceMerger::get_first_lod_distance_squared);
|
||||
|
@ -66,22 +66,37 @@ public:
|
||||
|
||||
//Meshes
|
||||
RID mesh_get(const int index);
|
||||
void mesh_add(const RID value);
|
||||
RID mesh_instance_get(const int index);
|
||||
void mesh_add(const RID mesh_instance, const RID mesh);
|
||||
int mesh_get_num() const;
|
||||
void meshs_clear();
|
||||
void meshes_clear();
|
||||
void meshes_create(const int num);
|
||||
|
||||
Vector<Variant> meshes_get();
|
||||
void meshes_set(const Vector<Variant> &meshes);
|
||||
|
||||
//Colliders
|
||||
RID collider_get(const int index);
|
||||
void collider_add(const RID value);
|
||||
Transform collider_local_transform_get(const int index);
|
||||
RID collider_body_get(const int index);
|
||||
Ref<Shape> collider_shape_get(const int index);
|
||||
RID collider_shape_rid_get(const int index);
|
||||
int collider_add(const Transform &local_transform, const Ref<Shape> &shape, const RID &shape_rid, const RID &body);
|
||||
int collider_get_num() const;
|
||||
void colliders_clear();
|
||||
|
||||
Vector<Variant> colliders_get();
|
||||
void colliders_set(const Vector<Variant> &colliders);
|
||||
|
||||
//Debug
|
||||
void debug_mesh_allocate();
|
||||
void debug_mesh_free();
|
||||
bool debug_mesh_has();
|
||||
void debug_mesh_clear();
|
||||
void debug_mesh_array_clear();
|
||||
void debug_mesh_add_vertices_to(const PoolVector3Array &arr);
|
||||
void debug_mesh_send();
|
||||
void draw_debug_mdr_colliders();
|
||||
|
||||
float get_first_lod_distance_squared();
|
||||
void set_first_lod_distance_squared(const float dist);
|
||||
|
||||
@ -105,6 +120,19 @@ protected:
|
||||
void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
struct ColliderBody {
|
||||
Transform transform;
|
||||
RID body;
|
||||
Ref<Shape> shape;
|
||||
RID shape_rid;
|
||||
};
|
||||
|
||||
struct MeshEntry {
|
||||
RID mesh;
|
||||
RID mesh_instance;
|
||||
};
|
||||
|
||||
private:
|
||||
Ref<PropData> _prop_data;
|
||||
|
||||
@ -118,11 +146,16 @@ private:
|
||||
#endif
|
||||
|
||||
Vector<Ref<Material> > _materials;
|
||||
Vector<RID> _meshes;
|
||||
Vector<RID> _colliders;
|
||||
Vector<MeshEntry> _meshes;
|
||||
Vector<ColliderBody> _colliders;
|
||||
|
||||
float _first_lod_distance_squared;
|
||||
float _lod_reduction_distance_squared;
|
||||
|
||||
//debug
|
||||
RID _debug_mesh_rid;
|
||||
RID _debug_mesh_instance;
|
||||
PoolVector3Array _debug_mesh_array;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -22,7 +22,16 @@ SOFTWARE.
|
||||
|
||||
#include "prop_instance_prop_job.h"
|
||||
|
||||
#include "core/version.h"
|
||||
|
||||
#if VERSION_MAYOR > 3
|
||||
#define GET_WORLD get_world_3d
|
||||
#else
|
||||
#define GET_WORLD get_world
|
||||
#endif
|
||||
|
||||
#include "prop_instance.h"
|
||||
#include "prop_instance_merger.h"
|
||||
#include "prop_mesher.h"
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
@ -38,11 +47,11 @@ SOFTWARE.
|
||||
#endif
|
||||
|
||||
#if MESH_DATA_RESOURCE_PRESENT
|
||||
//define PROPS_PRESENT, so things compile. That module's scsub will define this too while compiling,
|
||||
//define PROPS_PRESENT, so things compile. That module's scsub will define this too while compiling,
|
||||
//but not when included from here.
|
||||
#define PROPS_PRESENT 1
|
||||
#include "../mesh_data_resource/props/prop_data_mesh_data.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TEXTURE_PACKER_PRESENT
|
||||
Ref<TexturePacker> PropInstancePropJob::get_texture_packer() {
|
||||
@ -53,14 +62,14 @@ void PropInstancePropJob::set_texture_packer(const Ref<TexturePacker> &packer) {
|
||||
}
|
||||
#endif
|
||||
|
||||
PropInstance *PropInstancePropJob::get_prop_instace() {
|
||||
PropInstanceMerger *PropInstancePropJob::get_prop_instace() {
|
||||
return _prop_instace;
|
||||
}
|
||||
void PropInstancePropJob::set_prop_instace(PropInstance *prop) {
|
||||
void PropInstancePropJob::set_prop_instace(PropInstanceMerger *prop) {
|
||||
_prop_instace = prop;
|
||||
}
|
||||
void PropInstancePropJob::set_prop_instace_bind(Node *prop) {
|
||||
set_prop_instace(Object::cast_to<PropInstance>(prop));
|
||||
set_prop_instace(Object::cast_to<PropInstanceMerger>(prop));
|
||||
}
|
||||
|
||||
Ref<PropMesher> PropInstancePropJob::get_prop_mesher() const {
|
||||
@ -85,19 +94,28 @@ void PropInstancePropJob::clear_meshes() {
|
||||
#endif
|
||||
|
||||
void PropInstancePropJob::phase_physics_process() {
|
||||
/*
|
||||
Ref<TerraChunkDefault> chunk = _chunk;
|
||||
|
||||
//TODO this should only update the differences
|
||||
for (int i = 0; i < chunk->collider_get_count(); ++i) {
|
||||
PhysicsServer::get_singleton()->free(chunk->collider_get_body(i));
|
||||
for (int i = 0; i < _prop_instace->collider_get_num(); ++i) {
|
||||
PhysicsServer::get_singleton()->free(_prop_instace->collider_body_get(i));
|
||||
}
|
||||
|
||||
chunk->colliders_clear();
|
||||
_prop_instace->colliders_clear();
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
for (int i = 0; i < chunk->mesh_data_resource_get_count(); ++i) {
|
||||
Ref<MeshDataResource> mdr = chunk->mesh_data_resource_get(i);
|
||||
for (int i = 0; i < _prop_mesh_datas.size(); ++i) {
|
||||
PMDREntry &e = _prop_mesh_datas.write[i];
|
||||
|
||||
Ref<PropDataMeshData> pe = e.mesh_data;
|
||||
|
||||
ERR_CONTINUE(!pe.is_valid());
|
||||
|
||||
Ref<MeshDataResource> mdr = pe->get_mesh();
|
||||
|
||||
ERR_CONTINUE(!mdr.is_valid());
|
||||
|
||||
Transform t = pe->get_transform();
|
||||
t *= e.base_transform;
|
||||
|
||||
for (int j = 0; j < mdr->get_collision_shape_count(); ++j) {
|
||||
Ref<Shape> shape = mdr->get_collision_shape(j);
|
||||
@ -109,7 +127,7 @@ void PropInstancePropJob::phase_physics_process() {
|
||||
|
||||
RID body = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC);
|
||||
|
||||
Transform transform = chunk->mesh_data_resource_get_transform(i);
|
||||
Transform transform = t;
|
||||
transform *= offset;
|
||||
|
||||
PhysicsServer::get_singleton()->body_add_shape(body, shape->get_rid());
|
||||
@ -118,24 +136,24 @@ void PropInstancePropJob::phase_physics_process() {
|
||||
PhysicsServer::get_singleton()->body_set_collision_layer(body, 1);
|
||||
PhysicsServer::get_singleton()->body_set_collision_mask(body, 1);
|
||||
|
||||
if (chunk->get_voxel_world()->is_inside_tree() && chunk->get_voxel_world()->is_inside_world()) {
|
||||
Ref<World> world = chunk->get_voxel_world()->GET_WORLD();
|
||||
if (_prop_instace->is_inside_tree() && _prop_instace->is_inside_world()) {
|
||||
Ref<World> world = _prop_instace->GET_WORLD();
|
||||
|
||||
if (world.is_valid() && world->get_space() != RID()) {
|
||||
PhysicsServer::get_singleton()->body_set_space(body, world->get_space());
|
||||
}
|
||||
}
|
||||
|
||||
PhysicsServer::get_singleton()->body_set_state(body, PhysicsServer::BODY_STATE_TRANSFORM, chunk->get_transform() * transform);
|
||||
PhysicsServer::get_singleton()->body_set_state(body, PhysicsServer::BODY_STATE_TRANSFORM, _prop_instace->get_transform() * transform);
|
||||
|
||||
chunk->collider_add(transform, shape, shape->get_rid(), body);
|
||||
_prop_instace->collider_add(transform, shape, shape->get_rid(), body);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if TOOLS_ENABLED
|
||||
if (SceneTree::get_singleton()->is_debugging_collisions_hint() && chunk->collider_get_count() > 0) {
|
||||
chunk->draw_debug_mdr_colliders();
|
||||
if (SceneTree::get_singleton()->is_debugging_collisions_hint() && _prop_instace->collider_get_num() > 0) {
|
||||
_prop_instace->draw_debug_mdr_colliders();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -145,32 +163,45 @@ void PropInstancePropJob::phase_physics_process() {
|
||||
|
||||
void PropInstancePropJob::phase_prop() {
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
Ref<TerraChunkDefault> chunk = _chunk;
|
||||
|
||||
if (!get_prop_mesher().is_valid()) {
|
||||
if (!_prop_mesher.is_valid()) {
|
||||
set_complete(true); //So threadpool knows it's done
|
||||
next_job();
|
||||
return;
|
||||
}
|
||||
|
||||
if (should_do()) {
|
||||
if (chunk->mesh_data_resource_get_count() == 0) {
|
||||
if (_prop_mesh_datas.size() == 0) {
|
||||
set_complete(true); //So threadpool knows it's done
|
||||
next_job();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < chunk->mesh_data_resource_get_count(); ++i) {
|
||||
if (chunk->mesh_data_resource_get_is_inside(i)) {
|
||||
get_prop_mesher()->add_mesh_data_resource_transform(chunk->mesh_data_resource_get(i), chunk->mesh_data_resource_get_transform(i), chunk->mesh_data_resource_get_uv_rect(i));
|
||||
for (int i = 0; i < _prop_mesh_datas.size(); ++i) {
|
||||
PMDREntry &e = _prop_mesh_datas.write[i];
|
||||
|
||||
Ref<PropDataMeshData> pmd = e.mesh_data;
|
||||
|
||||
Ref<MeshDataResource> mesh = pmd->get_mesh();
|
||||
Ref<Texture> tex = pmd->get_texture();
|
||||
Transform t = pmd->get_transform();
|
||||
t *= e.base_transform;
|
||||
|
||||
Rect2 uvr = Rect2(0, 0, 1, 1);
|
||||
|
||||
if (_texture_packer.is_valid() && tex.is_valid()) {
|
||||
Ref<AtlasTexture> at = _texture_packer->get_texture(tex);
|
||||
|
||||
if (at.is_valid()) {
|
||||
uvr = at->get_region();
|
||||
}
|
||||
}
|
||||
|
||||
get_prop_mesher()->add_mesh_data_resource_transform(mesh, t, uvr);
|
||||
}
|
||||
|
||||
if (get_prop_mesher()->get_vertex_count() == 0) {
|
||||
//reset_stages();
|
||||
|
||||
set_complete(true); //So threadpool knows it's done
|
||||
next_job();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -179,16 +210,20 @@ void PropInstancePropJob::phase_prop() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (should_do()) {
|
||||
if ((chunk->get_build_flags() & TerraChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0) {
|
||||
get_prop_mesher()->bake_colors(_chunk);
|
||||
_prop_mesher->bake_colors(_chunk);
|
||||
}
|
||||
|
||||
if (should_return()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
//lights should be added here by the prop instance preemtively
|
||||
//Also this system should use it's own lights
|
||||
if (should_do()) {
|
||||
if ((chunk->get_build_flags() & TerraChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0) {
|
||||
TerraWorldDefault *world = Object::cast_to<TerraWorldDefault>(chunk->get_voxel_world());
|
||||
@ -226,6 +261,7 @@ void PropInstancePropJob::phase_prop() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (get_prop_mesher()->get_vertex_count() != 0) {
|
||||
if (should_do()) {
|
||||
@ -236,9 +272,14 @@ void PropInstancePropJob::phase_prop() {
|
||||
}
|
||||
}
|
||||
|
||||
RID mesh_rid = chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 0);
|
||||
|
||||
if (should_do()) {
|
||||
if (_prop_instace->mesh_get_num() == 0) {
|
||||
_prop_instace->meshes_create(1);
|
||||
}
|
||||
|
||||
RID mesh_rid = _prop_instace->mesh_get(0);
|
||||
|
||||
/*
|
||||
if (mesh_rid == RID()) {
|
||||
if ((chunk->get_build_flags() & TerraChunkDefault::BUILD_FLAG_CREATE_LODS) != 0)
|
||||
chunk->meshes_create(TerraChunkDefault::MESH_INDEX_PROP, chunk->get_lod_num() + 1);
|
||||
@ -246,7 +287,7 @@ void PropInstancePropJob::phase_prop() {
|
||||
chunk->meshes_create(TerraChunkDefault::MESH_INDEX_PROP, 1);
|
||||
|
||||
mesh_rid = chunk->mesh_rid_get_index(TerraChunkDefault::MESH_INDEX_PROP, TerraChunkDefault::MESH_TYPE_INDEX_MESH, 0);
|
||||
}
|
||||
}*/
|
||||
|
||||
if (VS::get_singleton()->mesh_get_surface_count(mesh_rid) > 0)
|
||||
#if !GODOT4
|
||||
@ -262,16 +303,22 @@ void PropInstancePropJob::phase_prop() {
|
||||
|
||||
if (should_do()) {
|
||||
|
||||
RID mesh_rid = _prop_instace->mesh_get(0);
|
||||
|
||||
VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
|
||||
|
||||
if (chunk->get_library()->prop_material_get(0).is_valid())
|
||||
VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->prop_material_get(0)->get_rid());
|
||||
Ref<Material> mat = _prop_instace->material_get(0);
|
||||
|
||||
if (mat.is_valid())
|
||||
VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, mat->get_rid());
|
||||
|
||||
if (should_return()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
//skip lod generation for now
|
||||
if ((chunk->get_build_flags() & TerraChunkDefault::BUILD_FLAG_CREATE_LODS) != 0) {
|
||||
if (should_do()) {
|
||||
|
||||
@ -357,10 +404,11 @@ void PropInstancePropJob::phase_prop() {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#endif
|
||||
*/
|
||||
|
||||
set_complete(true); //So threadpool knows it's done
|
||||
finished();
|
||||
}
|
||||
@ -417,6 +465,8 @@ void PropInstancePropJob::_reset() {
|
||||
|
||||
PropInstancePropJob::PropInstancePropJob() {
|
||||
set_build_phase_type(BUILD_PHASE_TYPE_PHYSICS_PROCESS);
|
||||
|
||||
_prop_instace = NULL;
|
||||
}
|
||||
|
||||
PropInstancePropJob::~PropInstancePropJob() {
|
||||
|
@ -31,6 +31,7 @@ class TexturePacker;
|
||||
|
||||
class PropMesher;
|
||||
class PropInstance;
|
||||
class PropInstanceMerger;
|
||||
|
||||
#if MESH_DATA_RESOURCE_PRESENT
|
||||
class PropDataMeshData;
|
||||
@ -45,8 +46,8 @@ public:
|
||||
void set_texture_packer(const Ref<TexturePacker> &packer);
|
||||
#endif
|
||||
|
||||
PropInstance *get_prop_instace();
|
||||
void set_prop_instace(PropInstance *prop);
|
||||
PropInstanceMerger *get_prop_instace();
|
||||
void set_prop_instace(PropInstanceMerger *prop);
|
||||
void set_prop_instace_bind(Node *prop);
|
||||
|
||||
Ref<PropMesher> get_prop_mesher() const;
|
||||
@ -82,7 +83,7 @@ protected:
|
||||
Ref<TexturePacker> _texture_packer;
|
||||
#endif
|
||||
Ref<PropMesher> _prop_mesher;
|
||||
PropInstance *_prop_instace;
|
||||
PropInstanceMerger *_prop_instace;
|
||||
|
||||
#if MESH_DATA_RESOURCE_PRESENT
|
||||
Vector<PMDREntry> _prop_mesh_datas;
|
||||
|
Loading…
Reference in New Issue
Block a user