21 #define DSPLIT_NON_UNIFORM -1
22 #define STITCH_NGON_CENTER_VERT_INDEX_OFFSET 0x60000000
23 #define STITCH_NGON_SPLIT_EDGE_CENTER_VERT_TAG (0x60000000 - 1)
42 if (
b.x <
a.x ||
b.y <
a.y) {
47 int DiagSplit::T(
Patch *patch,
float2 Pstart,
float2 Pend,
bool recursive_resolve)
54 float3 Plast = to_world(patch, Pstart);
59 float3 P = to_world(patch, Pstart +
t * (Pend - Pstart));
70 L =
len(
P - Plast) / pixel_width;
82 int res =
max(tmax, 1);
85 if (!recursive_resolve) {
89 float2 P = (Pstart + Pend) * 0.5f;
90 res = T(patch, Pstart,
P,
true) + T(patch,
P, Pend,
true);
94 limit_edge_factor(res, patch, Pstart, Pend);
98 void DiagSplit::partition_edge(
102 *
P = (Pstart + Pend) * 0.5f;
103 *t0 = T(patch, Pstart, *
P);
104 *t1 = T(patch, *
P, Pend);
109 int I = (int)
floorf((
float)
t * 0.5f);
119 int max_t_for_edge = int(max_t *
len(Pstart - Pend));
122 max_t_for_edge >>= 1;
125 T = (max_t_for_edge <= 1) ? 1 :
min(T, max_t_for_edge);
130 void DiagSplit::resolve_edge_factors(
Subpatch &sub)
147 void DiagSplit::split(
Subpatch &sub,
int depth)
151 assert(!
"diagsplit recursion limit reached");
158 subpatches.push_back(sub);
184 if (split_u && split_v) {
188 if (!split_u && !split_v) {
190 subpatches.push_back(sub);
191 Subpatch &subpatch = subpatches[subpatches.size() - 1];
194 for (
int i = 0; i < 4; i++) {
213 float2 *Pa, *Pb, *Pc, *Pd;
219 sub_a_across_0 = &sub_a.
edge_u0;
220 sub_a_across_1 = &sub_a.
edge_u1;
221 sub_b_across_0 = &sub_b.
edge_u0;
222 sub_b_across_1 = &sub_b.
edge_u1;
235 sub_a_across_0 = &sub_a.
edge_v0;
236 sub_a_across_1 = &sub_a.
edge_v1;
237 sub_b_across_0 = &sub_b.
edge_v0;
238 sub_b_across_1 = &sub_b.
edge_v1;
253 sub.
patch, &P0, &sub_a_across_0->
T, &sub_b_across_0->
T, *Pd, *Pb, sub_across_0->
T);
255 sub.
patch, &P1, &sub_a_across_1->
T, &sub_b_across_1->
T, *Pc, *Pa, sub_across_1->
T);
264 int tsplit =
T(sub.
patch, P0, P1);
266 if (depth == -2 && tsplit == 1) {
270 sub_a_split->
T = tsplit;
271 sub_b_split->
T = tsplit;
273 resolve_edge_factors(sub_a);
274 resolve_edge_factors(sub_b);
296 split(sub_a, depth + 1);
302 edge.bottom_offset = sub_across_0->
edge->
T;
305 split(sub_b, depth + 1);
307 assert(
edge.T == edge_t);
314 int DiagSplit::alloc_verts(
int n)
316 int a = num_alloced_verts;
317 num_alloced_verts += n;
323 edges.emplace_back();
324 return &edges.back();
334 Patch *patch = (
Patch *)(((
char *)patches) + patch_index * patches_byte_stride);
348 params.
mesh->vert_to_stitching_key_map.clear();
349 params.
mesh->vert_stitching_map.clear();
374 edge->is_stitch_edge =
true;
375 edge->stitch_start_vert_index =
a;
376 edge->stitch_end_vert_index =
b;
378 edge->start_vert_index = v0;
379 edge->end_vert_index =
v1;
381 edge->stitch_edge_key = {
a,
b};
390 int v = alloc_verts(4);
392 bool v0_reversed, u1_reversed, v1_reversed, u0_reversed;
394 this, params.
mesh, face, 3, v0_reversed,
v + 3,
v + 0);
396 this, params.
mesh, face, 2, u1_reversed,
v + 2,
v + 3);
398 this, params.
mesh, face, 1, v1_reversed,
v + 1,
v + 2);
400 this, params.
mesh, face, 0, u0_reversed,
v + 0,
v + 1);
437 edge->stitch_edge_key = {
b,
a};
440 edge->stitch_edge_key = {
a,
b};
457 edge->is_stitch_edge =
true;
458 edge->stitch_start_vert_index =
a;
459 edge->stitch_end_vert_index =
b;
461 edge->start_vert_index = v0;
462 edge->end_vert_index =
v1;
469 Edge *prev_edge_u0 =
nullptr;
470 Edge *first_edge_v0 =
nullptr;
477 int v = alloc_verts(4);
504 bool v0_reversed, u0_reversed;
546 resolve_edge_factors(subpatch);
593 int num_stitch_verts = 0;
597 foreach (
Edge &edge, edges) {
598 if (edge.second_vert_index < 0) {
599 edge.second_vert_index = alloc_verts(edge.T - 1);
602 if (edge.is_stitch_edge) {
603 num_stitch_verts =
max(num_stitch_verts,
604 max(edge.stitch_start_vert_index, edge.stitch_end_vert_index));
608 num_stitch_verts += 1;
612 size_t operator()(
const pair<int, int> &k)
const
617 typedef unordered_map<pair<int, int>, int, pair_hasher> edge_stitch_verts_map_t;
618 edge_stitch_verts_map_t edge_stitch_verts_map;
620 foreach (
Edge &edge, edges) {
621 if (edge.is_stitch_edge) {
622 if (edge.stitch_edge_T == 0) {
623 edge.stitch_edge_T = edge.T;
626 if (edge_stitch_verts_map.find(edge.stitch_edge_key) == edge_stitch_verts_map.end()) {
627 edge_stitch_verts_map[edge.stitch_edge_key] = num_stitch_verts;
628 num_stitch_verts += edge.stitch_edge_T - 1;
634 foreach (
Edge &edge, edges) {
635 if (edge.start_vert_index < 0) {
637 if (edge.top_indices_decrease) {
638 edge.top_offset = edge.top->T - edge.top_offset;
641 edge.start_vert_index = edge.top->get_vert_along_edge(edge.top_offset);
644 if (edge.end_vert_index < 0) {
645 if (edge.bottom_indices_decrease) {
646 edge.bottom_offset = edge.bottom->T - edge.bottom_offset;
649 edge.end_vert_index = edge.bottom->get_vert_along_edge(edge.bottom_offset);
653 int vert_offset = params.
mesh->verts.
size();
656 foreach (
const Edge &edge, edges) {
657 if (edge.is_stitch_edge) {
658 int second_stitch_vert_index = edge_stitch_verts_map[edge.stitch_edge_key];
660 for (
int i = 0; i <= edge.T; i++) {
665 key = edge.stitch_start_vert_index;
667 else if (i == edge.T) {
668 key = edge.stitch_end_vert_index;
671 key = second_stitch_vert_index + i - 1 + edge.stitch_offset;
676 key = second_stitch_vert_index - 1 + edge.stitch_offset;
678 else if (i == edge.T) {
679 key = second_stitch_vert_index - 1 + edge.T;
682 else if (key < 0 && edge.top) {
683 int s = edge_stitch_verts_map[edge.top->stitch_edge_key];
684 if (edge.stitch_top_offset >= 0) {
685 key = s - 1 + edge.stitch_top_offset;
688 key = s - 1 + edge.top->stitch_edge_T + edge.stitch_top_offset;
693 int vert = edge.get_vert_along_edge(i) + vert_offset;
696 if (params.
mesh->vert_to_stitching_key_map.find(vert) ==
697 params.
mesh->vert_to_stitching_key_map.end()) {
698 params.
mesh->vert_to_stitching_key_map[vert] = key;
699 params.
mesh->vert_stitching_map.insert({key, vert});
708 int num_verts = num_alloced_verts;
709 int num_triangles = 0;
711 for (
size_t i = 0; i < subpatches.size(); i++) {
712 subpatches[i].inner_grid_vert_offset = num_verts;
713 num_verts += subpatches[i].calc_num_inner_verts();
714 num_triangles += subpatches[i].calc_num_triangles();
717 dice.
reserve(num_verts, num_triangles);
719 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
SyclQueue void void size_t num_bytes void
ccl_device_inline uint hash_uint2(uint kx, uint ky)
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
float world_to_raster_size(float3 P)
int stitch_end_vert_index
pair< int, int > stitch_edge_key
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 int mod(int x, int m)