2014-11-18 21:04:19 +01:00
|
|
|
/************************************************************************
|
|
|
|
* Minetest-c55
|
|
|
|
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
*
|
|
|
|
* mapblock_mesh.h
|
|
|
|
* voxelands - 3d voxel world sandbox game
|
|
|
|
* Copyright (C) Lisa 'darkrose' Milne 2014 <lisa@ltmnet.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
|
|
|
|
* for Voxelands.
|
|
|
|
************************************************************************/
|
2013-04-15 14:42:24 +02:00
|
|
|
|
|
|
|
#ifndef MAPBLOCK_MESH_HEADER
|
|
|
|
#define MAPBLOCK_MESH_HEADER
|
|
|
|
|
|
|
|
#include "common_irrlicht.h"
|
|
|
|
#include "voxel.h"
|
2015-05-02 09:29:42 +02:00
|
|
|
#include <vector>
|
2015-11-15 08:25:55 +01:00
|
|
|
#include <map>
|
2013-04-15 14:42:24 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Mesh making stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Helper functions
|
2015-12-31 16:49:18 +01:00
|
|
|
std::string getGrassTile(u8 p2, std::string base, std::string overlay);
|
2015-11-15 08:25:55 +01:00
|
|
|
TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir, SelectedNode &select, NodeMetadata *meta = NULL);
|
|
|
|
TileSpec getMetaTile(MapNode mn, v3s16 p, v3s16 face_dir, SelectedNode &select);
|
2015-05-31 21:03:50 +02:00
|
|
|
u8 getSmoothLight(v3s16 p, v3s16 corner, VoxelManipulator &vmanip);
|
2015-11-19 18:50:29 +01:00
|
|
|
video::SColor blend_light(u32 data, u32 daylight_factor);
|
2013-04-15 14:42:24 +02:00
|
|
|
|
|
|
|
class MapBlock;
|
2014-04-01 12:44:48 +02:00
|
|
|
class Environment;
|
2013-04-15 14:42:24 +02:00
|
|
|
|
2015-05-02 09:29:42 +02:00
|
|
|
struct MeshData
|
|
|
|
{
|
|
|
|
bool single;
|
|
|
|
v3s16 pos;
|
|
|
|
video::SMaterial material;
|
|
|
|
std::vector<u16> indices;
|
2015-05-02 20:52:06 +02:00
|
|
|
std::vector<video::S3DVertex> vertices;
|
2015-05-30 18:34:15 +02:00
|
|
|
std::vector<u32> colours;
|
2015-05-02 09:29:42 +02:00
|
|
|
std::vector<MeshData*> siblings;
|
|
|
|
MeshData* parent;
|
|
|
|
};
|
|
|
|
|
2015-04-11 10:19:43 +02:00
|
|
|
struct MapBlockSound
|
|
|
|
{
|
|
|
|
int id;
|
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
2013-04-15 14:42:24 +02:00
|
|
|
struct MeshMakeData
|
|
|
|
{
|
|
|
|
u32 m_daynight_ratio;
|
2015-05-02 21:26:58 +02:00
|
|
|
bool m_refresh_only;
|
2013-04-15 14:42:24 +02:00
|
|
|
VoxelManipulator m_vmanip;
|
|
|
|
v3s16 m_blockpos;
|
2015-05-02 20:52:06 +02:00
|
|
|
v3s16 m_blockpos_nodes;
|
|
|
|
bool m_smooth_lighting;
|
2014-04-01 12:44:48 +02:00
|
|
|
Environment *m_env;
|
2015-05-02 09:29:42 +02:00
|
|
|
std::vector<MeshData> m_meshdata;
|
2015-05-31 22:24:47 +02:00
|
|
|
std::vector<MeshData> m_fardata;
|
2015-11-19 18:50:29 +01:00
|
|
|
std::map<v3s16,SelectedNode> m_selected;
|
2015-05-02 09:29:42 +02:00
|
|
|
MeshData *m_single;
|
2015-11-19 18:50:29 +01:00
|
|
|
float m_BS;
|
|
|
|
float m_BSd;
|
2013-04-15 14:42:24 +02:00
|
|
|
|
2015-04-11 10:19:43 +02:00
|
|
|
std::map<v3s16,MapBlockSound> *m_sounds;
|
|
|
|
|
2015-05-02 09:29:42 +02:00
|
|
|
MeshMakeData():
|
2015-05-02 21:26:58 +02:00
|
|
|
m_refresh_only(false),
|
2015-05-02 09:29:42 +02:00
|
|
|
m_single(NULL),
|
2015-11-19 18:50:29 +01:00
|
|
|
m_BS(BS),
|
|
|
|
m_BSd(0.0),
|
2015-05-02 09:29:42 +02:00
|
|
|
m_sounds(NULL)
|
|
|
|
{}
|
|
|
|
|
2013-04-15 14:42:24 +02:00
|
|
|
/*
|
|
|
|
Copy central data directly from block, and other data from
|
|
|
|
parent of block.
|
|
|
|
*/
|
|
|
|
void fill(u32 daynight_ratio, MapBlock *block);
|
|
|
|
|
2015-05-02 09:29:42 +02:00
|
|
|
void startSingle(v3s16 pos, video::SMaterial material)
|
|
|
|
{
|
|
|
|
MeshData dd;
|
|
|
|
dd.single = true;
|
|
|
|
dd.pos = pos;
|
|
|
|
dd.material = material;
|
|
|
|
dd.parent = NULL;
|
|
|
|
m_meshdata.push_back(dd);
|
|
|
|
m_single = &m_meshdata[m_meshdata.size()-1];
|
|
|
|
}
|
|
|
|
void endSingle()
|
|
|
|
{
|
|
|
|
m_single = NULL;
|
|
|
|
}
|
|
|
|
void append(
|
|
|
|
video::SMaterial material,
|
2015-05-02 20:52:06 +02:00
|
|
|
const video::S3DVertex* const vertices,
|
2015-05-02 09:29:42 +02:00
|
|
|
u32 v_count,
|
|
|
|
const u16* const indices,
|
2015-05-02 20:52:06 +02:00
|
|
|
u32 i_count,
|
2015-05-30 18:34:15 +02:00
|
|
|
std::vector<u32> colours
|
2015-05-02 09:29:42 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
MeshData *d = NULL;
|
|
|
|
if (m_single) {
|
|
|
|
if (m_single->parent)
|
|
|
|
m_single = m_single->parent;
|
|
|
|
if (m_single->material != material) {
|
|
|
|
for (u16 i=0; i<m_single->siblings.size(); i++) {
|
|
|
|
if (m_single->siblings[i]->material == material) {
|
|
|
|
d = m_single->siblings[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (d == NULL) {
|
|
|
|
MeshData dd;
|
|
|
|
dd.single = true;
|
|
|
|
dd.pos = m_single->pos;
|
|
|
|
dd.material = material;
|
|
|
|
dd.parent = m_single;
|
|
|
|
m_meshdata.push_back(dd);
|
|
|
|
d = &m_meshdata[m_meshdata.size()-1];
|
|
|
|
m_single->siblings.push_back(d);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
d = m_single;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
for (u32 i=0; i<m_meshdata.size(); i++) {
|
|
|
|
MeshData &dd = m_meshdata[i];
|
|
|
|
if (dd.material != material)
|
|
|
|
continue;
|
|
|
|
if (dd.vertices.size() + v_count > 65535)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
d = ⅆ
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d == NULL) {
|
|
|
|
MeshData dd;
|
|
|
|
dd.single = false;
|
|
|
|
dd.material = material;
|
|
|
|
m_meshdata.push_back(dd);
|
|
|
|
d = &m_meshdata[m_meshdata.size()-1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-30 18:34:15 +02:00
|
|
|
for (u32 k=0; k<colours.size(); k++) {
|
|
|
|
d->colours.push_back(colours[k]);
|
2015-05-02 20:52:06 +02:00
|
|
|
}
|
|
|
|
|
2015-05-31 22:24:47 +02:00
|
|
|
u32 vertex_count = d->vertices.size();
|
|
|
|
for(u32 i=0; i<i_count; i++) {
|
|
|
|
u32 j = indices[i] + vertex_count;
|
|
|
|
d->indices.push_back(j);
|
|
|
|
}
|
|
|
|
for(u32 i=0; i<v_count; i++) {
|
|
|
|
d->vertices.push_back(vertices[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void appendFar(
|
|
|
|
video::SMaterial material,
|
|
|
|
const video::S3DVertex* const vertices,
|
|
|
|
u32 v_count,
|
|
|
|
const u16* const indices,
|
|
|
|
u32 i_count
|
|
|
|
)
|
|
|
|
{
|
|
|
|
MeshData *d = NULL;
|
|
|
|
for (u32 i=0; i<m_fardata.size(); i++) {
|
|
|
|
MeshData &dd = m_fardata[i];
|
|
|
|
if (dd.material != material)
|
|
|
|
continue;
|
|
|
|
if (dd.vertices.size() + v_count > 65535)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
d = ⅆ
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d == NULL) {
|
|
|
|
MeshData dd;
|
|
|
|
dd.single = false;
|
|
|
|
dd.material = material;
|
|
|
|
m_fardata.push_back(dd);
|
|
|
|
d = &m_fardata[m_fardata.size()-1];
|
|
|
|
}
|
|
|
|
|
2015-05-02 09:29:42 +02:00
|
|
|
u32 vertex_count = d->vertices.size();
|
|
|
|
for(u32 i=0; i<i_count; i++) {
|
|
|
|
u32 j = indices[i] + vertex_count;
|
|
|
|
d->indices.push_back(j);
|
|
|
|
}
|
|
|
|
for(u32 i=0; i<v_count; i++) {
|
|
|
|
d->vertices.push_back(vertices[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-04-15 14:42:24 +02:00
|
|
|
|
2014-04-05 18:03:03 +02:00
|
|
|
class MapBlockMesh
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MapBlockMesh(MeshMakeData *data, v3s16 camera_offset);
|
|
|
|
~MapBlockMesh();
|
|
|
|
|
|
|
|
scene::SMesh* getMesh()
|
|
|
|
{
|
|
|
|
return m_mesh;
|
|
|
|
}
|
|
|
|
|
2015-05-31 22:24:47 +02:00
|
|
|
scene::SMesh* getFarMesh()
|
|
|
|
{
|
|
|
|
return m_farmesh;
|
|
|
|
}
|
|
|
|
|
2015-05-30 18:34:15 +02:00
|
|
|
void generate(MeshMakeData *data, v3s16 camera_offset, JMutex *mutex);
|
2015-05-02 09:29:42 +02:00
|
|
|
void refresh(u32 daynight_ratio);
|
|
|
|
|
2014-04-05 18:03:03 +02:00
|
|
|
void updateCameraOffset(v3s16 camera_offset);
|
|
|
|
|
2015-06-07 16:13:28 +02:00
|
|
|
bool isfar;
|
2014-04-05 18:03:03 +02:00
|
|
|
private:
|
2015-05-30 18:34:15 +02:00
|
|
|
v3s16 m_pos;
|
2014-04-05 18:03:03 +02:00
|
|
|
scene::SMesh *m_mesh;
|
2015-05-31 22:24:47 +02:00
|
|
|
scene::SMesh *m_farmesh;
|
2014-04-05 18:03:03 +02:00
|
|
|
v3s16 m_camera_offset;
|
2015-05-02 09:29:42 +02:00
|
|
|
std::vector<MeshData> m_meshdata;
|
2015-05-31 22:24:47 +02:00
|
|
|
std::vector<MeshData> m_fardata;
|
2014-04-05 18:03:03 +02:00
|
|
|
};
|
|
|
|
|
2013-04-15 14:42:24 +02:00
|
|
|
#endif
|
|
|
|
|