]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/mesh.h
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / client / mesh.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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
22 #include "irrlichttypes_extrabloated.h"
23 #include "nodedef.h"
24
25 /*!
26  * Applies shading to a color based on the surface's
27  * normal vector.
28  */
29 void applyFacesShading(video::SColor &color, const v3f &normal);
30
31 /*
32         Create a new cube mesh.
33         Vertices are at (+-scale.X/2, +-scale.Y/2, +-scale.Z/2).
34
35         The resulting mesh has 6 materials (up, down, right, left, back, front)
36         which must be defined by the caller.
37 */
38 scene::IAnimatedMesh* createCubeMesh(v3f scale);
39
40 /*
41         Multiplies each vertex coordinate by the specified scaling factors
42         (componentwise vector multiplication).
43 */
44 void scaleMesh(scene::IMesh *mesh, v3f scale);
45
46 /*
47         Translate each vertex coordinate by the specified vector.
48 */
49 void translateMesh(scene::IMesh *mesh, v3f vec);
50
51 /*!
52  * Sets a constant color for all vertices in the mesh buffer.
53  */
54 void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color);
55
56 /*
57         Set a constant color for all vertices in the mesh
58 */
59 void setMeshColor(scene::IMesh *mesh, const video::SColor &color);
60
61
62 /*
63         Sets texture coords for vertices in the mesh buffer.
64         `uv[]` must have `count` elements
65 */
66 void setMeshBufferTextureCoords(scene::IMeshBuffer *buf, const v2f *uv, u32 count);
67
68 /*
69         Set a constant color for an animated mesh
70 */
71 void setAnimatedMeshColor(scene::IAnimatedMeshSceneNode *node, const video::SColor &color);
72
73 /*!
74  * Overwrites the color of a mesh buffer.
75  * The color is darkened based on the normal vector of the vertices.
76  */
77 void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor);
78
79 /*
80         Set the color of all vertices in the mesh.
81         For each vertex, determine the largest absolute entry in
82         the normal vector, and choose one of colorX, colorY or
83         colorZ accordingly.
84 */
85 void setMeshColorByNormalXYZ(scene::IMesh *mesh,
86                 const video::SColor &colorX,
87                 const video::SColor &colorY,
88                 const video::SColor &colorZ);
89
90 void setMeshColorByNormal(scene::IMesh *mesh, const v3f &normal,
91                 const video::SColor &color);
92
93 /*
94         Rotate the mesh by 6d facedir value.
95         Method only for meshnodes, not suitable for entities.
96 */
97 void rotateMeshBy6dFacedir(scene::IMesh *mesh, int facedir);
98
99 /*
100         Rotate the mesh around the axis and given angle in degrees.
101 */
102 void rotateMeshXYby (scene::IMesh *mesh, f64 degrees);
103 void rotateMeshXZby (scene::IMesh *mesh, f64 degrees);
104 void rotateMeshYZby (scene::IMesh *mesh, f64 degrees);
105
106 /*
107  *  Clone the mesh buffer.
108  *  The returned pointer should be dropped.
109  */
110 scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer);
111
112 /*
113         Clone the mesh.
114 */
115 scene::SMesh* cloneMesh(scene::IMesh *src_mesh);
116
117 /*
118         Convert nodeboxes to mesh. Each tile goes into a different buffer.
119         boxes - set of nodeboxes to be converted into cuboids
120         uv_coords[24] - table of texture uv coords for each cuboid face
121         expand - factor by which cuboids will be resized
122 */
123 scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
124                 const f32 *uv_coords = NULL, float expand = 0);
125
126 /*
127         Update bounding box for a mesh.
128 */
129 void recalculateBoundingBox(scene::IMesh *src_mesh);
130
131 /*
132         Check if mesh has valid normals and return true if it does.
133         We assume normal to be valid when it's 0 < length < Inf. and not NaN
134  */
135 bool checkMeshNormals(scene::IMesh *mesh);
136
137 /*
138         Vertex cache optimization according to the Forsyth paper:
139         http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
140         Ported from irrlicht 1.8
141 */
142 scene::IMesh* createForsythOptimizedMesh(const scene::IMesh *mesh);