Skip to content

Commit

Permalink
Added support for PropDataStaticBody in PropInstance and PropInstance…
Browse files Browse the repository at this point in the history
…Merger.
  • Loading branch information
Relintai committed Oct 13, 2023
1 parent 2aa3fbf commit 0fa7faf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
29 changes: 23 additions & 6 deletions modules/props/prop_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "../mesh_data_resource/nodes/mesh_data_instance.h"

#include "scene/3d/light.h"
#include "scene/3d/physics_body.h"

#include "modules/modules_enabled.gen.h"

Expand All @@ -14,6 +15,7 @@
#include "./props/prop_data_light.h"
#include "./props/prop_data_prop.h"
#include "./props/prop_data_scene.h"
#include "./props/prop_data_static_body.h"
#include "./props/prop_data_tiled_wall.h"

#include "tiled_wall/tiled_wall.h"
Expand All @@ -23,8 +25,9 @@ Ref<PropData> PropInstance::get_prop_data() {
return _prop_data;
}
void PropInstance::set_prop_data(const Ref<PropData> &data) {
if (_prop_data == data)
if (_prop_data == data) {
return;
}

_prop_data = data;

Expand Down Expand Up @@ -103,8 +106,9 @@ void PropInstance::_build() {
}
}

if (!_prop_data.is_valid())
if (!_prop_data.is_valid()) {
return;
}

prop_preprocess(Transform(), _prop_data);
}
Expand All @@ -130,8 +134,9 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref<PropData> &pr
for (int i = 0; i < count; ++i) {
Ref<PropDataEntry> e = prop->get_prop(i);

if (!e.is_valid())
if (!e.is_valid()) {
continue;
}

Transform t = transform * e->get_transform();

Expand All @@ -140,8 +145,9 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref<PropData> &pr
if (prop_entry_data.is_valid()) {
Ref<PropData> p = prop_entry_data->get_prop();

if (!p.is_valid())
if (!p.is_valid()) {
continue;
}

prop_preprocess(t, p);

Expand Down Expand Up @@ -170,8 +176,9 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref<PropData> &pr
if (scene_data.is_valid()) {
Ref<PackedScene> sc = scene_data->get_scene();

if (!sc.is_valid())
if (!sc.is_valid()) {
continue;
}

Node *n = sc->instance();
add_child(n);
Expand All @@ -197,14 +204,24 @@ void PropInstance::_prop_preprocess(Transform transform, const Ref<PropData> &pr
continue;
}

Ref<PropDataStaticBody> static_body_data = e;

if (static_body_data.is_valid()) {
Node *static_body = static_body_data->processor_get_node_for(t);
add_child(static_body);

continue;
}

#ifdef MODULE_MESH_DATA_RESOURCE_ENABLED
Ref<PropDataMeshData> mesh_data = e;

if (mesh_data.is_valid()) {
Ref<MeshDataResource> mdr = mesh_data->get_mesh();

if (!mdr.is_valid())
if (!mdr.is_valid()) {
continue;
}

MeshDataInstance *mdi = memnew(MeshDataInstance);
add_child(mdi);
Expand Down
18 changes: 18 additions & 0 deletions modules/props/prop_instance_merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "./props/prop_data_light.h"
#include "./props/prop_data_prop.h"
#include "./props/prop_data_scene.h"
#include "./props/prop_data_static_body.h"

#include "jobs/prop_mesher_job_step.h"
#include "lights/prop_light.h"
#include "material_cache/prop_material_cache.h"
Expand Down Expand Up @@ -599,6 +601,22 @@ void PropInstanceMerger::_prop_preprocess(Transform transform, const Ref<PropDat
continue;
}

Ref<PropDataStaticBody> static_body_data = e;

if (static_body_data.is_valid()) {
for (int j = 0; j < static_body_data->get_collision_shape_count(); ++j) {
Ref<Shape> collision_shape = static_body_data->get_collision_shape(j);

if (collision_shape.is_valid()) {
Transform et = t * static_body_data->get_collision_shape_transform(j);

_job->add_collision_shape(collision_shape, et, true);
}
}

continue;
}

Ref<PropDataTiledWall> tiled_wall_data = e;

if (tiled_wall_data.is_valid()) {
Expand Down
3 changes: 2 additions & 1 deletion modules/props/props/prop_data_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ void PropDataEntry::set_transform(const Transform &value) {

#ifdef MODULE_TEXTURE_PACKER_ENABLED
void PropDataEntry::add_textures_into(Ref<TexturePacker> texture_packer) {
if (has_method("_add_textures_into"))
if (has_method("_add_textures_into")) {
call("_add_textures_into", texture_packer);
}
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion modules/props/props/prop_data_static_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void PropDataStaticBody::_processor_process(Ref<PropData> prop_data, Node *node,

Node *PropDataStaticBody::_processor_get_node_for(const Transform &transform) {
StaticBody *sb = memnew(StaticBody);
sb->set_transform(get_transform());
sb->set_transform(transform);
sb->set_physics_material_override(_physics_material_override);
sb->set_constant_linear_velocity(_constant_linear_velocity);
sb->set_constant_angular_velocity(_constant_angular_velocity);
Expand Down

0 comments on commit 0fa7faf

Please sign in to comment.