Skip to content

Commit 9fcc0c1

Browse files
numberZeronerzhul
authored andcommittedMar 22, 2018
Update mesh collector and move it to a separate file (#6904)
* Update MeshCollector * Simplify MeshCollector
1 parent 8986a9e commit 9fcc0c1

File tree

8 files changed

+222
-291
lines changed

8 files changed

+222
-291
lines changed
 

Diff for: ‎build/android/jni/Android.mk

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ LOCAL_SRC_FILES := \
274274
jni/src/unittest/test_voxelmanipulator.cpp \
275275
jni/src/settings.cpp \
276276
jni/src/wieldmesh.cpp \
277+
jni/src/client/meshgen/collector.cpp \
277278
jni/src/client/clientlauncher.cpp \
278279
jni/src/client/gameui.cpp \
279280
jni/src/client/hud.cpp \

Diff for: ‎src/client/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(client_SRCS
2+
${CMAKE_CURRENT_SOURCE_DIR}/meshgen/collector.cpp
23
${CMAKE_CURRENT_SOURCE_DIR}/render/anaglyph.cpp
34
${CMAKE_CURRENT_SOURCE_DIR}/render/core.cpp
45
${CMAKE_CURRENT_SOURCE_DIR}/render/factory.cpp

Diff for: ‎src/client/meshgen/collector.cpp

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2018 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#include "collector.h"
21+
#include <stdexcept>
22+
#include "log.h"
23+
#include "mesh.h"
24+
25+
void MeshCollector::append(const TileSpec &tile, const video::S3DVertex *vertices,
26+
u32 numVertices, const u16 *indices, u32 numIndices)
27+
{
28+
for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
29+
const TileLayer *layer = &tile.layers[layernum];
30+
if (layer->texture_id == 0)
31+
continue;
32+
append(*layer, vertices, numVertices, indices, numIndices, layernum,
33+
tile.world_aligned);
34+
}
35+
}
36+
37+
void MeshCollector::append(const TileLayer &layer, const video::S3DVertex *vertices,
38+
u32 numVertices, const u16 *indices, u32 numIndices, u8 layernum,
39+
bool use_scale)
40+
{
41+
PreMeshBuffer &p = findBuffer(layer, layernum, numVertices);
42+
43+
f32 scale = 1.0f;
44+
if (use_scale)
45+
scale = 1.0f / layer.scale;
46+
47+
u32 vertex_count = p.vertices.size();
48+
for (u32 i = 0; i < numVertices; i++)
49+
p.vertices.emplace_back(vertices[i].Pos, vertices[i].Normal,
50+
vertices[i].Color, scale * vertices[i].TCoords);
51+
52+
for (u32 i = 0; i < numIndices; i++)
53+
p.indices.push_back(indices[i] + vertex_count);
54+
}
55+
56+
void MeshCollector::append(const TileSpec &tile, const video::S3DVertex *vertices,
57+
u32 numVertices, const u16 *indices, u32 numIndices, v3f pos,
58+
video::SColor c, u8 light_source)
59+
{
60+
for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
61+
const TileLayer *layer = &tile.layers[layernum];
62+
if (layer->texture_id == 0)
63+
continue;
64+
append(*layer, vertices, numVertices, indices, numIndices, pos, c,
65+
light_source, layernum, tile.world_aligned);
66+
}
67+
}
68+
69+
void MeshCollector::append(const TileLayer &layer, const video::S3DVertex *vertices,
70+
u32 numVertices, const u16 *indices, u32 numIndices, v3f pos,
71+
video::SColor c, u8 light_source, u8 layernum, bool use_scale)
72+
{
73+
PreMeshBuffer &p = findBuffer(layer, layernum, numVertices);
74+
75+
f32 scale = 1.0f;
76+
if (use_scale)
77+
scale = 1.0f / layer.scale;
78+
79+
u32 vertex_count = p.vertices.size();
80+
for (u32 i = 0; i < numVertices; i++) {
81+
video::SColor color = c;
82+
if (!light_source)
83+
applyFacesShading(color, vertices[i].Normal);
84+
p.vertices.emplace_back(vertices[i].Pos + pos, vertices[i].Normal, color,
85+
scale * vertices[i].TCoords);
86+
}
87+
88+
for (u32 i = 0; i < numIndices; i++)
89+
p.indices.push_back(indices[i] + vertex_count);
90+
}
91+
92+
PreMeshBuffer &MeshCollector::findBuffer(
93+
const TileLayer &layer, u8 layernum, u32 numVertices)
94+
{
95+
if (numVertices > U16_MAX)
96+
throw std::invalid_argument(
97+
"Mesh can't contain more than 65536 vertices");
98+
std::vector<PreMeshBuffer> &buffers = prebuffers[layernum];
99+
for (PreMeshBuffer &p : buffers)
100+
if (p.layer == layer && p.vertices.size() + numVertices <= U16_MAX)
101+
return p;
102+
buffers.emplace_back(layer);
103+
return buffers.back();
104+
}

Diff for: ‎src/client/meshgen/collector.h

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2018 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#pragma once
21+
#include <array>
22+
#include <vector>
23+
#include "irrlichttypes.h"
24+
#include <S3DVertex.h>
25+
#include "client/tile.h"
26+
27+
struct PreMeshBuffer
28+
{
29+
TileLayer layer;
30+
std::vector<u16> indices;
31+
std::vector<video::S3DVertex> vertices;
32+
33+
PreMeshBuffer() = default;
34+
explicit PreMeshBuffer(const TileLayer &layer) : layer(layer) {}
35+
};
36+
37+
struct MeshCollector
38+
{
39+
std::array<std::vector<PreMeshBuffer>, MAX_TILE_LAYERS> prebuffers;
40+
41+
// clang-format off
42+
void append(const TileSpec &material,
43+
const video::S3DVertex *vertices, u32 numVertices,
44+
const u16 *indices, u32 numIndices);
45+
void append(const TileSpec &material,
46+
const video::S3DVertex *vertices, u32 numVertices,
47+
const u16 *indices, u32 numIndices,
48+
v3f pos, video::SColor c, u8 light_source);
49+
// clang-format on
50+
51+
private:
52+
// clang-format off
53+
void append(const TileLayer &material,
54+
const video::S3DVertex *vertices, u32 numVertices,
55+
const u16 *indices, u32 numIndices,
56+
u8 layernum, bool use_scale = false);
57+
void append(const TileLayer &material,
58+
const video::S3DVertex *vertices, u32 numVertices,
59+
const u16 *indices, u32 numIndices,
60+
v3f pos, video::SColor c, u8 light_source,
61+
u8 layernum, bool use_scale = false);
62+
// clang-format on
63+
64+
PreMeshBuffer &findBuffer(const TileLayer &layer, u8 layernum, u32 numVertices);
65+
};

Diff for: ‎src/content_mapblock.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2626
#include "client/tile.h"
2727
#include "mesh.h"
2828
#include <IMeshManipulator.h>
29+
#include "client/meshgen/collector.h"
2930
#include "client/renderingengine.h"
3031
#include "client.h"
3132
#include "noise.h"

Diff for: ‎src/mapblock_mesh.cpp

+48-245
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
#include "minimap.h"
2828
#include "content_mapblock.h"
2929
#include "util/directiontables.h"
30+
#include "client/meshgen/collector.h"
3031
#include "client/renderingengine.h"
3132
#include <array>
3233

@@ -450,16 +451,14 @@ static void getNodeTextureCoords(v3f base, const v3f &scale, v3s16 dir, float *u
450451

451452
struct FastFace
452453
{
453-
TileLayer layer;
454+
TileSpec tile;
454455
video::S3DVertex vertices[4]; // Precalculated vertices
455456
/*!
456457
* The face is divided into two triangles. If this is true,
457458
* vertices 0 and 2 are connected, othervise vertices 1 and 3
458459
* are connected.
459460
*/
460461
bool vertex_0_2_connected;
461-
u8 layernum;
462-
bool world_aligned;
463462
};
464463

465464
static void makeFastFace(const TileSpec &tile, u16 li0, u16 li1, u16 li2, u16 li3,
@@ -630,35 +629,25 @@ static void makeFastFace(const TileSpec &tile, u16 li0, u16 li1, u16 li2, u16 li
630629
core::vector2d<f32>(x0, y0),
631630
core::vector2d<f32>(x0 + w * abs_scale, y0) };
632631

633-
for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
634-
const TileLayer *layer = &tile.layers[layernum];
635-
if (layer->texture_id == 0)
636-
continue;
637-
638-
// equivalent to dest.push_back(FastFace()) but faster
639-
dest.emplace_back();
640-
FastFace& face = *dest.rbegin();
641-
642-
for (u8 i = 0; i < 4; i++) {
643-
video::SColor c = encode_light(li[i], tile.emissive_light);
644-
if (!tile.emissive_light)
645-
applyFacesShading(c, normal);
646-
647-
face.vertices[i] = video::S3DVertex(vertex_pos[i], normal, c, f[i]);
648-
}
649-
650-
/*
651-
Revert triangles for nicer looking gradient if the
652-
brightness of vertices 1 and 3 differ less than
653-
the brightness of vertices 0 and 2.
654-
*/
655-
face.vertex_0_2_connected = vertex_0_2_connected;
632+
// equivalent to dest.push_back(FastFace()) but faster
633+
dest.emplace_back();
634+
FastFace& face = *dest.rbegin();
656635

657-
face.layer = *layer;
658-
face.layernum = layernum;
636+
for (u8 i = 0; i < 4; i++) {
637+
video::SColor c = encode_light(li[i], tile.emissive_light);
638+
if (!tile.emissive_light)
639+
applyFacesShading(c, normal);
659640

660-
face.world_aligned = tile.world_aligned;
641+
face.vertices[i] = video::S3DVertex(vertex_pos[i], normal, c, f[i]);
661642
}
643+
644+
/*
645+
Revert triangles for nicer looking gradient if the
646+
brightness of vertices 1 and 3 differ less than
647+
the brightness of vertices 0 and 2.
648+
*/
649+
face.vertex_0_2_connected = vertex_0_2_connected;
650+
face.tile = tile;
662651
}
663652

664653
/*
@@ -1012,6 +1001,20 @@ static void updateAllFastFaceRows(MeshMakeData *data,
10121001
dest);
10131002
}
10141003

1004+
static void applyTileColor(PreMeshBuffer &pmb)
1005+
{
1006+
video::SColor tc = pmb.layer.color;
1007+
if (tc == video::SColor(0xFFFFFFFF))
1008+
return;
1009+
for (video::S3DVertex &vertex : pmb.vertices) {
1010+
video::SColor *c = &vertex.Color;
1011+
c->set(c->getAlpha(),
1012+
c->getRed() * tc.getRed() / 255,
1013+
c->getGreen() * tc.getGreen() / 255,
1014+
c->getBlue() * tc.getBlue() / 255);
1015+
}
1016+
}
1017+
10151018
/*
10161019
MapBlockMesh
10171020
*/
@@ -1061,7 +1064,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
10611064
Convert FastFaces to MeshCollector
10621065
*/
10631066

1064-
MeshCollector collector(m_use_tangent_vertices);
1067+
MeshCollector collector;
10651068

10661069
{
10671070
// avg 0ms (100ms spikes when loading textures the first time)
@@ -1071,15 +1074,9 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
10711074
for (const FastFace &f : fastfaces_new) {
10721075
static const u16 indices[] = {0, 1, 2, 2, 3, 0};
10731076
static const u16 indices_alternate[] = {0, 1, 3, 2, 3, 1};
1074-
1075-
if (!f.layer.texture)
1076-
continue;
1077-
10781077
const u16 *indices_p =
10791078
f.vertex_0_2_connected ? indices : indices_alternate;
1080-
1081-
collector.append(f.layer, f.vertices, 4, indices_p, 6,
1082-
f.layernum, f.world_aligned);
1079+
collector.append(f.tile, f.vertices, 4, indices_p, 6);
10831080
}
10841081
}
10851082

@@ -1096,8 +1093,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
10961093
generator.generate();
10971094
}
10981095

1099-
collector.applyTileColors();
1100-
11011096
/*
11021097
Convert MeshCollector to SMesh
11031098
*/
@@ -1107,6 +1102,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
11071102
{
11081103
PreMeshBuffer &p = collector.prebuffers[layer][i];
11091104

1105+
applyTileColor(p);
1106+
11101107
// Generate animation data
11111108
// - Cracks
11121109
if (p.layer.material_flags & MATERIAL_FLAG_CRACK) {
@@ -1151,16 +1148,10 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
11511148
// Dummy sunlight to handle non-sunlit areas
11521149
video::SColorf sunlight;
11531150
get_sunlight_color(&sunlight, 0);
1154-
u32 vertex_count = m_use_tangent_vertices ?
1155-
p.tangent_vertices.size() : p.vertices.size();
1151+
u32 vertex_count = p.vertices.size();
11561152
for (u32 j = 0; j < vertex_count; j++) {
1157-
video::SColor *vc;
1158-
if (m_use_tangent_vertices) {
1159-
vc = &p.tangent_vertices[j].Color;
1160-
} else {
1161-
vc = &p.vertices[j].Color;
1162-
}
1163-
video::SColor copy(*vc);
1153+
video::SColor *vc = &p.vertices[j].Color;
1154+
video::SColor copy = *vc;
11641155
if (vc->getAlpha() == 0) // No sunlight - no need to animate
11651156
final_color_blend(vc, copy, sunlight); // Finalize color
11661157
else // Record color to animate
@@ -1197,24 +1188,23 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
11971188
if (m_use_tangent_vertices) {
11981189
scene::SMeshBufferTangents *buf =
11991190
new scene::SMeshBufferTangents();
1200-
// Set material
12011191
buf->Material = material;
1202-
// Add to mesh
1192+
buf->Vertices.reallocate(p.vertices.size());
1193+
buf->Indices.reallocate(p.indices.size());
1194+
for (const video::S3DVertex &v: p.vertices)
1195+
buf->Vertices.push_back(video::S3DVertexTangents(v.Pos, v.Color, v.TCoords));
1196+
for (u16 i: p.indices)
1197+
buf->Indices.push_back(i);
1198+
buf->recalculateBoundingBox();
12031199
mesh->addMeshBuffer(buf);
1204-
// Mesh grabbed it
12051200
buf->drop();
1206-
buf->append(&p.tangent_vertices[0], p.tangent_vertices.size(),
1207-
&p.indices[0], p.indices.size());
12081201
} else {
12091202
scene::SMeshBuffer *buf = new scene::SMeshBuffer();
1210-
// Set material
12111203
buf->Material = material;
1212-
// Add to mesh
1213-
mesh->addMeshBuffer(buf);
1214-
// Mesh grabbed it
1215-
buf->drop();
12161204
buf->append(&p.vertices[0], p.vertices.size(),
12171205
&p.indices[0], p.indices.size());
1206+
mesh->addMeshBuffer(buf);
1207+
buf->drop();
12181208
}
12191209
}
12201210

@@ -1370,193 +1360,6 @@ void MapBlockMesh::updateCameraOffset(v3s16 camera_offset)
13701360
}
13711361
}
13721362

1373-
/*
1374-
MeshCollector
1375-
*/
1376-
1377-
void MeshCollector::append(const TileSpec &tile,
1378-
const video::S3DVertex *vertices, u32 numVertices,
1379-
const u16 *indices, u32 numIndices)
1380-
{
1381-
for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
1382-
const TileLayer *layer = &tile.layers[layernum];
1383-
if (layer->texture_id == 0)
1384-
continue;
1385-
append(*layer, vertices, numVertices, indices, numIndices,
1386-
layernum, tile.world_aligned);
1387-
}
1388-
}
1389-
1390-
void MeshCollector::append(const TileLayer &layer,
1391-
const video::S3DVertex *vertices, u32 numVertices,
1392-
const u16 *indices, u32 numIndices, u8 layernum,
1393-
bool use_scale)
1394-
{
1395-
if (numIndices > 65535) {
1396-
dstream << "FIXME: MeshCollector::append() called with numIndices="
1397-
<< numIndices << " (limit 65535)" << std::endl;
1398-
return;
1399-
}
1400-
std::vector<PreMeshBuffer> *buffers = &prebuffers[layernum];
1401-
1402-
PreMeshBuffer *p = NULL;
1403-
for (PreMeshBuffer &pp : *buffers) {
1404-
if (pp.layer == layer && pp.indices.size() + numIndices <= 65535) {
1405-
p = &pp;
1406-
break;
1407-
}
1408-
}
1409-
1410-
if (p == NULL) {
1411-
PreMeshBuffer pp;
1412-
pp.layer = layer;
1413-
buffers->push_back(pp);
1414-
p = &(*buffers)[buffers->size() - 1];
1415-
}
1416-
1417-
f32 scale = 1.0;
1418-
if (use_scale)
1419-
scale = 1.0 / layer.scale;
1420-
1421-
u32 vertex_count;
1422-
if (m_use_tangent_vertices) {
1423-
vertex_count = p->tangent_vertices.size();
1424-
for (u32 i = 0; i < numVertices; i++) {
1425-
1426-
video::S3DVertexTangents vert(vertices[i].Pos, vertices[i].Normal,
1427-
vertices[i].Color, scale * vertices[i].TCoords);
1428-
p->tangent_vertices.push_back(vert);
1429-
}
1430-
} else {
1431-
vertex_count = p->vertices.size();
1432-
for (u32 i = 0; i < numVertices; i++) {
1433-
video::S3DVertex vert(vertices[i].Pos, vertices[i].Normal,
1434-
vertices[i].Color, scale * vertices[i].TCoords);
1435-
1436-
p->vertices.push_back(vert);
1437-
}
1438-
}
1439-
1440-
for (u32 i = 0; i < numIndices; i++) {
1441-
u32 j = indices[i] + vertex_count;
1442-
p->indices.push_back(j);
1443-
}
1444-
}
1445-
1446-
/*
1447-
MeshCollector - for meshnodes and converted drawtypes.
1448-
*/
1449-
1450-
void MeshCollector::append(const TileSpec &tile,
1451-
const video::S3DVertex *vertices, u32 numVertices,
1452-
const u16 *indices, u32 numIndices,
1453-
v3f pos, video::SColor c, u8 light_source)
1454-
{
1455-
for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
1456-
const TileLayer *layer = &tile.layers[layernum];
1457-
if (layer->texture_id == 0)
1458-
continue;
1459-
append(*layer, vertices, numVertices, indices, numIndices, pos,
1460-
c, light_source, layernum, tile.world_aligned);
1461-
}
1462-
}
1463-
1464-
void MeshCollector::append(const TileLayer &layer,
1465-
const video::S3DVertex *vertices, u32 numVertices,
1466-
const u16 *indices, u32 numIndices,
1467-
v3f pos, video::SColor c, u8 light_source, u8 layernum,
1468-
bool use_scale)
1469-
{
1470-
if (numIndices > 65535) {
1471-
dstream << "FIXME: MeshCollector::append() called with numIndices="
1472-
<< numIndices << " (limit 65535)" << std::endl;
1473-
return;
1474-
}
1475-
std::vector<PreMeshBuffer> *buffers = &prebuffers[layernum];
1476-
1477-
PreMeshBuffer *p = NULL;
1478-
for (PreMeshBuffer &pp : *buffers) {
1479-
if (pp.layer == layer && pp.indices.size() + numIndices <= 65535) {
1480-
p = &pp;
1481-
break;
1482-
}
1483-
}
1484-
1485-
if (p == NULL) {
1486-
PreMeshBuffer pp;
1487-
pp.layer = layer;
1488-
buffers->push_back(pp);
1489-
p = &(*buffers)[buffers->size() - 1];
1490-
}
1491-
1492-
f32 scale = 1.0;
1493-
if (use_scale)
1494-
scale = 1.0 / layer.scale;
1495-
1496-
video::SColor original_c = c;
1497-
u32 vertex_count;
1498-
if (m_use_tangent_vertices) {
1499-
vertex_count = p->tangent_vertices.size();
1500-
for (u32 i = 0; i < numVertices; i++) {
1501-
if (!light_source) {
1502-
c = original_c;
1503-
applyFacesShading(c, vertices[i].Normal);
1504-
}
1505-
video::S3DVertexTangents vert(vertices[i].Pos + pos,
1506-
vertices[i].Normal, c, scale * vertices[i].TCoords);
1507-
p->tangent_vertices.push_back(vert);
1508-
}
1509-
} else {
1510-
vertex_count = p->vertices.size();
1511-
for (u32 i = 0; i < numVertices; i++) {
1512-
if (!light_source) {
1513-
c = original_c;
1514-
applyFacesShading(c, vertices[i].Normal);
1515-
}
1516-
video::S3DVertex vert(vertices[i].Pos + pos, vertices[i].Normal, c,
1517-
scale * vertices[i].TCoords);
1518-
p->vertices.push_back(vert);
1519-
}
1520-
}
1521-
1522-
for (u32 i = 0; i < numIndices; i++) {
1523-
u32 j = indices[i] + vertex_count;
1524-
p->indices.push_back(j);
1525-
}
1526-
}
1527-
1528-
void MeshCollector::applyTileColors()
1529-
{
1530-
if (m_use_tangent_vertices)
1531-
for (auto &prebuffer : prebuffers) {
1532-
for (PreMeshBuffer &pmb : prebuffer) {
1533-
video::SColor tc = pmb.layer.color;
1534-
if (tc == video::SColor(0xFFFFFFFF))
1535-
continue;
1536-
for (video::S3DVertexTangents &tangent_vertex : pmb.tangent_vertices) {
1537-
video::SColor *c = &tangent_vertex.Color;
1538-
c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255,
1539-
c->getGreen() * tc.getGreen() / 255,
1540-
c->getBlue() * tc.getBlue() / 255);
1541-
}
1542-
}
1543-
}
1544-
else
1545-
for (auto &prebuffer : prebuffers) {
1546-
for (PreMeshBuffer &pmb : prebuffer) {
1547-
video::SColor tc = pmb.layer.color;
1548-
if (tc == video::SColor(0xFFFFFFFF))
1549-
continue;
1550-
for (video::S3DVertex &vertex : pmb.vertices) {
1551-
video::SColor *c = &vertex.Color;
1552-
c->set(c->getAlpha(), c->getRed() * tc.getRed() / 255,
1553-
c->getGreen() * tc.getGreen() / 255,
1554-
c->getBlue() * tc.getBlue() / 255);
1555-
}
1556-
}
1557-
}
1558-
}
1559-
15601363
video::SColor encode_light(u16 light, u8 emissive_light)
15611364
{
15621365
// Get components

Diff for: ‎src/mapblock_mesh.h

-45
Original file line numberDiff line numberDiff line change
@@ -173,51 +173,6 @@ class MapBlockMesh
173173
v3s16 m_camera_offset;
174174
};
175175

176-
177-
178-
/*
179-
This is used because CMeshBuffer::append() is very slow
180-
*/
181-
struct PreMeshBuffer
182-
{
183-
TileLayer layer;
184-
std::vector<u16> indices;
185-
std::vector<video::S3DVertex> vertices;
186-
std::vector<video::S3DVertexTangents> tangent_vertices;
187-
};
188-
189-
struct MeshCollector
190-
{
191-
std::array<std::vector<PreMeshBuffer>, MAX_TILE_LAYERS> prebuffers;
192-
bool m_use_tangent_vertices;
193-
194-
MeshCollector(bool use_tangent_vertices):
195-
m_use_tangent_vertices(use_tangent_vertices)
196-
{
197-
}
198-
199-
void append(const TileSpec &material,
200-
const video::S3DVertex *vertices, u32 numVertices,
201-
const u16 *indices, u32 numIndices);
202-
void append(const TileLayer &material,
203-
const video::S3DVertex *vertices, u32 numVertices,
204-
const u16 *indices, u32 numIndices, u8 layernum,
205-
bool use_scale = false);
206-
void append(const TileSpec &material,
207-
const video::S3DVertex *vertices, u32 numVertices,
208-
const u16 *indices, u32 numIndices, v3f pos,
209-
video::SColor c, u8 light_source);
210-
void append(const TileLayer &material,
211-
const video::S3DVertex *vertices, u32 numVertices,
212-
const u16 *indices, u32 numIndices, v3f pos,
213-
video::SColor c, u8 light_source, u8 layernum,
214-
bool use_scale = false);
215-
/*!
216-
* Colorizes all vertices in the collector.
217-
*/
218-
void applyTileColors();
219-
};
220-
221176
/*!
222177
* Encodes light of a node.
223178
* The result is not the final color, but a

Diff for: ‎src/wieldmesh.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2727
#include "mesh.h"
2828
#include "content_mapblock.h"
2929
#include "mapblock_mesh.h"
30+
#include "client/meshgen/collector.h"
3031
#include "client/tile.h"
3132
#include "log.h"
3233
#include "util/numeric.h"
@@ -304,7 +305,7 @@ void WieldMeshSceneNode::setExtruded(const std::string &imagename,
304305
scene::SMesh *createSpecialNodeMesh(Client *client, content_t id, std::vector<ItemPartColor> *colors)
305306
{
306307
MeshMakeData mesh_make_data(client, false, false);
307-
MeshCollector collector(false);
308+
MeshCollector collector;
308309
mesh_make_data.setSmoothLighting(false);
309310
MapblockMeshGenerator gen(&mesh_make_data, &collector);
310311
gen.renderSingle(id);

0 commit comments

Comments
 (0)
Please sign in to comment.