34 #define DSPLIT_NON_UNIFORM -1
35 #define STITCH_NGON_CENTER_VERT_INDEX_OFFSET 0x60000000
36 #define STITCH_NGON_SPLIT_EDGE_CENTER_VERT_TAG (0x60000000 - 1)
55 if (b.
x <
a.x || b.
y <
a.y) {
60 int DiagSplit::T(
Patch *patch,
float2 Pstart,
float2 Pend,
bool recursive_resolve)
67 float3 Plast = to_world(patch, Pstart);
72 float3 P = to_world(patch, Pstart +
t * (Pend - Pstart));
83 L =
len(
P - Plast) / pixel_width;
95 int res =
max(tmax, 1);
98 if (!recursive_resolve) {
102 float2 P = (Pstart + Pend) * 0.5f;
103 res = T(patch, Pstart,
P,
true) + T(patch,
P, Pend,
true);
107 limit_edge_factor(res, patch, Pstart, Pend);
111 void DiagSplit::partition_edge(
115 *
P = (Pstart + Pend) * 0.5f;
116 *t0 = T(patch, Pstart, *
P);
117 *t1 = T(patch, *
P, Pend);
122 int I = (int)
floorf((
float)
t * 0.5f);
132 int max_t_for_edge = int(max_t *
len(Pstart - Pend));
135 max_t_for_edge >>= 1;
138 T = (max_t_for_edge <= 1) ? 1 :
min(T, max_t_for_edge);
143 void DiagSplit::resolve_edge_factors(
Subpatch &sub)
160 void DiagSplit::split(
Subpatch &sub,
int depth)
164 assert(!
"diagsplit recursion limit reached");
171 subpatches.push_back(sub);
197 if (split_u && split_v) {
201 if (!split_u && !split_v) {
203 subpatches.push_back(sub);
204 Subpatch &subpatch = subpatches[subpatches.size() - 1];
207 for (
int i = 0; i < 4; i++) {
226 float2 *Pa, *Pb, *Pc, *Pd;
232 sub_a_across_0 = &sub_a.
edge_u0;
233 sub_a_across_1 = &sub_a.
edge_u1;
234 sub_b_across_0 = &sub_b.
edge_u0;
235 sub_b_across_1 = &sub_b.
edge_u1;
248 sub_a_across_0 = &sub_a.
edge_v0;
249 sub_a_across_1 = &sub_a.
edge_v1;
250 sub_b_across_0 = &sub_b.
edge_v0;
251 sub_b_across_1 = &sub_b.
edge_v1;
266 sub.
patch, &P0, &sub_a_across_0->
T, &sub_b_across_0->
T, *Pd, *Pb, sub_across_0->
T);
268 sub.
patch, &P1, &sub_a_across_1->
T, &sub_b_across_1->
T, *Pc, *Pa, sub_across_1->
T);
277 int tsplit =
T(sub.
patch, P0, P1);
279 if (depth == -2 && tsplit == 1) {
283 sub_a_split->
T = tsplit;
284 sub_b_split->
T = tsplit;
286 resolve_edge_factors(sub_a);
287 resolve_edge_factors(sub_b);
292 sub_a_split->
edge = &edge;
293 sub_b_split->
edge = &edge;
309 split(sub_a, depth + 1);
318 split(sub_b, depth + 1);
320 assert(edge.
T == edge_t);
327 int DiagSplit::alloc_verts(
int n)
329 int a = num_alloced_verts;
330 num_alloced_verts += n;
336 edges.emplace_back();
337 return &edges.back();
347 Patch *patch = (
Patch *)(((
char *)patches) + patch_index * patches_byte_stride);
361 params.
mesh->vert_to_stitching_key_map.clear();
362 params.
mesh->vert_stitching_map.clear();
403 int v = alloc_verts(4);
405 bool v0_reversed, u1_reversed, v1_reversed, u0_reversed;
407 this, params.
mesh, face, 3, v0_reversed,
v + 3,
v + 0);
409 this, params.
mesh, face, 2, u1_reversed,
v + 2,
v + 3);
411 this, params.
mesh, face, 1, v1_reversed,
v + 1,
v + 2);
413 this, params.
mesh, face, 0, u0_reversed,
v + 0,
v + 1);
482 Edge *prev_edge_u0 =
nullptr;
483 Edge *first_edge_v0 =
nullptr;
490 int v = alloc_verts(4);
517 bool v0_reversed, u0_reversed;
559 resolve_edge_factors(subpatch);
606 int num_stitch_verts = 0;
610 foreach (
Edge &edge, edges) {
616 num_stitch_verts =
max(num_stitch_verts,
621 num_stitch_verts += 1;
625 size_t operator()(
const pair<int, int> &k)
const
630 typedef unordered_map<pair<int, int>, int, pair_hasher> edge_stitch_verts_map_t;
631 edge_stitch_verts_map_t edge_stitch_verts_map;
633 foreach (
Edge &edge, edges) {
639 if (edge_stitch_verts_map.find(edge.
stitch_edge_key) == edge_stitch_verts_map.end()) {
647 foreach (
Edge &edge, edges) {
666 int vert_offset = params.
mesh->verts.
size();
669 foreach (
const Edge &edge, edges) {
671 int second_stitch_vert_index = edge_stitch_verts_map[edge.
stitch_edge_key];
673 for (
int i = 0; i <= edge.
T; i++) {
680 else if (i == edge.
T) {
691 else if (i == edge.
T) {
692 key = second_stitch_vert_index - 1 + edge.
T;
695 else if (key < 0 && edge.
top) {
709 if (params.
mesh->vert_to_stitching_key_map.find(vert) ==
710 params.
mesh->vert_to_stitching_key_map.end()) {
711 params.
mesh->vert_to_stitching_key_map[vert] = key;
712 params.
mesh->vert_stitching_map.insert({key, vert});
721 int num_verts = num_alloced_verts;
722 int num_triangles = 0;
724 for (
size_t i = 0; i < subpatches.size(); i++) {
725 subpatches[i].inner_grid_vert_offset = num_verts;
726 num_verts += subpatches[i].calc_num_inner_verts();
727 num_triangles += subpatches[i].calc_num_triangles();
730 dice.
reserve(num_verts, num_triangles);
732 for (
size_t i = 0; i < subpatches.size(); i++) {
typedef float(TangentPoint)[2]
_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 GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
_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 * v
void split_patches(Patch *patches, size_t patches_byte_stride)
void split_quad(const Mesh::SubdFace &face, Patch *patch)
void split_ngon(const Mesh::SubdFace &face, Patch *patches, size_t patches_byte_stride)
DiagSplit(const SubdParams ¶ms)
void reserve(int num_verts, int num_triangles)
virtual void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v)=0
#define CCL_NAMESPACE_END
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
float world_to_raster_size(float3 P)
bool bottom_indices_decrease
int stitch_end_vert_index
pair< int, int > stitch_edge_key
bool top_indices_decrease
int get_vert_along_edge(int n) const
int stitch_start_vert_index
size_t get_num_subd_faces() const
SubdFace get_subd_face(size_t index) const
bool sub_edges_created_in_reverse_order
bool indices_decrease_along_edge
#define DSPLIT_NON_UNIFORM
static Edge * create_split_edge_from_corner(DiagSplit *split, const Mesh *mesh, const Mesh::SubdFace &face, int corner, int side, bool &reversed, int v0, int v1, int vc)
#define STITCH_NGON_CENTER_VERT_INDEX_OFFSET
static Edge * create_edge_from_corner(DiagSplit *split, const Mesh *mesh, const Mesh::SubdFace &face, int corner, bool &reversed, int v0, int v1)
static void order_float2(float2 &a, float2 &b)
#define STITCH_NGON_SPLIT_EDGE_CENTER_VERT_TAG
ccl_device_inline uint hash_uint2(uint kx, uint ky)
ccl_device_inline int mod(int x, int m)
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)