mirror of
https://github.com/Relintai/terraman_2d.git
synced 2025-02-20 17:24:45 +01:00
Initial 2d conversion step.
This commit is contained in:
parent
da473b0794
commit
208d21cd40
@ -28,16 +28,12 @@ _FORCE_INLINE_ int Terrain2DLight::get_world_position_x() const {
|
||||
_FORCE_INLINE_ int Terrain2DLight::get_world_position_y() const {
|
||||
return _world_position_y;
|
||||
}
|
||||
_FORCE_INLINE_ int Terrain2DLight::get_world_position_z() const {
|
||||
return _world_position_z;
|
||||
Vector2 Terrain2DLight::get_world_position() {
|
||||
return Vector2(_world_position_x, _world_position_y);
|
||||
}
|
||||
Vector3 Terrain2DLight::get_world_position() {
|
||||
return Vector3(_world_position_x, _world_position_y, _world_position_z);
|
||||
}
|
||||
void Terrain2DLight::set_world_position(const int x, const int y, const int z) {
|
||||
void Terrain2DLight::set_world_position(const int x, const int y) {
|
||||
_world_position_x = x;
|
||||
_world_position_y = y;
|
||||
_world_position_z = z;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Color Terrain2DLight::get_color() const {
|
||||
@ -56,6 +52,8 @@ void Terrain2DLight::set_size(const float size) {
|
||||
|
||||
Terrain2DLight::Terrain2DLight() {
|
||||
_size = 0;
|
||||
_world_position_x = 0;
|
||||
_world_position_y = 0;
|
||||
}
|
||||
|
||||
Terrain2DLight::~Terrain2DLight() {
|
||||
@ -64,8 +62,7 @@ Terrain2DLight::~Terrain2DLight() {
|
||||
void Terrain2DLight::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_world_position_x"), &Terrain2DLight::get_world_position_x);
|
||||
ClassDB::bind_method(D_METHOD("get_world_position_y"), &Terrain2DLight::get_world_position_y);
|
||||
ClassDB::bind_method(D_METHOD("get_world_position_z"), &Terrain2DLight::get_world_position_z);
|
||||
ClassDB::bind_method(D_METHOD("set_world_position", "x", "y", "z"), &Terrain2DLight::set_world_position);
|
||||
ClassDB::bind_method(D_METHOD("set_world_position", "x", "y"), &Terrain2DLight::set_world_position);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_color"), &Terrain2DLight::get_color);
|
||||
ClassDB::bind_method(D_METHOD("set_color"), &Terrain2DLight::set_color);
|
||||
|
@ -45,9 +45,8 @@ class Terrain2DLight : public Reference {
|
||||
public:
|
||||
int get_world_position_x() const;
|
||||
int get_world_position_y() const;
|
||||
int get_world_position_z() const;
|
||||
Vector3 get_world_position();
|
||||
void set_world_position(const int x, const int y, const int z);
|
||||
Vector2 get_world_position();
|
||||
void set_world_position(const int x, const int y);
|
||||
|
||||
Color get_color() const;
|
||||
void set_color(const Color &color);
|
||||
@ -62,13 +61,8 @@ private:
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
int _chunk_position_x;
|
||||
int _chunk_position_y;
|
||||
int _chunk_position_z;
|
||||
|
||||
int _world_position_x;
|
||||
int _world_position_y;
|
||||
int _world_position_z;
|
||||
|
||||
Color _color;
|
||||
int _size;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -48,14 +48,6 @@ public:
|
||||
|
||||
void add_chunk_normal(Ref<Terrain2DChunkDefault> chunk);
|
||||
|
||||
void add_chunk_lod(Ref<Terrain2DChunkDefault> chunk);
|
||||
void create_margin_zmin(Ref<Terrain2DChunkDefault> chunk);
|
||||
void create_margin_zmax(Ref<Terrain2DChunkDefault> chunk);
|
||||
void create_margin_xmin(Ref<Terrain2DChunkDefault> chunk);
|
||||
void create_margin_xmax(Ref<Terrain2DChunkDefault> chunk);
|
||||
void create_margin_corners(Ref<Terrain2DChunkDefault> chunk);
|
||||
void create_face(Ref<Terrain2DChunkDefault> chunk, int dataxmin, int dataxmax, int datazmin, int datazmax);
|
||||
|
||||
Terrain2DMesherBlocky();
|
||||
~Terrain2DMesherBlocky();
|
||||
|
||||
|
@ -61,13 +61,13 @@ void Terrain2DMesherDefault::_bake_colors(Ref<Terrain2DChunk> chunk) {
|
||||
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
Vertex vertex = _vertices[i];
|
||||
Vector3 vert = vertex.vertex;
|
||||
Vector2 vert = vertex.vertex;
|
||||
|
||||
unsigned int x = (unsigned int)(vert.x / _voxel_scale);
|
||||
unsigned int z = (unsigned int)(vert.z / _voxel_scale);
|
||||
unsigned int y = (unsigned int)(vert.y / _voxel_scale);
|
||||
|
||||
if (chunk->validate_data_position(x, z)) {
|
||||
int indx = chunk->get_data_index(x, z);
|
||||
if (chunk->validate_data_position(x, y)) {
|
||||
int indx = chunk->get_data_index(x, y);
|
||||
|
||||
Color light = Color(
|
||||
channel_color_r[indx] / 255.0,
|
||||
@ -122,19 +122,19 @@ void Terrain2DMesherDefault::_bake_liquid_colors(Ref<Terrain2DChunk> chunk) {
|
||||
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
Vertex vertex = _vertices[i];
|
||||
Vector3 vert = vertex.vertex;
|
||||
Vector2 vert = vertex.vertex;
|
||||
|
||||
//Is this needed?
|
||||
if (vert.x < 0 || vert.y < 0 || vert.z < 0) {
|
||||
if (vert.x < 0 || vert.y < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned int x = (unsigned int)(vert.x / _voxel_scale);
|
||||
//unsigned int y = (unsigned int)(vert.y / _voxel_scale);
|
||||
unsigned int z = (unsigned int)(vert.z / _voxel_scale);
|
||||
unsigned int y = (unsigned int)(vert.y / _voxel_scale);
|
||||
|
||||
if (chunk->validate_data_position(x, z)) {
|
||||
int indx = chunk->get_data_index(x, z);
|
||||
if (chunk->validate_data_position(x, y)) {
|
||||
int indx = chunk->get_data_index(x, y);
|
||||
|
||||
Color light = Color(
|
||||
channel_color_r[indx] / 255.0,
|
||||
|
@ -36,15 +36,6 @@ bool Terrain2DMesher::Vertex::operator==(const Vertex &p_vertex) const {
|
||||
if (uv != p_vertex.uv)
|
||||
return false;
|
||||
|
||||
if (uv2 != p_vertex.uv2)
|
||||
return false;
|
||||
|
||||
if (normal != p_vertex.normal)
|
||||
return false;
|
||||
|
||||
if (binormal != p_vertex.binormal)
|
||||
return false;
|
||||
|
||||
if (color != p_vertex.color)
|
||||
return false;
|
||||
|
||||
@ -66,11 +57,7 @@ bool Terrain2DMesher::Vertex::operator==(const Vertex &p_vertex) const {
|
||||
|
||||
uint32_t Terrain2DMesher::VertexHasher::hash(const Vertex &p_vtx) {
|
||||
uint32_t h = hash_djb2_buffer((const uint8_t *)&p_vtx.vertex, sizeof(real_t) * 3);
|
||||
h = hash_djb2_buffer((const uint8_t *)&p_vtx.normal, sizeof(real_t) * 3, h);
|
||||
h = hash_djb2_buffer((const uint8_t *)&p_vtx.binormal, sizeof(real_t) * 3, h);
|
||||
h = hash_djb2_buffer((const uint8_t *)&p_vtx.tangent, sizeof(real_t) * 3, h);
|
||||
h = hash_djb2_buffer((const uint8_t *)&p_vtx.uv, sizeof(real_t) * 2, h);
|
||||
h = hash_djb2_buffer((const uint8_t *)&p_vtx.uv2, sizeof(real_t) * 2, h);
|
||||
h = hash_djb2_buffer((const uint8_t *)&p_vtx.color, sizeof(real_t) * 4, h);
|
||||
h = hash_djb2_buffer((const uint8_t *)p_vtx.bones.ptr(), p_vtx.bones.size() * sizeof(int), h);
|
||||
h = hash_djb2_buffer((const uint8_t *)p_vtx.weights.ptr(), p_vtx.weights.size() * sizeof(float), h);
|
||||
@ -84,13 +71,6 @@ void Terrain2DMesher::set_channel_index_type(const int value) {
|
||||
_channel_index_type = value;
|
||||
}
|
||||
|
||||
int Terrain2DMesher::get_channel_index_isolevel() const {
|
||||
return _channel_index_isolevel;
|
||||
}
|
||||
void Terrain2DMesher::set_channel_index_isolevel(const int value) {
|
||||
_channel_index_isolevel = value;
|
||||
}
|
||||
|
||||
int Terrain2DMesher::get_mesher_index() const {
|
||||
return _mesher_index;
|
||||
}
|
||||
@ -171,10 +151,10 @@ Array Terrain2DMesher::build_mesh() {
|
||||
}
|
||||
|
||||
{
|
||||
PoolVector<Vector3> array;
|
||||
PoolVector<Vector2> array;
|
||||
array.resize(_vertices.size());
|
||||
#if !GODOT4
|
||||
PoolVector<Vector3>::Write w = array.write();
|
||||
PoolVector<Vector2>::Write w = array.write();
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
@ -192,31 +172,6 @@ Array Terrain2DMesher::build_mesh() {
|
||||
a[VisualServer::ARRAY_VERTEX] = array;
|
||||
}
|
||||
|
||||
if ((_format & VisualServer::ARRAY_FORMAT_NORMAL) == 0) {
|
||||
generate_normals();
|
||||
}
|
||||
|
||||
{
|
||||
PoolVector<Vector3> array;
|
||||
array.resize(_vertices.size());
|
||||
#if !GODOT4
|
||||
PoolVector<Vector3>::Write w = array.write();
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
#if !GODOT4
|
||||
w[i] = _vertices[i].normal;
|
||||
#else
|
||||
array.set(i, _vertices[i].normal);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GODOT4
|
||||
w.release();
|
||||
#endif
|
||||
a[VisualServer::ARRAY_NORMAL] = array;
|
||||
}
|
||||
|
||||
if ((_format & VisualServer::ARRAY_FORMAT_COLOR) != 0) {
|
||||
PoolVector<Color> array;
|
||||
array.resize(_vertices.size());
|
||||
@ -260,27 +215,6 @@ Array Terrain2DMesher::build_mesh() {
|
||||
a[VisualServer::ARRAY_TEX_UV] = array;
|
||||
}
|
||||
|
||||
if ((_format & VisualServer::ARRAY_FORMAT_TEX_UV2) != 0) {
|
||||
PoolVector<Vector2> array;
|
||||
array.resize(_vertices.size());
|
||||
#if !GODOT4
|
||||
PoolVector<Vector2>::Write w = array.write();
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
#if !GODOT4
|
||||
w[i] = _vertices[i].uv2;
|
||||
#else
|
||||
array.set(i, _vertices[i].uv2);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !GODOT4
|
||||
w.release();
|
||||
#endif
|
||||
a[VisualServer::ARRAY_TEX_UV2] = array;
|
||||
}
|
||||
|
||||
if (_indices.size() > 0) {
|
||||
PoolVector<int> array;
|
||||
array.resize(_indices.size());
|
||||
@ -323,38 +257,6 @@ void Terrain2DMesher::build_mesh_into(RID mesh) {
|
||||
VS::get_singleton()->mesh_surface_set_material(mesh, 0, _library->material_lod_get(0)->get_rid());
|
||||
}
|
||||
|
||||
void Terrain2DMesher::generate_normals(bool p_flip) {
|
||||
_format = _format | VisualServer::ARRAY_FORMAT_NORMAL;
|
||||
|
||||
for (int i = 0; i < _indices.size(); i += 3) {
|
||||
int i0 = _indices[i];
|
||||
int i1 = _indices[i + 1];
|
||||
int i2 = _indices[i + 2];
|
||||
|
||||
ERR_FAIL_INDEX(i0, _vertices.size());
|
||||
ERR_FAIL_INDEX(i1, _vertices.size());
|
||||
ERR_FAIL_INDEX(i2, _vertices.size());
|
||||
|
||||
Vertex v0 = _vertices.get(i0);
|
||||
Vertex v1 = _vertices.get(i1);
|
||||
Vertex v2 = _vertices.get(i2);
|
||||
|
||||
Vector3 normal;
|
||||
if (!p_flip)
|
||||
normal = Plane(v0.vertex, v1.vertex, v2.vertex).normal;
|
||||
else
|
||||
normal = Plane(v2.vertex, v1.vertex, v0.vertex).normal;
|
||||
|
||||
v0.normal = normal;
|
||||
v1.normal = normal;
|
||||
v2.normal = normal;
|
||||
|
||||
_vertices.set(i0, v0);
|
||||
_vertices.set(i1, v1);
|
||||
_vertices.set(i2, v2);
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain2DMesher::remove_doubles() {
|
||||
if (_vertices.size() == 0)
|
||||
return;
|
||||
@ -458,12 +360,9 @@ void Terrain2DMesher::reset() {
|
||||
_indices.resize(0);
|
||||
|
||||
_last_color = Color();
|
||||
_last_normal = Vector3();
|
||||
_last_uv = Vector2();
|
||||
_last_uv2 = Vector2();
|
||||
_last_bones.clear();
|
||||
_last_weights.clear();
|
||||
_last_tangent = Plane();
|
||||
}
|
||||
|
||||
void Terrain2DMesher::add_chunk(Ref<Terrain2DChunk> chunk) {
|
||||
@ -475,19 +374,18 @@ void Terrain2DMesher::add_chunk(Ref<Terrain2DChunk> chunk) {
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
void Terrain2DMesher::add_mesh_data_resource(Ref<MeshDataResource> mesh, const Vector3 position, const Vector3 rotation, const Vector3 scale, const Rect2 uv_rect) {
|
||||
Transform transform = Transform(Basis(rotation).scaled(scale), position);
|
||||
|
||||
add_mesh_data_resource_transform(mesh, transform, uv_rect);
|
||||
//Transform2D transform = Transform(Basis(rotation).scaled(scale), position);
|
||||
//TODO
|
||||
add_mesh_data_resource_transform(mesh, Transform2D(), uv_rect);
|
||||
}
|
||||
|
||||
void Terrain2DMesher::add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, const Transform transform, const Rect2 uv_rect) {
|
||||
void Terrain2DMesher::add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, const Transform2D transform, const Rect2 uv_rect) {
|
||||
if (mesh->get_array().size() == 0)
|
||||
return;
|
||||
|
||||
const Array &arr = mesh->get_array();
|
||||
|
||||
PoolVector3Array vertices = arr[Mesh::ARRAY_VERTEX];
|
||||
PoolVector3Array normals = arr[Mesh::ARRAY_NORMAL];
|
||||
PoolVector2Array vertices = arr[Mesh::ARRAY_VERTEX];
|
||||
PoolVector2Array uvs = arr[Mesh::ARRAY_TEX_UV];
|
||||
PoolColorArray colors = arr[Mesh::ARRAY_COLOR];
|
||||
PoolIntArray indices = arr[Mesh::ARRAY_INDEX];
|
||||
@ -498,10 +396,7 @@ void Terrain2DMesher::add_mesh_data_resource_transform(Ref<MeshDataResource> mes
|
||||
int orig_vert_size = _vertices.size();
|
||||
|
||||
for (int i = 0; i < vertices.size(); ++i) {
|
||||
if (normals.size() > 0)
|
||||
add_normal(transform.basis.xform(normals[i]));
|
||||
|
||||
if (normals.size() > 0) {
|
||||
if (uvs.size() > 0) {
|
||||
Vector2 uv = uvs[i];
|
||||
|
||||
uv.x = uv_rect.size.width * uv.x + uv_rect.position.x;
|
||||
@ -524,14 +419,13 @@ void Terrain2DMesher::add_mesh_data_resource_transform(Ref<MeshDataResource> mes
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain2DMesher::add_mesh_data_resource_transform_colored(Ref<MeshDataResource> mesh, const Transform transform, const PoolColorArray &colors, const Rect2 uv_rect) {
|
||||
void Terrain2DMesher::add_mesh_data_resource_transform_colored(Ref<MeshDataResource> mesh, const Transform2D transform, const PoolColorArray &colors, const Rect2 uv_rect) {
|
||||
if (mesh->get_array().size() == 0)
|
||||
return;
|
||||
|
||||
const Array &arr = mesh->get_array();
|
||||
|
||||
PoolVector3Array vertices = arr[Mesh::ARRAY_VERTEX];
|
||||
PoolVector3Array normals = arr[Mesh::ARRAY_NORMAL];
|
||||
PoolVector2Array vertices = arr[Mesh::ARRAY_VERTEX];
|
||||
PoolVector2Array uvs = arr[Mesh::ARRAY_TEX_UV];
|
||||
PoolIntArray indices = arr[Mesh::ARRAY_INDEX];
|
||||
|
||||
@ -541,10 +435,7 @@ void Terrain2DMesher::add_mesh_data_resource_transform_colored(Ref<MeshDataResou
|
||||
int orig_vert_size = _vertices.size();
|
||||
|
||||
for (int i = 0; i < vertices.size(); ++i) {
|
||||
if (normals.size() > 0)
|
||||
add_normal(transform.basis.xform(normals[i]));
|
||||
|
||||
if (normals.size() > 0) {
|
||||
if (uvs.size() > 0) {
|
||||
Vector2 uv = uvs[i];
|
||||
|
||||
uv.x = uv_rect.size.width * uv.x + uv_rect.position.x;
|
||||
@ -605,8 +496,8 @@ void Terrain2DMesher::bake_liquid_colors(Ref<Terrain2DChunk> chunk) {
|
||||
}
|
||||
}
|
||||
|
||||
PoolVector<Vector3> Terrain2DMesher::build_collider() const {
|
||||
PoolVector<Vector3> face_points;
|
||||
PoolVector<Vector2> Terrain2DMesher::build_collider() const {
|
||||
PoolVector<Vector2> face_points;
|
||||
|
||||
if (_vertices.size() == 0)
|
||||
return face_points;
|
||||
@ -642,11 +533,10 @@ void Terrain2DMesher::bake_lights(MeshInstance *node, Vector<Ref<Terrain2DLight>
|
||||
|
||||
for (int v = 0; v < _vertices.size(); ++v) {
|
||||
Vertex vertexv = _vertices.get(v);
|
||||
Vector3 vet = vertexv.vertex;
|
||||
Vector3 vertex = node->to_global(vet);
|
||||
|
||||
//grab normal
|
||||
Vector3 normal = vertexv.normal;
|
||||
Vector2 vet = vertexv.vertex;
|
||||
//TODO
|
||||
//Vector2 vertex = node->to_global(vet);
|
||||
Vector2 vertex = vet;
|
||||
|
||||
Vector3 v_lightDiffuse;
|
||||
|
||||
@ -654,36 +544,19 @@ void Terrain2DMesher::bake_lights(MeshInstance *node, Vector<Ref<Terrain2DLight>
|
||||
for (int i = 0; i < lights.size(); ++i) {
|
||||
Ref<Terrain2DLight> light = lights.get(i);
|
||||
|
||||
Vector3 lightDir = light->get_world_position() - vertex;
|
||||
Vector2 lightDir = light->get_world_position() - vertex;
|
||||
|
||||
float dist2 = lightDir.dot(lightDir);
|
||||
//inverse sqrt
|
||||
lightDir *= (1.0 / sqrt(dist2));
|
||||
|
||||
float NdotL = normal.dot(lightDir);
|
||||
|
||||
if (NdotL > 1.0) {
|
||||
NdotL = 1.0;
|
||||
} else if (NdotL < 0.0) {
|
||||
NdotL = 0.0;
|
||||
}
|
||||
|
||||
Color cc = light->get_color();
|
||||
Vector3 cv(cc.r, cc.g, cc.b);
|
||||
|
||||
Vector3 value = cv * (NdotL / (1.0 + dist2));
|
||||
Vector3 value = cv * (1.0 / (1.0 + dist2));
|
||||
|
||||
value *= light->get_size();
|
||||
v_lightDiffuse += value;
|
||||
|
||||
/*
|
||||
float dist2 = Mathf.Clamp(Vector3.Distance(transformedLights[i], vertices), 0f, 15f);
|
||||
dist2 /= 35f;
|
||||
|
||||
Vector3 value = Vector3.one;
|
||||
value *= ((float) lights[i].Strength) / 255f;
|
||||
value *= (1 - dist2);
|
||||
v_lightDiffuse += value;*/
|
||||
}
|
||||
|
||||
Color f = vertexv.color;
|
||||
@ -722,8 +595,8 @@ void Terrain2DMesher::bake_lights(MeshInstance *node, Vector<Ref<Terrain2DLight>
|
||||
// }
|
||||
}
|
||||
|
||||
PoolVector<Vector3> Terrain2DMesher::get_vertices() const {
|
||||
PoolVector<Vector3> arr;
|
||||
PoolVector<Vector2> Terrain2DMesher::get_vertices() const {
|
||||
PoolVector<Vector2> arr;
|
||||
|
||||
arr.resize(_vertices.size());
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
@ -733,13 +606,13 @@ PoolVector<Vector3> Terrain2DMesher::get_vertices() const {
|
||||
return arr;
|
||||
}
|
||||
|
||||
void Terrain2DMesher::set_vertices(const PoolVector<Vector3> &values) {
|
||||
void Terrain2DMesher::set_vertices(const PoolVector<Vector2> &values) {
|
||||
ERR_FAIL_COND(values.size() != _vertices.size());
|
||||
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
Vertex v = _vertices[i];
|
||||
|
||||
v.normal = values[i];
|
||||
v.vertex = values[i];
|
||||
|
||||
_vertices.set(i, v);
|
||||
}
|
||||
@ -749,23 +622,19 @@ int Terrain2DMesher::get_vertex_count() const {
|
||||
return _vertices.size();
|
||||
}
|
||||
|
||||
void Terrain2DMesher::add_vertex(const Vector3 &vertex) {
|
||||
void Terrain2DMesher::add_vertex(const Vector2 &vertex) {
|
||||
Vertex vtx;
|
||||
vtx.vertex = vertex;
|
||||
vtx.color = _last_color;
|
||||
vtx.normal = _last_normal;
|
||||
vtx.uv = _last_uv;
|
||||
vtx.uv2 = _last_uv2;
|
||||
// Todo?
|
||||
// vtx.weights = _last_weights;
|
||||
// vtx.bones = _last_bones;
|
||||
// vtx.tangent = _last_tangent.normal;
|
||||
// vtx.binormal = _last_normal.cross(_last_tangent.normal).normalized() * _last_tangent.d;
|
||||
|
||||
_vertices.push_back(vtx);
|
||||
}
|
||||
|
||||
Vector3 Terrain2DMesher::get_vertex(const int idx) const {
|
||||
Vector2 Terrain2DMesher::get_vertex(const int idx) const {
|
||||
return _vertices.get(idx).vertex;
|
||||
}
|
||||
|
||||
@ -773,37 +642,6 @@ void Terrain2DMesher::remove_vertex(const int idx) {
|
||||
_vertices.VREMOVE(idx);
|
||||
}
|
||||
|
||||
PoolVector<Vector3> Terrain2DMesher::get_normals() const {
|
||||
PoolVector<Vector3> arr;
|
||||
|
||||
arr.resize(_vertices.size());
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
arr.set(i, _vertices.get(i).normal);
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
void Terrain2DMesher::set_normals(const PoolVector<Vector3> &values) {
|
||||
ERR_FAIL_COND(values.size() != _vertices.size());
|
||||
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
Vertex v = _vertices[i];
|
||||
|
||||
v.normal = values[i];
|
||||
|
||||
_vertices.set(i, v);
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain2DMesher::add_normal(const Vector3 &normal) {
|
||||
_last_normal = normal;
|
||||
}
|
||||
|
||||
Vector3 Terrain2DMesher::get_normal(int idx) const {
|
||||
return _vertices.get(idx).normal;
|
||||
}
|
||||
|
||||
PoolVector<Color> Terrain2DMesher::get_colors() const {
|
||||
PoolVector<Color> arr;
|
||||
|
||||
@ -866,37 +704,6 @@ Vector2 Terrain2DMesher::get_uv(const int idx) const {
|
||||
return _vertices.get(idx).uv;
|
||||
}
|
||||
|
||||
PoolVector<Vector2> Terrain2DMesher::get_uv2s() const {
|
||||
PoolVector<Vector2> arr;
|
||||
|
||||
arr.resize(_vertices.size());
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
arr.set(i, _vertices.get(i).uv2);
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
void Terrain2DMesher::set_uv2s(const PoolVector<Vector2> &values) {
|
||||
ERR_FAIL_COND(values.size() != _vertices.size());
|
||||
|
||||
for (int i = 0; i < _vertices.size(); ++i) {
|
||||
Vertex v = _vertices[i];
|
||||
|
||||
v.uv2 = values[i];
|
||||
|
||||
_vertices.set(i, v);
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain2DMesher::add_uv2(const Vector2 &uv) {
|
||||
_last_uv2 = uv;
|
||||
}
|
||||
|
||||
Vector2 Terrain2DMesher::get_uv2(const int idx) const {
|
||||
return _vertices.get(idx).uv2;
|
||||
}
|
||||
|
||||
PoolVector<int> Terrain2DMesher::get_indices() const {
|
||||
return _indices;
|
||||
}
|
||||
@ -930,7 +737,6 @@ Terrain2DMesher::Terrain2DMesher(const Ref<Terrain2DLibrary> &library) {
|
||||
_base_light_value = 0.5;
|
||||
_uv_margin = Rect2(0, 0, 1, 1);
|
||||
_channel_index_type = 0;
|
||||
_channel_index_isolevel = 0;
|
||||
|
||||
_format = 0;
|
||||
_texture_scale = 1;
|
||||
@ -944,7 +750,6 @@ Terrain2DMesher::Terrain2DMesher() {
|
||||
_uv_margin = Rect2(0, 0, 1, 1);
|
||||
_format = 0;
|
||||
_channel_index_type = 0;
|
||||
_channel_index_isolevel = 0;
|
||||
_texture_scale = 1;
|
||||
_lod_index = 0;
|
||||
}
|
||||
@ -970,10 +775,6 @@ void Terrain2DMesher::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_channel_index_type", "value"), &Terrain2DMesher::set_channel_index_type);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "channel_index_type"), "set_channel_index_type", "get_channel_index_type");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_channel_index_isolevel"), &Terrain2DMesher::get_channel_index_isolevel);
|
||||
ClassDB::bind_method(D_METHOD("set_channel_index_isolevel", "value"), &Terrain2DMesher::set_channel_index_isolevel);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "channel_index_isolevel"), "set_channel_index_isolevel", "get_channel_index_isolevel");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mesher_index"), &Terrain2DMesher::get_mesher_index);
|
||||
ClassDB::bind_method(D_METHOD("set_mesher_index", "value"), &Terrain2DMesher::set_mesher_index);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "mesher_index"), "set_mesher_index", "get_mesher_index");
|
||||
@ -1041,11 +842,6 @@ void Terrain2DMesher::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("remove_vertex", "idx"), &Terrain2DMesher::remove_vertex);
|
||||
ClassDB::bind_method(D_METHOD("add_vertex", "vertex"), &Terrain2DMesher::add_vertex);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_normals"), &Terrain2DMesher::get_normals);
|
||||
ClassDB::bind_method(D_METHOD("set_normals", "values"), &Terrain2DMesher::set_normals);
|
||||
ClassDB::bind_method(D_METHOD("get_normal", "idx"), &Terrain2DMesher::get_normal);
|
||||
ClassDB::bind_method(D_METHOD("add_normal", "normal"), &Terrain2DMesher::add_normal);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_colors"), &Terrain2DMesher::get_colors);
|
||||
ClassDB::bind_method(D_METHOD("set_colors", "values"), &Terrain2DMesher::set_colors);
|
||||
ClassDB::bind_method(D_METHOD("get_color", "idx"), &Terrain2DMesher::get_color);
|
||||
@ -1056,11 +852,6 @@ void Terrain2DMesher::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_uv", "idx"), &Terrain2DMesher::get_uv);
|
||||
ClassDB::bind_method(D_METHOD("add_uv", "uv"), &Terrain2DMesher::add_uv);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_uv2s"), &Terrain2DMesher::get_uv2s);
|
||||
ClassDB::bind_method(D_METHOD("set_uv2s", "values"), &Terrain2DMesher::set_uv2s);
|
||||
ClassDB::bind_method(D_METHOD("get_uv2", "idx"), &Terrain2DMesher::get_uv2);
|
||||
ClassDB::bind_method(D_METHOD("add_uv2", "uv"), &Terrain2DMesher::add_uv2);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_indices"), &Terrain2DMesher::get_indices);
|
||||
ClassDB::bind_method(D_METHOD("set_indices", "values"), &Terrain2DMesher::set_indices);
|
||||
ClassDB::bind_method(D_METHOD("get_indices_count"), &Terrain2DMesher::get_indices_count);
|
||||
@ -1076,8 +867,6 @@ void Terrain2DMesher::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("build_mesh_into", "mesh_rid"), &Terrain2DMesher::build_mesh_into);
|
||||
ClassDB::bind_method(D_METHOD("build_collider"), &Terrain2DMesher::build_collider);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("generate_normals", "flip"), &Terrain2DMesher::generate_normals, DEFVAL(false));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("remove_doubles"), &Terrain2DMesher::remove_doubles);
|
||||
ClassDB::bind_method(D_METHOD("remove_doubles_hashed"), &Terrain2DMesher::remove_doubles_hashed);
|
||||
}
|
||||
|
@ -69,13 +69,9 @@ public:
|
||||
const double PI = 3.141592653589793238463;
|
||||
|
||||
struct Vertex {
|
||||
Vector3 vertex;
|
||||
Vector2 vertex;
|
||||
Color color;
|
||||
Vector3 normal; // normal, binormal, tangent
|
||||
Vector3 binormal;
|
||||
Vector3 tangent;
|
||||
Vector2 uv;
|
||||
Vector2 uv2;
|
||||
Vector<int> bones;
|
||||
Vector<float> weights;
|
||||
|
||||
@ -100,9 +96,6 @@ public:
|
||||
int get_channel_index_type() const;
|
||||
void set_channel_index_type(const int value);
|
||||
|
||||
int get_channel_index_isolevel() const;
|
||||
void set_channel_index_isolevel(const int value);
|
||||
|
||||
int get_mesher_index() const;
|
||||
void set_mesher_index(const int value);
|
||||
|
||||
@ -139,8 +132,8 @@ public:
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
void add_mesh_data_resource(Ref<MeshDataResource> mesh, const Vector3 position = Vector3(0, 0, 0), const Vector3 rotation = Vector3(0, 0, 0), const Vector3 scale = Vector3(1.0, 1.0, 1.0), const Rect2 uv_rect = Rect2(0, 0, 1, 1));
|
||||
void add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, const Transform transform, const Rect2 uv_rect = Rect2(0, 0, 1, 1));
|
||||
void add_mesh_data_resource_transform_colored(Ref<MeshDataResource> mesh, const Transform transform, const PoolColorArray &colors, const Rect2 uv_rect = Rect2(0, 0, 1, 1));
|
||||
void add_mesh_data_resource_transform(Ref<MeshDataResource> mesh, const Transform2D transform, const Rect2 uv_rect = Rect2(0, 0, 1, 1));
|
||||
void add_mesh_data_resource_transform_colored(Ref<MeshDataResource> mesh, const Transform2D transform, const PoolColorArray &colors, const Rect2 uv_rect = Rect2(0, 0, 1, 1));
|
||||
#endif
|
||||
|
||||
void add_mesher(const Ref<Terrain2DMesher> &mesher);
|
||||
@ -149,28 +142,22 @@ public:
|
||||
void bake_colors(Ref<Terrain2DChunk> chunk);
|
||||
void bake_liquid_colors(Ref<Terrain2DChunk> chunk);
|
||||
|
||||
PoolVector<Vector3> build_collider() const;
|
||||
PoolVector<Vector2> build_collider() const;
|
||||
|
||||
void bake_lights(MeshInstance *node, Vector<Ref<Terrain2DLight>> &lights);
|
||||
|
||||
Array build_mesh();
|
||||
void build_mesh_into(RID mesh);
|
||||
|
||||
void generate_normals(bool p_flip = false);
|
||||
void remove_doubles();
|
||||
void remove_doubles_hashed();
|
||||
|
||||
PoolVector<Vector3> get_vertices() const;
|
||||
void set_vertices(const PoolVector<Vector3> &values);
|
||||
PoolVector<Vector2> get_vertices() const;
|
||||
void set_vertices(const PoolVector<Vector2> &values);
|
||||
int get_vertex_count() const;
|
||||
Vector3 get_vertex(const int idx) const;
|
||||
Vector2 get_vertex(const int idx) const;
|
||||
void remove_vertex(const int idx);
|
||||
void add_vertex(const Vector3 &vertex);
|
||||
|
||||
PoolVector<Vector3> get_normals() const;
|
||||
void set_normals(const PoolVector<Vector3> &values);
|
||||
Vector3 get_normal(const int idx) const;
|
||||
void add_normal(const Vector3 &normal);
|
||||
void add_vertex(const Vector2 &vertex);
|
||||
|
||||
PoolVector<Color> get_colors() const;
|
||||
void set_colors(const PoolVector<Color> &values);
|
||||
@ -182,11 +169,6 @@ public:
|
||||
Vector2 get_uv(const int idx) const;
|
||||
void add_uv(const Vector2 &vector);
|
||||
|
||||
PoolVector<Vector2> get_uv2s() const;
|
||||
void set_uv2s(const PoolVector<Vector2> &values);
|
||||
Vector2 get_uv2(const int idx) const;
|
||||
void add_uv2(const Vector2 &vector);
|
||||
|
||||
PoolVector<int> get_indices() const;
|
||||
void set_indices(const PoolVector<int> &values);
|
||||
int get_indices_count() const;
|
||||
@ -209,7 +191,6 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
int _channel_index_type;
|
||||
int _channel_index_isolevel;
|
||||
|
||||
int _mesher_index;
|
||||
|
||||
@ -223,12 +204,9 @@ protected:
|
||||
PoolVector<int> _indices;
|
||||
|
||||
Color _last_color;
|
||||
Vector3 _last_normal;
|
||||
Vector2 _last_uv;
|
||||
Vector2 _last_uv2;
|
||||
Vector<int> _last_bones;
|
||||
Vector<float> _last_weights;
|
||||
Plane _last_tangent;
|
||||
|
||||
Ref<Terrain2DLibrary> _library;
|
||||
Ref<Material> _material;
|
||||
|
@ -367,6 +367,7 @@ void Terrain2DChunkDefault::meshes_free(const int mesh_index) {
|
||||
}
|
||||
|
||||
void Terrain2DChunkDefault::colliders_create(const int mesh_index, const int layer_mask) {
|
||||
/*
|
||||
ERR_FAIL_COND(_voxel_world == NULL);
|
||||
ERR_FAIL_COND(PhysicsServer::get_singleton()->is_flushing_queries());
|
||||
//ERR_FAIL_COND(!get_voxel_world()->is_inside_tree());
|
||||
@ -400,8 +401,12 @@ void Terrain2DChunkDefault::colliders_create(const int mesh_index, const int lay
|
||||
m[MESH_TYPE_INDEX_SHAPE] = shape_rid;
|
||||
|
||||
_rids[mesh_index] = m;
|
||||
*/
|
||||
|
||||
//todo
|
||||
}
|
||||
void Terrain2DChunkDefault::colliders_create_area(const int mesh_index, const int layer_mask) {
|
||||
/*
|
||||
ERR_FAIL_COND(_voxel_world == NULL);
|
||||
ERR_FAIL_COND(PhysicsServer::get_singleton()->is_flushing_queries());
|
||||
|
||||
@ -440,6 +445,7 @@ void Terrain2DChunkDefault::colliders_create_area(const int mesh_index, const in
|
||||
m[MESH_TYPE_INDEX_SHAPE] = shape_rid;
|
||||
|
||||
_rids[mesh_index] = m;
|
||||
*/
|
||||
}
|
||||
|
||||
void Terrain2DChunkDefault::colliders_free(const int mesh_index) {
|
||||
@ -452,13 +458,13 @@ void Terrain2DChunkDefault::colliders_free(const int mesh_index) {
|
||||
if (m.has(MESH_TYPE_INDEX_SHAPE)) {
|
||||
RID r = m[MESH_TYPE_INDEX_SHAPE];
|
||||
|
||||
PhysicsServer::get_singleton()->free(r);
|
||||
//PhysicsServer::get_singleton()->free(r);
|
||||
}
|
||||
|
||||
if (m.has(MESH_TYPE_INDEX_BODY)) {
|
||||
RID r = m[MESH_TYPE_INDEX_BODY];
|
||||
|
||||
PhysicsServer::get_singleton()->free(r);
|
||||
//PhysicsServer::get_singleton()->free(r);
|
||||
}
|
||||
|
||||
m.erase(MESH_TYPE_INDEX_SHAPE);
|
||||
@ -502,20 +508,22 @@ void Terrain2DChunkDefault::update_transforms() {
|
||||
if (d.has(MESH_TYPE_INDEX_BODY)) {
|
||||
RID rid = d[MESH_TYPE_INDEX_BODY];
|
||||
|
||||
if (rid != empty_rid)
|
||||
PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, t);
|
||||
if (rid != empty_rid) {
|
||||
//PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, t);
|
||||
}
|
||||
}
|
||||
|
||||
if (d.has(MESH_TYPE_INDEX_AREA)) {
|
||||
RID rid = d[MESH_TYPE_INDEX_AREA];
|
||||
|
||||
if (rid != empty_rid)
|
||||
PhysicsServer::get_singleton()->area_set_shape_transform(rid, 0, t);
|
||||
if (rid != empty_rid) {
|
||||
//PhysicsServer::get_singleton()->area_set_shape_transform(rid, 0, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < collider_get_count(); ++i) {
|
||||
PhysicsServer::get_singleton()->body_set_state(collider_get_body(i), PhysicsServer::BODY_STATE_TRANSFORM, get_transform() * collider_get_transform(i));
|
||||
//PhysicsServer::get_singleton()->body_set_state(collider_get_body(i), PhysicsServer::BODY_STATE_TRANSFORM, get_transform() * collider_get_transform(i));
|
||||
}
|
||||
|
||||
if (_debug_mesh_instance != RID()) {
|
||||
@ -644,23 +652,23 @@ void Terrain2DChunkDefault::draw_debug_voxels(int max, Color color) {
|
||||
int64_t sx = static_cast<int64_t>(_size_x);
|
||||
int64_t sz = static_cast<int64_t>(_size_z);
|
||||
|
||||
for (int z = 0; z < sz; ++z) {
|
||||
for (int x = 0; x < sx; ++x) {
|
||||
int type = get_voxel(x, z, Terrain2DChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
for (int z = 0; z < sz; ++z) {
|
||||
for (int x = 0; x < sx; ++x) {
|
||||
int type = get_voxel(x, z, Terrain2DChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
|
||||
if (type == 0) {
|
||||
continue;
|
||||
}
|
||||
if (type == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
draw_cross_voxels_fill(Vector3(x, 0, z), 1);
|
||||
draw_cross_voxels_fill(Vector3(x, 0, z), 1);
|
||||
|
||||
++a;
|
||||
++a;
|
||||
|
||||
if (a > max) {
|
||||
break;
|
||||
}
|
||||
if (a > max) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug_mesh_send();
|
||||
}
|
||||
@ -678,7 +686,7 @@ void Terrain2DChunkDefault::draw_debug_voxel_lights() {
|
||||
Ref<Terrain2DLight> v = _lights[i];
|
||||
|
||||
int pos_x = v->get_world_position_x() - (_size_x * _position_x);
|
||||
int pos_z = v->get_world_position_z() - (_size_z * _position_z);
|
||||
int pos_z = v->get_world_position_y() - (_size_z * _position_z);
|
||||
|
||||
draw_cross_voxels_fill(Vector3(pos_x, 0, pos_z), 1.0);
|
||||
}
|
||||
@ -692,14 +700,15 @@ void Terrain2DChunkDefault::draw_debug_mdr_colliders() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < collider_get_count(); ++i) {
|
||||
Ref<Shape> shape = collider_get_shape(i);
|
||||
Ref<Shape2D> shape = collider_get_shape(i);
|
||||
|
||||
if (!shape.is_valid())
|
||||
continue;
|
||||
|
||||
Transform t = collider_get_transform(i);
|
||||
Transform2D t = collider_get_transform(i);
|
||||
|
||||
shape->add_vertices_to_array(_debug_mesh_array, t);
|
||||
//shape->add_vertices_to_array(_debug_mesh_array, t);
|
||||
//draw
|
||||
}
|
||||
}
|
||||
|
||||
@ -759,13 +768,11 @@ void Terrain2DChunkDefault::_bake_light(Ref<Terrain2DLight> light) {
|
||||
int size = light->get_size();
|
||||
|
||||
int local_x = light->get_world_position_x() - (_position_x * _size_x);
|
||||
int local_y = light->get_world_position_y();
|
||||
int local_z = light->get_world_position_z() - (_position_z * _size_z);
|
||||
int local_z = light->get_world_position_y() - (_position_z * _size_z);
|
||||
|
||||
ERR_FAIL_COND(size < 0);
|
||||
|
||||
int64_t dsx = static_cast<int64_t>(_data_size_x);
|
||||
int64_t dsy = static_cast<int64_t>(_world_height);
|
||||
int64_t dsz = static_cast<int64_t>(_data_size_z);
|
||||
|
||||
uint8_t *channel_color_r = channel_get(Terrain2DChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R);
|
||||
@ -774,51 +781,45 @@ void Terrain2DChunkDefault::_bake_light(Ref<Terrain2DLight> light) {
|
||||
|
||||
ERR_FAIL_COND(channel_color_r == NULL || channel_color_g == NULL || channel_color_b == NULL);
|
||||
|
||||
for (int y = local_y - size; y <= local_y + size; ++y) {
|
||||
if (y < 0 || y >= dsy)
|
||||
for (int z = local_z - size; z <= local_z + size; ++z) {
|
||||
if (z < 0 || z >= dsz)
|
||||
continue;
|
||||
|
||||
for (int z = local_z - size; z <= local_z + size; ++z) {
|
||||
if (z < 0 || z >= dsz)
|
||||
for (int x = local_x - size; x <= local_x + size; ++x) {
|
||||
if (x < 0 || x >= dsx)
|
||||
continue;
|
||||
|
||||
for (int x = local_x - size; x <= local_x + size; ++x) {
|
||||
if (x < 0 || x >= dsx)
|
||||
continue;
|
||||
int lx = x - local_x;
|
||||
int lz = z - local_z;
|
||||
|
||||
int lx = x - local_x;
|
||||
int ly = y - local_y;
|
||||
int lz = z - local_z;
|
||||
float str = size - (((float)lx * lx + lz * lz));
|
||||
str /= size;
|
||||
|
||||
float str = size - (((float)lx * lx + ly * ly + lz * lz));
|
||||
str /= size;
|
||||
if (str < 0)
|
||||
continue;
|
||||
|
||||
if (str < 0)
|
||||
continue;
|
||||
int index = get_data_index(x, z);
|
||||
|
||||
int index = get_data_index(x, z);
|
||||
int r = color.r * str * 255.0;
|
||||
int g = color.g * str * 255.0;
|
||||
int b = color.b * str * 255.0;
|
||||
|
||||
int r = color.r * str * 255.0;
|
||||
int g = color.g * str * 255.0;
|
||||
int b = color.b * str * 255.0;
|
||||
r += channel_color_r[index];
|
||||
g += channel_color_g[index];
|
||||
b += channel_color_b[index];
|
||||
|
||||
r += channel_color_r[index];
|
||||
g += channel_color_g[index];
|
||||
b += channel_color_b[index];
|
||||
if (r > 255)
|
||||
r = 255;
|
||||
|
||||
if (r > 255)
|
||||
r = 255;
|
||||
if (g > 255)
|
||||
g = 255;
|
||||
|
||||
if (g > 255)
|
||||
g = 255;
|
||||
if (b > 255)
|
||||
b = 255;
|
||||
|
||||
if (b > 255)
|
||||
b = 255;
|
||||
|
||||
channel_color_r[index] = r;
|
||||
channel_color_g[index] = g;
|
||||
channel_color_b[index] = b;
|
||||
}
|
||||
channel_color_r[index] = r;
|
||||
channel_color_g[index] = g;
|
||||
channel_color_b[index] = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,8 @@ void Terrain2DProp2DJob::phase_physics_process() {
|
||||
chunk->colliders_clear();
|
||||
|
||||
#ifdef MESH_DATA_RESOURCE_PRESENT
|
||||
//TODO
|
||||
/*
|
||||
for (int i = 0; i < chunk->mesh_data_resource_get_count(); ++i) {
|
||||
Ref<MeshDataResource> mdr = chunk->mesh_data_resource_get(i);
|
||||
|
||||
@ -95,6 +97,7 @@ void Terrain2DProp2DJob::phase_physics_process() {
|
||||
chunk->collider_add(transform, shape, shape->get_rid(), body);
|
||||
}
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
#if TOOLS_ENABLED
|
||||
@ -147,6 +150,8 @@ void Terrain2DProp2DJob::phase_prop() {
|
||||
}
|
||||
|
||||
if (should_do()) {
|
||||
//TODO
|
||||
/*
|
||||
if ((chunk->get_build_flags() & Terrain2DChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0) {
|
||||
Terrain2DWorldDefault *world = Object::cast_to<Terrain2DWorldDefault>(chunk->get_voxel_world());
|
||||
|
||||
@ -178,6 +183,7 @@ void Terrain2DProp2DJob::phase_prop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (get_prop_mesher()->get_vertex_count() == 0) {
|
||||
|
@ -55,7 +55,7 @@ protected:
|
||||
|
||||
Ref<Terrain2DMesher> _prop_mesher;
|
||||
|
||||
PoolVector<Vector3> temp_arr_collider;
|
||||
PoolVector<Vector2> temp_arr_collider;
|
||||
Array temp_mesh_arr;
|
||||
};
|
||||
|
||||
|
@ -67,8 +67,8 @@ protected:
|
||||
Ref<Terrain2DMesher> _mesher;
|
||||
Ref<Terrain2DMesher> _liquid_mesher;
|
||||
|
||||
PoolVector<Vector3> temp_arr_collider;
|
||||
PoolVector<Vector3> temp_arr_collider_liquid;
|
||||
PoolVector<Vector2> temp_arr_collider;
|
||||
PoolVector<Vector2> temp_arr_collider_liquid;
|
||||
Array temp_mesh_arr;
|
||||
};
|
||||
|
||||
|
@ -720,7 +720,7 @@ void Terrain2DChunk::clear_baked_lights() {
|
||||
}
|
||||
|
||||
#if PROPS_2D_PRESENT
|
||||
void Terrain2DChunk::prop_add(const Transform &tarnsform, const Ref<Prop2DData> &prop) {
|
||||
void Terrain2DChunk::prop_add(const Transform2D &tarnsform, const Ref<Prop2DData> &prop) {
|
||||
ERR_FAIL_COND(!prop.is_valid());
|
||||
|
||||
Prop2DDataStore s;
|
||||
@ -734,8 +734,8 @@ Ref<Prop2DData> Terrain2DChunk::prop_get(int index) {
|
||||
|
||||
return _props.get(index).prop;
|
||||
}
|
||||
Transform Terrain2DChunk::prop_get_tarnsform(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _props.size(), Transform());
|
||||
Transform2D Terrain2DChunk::prop_get_tarnsform(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _props.size(), Transform2D());
|
||||
|
||||
return _props.get(index).transform;
|
||||
}
|
||||
@ -753,47 +753,57 @@ void Terrain2DChunk::props_clear() {
|
||||
#endif
|
||||
|
||||
#if MESH_DATA_RESOURCE_PRESENT
|
||||
int Terrain2DChunk::mesh_data_resource_addv(const Vector3 &local_data_pos, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture, const Color &color, const bool apply_voxel_scale) {
|
||||
ERR_FAIL_COND_V(!mesh.is_valid(), 0);
|
||||
int Terrain2DChunk::mesh_data_resource_addv(const Vector2 &local_data_pos, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture, const Color &color, const bool apply_voxel_scale) {
|
||||
//TODO
|
||||
/*
|
||||
|
||||
int index = _mesh_data_resources.size();
|
||||
ERR_FAIL_COND_V(!mesh.is_valid(), 0);
|
||||
|
||||
MeshDataResourceEntry e;
|
||||
int index = _mesh_data_resources.size();
|
||||
|
||||
if (apply_voxel_scale) {
|
||||
e.transform = Transform(Basis().scaled(Vector3(_voxel_scale, _voxel_scale, _voxel_scale)));
|
||||
e.transform.origin = local_data_pos * _voxel_scale;
|
||||
} else {
|
||||
e.transform.origin = local_data_pos;
|
||||
}
|
||||
MeshDataResourceEntry e;
|
||||
|
||||
e.mesh = mesh;
|
||||
e.texture = texture;
|
||||
e.color = color;
|
||||
if (apply_voxel_scale) {
|
||||
e.transform = Transform(Basis().scaled(Vector3(_voxel_scale, _voxel_scale, _voxel_scale)));
|
||||
e.transform.origin = local_data_pos * _voxel_scale;
|
||||
} else {
|
||||
e.transform.origin = local_data_pos;
|
||||
}
|
||||
|
||||
AABB aabb = AABB(Vector3(), get_world_size());
|
||||
AABB mesh_aabb = e.transform.xform(mesh->get_aabb());
|
||||
e.is_inside = aabb.encloses(mesh_aabb);
|
||||
e.mesh = mesh;
|
||||
e.texture = texture;
|
||||
e.color = color;
|
||||
|
||||
#if PROPS_2D_PRESENT
|
||||
if (get_library().is_valid() && texture.is_valid()) {
|
||||
e.uv_rect = get_library()->get_prop_uv_rect(texture);
|
||||
} else {
|
||||
AABB aabb = AABB(Vector3(), get_world_size());
|
||||
AABB mesh_aabb = e.transform.xform(mesh->get_aabb());
|
||||
e.is_inside = aabb.encloses(mesh_aabb);
|
||||
|
||||
#if PROPS_2D_PRESENT
|
||||
if (get_library().is_valid() && texture.is_valid()) {
|
||||
e.uv_rect = get_library()->get_prop_uv_rect(texture);
|
||||
} else {
|
||||
e.uv_rect = Rect2(0, 0, 1, 1);
|
||||
}
|
||||
#else
|
||||
e.uv_rect = Rect2(0, 0, 1, 1);
|
||||
}
|
||||
#else
|
||||
e.uv_rect = Rect2(0, 0, 1, 1);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
_mesh_data_resources.push_back(e);
|
||||
_mesh_data_resources.push_back(e);
|
||||
|
||||
if (has_method("_mesh_data_resource_added"))
|
||||
call("_mesh_data_resource_added", index);
|
||||
if (has_method("_mesh_data_resource_added"))
|
||||
call("_mesh_data_resource_added", index);
|
||||
|
||||
return index;
|
||||
return index;
|
||||
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Terrain2DChunk::mesh_data_resource_add(const Transform &local_transform, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture, const Color &color, const bool apply_voxel_scale) {
|
||||
int Terrain2DChunk::mesh_data_resource_add(const Transform2D &local_transform, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture, const Color &color, const bool apply_voxel_scale) {
|
||||
//TODO
|
||||
|
||||
/*
|
||||
ERR_FAIL_COND_V(!mesh.is_valid(), 0);
|
||||
|
||||
int index = _mesh_data_resources.size();
|
||||
@ -830,6 +840,9 @@ int Terrain2DChunk::mesh_data_resource_add(const Transform &local_transform, con
|
||||
call("_mesh_data_resource_added", index);
|
||||
|
||||
return index;
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ref<MeshDataResource> Terrain2DChunk::mesh_data_resource_get(const int index) {
|
||||
@ -875,12 +888,12 @@ void Terrain2DChunk::mesh_data_resource_set_uv_rect(const int index, const Rect2
|
||||
_mesh_data_resources.write[index].uv_rect = uv_rect;
|
||||
}
|
||||
|
||||
Transform Terrain2DChunk::mesh_data_resource_get_transform(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _mesh_data_resources.size(), Transform());
|
||||
Transform2D Terrain2DChunk::mesh_data_resource_get_transform(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _mesh_data_resources.size(), Transform2D());
|
||||
|
||||
return _mesh_data_resources.write[index].transform;
|
||||
}
|
||||
void Terrain2DChunk::mesh_data_resource_set_transform(const int index, const Transform &transform) {
|
||||
void Terrain2DChunk::mesh_data_resource_set_transform(const int index, const Transform2D &transform) {
|
||||
ERR_FAIL_INDEX(index, _mesh_data_resources.size());
|
||||
|
||||
_mesh_data_resources.write[index].transform = transform;
|
||||
@ -911,7 +924,7 @@ void Terrain2DChunk::mesh_data_resource_clear() {
|
||||
|
||||
#endif
|
||||
|
||||
int Terrain2DChunk::collider_add(const Transform &local_transform, const Ref<Shape> &shape, const RID &shape_rid, const RID &body) {
|
||||
int Terrain2DChunk::collider_add(const Transform2D &local_transform, const Ref<Shape2D> &shape, const RID &shape_rid, const RID &body) {
|
||||
ERR_FAIL_COND_V(!shape.is_valid() && shape_rid == RID(), 0);
|
||||
|
||||
int index = _colliders.size();
|
||||
@ -927,24 +940,24 @@ int Terrain2DChunk::collider_add(const Transform &local_transform, const Ref<Sha
|
||||
return index;
|
||||
}
|
||||
|
||||
Transform Terrain2DChunk::collider_get_transform(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _colliders.size(), Transform());
|
||||
Transform2D Terrain2DChunk::collider_get_transform(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _colliders.size(), Transform2D());
|
||||
|
||||
return _colliders[index].transform;
|
||||
}
|
||||
void Terrain2DChunk::collider_set_transform(const int index, const Transform &transform) {
|
||||
void Terrain2DChunk::collider_set_transform(const int index, const Transform2D &transform) {
|
||||
ERR_FAIL_INDEX(index, _colliders.size());
|
||||
|
||||
_colliders.write[index].transform = transform;
|
||||
}
|
||||
|
||||
Ref<Shape> Terrain2DChunk::collider_get_shape(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _colliders.size(), Ref<Shape>());
|
||||
Ref<Shape2D> Terrain2DChunk::collider_get_shape(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _colliders.size(), Ref<Shape2D>());
|
||||
|
||||
return _colliders[index].shape;
|
||||
}
|
||||
|
||||
void Terrain2DChunk::collider_set_shape(const int index, const Ref<Shape> &shape) {
|
||||
void Terrain2DChunk::collider_set_shape(const int index, const Ref<Shape2D> &shape) {
|
||||
ERR_FAIL_INDEX(index, _colliders.size());
|
||||
|
||||
_colliders.write[index].shape = shape;
|
||||
@ -1130,7 +1143,7 @@ Terrain2DChunk::~Terrain2DChunk() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < _colliders.size(); ++i) {
|
||||
PhysicsServer::get_singleton()->free(_colliders[i].body);
|
||||
//PhysicsServer::get_singleton()->free(_colliders[i].body);
|
||||
}
|
||||
|
||||
_colliders.clear();
|
||||
|
@ -64,6 +64,8 @@ include_pool_vector
|
||||
#define Texture Texture2D
|
||||
#endif
|
||||
|
||||
#include "scene/resources/shape_2d.h"
|
||||
|
||||
#include "../library/terrain_2d_surface.h"
|
||||
#include "../library/terrain_2d_library.h"
|
||||
; //hackfix for a clang format issue
|
||||
@ -234,17 +236,17 @@ public:
|
||||
void clear_baked_lights();
|
||||
|
||||
#if PROPS_2D_PRESENT
|
||||
void prop_add(const Transform &tarnsform, const Ref<Prop2DData> &prop);
|
||||
void prop_add(const Transform2D &tarnsform, const Ref<Prop2DData> &prop);
|
||||
Ref<Prop2DData> prop_get(const int index);
|
||||
Transform prop_get_tarnsform(const int index);
|
||||
Transform2D prop_get_tarnsform(const int index);
|
||||
int prop_get_count() const;
|
||||
void prop_remove(const int index);
|
||||
void props_clear();
|
||||
#endif
|
||||
|
||||
#if MESH_DATA_RESOURCE_PRESENT
|
||||
int mesh_data_resource_addv(const Vector3 &local_data_pos, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture = Ref<Texture>(), const Color &color = Color(1, 1, 1, 1), const bool apply_voxel_scale = true);
|
||||
int mesh_data_resource_add(const Transform &local_transform, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture = Ref<Texture>(), const Color &color = Color(1, 1, 1, 1), const bool apply_voxel_scale = true);
|
||||
int mesh_data_resource_addv(const Vector2 &local_data_pos, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture = Ref<Texture>(), const Color &color = Color(1, 1, 1, 1), const bool apply_voxel_scale = true);
|
||||
int mesh_data_resource_add(const Transform2D &local_transform, const Ref<MeshDataResource> &mesh, const Ref<Texture> &texture = Ref<Texture>(), const Color &color = Color(1, 1, 1, 1), const bool apply_voxel_scale = true);
|
||||
|
||||
Ref<MeshDataResource> mesh_data_resource_get(const int index);
|
||||
void mesh_data_resource_set(const int index, const Ref<MeshDataResource> &mesh);
|
||||
@ -258,8 +260,8 @@ public:
|
||||
Rect2 mesh_data_resource_get_uv_rect(const int index);
|
||||
void mesh_data_resource_set_uv_rect(const int index, const Rect2 &uv_rect);
|
||||
|
||||
Transform mesh_data_resource_get_transform(const int index);
|
||||
void mesh_data_resource_set_transform(const int index, const Transform &transform);
|
||||
Transform2D mesh_data_resource_get_transform(const int index);
|
||||
void mesh_data_resource_set_transform(const int index, const Transform2D &transform);
|
||||
|
||||
bool mesh_data_resource_get_is_inside(const int index);
|
||||
void mesh_data_resource_set_is_inside(const int index, const bool inside);
|
||||
@ -270,13 +272,13 @@ public:
|
||||
#endif
|
||||
|
||||
//Colliders
|
||||
int collider_add(const Transform &local_transform, const Ref<Shape> &shape, const RID &shape_rid = RID(), const RID &body = RID());
|
||||
int collider_add(const Transform2D &local_transform, const Ref<Shape2D> &shape, const RID &shape_rid = RID(), const RID &body = RID());
|
||||
|
||||
Transform collider_get_transform(const int index);
|
||||
void collider_set_transform(const int index, const Transform &transform);
|
||||
Transform2D collider_get_transform(const int index);
|
||||
void collider_set_transform(const int index, const Transform2D &transform);
|
||||
|
||||
Ref<Shape> collider_get_shape(const int index);
|
||||
void collider_set_shape(const int index, const Ref<Shape> &shape);
|
||||
Ref<Shape2D> collider_get_shape(const int index);
|
||||
void collider_set_shape(const int index, const Ref<Shape2D> &shape);
|
||||
|
||||
RID collider_get_shape_rid(const int index);
|
||||
void collider_set_shape_rid(const int index, const RID &rid);
|
||||
@ -321,7 +323,7 @@ protected:
|
||||
protected:
|
||||
#if PROPS_2D_PRESENT
|
||||
struct Prop2DDataStore {
|
||||
Transform transform;
|
||||
Transform2D transform;
|
||||
Ref<Prop2DData> prop;
|
||||
};
|
||||
#endif
|
||||
@ -332,15 +334,15 @@ protected:
|
||||
Ref<Texture> texture;
|
||||
Color color;
|
||||
Rect2 uv_rect;
|
||||
Transform transform;
|
||||
Transform2D transform;
|
||||
bool is_inside;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct ColliderBody {
|
||||
Transform transform;
|
||||
Transform2D transform;
|
||||
RID body;
|
||||
Ref<Shape> shape;
|
||||
Ref<Shape2D> shape;
|
||||
RID shape_rid;
|
||||
};
|
||||
|
||||
|
@ -588,6 +588,8 @@ int Terrain2DWorld::generation_get_size() const {
|
||||
|
||||
#if PROPS_2D_PRESENT
|
||||
void Terrain2DWorld::prop_add(Transform transform, const Ref<Prop2DData> &prop, const bool apply_voxel_scale) {
|
||||
//TODO
|
||||
/*
|
||||
ERR_FAIL_COND(!prop.is_valid());
|
||||
|
||||
if (apply_voxel_scale) {
|
||||
@ -652,7 +654,7 @@ void Terrain2DWorld::prop_add(Transform transform, const Ref<Prop2DData> &prop,
|
||||
Ref<Terrain2DLight> light;
|
||||
light.INSTANCE();
|
||||
|
||||
light->set_world_position(wp.x / get_voxel_scale(), wp.y / get_voxel_scale(), wp.z / get_voxel_scale());
|
||||
light->set_world_position(wp.x / get_voxel_scale(), wp.y / get_voxel_scale());
|
||||
light->set_color(light_data->get_light_color());
|
||||
light->set_size(light_data->get_light_size());
|
||||
|
||||
@ -680,6 +682,8 @@ void Terrain2DWorld::prop_add(Transform transform, const Ref<Prop2DData> &prop,
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user