Blender  V2.93
mesh.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __MESH_H__
18 #define __MESH_H__
19 
20 #include "graph/node.h"
21 
22 #include "bvh/bvh_params.h"
23 #include "render/attribute.h"
24 #include "render/geometry.h"
25 #include "render/shader.h"
26 
27 #include "util/util_array.h"
28 #include "util/util_boundbox.h"
29 #include "util/util_list.h"
30 #include "util/util_map.h"
31 #include "util/util_param.h"
32 #include "util/util_set.h"
33 #include "util/util_types.h"
34 #include "util/util_vector.h"
35 
37 
38 class Attribute;
39 class BVH;
40 class Device;
41 class DeviceScene;
42 class Mesh;
43 class Progress;
44 class RenderStats;
45 class Scene;
46 class SceneParams;
47 class AttributeRequest;
48 struct SubdParams;
49 class DiagSplit;
50 struct PackedPatchTable;
51 
52 /* Mesh */
53 
54 class Mesh : public Geometry {
55  protected:
56  Mesh(const NodeType *node_type_, Type geom_type_);
57 
58  public:
60 
61  /* Mesh Triangle */
62  struct Triangle {
63  int v[3];
64 
65  void bounds_grow(const float3 *verts, BoundBox &bounds) const;
66 
67  void motion_verts(const float3 *verts,
68  const float3 *vert_steps,
69  size_t num_verts,
70  size_t num_steps,
71  float time,
72  float3 r_verts[3]) const;
73 
74  void verts_for_step(const float3 *verts,
75  const float3 *vert_steps,
76  size_t num_verts,
77  size_t num_steps,
78  size_t step,
79  float3 r_verts[3]) const;
80 
81  float3 compute_normal(const float3 *verts) const;
82 
83  bool valid(const float3 *verts) const;
84  };
85 
86  Triangle get_triangle(size_t i) const
87  {
88  Triangle tri = {{triangles[i * 3 + 0], triangles[i * 3 + 1], triangles[i * 3 + 2]}};
89  return tri;
90  }
91 
92  size_t num_triangles() const
93  {
94  return triangles.size() / 3;
95  }
96 
97  /* Mesh SubdFace */
98  struct SubdFace {
101  int shader;
102  bool smooth;
104 
105  bool is_quad()
106  {
107  return num_corners == 4;
108  }
109  float3 normal(const Mesh *mesh) const;
110  int num_ptex_faces() const
111  {
112  return num_corners == 4 ? 1 : num_corners;
113  }
114  };
115 
116  struct SubdEdgeCrease {
117  int v[2];
118  float crease;
119  };
120 
122  {
123  SubdEdgeCrease s;
124  s.v[0] = subd_creases_edge[i * 2];
125  s.v[1] = subd_creases_edge[i * 2 + 1];
126  s.crease = subd_creases_weight[i];
127  return s;
128  }
129 
130  bool need_tesselation();
131 
136  };
137 
138  NODE_SOCKET_API(SubdivisionType, subdivision_type)
139 
140  /* Mesh Data */
145 
146  /* used for storing patch info for subd triangles, only allocated if there are patches */
147  NODE_SOCKET_API_ARRAY(array<int>, triangle_patch) /* must be < 0 for non subd triangles */
148  NODE_SOCKET_API_ARRAY(array<float2>, vert_patch_uv)
149 
150  /* SubdFaces */
151  NODE_SOCKET_API_ARRAY(array<int>, subd_start_corner)
152  NODE_SOCKET_API_ARRAY(array<int>, subd_num_corners)
153  NODE_SOCKET_API_ARRAY(array<int>, subd_shader)
154  NODE_SOCKET_API_ARRAY(array<bool>, subd_smooth)
155  NODE_SOCKET_API_ARRAY(array<int>, subd_ptex_offset)
156 
157  NODE_SOCKET_API_ARRAY(array<int>, subd_face_corners)
158  NODE_SOCKET_API(int, num_ngons)
159 
160  NODE_SOCKET_API_ARRAY(array<int>, subd_creases_edge)
161  NODE_SOCKET_API_ARRAY(array<float>, subd_creases_weight)
162 
163  /* Subdivisions parameters */
164  NODE_SOCKET_API(float, subd_dicing_rate)
165  NODE_SOCKET_API(int, subd_max_level)
166  NODE_SOCKET_API(Transform, subd_objecttoworld)
167 
168  AttributeSet subd_attributes;
169 
170  private:
171  PackedPatchTable *patch_table;
172  /* BVH */
173  size_t vert_offset;
174 
175  size_t patch_offset;
176  size_t patch_table_offset;
177  size_t face_offset;
178  size_t corner_offset;
179 
180  size_t num_subd_verts;
181  size_t num_subd_faces;
182 
183  unordered_map<int, int> vert_to_stitching_key_map; /* real vert index -> stitching index */
184  unordered_multimap<int, int>
185  vert_stitching_map; /* stitching index -> multiple real vert indices */
186 
187  friend class BVH2;
188  friend class BVHBuild;
189  friend class BVHSpatialSplit;
190  friend class DiagSplit;
191  friend class EdgeDice;
192  friend class GeometryManager;
193  friend class ObjectManager;
194 
195  SubdParams *subd_params = nullptr;
196 
197  public:
198  /* Functions */
199  Mesh();
200  ~Mesh();
201 
202  void resize_mesh(int numverts, int numfaces);
203  void reserve_mesh(int numverts, int numfaces);
204  void resize_subd_faces(int numfaces, int num_ngons, int numcorners);
205  void reserve_subd_faces(int numfaces, int num_ngons, int numcorners);
206  void reserve_subd_creases(size_t num_creases);
207  void clear_non_sockets();
208  void clear(bool preserve_shaders = false) override;
209  void add_vertex(float3 P);
210  void add_vertex_slow(float3 P);
211  void add_triangle(int v0, int v1, int v2, int shader, bool smooth);
212  void add_subd_face(int *corners, int num_corners, int shader_, bool smooth_);
213  void add_crease(int v0, int v1, float weight);
214 
215  void copy_center_to_motion_step(const int motion_step);
216 
217  void compute_bounds() override;
218  void apply_transform(const Transform &tfm, const bool apply_to_motion) override;
219  void add_face_normals();
220  void add_vertex_normals();
221  void add_undisplaced();
222 
223  void get_uv_tiles(ustring map, unordered_set<int> &tiles) override;
224 
226  void pack_normals(float4 *vnormal);
227  void pack_verts(const vector<uint> &tri_prim_index,
228  uint4 *tri_vindex,
229  uint *tri_patch,
230  float2 *tri_patch_uv,
231  size_t vert_offset,
232  size_t tri_offset);
233  void pack_patches(uint *patch_data, uint vert_offset, uint face_offset, uint corner_offset);
234 
235  void pack_primitives(PackedBVH *pack,
236  int object,
237  uint visibility,
238  PackFlags pack_flags) override;
239 
240  void tessellate(DiagSplit *split);
241 
242  SubdFace get_subd_face(size_t index) const;
243 
245 
246  size_t get_num_subd_faces() const
247  {
248  return num_subd_faces;
249  }
250 
251  void set_num_subd_faces(size_t num_subd_faces_)
252  {
253  num_subd_faces = num_subd_faces_;
254  }
255 
257  {
258  return num_subd_verts;
259  }
260 
261  protected:
262  void clear(bool preserve_shaders, bool preserve_voxel_data);
263 };
264 
266 
267 #endif /* __MESH_H__ */
unsigned int uint
Definition: BLI_sys_types.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v2
Definition: bvh2.h:46
Definition: bvh/bvh.h:80
Definition: device.h:293
BoundBox bounds
Definition: geometry.h:87
size_t index
Definition: geometry.h:114
int motion_step(float time) const
Definition: geometry.cpp:150
double time
Scene scene
static float verts[][3]
PackFlags
Definition: geometry.h:47
#define CCL_NAMESPACE_END
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
static float P(float k)
Definition: math_interp.c:41
static void vnormal(PROCESS *process, const float point[3], float r_no[3])
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition: abc_util.cc:115
#define NODE_SOCKET_API(type_, name)
Definition: node.h:63
#define NODE_DECLARE
Definition: node_type.h:148
int num_ptex_faces() const
Definition: mesh.h:110
int ptex_offset
Definition: mesh.h:103
int start_corner
Definition: mesh.h:99
bool smooth
Definition: mesh.h:102
int num_corners
Definition: mesh.h:100
int shader
Definition: mesh.h:101
bool is_quad()
Definition: mesh.h:105
float3 normal(const Mesh *mesh) const
Definition: mesh.cpp:115
bool valid(const float3 *verts) const
Definition: mesh.cpp:108
int v[3]
Definition: mesh.h:63
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
Definition: mesh.cpp:47
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
Definition: mesh.cpp:69
void bounds_grow(const float3 *verts, BoundBox &bounds) const
Definition: mesh.cpp:40
float3 compute_normal(const float3 *verts) const
Definition: mesh.cpp:95
void pack_primitives(PackedBVH *pack, int object, uint visibility, PackFlags pack_flags) override
Definition: mesh.cpp:808
void tessellate(DiagSplit *split)
SubdParams * get_subd_params()
Definition: mesh.cpp:162
void reserve_subd_faces(int numfaces, int num_ngons, int numcorners)
Definition: mesh.cpp:260
NODE_SOCKET_API_ARRAY(array< int >, triangle_patch) AttributeSet subd_attributes
size_t get_num_subd_faces() const
Definition: mesh.h:246
Mesh()
Definition: mesh.cpp:205
void reserve_subd_creases(size_t num_creases)
Definition: mesh.cpp:274
void add_undisplaced()
Definition: mesh.cpp:656
void compute_bounds() override
Definition: mesh.cpp:460
void add_vertex_normals()
Definition: mesh.cpp:565
Triangle get_triangle(size_t i) const
Definition: mesh.h:86
void copy_center_to_motion_step(const int motion_step)
Definition: mesh.cpp:422
void clear(bool preserve_shaders=false) override
Definition: mesh.cpp:325
void resize_subd_faces(int numfaces, int num_ngons, int numcorners)
Definition: mesh.cpp:246
void pack_verts(const vector< uint > &tri_prim_index, uint4 *tri_vindex, uint *tri_patch, float2 *tri_patch_uv, size_t vert_offset, size_t tri_offset)
Definition: mesh.cpp:732
void reserve_mesh(int numverts, int numfaces)
Definition: mesh.cpp:230
void pack_normals(float4 *vnormal)
Definition: mesh.cpp:708
void pack_patches(uint *patch_data, uint vert_offset, uint face_offset, uint corner_offset)
Definition: mesh.cpp:762
void add_vertex_slow(float3 P)
Definition: mesh.cpp:341
bool need_tesselation()
Definition: mesh.cpp:179
SubdivisionType
Definition: mesh.h:132
@ SUBDIVISION_NONE
Definition: mesh.h:133
@ SUBDIVISION_LINEAR
Definition: mesh.h:134
@ SUBDIVISION_CATMULL_CLARK
Definition: mesh.h:135
size_t num_triangles() const
Definition: mesh.h:92
void clear_non_sockets()
Definition: mesh.cpp:280
void set_num_subd_faces(size_t num_subd_faces_)
Definition: mesh.h:251
void add_crease(int v0, int v1, float weight)
Definition: mesh.cpp:411
void add_vertex(float3 P)
Definition: mesh.cpp:330
SubdEdgeCrease get_subd_crease(size_t i) const
Definition: mesh.h:121
void get_uv_tiles(ustring map, unordered_set< int > &tiles) override
Definition: mesh.cpp:439
void add_triangle(int v0, int v1, int v2, int shader, bool smooth)
Definition: mesh.cpp:352
void add_subd_face(int *corners, int num_corners, int shader_, bool smooth_)
Definition: mesh.cpp:370
SubdFace get_subd_face(size_t index) const
Definition: mesh.cpp:400
void pack_shaders(Scene *scene, uint *shader)
Definition: mesh.cpp:685
void resize_mesh(int numverts, int numfaces)
Definition: mesh.cpp:215
void add_face_normals()
Definition: mesh.cpp:535
void apply_transform(const Transform &tfm, const bool apply_to_motion) override
Definition: mesh.cpp:503
size_t get_num_subd_verts()
Definition: mesh.h:256
bool override
Definition: wm_files.c:854