Minetest 5.10.0-dev
 
Loading...
Searching...
No Matches
mesh.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include "SMaterialLayer.h"
24#include "nodedef.h"
25
30void applyFacesShading(video::SColor &color, const v3f &normal);
31
32/*
33 Create a new cube mesh.
34 Vertices are at (+-scale.X/2, +-scale.Y/2, +-scale.Z/2).
35
36 The resulting mesh has 6 materials (up, down, right, left, back, front)
37 which must be defined by the caller.
38*/
39scene::IAnimatedMesh* createCubeMesh(v3f scale);
40
41/*
42 Multiplies each vertex coordinate by the specified scaling factors
43 (componentwise vector multiplication).
44*/
45void scaleMesh(scene::IMesh *mesh, v3f scale);
46
47/*
48 Translate each vertex coordinate by the specified vector.
49*/
50void translateMesh(scene::IMesh *mesh, v3f vec);
51
55void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color);
56
57/*
58 Set a constant color for all vertices in the mesh
59*/
60void setMeshColor(scene::IMesh *mesh, const video::SColor &color);
61
62
63/*
64 Sets texture coords for vertices in the mesh buffer.
65 `uv[]` must have `count` elements
66*/
67void setMeshBufferTextureCoords(scene::IMeshBuffer *buf, const v2f *uv, u32 count);
68
69/*
70 Set a constant color for an animated mesh
71*/
72void setAnimatedMeshColor(scene::IAnimatedMeshSceneNode *node, const video::SColor &color);
73
78void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor);
79
80/*
81 Set the color of all vertices in the mesh.
82 For each vertex, determine the largest absolute entry in
83 the normal vector, and choose one of colorX, colorY or
84 colorZ accordingly.
85*/
86void setMeshColorByNormalXYZ(scene::IMesh *mesh,
87 const video::SColor &colorX,
88 const video::SColor &colorY,
89 const video::SColor &colorZ);
90
91void setMeshColorByNormal(scene::IMesh *mesh, const v3f &normal,
92 const video::SColor &color);
93
94/*
95 Rotate the mesh by 6d facedir value.
96 Method only for meshnodes, not suitable for entities.
97*/
98void rotateMeshBy6dFacedir(scene::IMesh *mesh, int facedir);
99
100/*
101 Rotate the mesh around the axis and given angle in degrees.
102*/
103void rotateMeshXYby (scene::IMesh *mesh, f64 degrees);
104void rotateMeshXZby (scene::IMesh *mesh, f64 degrees);
105void rotateMeshYZby (scene::IMesh *mesh, f64 degrees);
106
107/*
108 * Clone the mesh buffer.
109 * The returned pointer should be dropped.
110 */
111scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer);
112
113/*
114 Clone the mesh.
115*/
116scene::SMesh* cloneMesh(scene::IMesh *src_mesh);
117
118/*
119 Convert nodeboxes to mesh. Each tile goes into a different buffer.
120 boxes - set of nodeboxes to be converted into cuboids
121 uv_coords[24] - table of texture uv coords for each cuboid face
122 expand - factor by which cuboids will be resized
123*/
124scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
125 const f32 *uv_coords = NULL, float expand = 0);
126
127/*
128 Update bounding box for a mesh.
129*/
130void recalculateBoundingBox(scene::IMesh *src_mesh);
131
132/*
133 Check if mesh has valid normals and return true if it does.
134 We assume normal to be valid when it's 0 < length < Inf. and not NaN
135 */
136bool checkMeshNormals(scene::IMesh *mesh);
137
138/*
139 Set the MinFilter, MagFilter and AnisotropicFilter properties of a texture
140 layer according to the three relevant boolean values found in the Minetest
141 settings.
142*/
143void setMaterialFilters(video::SMaterialLayer &tex, bool bilinear, bool trilinear, bool anisotropic);
core::vector2d< f32 > v2f
Definition irr_v2d.h:26
core::vector3df v3f
Definition irr_v3d.h:26
scene::SMesh * cloneMesh(scene::IMesh *src_mesh)
Definition mesh.cpp:393
void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
Definition mesh.cpp:190
void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor)
Definition mesh.cpp:223
void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color)
Definition mesh.cpp:174
void rotateMeshXYby(scene::IMesh *mesh, f64 degrees)
Definition mesh.cpp:286
scene::IAnimatedMesh * createCubeMesh(v3f scale)
Definition mesh.cpp:56
scene::IMeshBuffer * cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer)
Definition mesh.cpp:356
void setAnimatedMeshColor(scene::IAnimatedMeshSceneNode *node, const video::SColor &color)
Definition mesh.cpp:183
void setMaterialFilters(video::SMaterialLayer &tex, bool bilinear, bool trilinear, bool anisotropic)
Definition mesh.cpp:509
void setMeshBufferTextureCoords(scene::IMeshBuffer *buf, const v2f *uv, u32 count)
Definition mesh.cpp:200
void applyFacesShading(video::SColor &color, const v3f &normal)
Definition mesh.cpp:36
void translateMesh(scene::IMesh *mesh, v3f vec)
Definition mesh.cpp:146
void rotateMeshXZby(scene::IMesh *mesh, f64 degrees)
Definition mesh.cpp:291
void rotateMeshYZby(scene::IMesh *mesh, f64 degrees)
Definition mesh.cpp:296
void rotateMeshBy6dFacedir(scene::IMesh *mesh, int facedir)
Definition mesh.cpp:301
void setMeshColorByNormalXYZ(scene::IMesh *mesh, const video::SColor &colorX, const video::SColor &colorY, const video::SColor &colorZ)
Definition mesh.cpp:238
bool checkMeshNormals(scene::IMesh *mesh)
Definition mesh.cpp:334
void recalculateBoundingBox(scene::IMesh *src_mesh)
Definition mesh.cpp:319
scene::IMesh * convertNodeboxesToMesh(const std::vector< aabb3f > &boxes, const f32 *uv_coords=NULL, float expand=0)
Definition mesh.cpp:406
void scaleMesh(scene::IMesh *mesh, v3f scale)
Definition mesh.cpp:118
void setMeshColorByNormal(scene::IMesh *mesh, const v3f &normal, const video::SColor &color)
Definition mesh.cpp:259