mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-11-19 02:47:18 +01:00
Moved VoxelBlock to its own file
This commit is contained in:
parent
aa4d04d1a0
commit
dc4f0c5cd1
29
voxel_block.cpp
Normal file
29
voxel_block.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "voxel_block.h"
|
||||
|
||||
MeshInstance *VoxelBlock::get_mesh_instance(const Node &root) {
|
||||
if (mesh_instance_path.is_empty())
|
||||
return NULL;
|
||||
Node *n = root.get_node(mesh_instance_path);
|
||||
if (n == NULL)
|
||||
return NULL;
|
||||
return n->cast_to<MeshInstance>();
|
||||
}
|
||||
|
||||
// Helper
|
||||
VoxelBlock *VoxelBlock::create(Vector3i bpos, Ref<VoxelBuffer> buffer, unsigned int size) {
|
||||
const int bs = size;
|
||||
ERR_FAIL_COND_V(buffer.is_null(), NULL);
|
||||
ERR_FAIL_COND_V(buffer->get_size() != Vector3i(bs, bs, bs), NULL);
|
||||
|
||||
VoxelBlock *block = memnew(VoxelBlock);
|
||||
block->pos = bpos;
|
||||
|
||||
block->voxels = buffer;
|
||||
//block->map = ↦
|
||||
return block;
|
||||
}
|
||||
|
||||
VoxelBlock::VoxelBlock()
|
||||
: voxels(NULL) {
|
||||
}
|
||||
|
25
voxel_block.h
Normal file
25
voxel_block.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef VOXEL_BLOCK_H
|
||||
#define VOXEL_BLOCK_H
|
||||
|
||||
#include "voxel_buffer.h"
|
||||
|
||||
#include <scene/3d/mesh_instance.h>
|
||||
#include <scene/3d/physics_body.h>
|
||||
|
||||
// Internal structure holding a reference to mesh visuals, physics and a block of voxel data.
|
||||
// TODO Voxel data should be separated from this
|
||||
class VoxelBlock {
|
||||
public:
|
||||
Ref<VoxelBuffer> voxels; // SIZE*SIZE*SIZE voxels
|
||||
Vector3i pos;
|
||||
NodePath mesh_instance_path;
|
||||
|
||||
static VoxelBlock *create(Vector3i bpos, Ref<VoxelBuffer> buffer, unsigned int size);
|
||||
|
||||
MeshInstance *get_mesh_instance(const Node &root);
|
||||
|
||||
private:
|
||||
VoxelBlock();
|
||||
};
|
||||
|
||||
#endif // VOXEL_BLOCK_H
|
@ -2,40 +2,6 @@
|
||||
#include "core/os/os.h"
|
||||
#include "cube_tables.h"
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// VoxelBlock
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
MeshInstance *VoxelBlock::get_mesh_instance(const Node &root) {
|
||||
if (mesh_instance_path.is_empty())
|
||||
return NULL;
|
||||
Node *n = root.get_node(mesh_instance_path);
|
||||
if (n == NULL)
|
||||
return NULL;
|
||||
return n->cast_to<MeshInstance>();
|
||||
}
|
||||
|
||||
// Helper
|
||||
VoxelBlock *VoxelBlock::create(Vector3i bpos, Ref<VoxelBuffer> buffer, unsigned int size) {
|
||||
const int bs = size;
|
||||
ERR_FAIL_COND_V(buffer.is_null(), NULL);
|
||||
ERR_FAIL_COND_V(buffer->get_size() != Vector3i(bs, bs, bs), NULL);
|
||||
|
||||
VoxelBlock *block = memnew(VoxelBlock);
|
||||
block->pos = bpos;
|
||||
|
||||
block->voxels = buffer;
|
||||
//block->map = ↦
|
||||
return block;
|
||||
}
|
||||
|
||||
VoxelBlock::VoxelBlock()
|
||||
: voxels(NULL) {
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// VoxelMap
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
VoxelMap::VoxelMap()
|
||||
: _last_accessed_block(NULL) {
|
||||
|
19
voxel_map.h
19
voxel_map.h
@ -2,26 +2,11 @@
|
||||
#define VOXEL_MAP_H
|
||||
|
||||
#include "voxel_buffer.h"
|
||||
#include "voxel_block.h"
|
||||
|
||||
#include <core/hash_map.h>
|
||||
#include <scene/3d/mesh_instance.h>
|
||||
#include <scene/3d/physics_body.h>
|
||||
#include <scene/main/node.h>
|
||||
|
||||
// Fixed-size voxel container used in VoxelMap. Used internally.
|
||||
class VoxelBlock {
|
||||
public:
|
||||
Ref<VoxelBuffer> voxels; // SIZE*SIZE*SIZE voxels
|
||||
Vector3i pos;
|
||||
NodePath mesh_instance_path;
|
||||
|
||||
static VoxelBlock *create(Vector3i bpos, Ref<VoxelBuffer> buffer, unsigned int size);
|
||||
|
||||
MeshInstance *get_mesh_instance(const Node &root);
|
||||
|
||||
private:
|
||||
VoxelBlock();
|
||||
};
|
||||
|
||||
// Infinite voxel storage by means of octants like Gridmap
|
||||
class VoxelMap : public Reference {
|
||||
GDCLASS(VoxelMap, Reference)
|
||||
|
Loading…
Reference in New Issue
Block a user