2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2018 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2018-11-01 11:06:00 +01:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2018-11-01 11:06:00 +01:00
|
|
|
*/
|
|
|
|
|
|
2018-11-02 06:59:51 +11:00
|
|
|
#pragma once
|
2018-11-01 11:06:00 +01:00
|
|
|
|
2018-11-07 12:19:10 +11:00
|
|
|
#include "BLI_assert.h"
|
|
|
|
|
#include "BLI_compiler_compat.h"
|
|
|
|
|
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_subdiv.hh"
|
2018-11-01 11:06:00 +01:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
*r_grid_u = 1.0f - ptex_v;
|
|
|
|
|
*r_grid_v = 1.0f - ptex_u;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-17 18:09:47 +01:00
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
*r_ptex_u = 1.0f - grid_v;
|
|
|
|
|
*r_ptex_v = 1.0f - grid_u;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 11:06:00 +01:00
|
|
|
BLI_INLINE int BKE_subdiv_grid_size_from_level(const int level)
|
|
|
|
|
{
|
|
|
|
|
return (1 << (level - 1)) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 15:20:31 +01:00
|
|
|
BLI_INLINE int BKE_subdiv_rotate_quad_to_corner(const float quad_u,
|
2019-01-17 10:41:40 +01:00
|
|
|
const float quad_v,
|
|
|
|
|
float *r_corner_u,
|
|
|
|
|
float *r_corner_v)
|
2018-11-01 15:20:31 +01:00
|
|
|
{
|
|
|
|
|
int corner;
|
2019-01-17 10:41:40 +01:00
|
|
|
if (quad_u <= 0.5f && quad_v <= 0.5f) {
|
2018-11-01 15:20:31 +01:00
|
|
|
corner = 0;
|
2019-01-17 10:41:40 +01:00
|
|
|
*r_corner_u = 2.0f * quad_u;
|
|
|
|
|
*r_corner_v = 2.0f * quad_v;
|
2018-11-01 15:20:31 +01:00
|
|
|
}
|
2019-01-17 10:41:40 +01:00
|
|
|
else if (quad_u > 0.5f && quad_v <= 0.5f) {
|
2018-11-01 15:20:31 +01:00
|
|
|
corner = 1;
|
2019-01-17 10:41:40 +01:00
|
|
|
*r_corner_u = 2.0f * quad_v;
|
|
|
|
|
*r_corner_v = 2.0f * (1.0f - quad_u);
|
2018-11-01 15:20:31 +01:00
|
|
|
}
|
2019-01-17 10:41:40 +01:00
|
|
|
else if (quad_u > 0.5f && quad_v > 0.5f) {
|
2018-11-01 15:20:31 +01:00
|
|
|
corner = 2;
|
2019-01-17 10:41:40 +01:00
|
|
|
*r_corner_u = 2.0f * (1.0f - quad_u);
|
|
|
|
|
*r_corner_v = 2.0f * (1.0f - quad_v);
|
2018-11-01 15:20:31 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2019-01-17 10:41:40 +01:00
|
|
|
BLI_assert(quad_u <= 0.5f && quad_v >= 0.5f);
|
2018-11-01 15:20:31 +01:00
|
|
|
corner = 3;
|
2019-01-17 10:41:40 +01:00
|
|
|
*r_corner_u = 2.0f * (1.0f - quad_v);
|
|
|
|
|
*r_corner_v = 2.0f * quad_u;
|
2018-11-01 15:20:31 +01:00
|
|
|
}
|
|
|
|
|
return corner;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-17 11:17:15 +01:00
|
|
|
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)
|
2019-01-17 10:47:14 +01:00
|
|
|
{
|
|
|
|
|
if (corner == 0) {
|
2019-01-17 11:17:15 +01:00
|
|
|
*r_quad_u = 0.5f - grid_v * 0.5f;
|
|
|
|
|
*r_quad_v = 0.5f - grid_u * 0.5f;
|
2019-01-17 10:47:14 +01:00
|
|
|
}
|
|
|
|
|
else if (corner == 1) {
|
2019-01-17 11:17:15 +01:00
|
|
|
*r_quad_u = 0.5f + grid_u * 0.5f;
|
|
|
|
|
*r_quad_v = 0.5f - grid_v * 0.5f;
|
2019-01-17 10:47:14 +01:00
|
|
|
}
|
|
|
|
|
else if (corner == 2) {
|
2019-01-17 11:17:15 +01:00
|
|
|
*r_quad_u = 0.5f + grid_v * 0.5f;
|
|
|
|
|
*r_quad_v = 0.5f + grid_u * 0.5f;
|
2019-01-17 10:47:14 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert(corner == 3);
|
2019-01-17 11:17:15 +01:00
|
|
|
*r_quad_u = 0.5f - grid_u * 0.5f;
|
|
|
|
|
*r_quad_v = 0.5f + grid_v * 0.5f;
|
2019-01-17 10:47:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Subdivision: add support for vertex creasing
This adds vertex creasing support for OpenSubDiv for modeling, rendering,
Alembic and USD I/O.
For modeling, vertex creasing follows the edge creasing implementation with an
operator accessible through the Vertex menu in Edit Mode, and some parameter in
the properties panel. The option in the Subsurf and Multires to use edge
creasing also affects vertex creasing.
The vertex crease data is stored as a CustomData layer, unlike edge creases
which for now are stored in `MEdge`, but will in the future also be moved to
a `CustomData` layer. See comments for details on the difference in behavior
for the `CD_CREASE` layer between egdes and vertices.
For Cycles this adds sockets on the Mesh node to hold data about which vertices
are creased (one socket for the indices, one for the weigths).
Viewport rendering of vertex creasing reuses the same color scheme as for edges
and creased vertices are drawn bigger than uncreased vertices.
For Alembic and USD, vertex crease support follows the edge crease
implementation, they are always read, but only exported if a `Subsurf` modifier
is present on the Mesh.
Reviewed By: brecht, fclem, sergey, sybren, campbellbarton
Differential Revision: https://developer.blender.org/D10145
2022-01-20 12:20:30 +01:00
|
|
|
BLI_INLINE float BKE_subdiv_crease_to_sharpness_f(float edge_crease)
|
2020-03-19 10:32:16 +01:00
|
|
|
{
|
|
|
|
|
return edge_crease * edge_crease * 10.0f;
|
|
|
|
|
}
|