Blender V4.3
scene/mesh.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __MESH_H__
6#define __MESH_H__
7
8#include "graph/node.h"
9
10#include "bvh/params.h"
11#include "scene/attribute.h"
12#include "scene/geometry.h"
13#include "scene/shader.h"
14
15#include "util/array.h"
16#include "util/boundbox.h"
17#include "util/list.h"
18#include "util/map.h"
19#include "util/param.h"
20#include "util/set.h"
21#include "util/types.h"
22#include "util/vector.h"
23
25
26class Attribute;
27class BVH;
28class Device;
29class DeviceScene;
30class Mesh;
31class Progress;
32class RenderStats;
33class Scene;
34class SceneParams;
36struct SubdParams;
37class DiagSplit;
38struct PackedPatchTable;
39
40/* Mesh */
41
42class Mesh : public Geometry {
43 protected:
44 Mesh(const NodeType *node_type_, Type geom_type_);
45
46 public:
48
49 /* Mesh Triangle */
50 struct Triangle {
51 int v[3];
52
53 void bounds_grow(const float3 *verts, BoundBox &bounds) const;
54
55 void motion_verts(const float3 *verts,
56 const float3 *vert_steps,
57 size_t num_verts,
58 size_t num_steps,
59 float time,
60 float3 r_verts[3]) const;
61
62 void verts_for_step(const float3 *verts,
63 const float3 *vert_steps,
64 size_t num_verts,
65 size_t num_steps,
66 size_t step,
67 float3 r_verts[3]) const;
68
69 float3 compute_normal(const float3 *verts) const;
70
71 bool valid(const float3 *verts) const;
72 };
73
74 Triangle get_triangle(size_t i) const
75 {
76 Triangle tri = {{triangles[i * 3 + 0], triangles[i * 3 + 1], triangles[i * 3 + 2]}};
77 return tri;
78 }
79
80 size_t num_triangles() const
81 {
82 return triangles.size() / 3;
83 }
84
85 /* Mesh SubdFace */
86 struct SubdFace {
89 int shader;
90 bool smooth;
92
93 bool is_quad()
94 {
95 return num_corners == 4;
96 }
97 float3 normal(const Mesh *mesh) const;
98 int num_ptex_faces() const
99 {
100 return num_corners == 4 ? 1 : num_corners;
101 }
102 };
103
105 int v[2];
106 float crease;
107 };
108
110 {
112 s.v[0] = subd_creases_edge[i * 2];
113 s.v[1] = subd_creases_edge[i * 2 + 1];
114 s.crease = subd_creases_weight[i];
115 return s;
116 }
117
118 bool need_tesselation();
119
125
126 NODE_SOCKET_API(SubdivisionType, subdivision_type)
127
128 /* Mesh Data */
133
134 /* used for storing patch info for subd triangles, only allocated if there are patches */
135 NODE_SOCKET_API_ARRAY(array<int>, triangle_patch) /* must be < 0 for non subd triangles */
137
138 /* SubdFaces */
139 NODE_SOCKET_API_ARRAY(array<int>, subd_start_corner)
140 NODE_SOCKET_API_ARRAY(array<int>, subd_num_corners)
143 NODE_SOCKET_API_ARRAY(array<int>, subd_ptex_offset)
144
145 NODE_SOCKET_API_ARRAY(array<int>, subd_face_corners)
146 NODE_SOCKET_API(int, num_ngons)
147
148 NODE_SOCKET_API_ARRAY(array<int>, subd_creases_edge)
149 NODE_SOCKET_API_ARRAY(array<float>, subd_creases_weight)
150
151 NODE_SOCKET_API_ARRAY(array<int>, subd_vert_creases)
152 NODE_SOCKET_API_ARRAY(array<float>, subd_vert_creases_weight)
153
154 /* Subdivisions parameters */
155 NODE_SOCKET_API(float, subd_dicing_rate)
156 NODE_SOCKET_API(int, subd_max_level)
157 NODE_SOCKET_API(Transform, subd_objecttoworld)
158
160
161 private:
162 PackedPatchTable *patch_table;
163 /* BVH */
164 size_t vert_offset;
165
166 size_t patch_offset;
167 size_t patch_table_offset;
168 size_t face_offset;
169 size_t corner_offset;
170
171 size_t num_subd_verts;
172 size_t num_subd_faces;
173
174 unordered_map<int, int> vert_to_stitching_key_map; /* real vert index -> stitching index */
175 unordered_multimap<int, int>
176 vert_stitching_map; /* stitching index -> multiple real vert indices */
177
178 friend class BVH2;
179 friend class BVHBuild;
180 friend class BVHSpatialSplit;
181 friend class DiagSplit;
182 friend class EdgeDice;
183 friend class GeometryManager;
184 friend class ObjectManager;
185
186 SubdParams *subd_params = nullptr;
187
188 public:
189 /* Functions */
190 Mesh();
191 ~Mesh();
192
193 void resize_mesh(int numverts, int numfaces);
194 void reserve_mesh(int numverts, int numfaces);
195 void resize_subd_faces(int numfaces, int num_ngons, int numcorners);
196 void reserve_subd_faces(int numfaces, int num_ngons, int numcorners);
197 void reserve_subd_creases(size_t num_creases);
198 void clear_non_sockets();
199 void clear(bool preserve_shaders = false) override;
200 void add_vertex(float3 P);
202 void add_triangle(int v0, int v1, int v2, int shader, bool smooth);
203 void add_subd_face(const int *corners, int num_corners, int shader_, bool smooth_);
204 void add_edge_crease(int v0, int v1, float weight);
205 void add_vertex_crease(int v, float weight);
206
208
210 void apply_transform(const Transform &tfm, const bool apply_to_motion) override;
211 void add_face_normals();
212 void add_vertex_normals();
213 void add_undisplaced();
214
215 void get_uv_tiles(ustring map, unordered_set<int> &tiles) override;
216
217 void pack_shaders(Scene *scene, uint *shader);
218 void pack_normals(packed_float3 *vnormal);
219 void pack_verts(packed_float3 *tri_verts,
220 packed_uint3 *tri_vindex,
221 uint *tri_patch,
222 float2 *tri_patch_uv);
223 void pack_patches(uint *patch_data);
224
226
227 void tessellate(DiagSplit *split);
228
229 SubdFace get_subd_face(size_t index) const;
230
232
233 size_t get_num_subd_faces() const
234 {
235 return num_subd_faces;
236 }
237
238 void set_num_subd_faces(size_t num_subd_faces_)
239 {
240 num_subd_faces = num_subd_faces_;
241 }
242
244 {
245 return num_subd_verts;
246 }
247
248 protected:
249 void clear(bool preserve_shaders, bool preserve_voxel_data);
250};
251
253
254#endif /* __MESH_H__ */
unsigned int uint
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
Definition bvh2.h:36
Definition bvh/bvh.h:66
BoundBox bounds
int motion_step(float time) const
#define CCL_NAMESPACE_END
static float verts[][3]
#define NODE_SOCKET_API_ARRAY(type_, name)
Definition graph/node.h:63
#define NODE_SOCKET_API(type_, name)
Definition graph/node.h:55
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
PrimitiveType
#define NODE_DECLARE
Definition node_type.h:142
int num_ptex_faces() const
Definition scene/mesh.h:98
float3 normal(const Mesh *mesh) const
bool valid(const float3 *verts) const
void motion_verts(const float3 *verts, const float3 *vert_steps, size_t num_verts, size_t num_steps, float time, float3 r_verts[3]) const
void verts_for_step(const float3 *verts, const float3 *vert_steps, size_t num_verts, size_t num_steps, size_t step, float3 r_verts[3]) const
void bounds_grow(const float3 *verts, BoundBox &bounds) const
float3 compute_normal(const float3 *verts) const
void tessellate(DiagSplit *split)
SubdParams * get_subd_params()
void reserve_subd_faces(int numfaces, int num_ngons, int numcorners)
size_t get_num_subd_faces() const
Definition scene/mesh.h:233
void add_edge_crease(int v0, int v1, float weight)
void reserve_subd_creases(size_t num_creases)
void add_undisplaced()
void compute_bounds() override
void add_vertex_normals()
AttributeSet subd_attributes
Definition scene/mesh.h:159
Triangle get_triangle(size_t i) const
Definition scene/mesh.h:74
void copy_center_to_motion_step(const int motion_step)
void clear(bool preserve_shaders=false) override
void resize_subd_faces(int numfaces, int num_ngons, int numcorners)
void pack_patches(uint *patch_data)
void pack_verts(packed_float3 *tri_verts, packed_uint3 *tri_vindex, uint *tri_patch, float2 *tri_patch_uv)
void reserve_mesh(int numverts, int numfaces)
void add_vertex_slow(float3 P)
bool need_tesselation()
SubdivisionType
Definition scene/mesh.h:120
@ SUBDIVISION_NONE
Definition scene/mesh.h:121
@ SUBDIVISION_LINEAR
Definition scene/mesh.h:122
@ SUBDIVISION_CATMULL_CLARK
Definition scene/mesh.h:123
size_t num_triangles() const
Definition scene/mesh.h:80
void clear_non_sockets()
void set_num_subd_faces(size_t num_subd_faces_)
Definition scene/mesh.h:238
void pack_normals(packed_float3 *vnormal)
void add_vertex(float3 P)
SubdEdgeCrease get_subd_crease(size_t i) const
Definition scene/mesh.h:109
void get_uv_tiles(ustring map, unordered_set< int > &tiles) override
void add_vertex_crease(int v, float weight)
void add_triangle(int v0, int v1, int v2, int shader, bool smooth)
SubdFace get_subd_face(size_t index) const
void pack_shaders(Scene *scene, uint *shader)
PrimitiveType primitive_type() const override
void resize_mesh(int numverts, int numfaces)
void add_subd_face(const int *corners, int num_corners, int shader_, bool smooth_)
void add_face_normals()
void apply_transform(const Transform &tfm, const bool apply_to_motion) override
size_t get_num_subd_verts()
Definition scene/mesh.h:243
bool override
Definition wm_files.cc:1167