Blender V4.3
mesh_tangent.cc File Reference
#include <climits>
#include "MEM_guardedalloc.h"
#include "BLI_math_geom.h"
#include "BLI_math_vector.h"
#include "BLI_string.h"
#include "BLI_task.h"
#include "BLI_utildefines.h"
#include "BKE_attribute.hh"
#include "BKE_customdata.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_tangent.hh"
#include "BKE_report.hh"
#include "mikktspace.hh"
#include "BLI_strict_flags.h"

Go to the source code of this file.

Classes

struct  BKEMeshToTangent
 
struct  SGLSLMeshToTangent
 

Functions

Mesh Tangent Calculations (Single Layer)
void BKE_mesh_calc_loop_tangent_single_ex (const float(*vert_positions)[3], const int, const int *corner_verts, float(*r_looptangent)[4], const float(*corner_normals)[3], const float(*loop_uvs)[2], const int, const OffsetIndices< int > faces, ReportList *reports)
 
void BKE_mesh_calc_loop_tangent_single (Mesh *mesh, const char *uvmap, float(*r_looptangents)[4], ReportList *reports)
 

Mesh Tangent Calculations (All Layers)

#define USE_TRI_DETECT_QUADS
 
static void DM_calc_loop_tangents_thread (TaskPool *__restrict, void *taskdata)
 
void BKE_mesh_add_loop_tangent_named_layer_for_uv (const CustomData *uv_data, CustomData *tan_data, int numLoopData, const char *layer_name)
 
void BKE_mesh_calc_loop_tangent_step_0 (const CustomData *loopData, bool calc_active_tangent, const char(*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME], int tangent_names_count, bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n, char *ract_uv_name, char *rren_uv_name, short *rtangent_mask)
 
void BKE_mesh_calc_loop_tangent_ex (const Span< float3 > vert_positions, const OffsetIndices< int > faces, const int *corner_verts, const int3 *corner_tris, const int *corner_tri_faces, const uint corner_tris_len, const Span< bool > sharp_faces, const CustomData *loopdata, bool calc_active_tangent, const char(*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME], int tangent_names_len, const Span< float3 > vert_normals, const Span< float3 > face_normals, const Span< float3 > corner_normals, const Span< float3 > vert_orco, CustomData *loopdata_out, const uint loopdata_out_len, short *tangent_mask_curr_p)
 
void BKE_mesh_calc_loop_tangents (Mesh *mesh_eval, bool calc_active_tangent, const char(*tangent_names)[MAX_CUSTOMDATA_LAYER_NAME], int tangent_names_len)
 

Detailed Description

Functions to evaluate mesh tangents.

Definition in file mesh_tangent.cc.

Macro Definition Documentation

◆ USE_TRI_DETECT_QUADS

#define USE_TRI_DETECT_QUADS

Definition at line 158 of file mesh_tangent.cc.

Function Documentation

◆ BKE_mesh_add_loop_tangent_named_layer_for_uv()

void BKE_mesh_add_loop_tangent_named_layer_for_uv ( const CustomData * uv_data,
CustomData * tan_data,
int numLoopData,
const char * layer_name )

◆ BKE_mesh_calc_loop_tangent_ex()

void BKE_mesh_calc_loop_tangent_ex ( const Span< float3 > vert_positions,
const OffsetIndices< int > faces,
const int * corner_verts,
const int3 * corner_tris,
const int * corner_tri_faces,
const uint corner_tris_len,
const Span< bool > sharp_faces,
const CustomData * loopdata,
bool calc_active_tangent,
const char(*) tangent_names[MAX_CUSTOMDATA_LAYER_NAME],
int tangent_names_len,
const Span< float3 > vert_normals,
const Span< float3 > face_normals,
const Span< float3 > corner_normals,
const Span< float3 > vert_orco,
CustomData * loopdata_out,
const uint loopdata_out_len,
short * tangent_mask_curr_p )

◆ BKE_mesh_calc_loop_tangent_single()

void BKE_mesh_calc_loop_tangent_single ( Mesh * mesh,
const char * uvmap,
float(*) r_looptangents[4],
ReportList * reports )

Wrapper around BKE_mesh_calc_loop_tangent_single_ex, which takes care of most boilerplate code.

Note
  • There must be a valid loop's CD_NORMALS available.
  • The mesh should be made of only triangles and quads!

Definition at line 118 of file mesh_tangent.cc.

References BKE_mesh_calc_loop_tangent_single_ex(), BKE_reportf(), CD_PROP_FLOAT2, CustomData_get_active_layer_name(), blender::Span< T >::data(), blender::Span< T >::is_empty(), and RPT_ERROR.

◆ BKE_mesh_calc_loop_tangent_single_ex()

void BKE_mesh_calc_loop_tangent_single_ex ( const float(*) vert_positions[3],
int numVerts,
const int * corner_verts,
float(*) r_looptangent[4],
const float(*) corner_normals[3],
const float(*) loopuv[2],
int numLoops,
blender::OffsetIndices< int > faces,
ReportList * reports )

Compute simplified tangent space normals, i.e. tangent vector + sign of bi-tangent one, which combined with split normals can be used to recreate the full tangent space.

Note
The mesh should be made of only triangles and quads!

Definition at line 84 of file mesh_tangent.cc.

References BKE_report(), BKEMeshToTangent::corner_normals, BKEMeshToTangent::corner_verts, BKEMeshToTangent::faces, faces, int, BKEMeshToTangent::luvs, BKEMeshToTangent::num_faces, BKEMeshToTangent::positions, RPT_ERROR, size(), and BKEMeshToTangent::tangents.

Referenced by BKE_mesh_calc_loop_tangent_single().

◆ BKE_mesh_calc_loop_tangent_step_0()

void BKE_mesh_calc_loop_tangent_step_0 ( const CustomData * loopData,
bool calc_active_tangent,
const char(*) tangent_names[MAX_CUSTOMDATA_LAYER_NAME],
int tangent_names_count,
bool * rcalc_act,
bool * rcalc_ren,
int * ract_uv_n,
int * rren_uv_n,
char * ract_uv_name,
char * rren_uv_name,
short * rtangent_mask )

Here we get some useful information such as active uv layer name and search if it is already in tangent_names. Also, we calculate tangent_mask that works as a descriptor of tangents state. If tangent_mask has changed, then recalculate tangents.

Definition at line 328 of file mesh_tangent.cc.

References BLI_strncpy(), CD_PROP_FLOAT2, CustomData_get_active_layer(), CustomData_get_layer_index(), CustomData_get_layer_name(), CustomData_get_render_layer(), CustomData_number_of_layers(), DM_TANGENT_MASK_ORCO, CustomData::layers, MAX_CUSTOMDATA_LAYER_NAME, CustomDataLayer::name, and STREQ.

Referenced by BKE_editmesh_loop_tangent_calc(), and BKE_mesh_calc_loop_tangent_ex().

◆ BKE_mesh_calc_loop_tangents()

void BKE_mesh_calc_loop_tangents ( Mesh * mesh_eval,
bool calc_active_tangent,
const char(*) tangent_names[MAX_CUSTOMDATA_LAYER_NAME],
int tangent_names_len )

◆ DM_calc_loop_tangents_thread()

static void DM_calc_loop_tangents_thread ( TaskPool * __restrict,
void * taskdata )
static

Definition at line 308 of file mesh_tangent.cc.

Referenced by BKE_mesh_calc_loop_tangent_ex().