Blender  V2.93
subdiv_inline.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2018 by Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 #include "BLI_assert.h"
27 #include "BLI_compiler_compat.h"
28 
29 #include "BKE_subdiv.h"
30 
32  const float ptex_v,
33  float *r_grid_u,
34  float *r_grid_v)
35 {
36  *r_grid_u = 1.0f - ptex_v;
37  *r_grid_v = 1.0f - ptex_u;
38 }
39 
41  const float grid_v,
42  float *r_ptex_u,
43  float *r_ptex_v)
44 {
45  *r_ptex_u = 1.0f - grid_v;
46  *r_ptex_v = 1.0f - grid_u;
47 }
48 
50 {
51  return (1 << (level - 1)) + 1;
52 }
53 
55  const float quad_v,
56  float *r_corner_u,
57  float *r_corner_v)
58 {
59  int corner;
60  if (quad_u <= 0.5f && quad_v <= 0.5f) {
61  corner = 0;
62  *r_corner_u = 2.0f * quad_u;
63  *r_corner_v = 2.0f * quad_v;
64  }
65  else if (quad_u > 0.5f && quad_v <= 0.5f) {
66  corner = 1;
67  *r_corner_u = 2.0f * quad_v;
68  *r_corner_v = 2.0f * (1.0f - quad_u);
69  }
70  else if (quad_u > 0.5f && quad_v > 0.5f) {
71  corner = 2;
72  *r_corner_u = 2.0f * (1.0f - quad_u);
73  *r_corner_v = 2.0f * (1.0f - quad_v);
74  }
75  else {
76  BLI_assert(quad_u <= 0.5f && quad_v >= 0.5f);
77  corner = 3;
78  *r_corner_u = 2.0f * (1.0f - quad_v);
79  *r_corner_v = 2.0f * quad_u;
80  }
81  return corner;
82 }
83 
85  const int corner, const float grid_u, const float grid_v, float *r_quad_u, float *r_quad_v)
86 {
87  if (corner == 0) {
88  *r_quad_u = 0.5f - grid_v * 0.5f;
89  *r_quad_v = 0.5f - grid_u * 0.5f;
90  }
91  else if (corner == 1) {
92  *r_quad_u = 0.5f + grid_u * 0.5f;
93  *r_quad_v = 0.5f - grid_v * 0.5f;
94  }
95  else if (corner == 2) {
96  *r_quad_u = 0.5f + grid_v * 0.5f;
97  *r_quad_v = 0.5f + grid_u * 0.5f;
98  }
99  else {
100  BLI_assert(corner == 3);
101  *r_quad_u = 0.5f - grid_u * 0.5f;
102  *r_quad_v = 0.5f + grid_v * 0.5f;
103  }
104 }
105 
107 {
108  return edge_crease * edge_crease * 10.0f;
109 }
110 
112 {
113  const float edge_crease_f = edge_crease / 255.0f;
114  return BKE_subdiv_edge_crease_to_sharpness_f(edge_crease_f);
115 }
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define BLI_INLINE
BLI_INLINE void BKE_subdiv_rotate_grid_to_quad(const int corner, const float grid_u, const float grid_v, float *r_quad_u, float *r_quad_v)
Definition: subdiv_inline.h:84
BLI_INLINE float BKE_subdiv_edge_crease_to_sharpness_char(char edge_crease)
BLI_INLINE int BKE_subdiv_grid_size_from_level(const int level)
Definition: subdiv_inline.h:49
BLI_INLINE int BKE_subdiv_rotate_quad_to_corner(const float quad_u, const float quad_v, float *r_corner_u, float *r_corner_v)
Definition: subdiv_inline.h:54
BLI_INLINE void BKE_subdiv_grid_uv_to_ptex_face_uv(const float grid_u, const float grid_v, float *r_ptex_u, float *r_ptex_v)
Definition: subdiv_inline.h:40
BLI_INLINE float BKE_subdiv_edge_crease_to_sharpness_f(float edge_crease)
BLI_INLINE void BKE_subdiv_ptex_face_uv_to_grid_uv(const float ptex_u, const float ptex_v, float *r_grid_u, float *r_grid_v)
Definition: subdiv_inline.h:31