2021-11-22 22:00:45 +01:00
|
|
|
/*
|
|
|
|
Copyright (c) 2019-2021 Péter Magyar
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
#include "terra_world_blocky_2d.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
#include "terra_chunk_blocky_2d.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
#include "../../meshers/blocky/terra_mesher_blocky_2d.h"
|
|
|
|
#include "../../meshers/blocky/terra_mesher_liquid_blocky_2d.h"
|
|
|
|
#include "../jobs/terra_light_job_2d.h"
|
|
|
|
#include "../jobs/terra_prop_job_2d.h"
|
|
|
|
#include "../jobs/terra_terrarin_job_2d.h"
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
Ref<TerraChunk2D> TerraWorldBlocky2D::_create_chunk(int x, int z, Ref<TerraChunk2D> chunk) {
|
2021-11-22 22:00:45 +01:00
|
|
|
if (!chunk.is_valid()) {
|
2021-11-22 23:51:16 +01:00
|
|
|
chunk = Ref<TerraChunk2D>(memnew(TerraChunkBlocky2D));
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (chunk->job_get_count() == 0) {
|
2021-11-22 23:51:16 +01:00
|
|
|
Ref<TerraTerrarinJob2D> tj;
|
2021-11-22 22:00:45 +01:00
|
|
|
tj.instance();
|
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
Ref<TerraLightJob2D> lj;
|
2021-11-22 22:00:45 +01:00
|
|
|
lj.instance();
|
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
Ref<TerraMesherJobStep2D> s;
|
2021-11-22 22:00:45 +01:00
|
|
|
s.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
s->set_job_type(TerraMesherJobStep2D::TYPE_NORMAL);
|
2021-11-22 22:00:45 +01:00
|
|
|
tj->add_jobs_step(s);
|
|
|
|
|
|
|
|
s.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
s->set_job_type(TerraMesherJobStep2D::TYPE_NORMAL_LOD);
|
2021-11-22 22:00:45 +01:00
|
|
|
s->set_lod_index(1);
|
|
|
|
tj->add_jobs_step(s);
|
|
|
|
|
|
|
|
s.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
s->set_job_type(TerraMesherJobStep2D::TYPE_NORMAL_LOD);
|
2021-11-22 22:00:45 +01:00
|
|
|
s->set_lod_index(2);
|
|
|
|
tj->add_jobs_step(s);
|
|
|
|
|
|
|
|
s.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
s->set_job_type(TerraMesherJobStep2D::TYPE_MERGE_VERTS);
|
2021-11-22 22:00:45 +01:00
|
|
|
tj->add_jobs_step(s);
|
|
|
|
|
|
|
|
s.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
s->set_job_type(TerraMesherJobStep2D::TYPE_BAKE_TEXTURE);
|
2021-11-22 22:00:45 +01:00
|
|
|
tj->add_jobs_step(s);
|
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
tj->set_mesher(Ref<TerraMesher2D>(memnew(TerraMesherBlocky2D())));
|
|
|
|
tj->set_liquid_mesher(Ref<TerraMesher2D>(memnew(TerraMesherLiquidBlocky2D())));
|
2021-11-22 22:00:45 +01:00
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
Ref<TerraPropJob2D> pj;
|
2021-11-22 22:00:45 +01:00
|
|
|
pj.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
pj->set_prop_mesher(Ref<TerraMesher2D>(memnew(TerraMesherBlocky2D)));
|
2021-11-22 22:00:45 +01:00
|
|
|
|
|
|
|
s.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
s->set_job_type(TerraMesherJobStep2D::TYPE_NORMAL);
|
2021-11-22 22:00:45 +01:00
|
|
|
pj->add_jobs_step(s);
|
|
|
|
|
|
|
|
s.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
s->set_job_type(TerraMesherJobStep2D::TYPE_MERGE_VERTS);
|
2021-11-22 22:00:45 +01:00
|
|
|
pj->add_jobs_step(s);
|
|
|
|
|
|
|
|
s.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
s->set_job_type(TerraMesherJobStep2D::TYPE_BAKE_TEXTURE);
|
2021-11-22 22:00:45 +01:00
|
|
|
pj->add_jobs_step(s);
|
|
|
|
|
|
|
|
s.instance();
|
2021-11-22 23:51:16 +01:00
|
|
|
s->set_job_type(TerraMesherJobStep2D::TYPE_SIMPLIFY_MESH);
|
2021-11-22 22:00:45 +01:00
|
|
|
#ifdef MESH_UTILS_PRESENT
|
|
|
|
Ref<FastQuadraticMeshSimplifier> fqms;
|
|
|
|
fqms.instance();
|
|
|
|
s->set_fqms(fqms);
|
|
|
|
s->set_simplification_steps(2);
|
|
|
|
#endif
|
|
|
|
pj->add_jobs_step(s);
|
|
|
|
|
|
|
|
chunk->job_add(lj);
|
|
|
|
chunk->job_add(tj);
|
|
|
|
chunk->job_add(pj);
|
|
|
|
}
|
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
return TerraWorld2D::_create_chunk(x, z, chunk);
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
TerraWorldBlocky2D::TerraWorldBlocky2D() {
|
2021-11-22 22:00:45 +01:00
|
|
|
set_data_margin_start(1);
|
|
|
|
set_data_margin_end(1);
|
|
|
|
}
|
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
TerraWorldBlocky2D ::~TerraWorldBlocky2D() {
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|
|
|
|
|
2021-11-22 23:51:16 +01:00
|
|
|
void TerraWorldBlocky2D::_bind_methods() {
|
2021-11-22 22:00:45 +01:00
|
|
|
}
|