mirror of
https://github.com/Relintai/godot_voxel.git
synced 2025-05-01 17:57:55 +02:00
Voxel raycast now considers smooth voxels too
This commit is contained in:
parent
5823dfcb8c
commit
f07ddb37e3
@ -1,6 +1,5 @@
|
|||||||
#include "voxel_mesher.h"
|
#include "voxel_mesher.h"
|
||||||
#include "voxel_library.h"
|
#include "voxel_library.h"
|
||||||
#include "voxel_mesher_smooth.h"
|
|
||||||
|
|
||||||
// The following tables respect the following conventions
|
// The following tables respect the following conventions
|
||||||
//
|
//
|
||||||
|
@ -423,24 +423,36 @@ void VoxelTerrain::update_block_mesh(Vector3i block_pos) {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
static bool _raycast_binding_predicate(Vector3i pos, void *context) {
|
struct _VoxelTerrainRaycastContext {
|
||||||
|
VoxelTerrain & terrain;
|
||||||
|
//unsigned int channel_mask;
|
||||||
|
};
|
||||||
|
|
||||||
ERR_FAIL_COND_V(context == NULL, false);
|
static bool _raycast_binding_predicate(Vector3i pos, void *context_ptr) {
|
||||||
VoxelTerrain * terrain = (VoxelTerrain*)context;
|
|
||||||
|
|
||||||
Ref<VoxelLibrary> lib_ref = terrain->get_voxel_library();
|
ERR_FAIL_COND_V(context_ptr == NULL, false);
|
||||||
|
_VoxelTerrainRaycastContext * context = (_VoxelTerrainRaycastContext*)context_ptr;
|
||||||
|
VoxelTerrain & terrain = context->terrain;
|
||||||
|
|
||||||
|
//unsigned int channel = context->channel;
|
||||||
|
|
||||||
|
Ref<VoxelMap> map = terrain.get_map();
|
||||||
|
int v0 = map->get_voxel(pos, Voxel::CHANNEL_TYPE);
|
||||||
|
|
||||||
|
Ref<VoxelLibrary> lib_ref = terrain.get_voxel_library();
|
||||||
if(lib_ref.is_null())
|
if(lib_ref.is_null())
|
||||||
return false;
|
return false;
|
||||||
const VoxelLibrary & lib = **lib_ref;
|
const VoxelLibrary & lib = **lib_ref;
|
||||||
|
|
||||||
Ref<VoxelMap> map = terrain->get_map();
|
if(lib.has_voxel(v0) == false)
|
||||||
// TODO In the future we may want to query more channels
|
|
||||||
int v = map->get_voxel(pos, 0);
|
|
||||||
if(lib.has_voxel(v) == false)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const Voxel & voxel = lib.get_voxel_const(v);
|
const Voxel & voxel = lib.get_voxel_const(v0);
|
||||||
return !voxel.is_transparent();
|
if(voxel.is_transparent() == false)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
int v1 = map->get_voxel(pos, Voxel::CHANNEL_ISOLEVEL);
|
||||||
|
return v1 - 128 >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant VoxelTerrain::_raycast_binding(Vector3 origin, Vector3 direction, real_t max_distance) {
|
Variant VoxelTerrain::_raycast_binding(Vector3 origin, Vector3 direction, real_t max_distance) {
|
||||||
@ -450,7 +462,9 @@ Variant VoxelTerrain::_raycast_binding(Vector3 origin, Vector3 direction, real_t
|
|||||||
Vector3i hit_pos;
|
Vector3i hit_pos;
|
||||||
Vector3i prev_pos;
|
Vector3i prev_pos;
|
||||||
|
|
||||||
if(voxel_raycast(origin, direction, _raycast_binding_predicate, this, max_distance, hit_pos, prev_pos)) {
|
_VoxelTerrainRaycastContext context = { *this };
|
||||||
|
|
||||||
|
if(voxel_raycast(origin, direction, _raycast_binding_predicate, &context, max_distance, hit_pos, prev_pos)) {
|
||||||
|
|
||||||
Dictionary hit = Dictionary();
|
Dictionary hit = Dictionary();
|
||||||
hit["position"] = hit_pos.to_vec3();
|
hit["position"] = hit_pos.to_vec3();
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <scene/main/node.h>
|
#include <scene/main/node.h>
|
||||||
#include "voxel_map.h"
|
#include "voxel_map.h"
|
||||||
#include "voxel_mesher.h"
|
#include "voxel_mesher.h"
|
||||||
|
#include "voxel_mesher_smooth.h"
|
||||||
#include "voxel_provider.h"
|
#include "voxel_provider.h"
|
||||||
#include "zprofiling.h"
|
#include "zprofiling.h"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user