mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
PropData can setup meshes into the mesher as well now.
This commit is contained in:
parent
8bbc6da5d2
commit
802e602336
@ -1,7 +1,7 @@
|
||||
#include "prop_data.h"
|
||||
|
||||
#include "prop_data_prop.h"
|
||||
#include "../world/voxel_chunk.h"
|
||||
#include "prop_data_prop.h"
|
||||
|
||||
bool PropData::get_snap_to_mesh() {
|
||||
return _snap_to_mesh;
|
||||
@ -114,8 +114,6 @@ void PropData::add_prop_lights_into(VoxelChunk *chunk, Transform parent_transfor
|
||||
} else {
|
||||
pd->add_prop_lights_into(chunk, parent_transform * pdataprop->get_transform(), allow_snap);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -127,6 +125,60 @@ void PropData::add_prop_lights_into_bind(Node *chunk, Transform parent_transform
|
||||
add_prop_lights_into(c, parent_transform, allow_snap);
|
||||
}
|
||||
|
||||
void PropData::add_meshes_into(Ref<VoxelMesher> mesher, Ref<TexturePacker> texture_packer, Transform parent_transform, Spatial *snap_spatial) {
|
||||
ERR_FAIL_COND(!mesher.is_valid());
|
||||
ERR_FAIL_COND(!texture_packer.is_valid());
|
||||
ERR_FAIL_COND(texture_packer->get_generated_texture_count() == 0);
|
||||
ERR_FAIL_COND(snap_spatial != NULL && !ObjectDB::instance_validate(snap_spatial));
|
||||
|
||||
Vector2 texsize = texture_packer->get_generated_texture(0)->get_size();
|
||||
|
||||
for (int i = 0; i < _props.size(); ++i) {
|
||||
Ref<PropDataEntry> entry = _props.get(i);
|
||||
|
||||
Ref<PropDataMesh> pmesh = entry;
|
||||
|
||||
if (pmesh.is_valid()) {
|
||||
|
||||
Rect2 reg = Rect2(0, 0, 1, 1);
|
||||
|
||||
if (pmesh->get_texture().is_valid()) {
|
||||
|
||||
Ref<AtlasTexture> at = texture_packer->get_texture(pmesh->get_texture());
|
||||
|
||||
reg = at->get_region();
|
||||
|
||||
reg.position.x /= texsize.x;
|
||||
reg.position.y /= texsize.y;
|
||||
reg.size.x /= texsize.x;
|
||||
reg.size.y /= texsize.y;
|
||||
}
|
||||
|
||||
if (snap_spatial != NULL)
|
||||
mesher->add_mesh_data_resource_transform(pmesh->get_mesh(), get_next_snapped_prop_transform(snap_spatial, parent_transform * pmesh->get_transform(), pmesh->get_snap_to_mesh(), pmesh->get_snap_axis()), reg);
|
||||
else
|
||||
mesher->add_mesh_data_resource_transform(pmesh->get_mesh(), parent_transform * pmesh->get_transform(), reg);
|
||||
}
|
||||
|
||||
Ref<PropDataProp> pdataprop = entry;
|
||||
|
||||
if (pdataprop.is_valid() && pdataprop->get_prop().is_valid()) {
|
||||
|
||||
if (snap_spatial != NULL)
|
||||
pdataprop->get_prop()->add_meshes_into(mesher, texture_packer, get_next_snapped_prop_transform(snap_spatial, parent_transform * pdataprop->get_transform(), pdataprop->get_snap_to_mesh(), pdataprop->get_snap_axis()), snap_spatial);
|
||||
else
|
||||
pdataprop->get_prop()->add_meshes_into(mesher, texture_packer, parent_transform * pmesh->get_transform(), snap_spatial);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
void PropData::add_meshes_into_bind(Ref<VoxelMesher> mesher, Ref<TexturePacker> texture_packer, Transform parent_transform, Node *snap_spatial) {
|
||||
Spatial *s = Object::cast_to<VoxelChunk>(snap_spatial);
|
||||
|
||||
ERR_FAIL_COND(s != NULL && !ObjectDB::instance_validate(s));
|
||||
|
||||
add_meshes_into(mesher, texture_packer, parent_transform, s);
|
||||
}
|
||||
|
||||
Transform PropData::get_next_snapped_prop_transform(Spatial *s, Transform parent_transform, bool snap_to_mesh, Vector3 snap_axis) {
|
||||
if (snap_to_mesh) {
|
||||
@ -187,5 +239,7 @@ void PropData::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_textures_into", "texture_packer"), &PropData::add_textures_into);
|
||||
ClassDB::bind_method(D_METHOD("add_prop_lights_into", "chunk", "parent_transform", "allow_snap"), &PropData::add_prop_lights_into_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_meshes_into", "mesher", "texture_packer", "parent_transform", "snap_spatial"), &PropData::add_meshes_into_bind);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_next_snapped_prop_transform", "spatial", "parent_transform", "snap_to_mesh", "snap_axis"), &PropData::get_next_snapped_prop_transform_bind);
|
||||
}
|
||||
|
@ -4,12 +4,17 @@
|
||||
#include "core/reference.h"
|
||||
#include "core/vector.h"
|
||||
#include "core/math/transform.h"
|
||||
#include "core/math/vector2.h"
|
||||
#include "core/math/vector3.h"
|
||||
#include "core/math/rect2.h"
|
||||
|
||||
#include "servers/physics_server.h"
|
||||
|
||||
#include "prop_data_entry.h"
|
||||
#include "prop_data_mesh.h"
|
||||
|
||||
#include "../meshers/voxel_mesher.h"
|
||||
|
||||
#include "../../texture_packer/texture_packer.h"
|
||||
|
||||
class Spatial;
|
||||
@ -38,6 +43,8 @@ public:
|
||||
void add_textures_into(Ref<TexturePacker> texture_packer);
|
||||
void add_prop_lights_into(VoxelChunk *chunk, Transform parent_transform, bool allow_snap);
|
||||
void add_prop_lights_into_bind(Node *chunk, Transform parent_transform, bool allow_snap);
|
||||
void add_meshes_into(Ref<VoxelMesher> mesher, Ref<TexturePacker> texture_packer, Transform parent_transform, Spatial *snap_spatial = NULL);
|
||||
void add_meshes_into_bind(Ref<VoxelMesher> mesher, Ref<TexturePacker> texture_packer, Transform parent_transform, Node *snap_spatial = NULL);
|
||||
|
||||
Transform get_next_snapped_prop_transform(Spatial *s, Transform parent_transform, bool snap_to_mesh, Vector3 snap_axis);
|
||||
Transform get_next_snapped_prop_transform_bind(Node *spatial, Transform parent_transform, bool snap_to_mesh, Vector3 snap_axis);
|
||||
|
Loading…
Reference in New Issue
Block a user