Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2014-01-11 14:31:44 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2014-01-11 14:51:19 +0400
commit8952f58375385a6e8a636aa1e86763e88fc68fc0 (patch)
treee0f82a77ed1e969b155517dd427505776dc6f2c1 /source/blender/makesrna/intern/rna_mesh_api.c
parent274b2590fb0eedaadbd5e588f629df7cb69ba0d8 (diff)
Add tangent space computation/access from RNA (i.e. python).
This simply mimics code used for loopnormals, to enable py scripts to generate and access (temporary) a tangent 3D vector and bitangent sign for each loop. Together with the split normals, this allow to recreate a complete tangent space for normal mapping (bitangent = bitangent_sign * cross(normal, tangent)). Expects all faces to be tri or quads. Reviewed By: Brecht, campbellbarton Differential Revision: https://developer.blender.org/D185
Diffstat (limited to 'source/blender/makesrna/intern/rna_mesh_api.c')
-rw-r--r--source/blender/makesrna/intern/rna_mesh_api.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c
index 34f21046a92..76097b04c99 100644
--- a/source/blender/makesrna/intern/rna_mesh_api.c
+++ b/source/blender/makesrna/intern/rna_mesh_api.c
@@ -34,6 +34,8 @@
#include "RNA_define.h"
+#include "DNA_customdata_types.h"
+
#include "BLI_sys_types.h"
#include "BLI_utildefines.h"
@@ -100,6 +102,32 @@ static void rna_Mesh_free_normals_split(Mesh *mesh)
CustomData_free_layers(&mesh->ldata, CD_NORMAL, mesh->totloop);
}
+static void rna_Mesh_calc_tangents(Mesh *mesh, ReportList *reports, const char *uvmap)
+{
+ float (*r_looptangents)[4];
+
+ if (CustomData_has_layer(&mesh->ldata, CD_MLOOPTANGENT)) {
+ r_looptangents = CustomData_get_layer(&mesh->ldata, CD_MLOOPTANGENT);
+ memset(r_looptangents, 0, sizeof(float[4]) * mesh->totloop);
+ }
+ else {
+ r_looptangents = CustomData_add_layer(&mesh->ldata, CD_MLOOPTANGENT, CD_CALLOC, NULL, mesh->totloop);
+ CustomData_set_layer_flag(&mesh->ldata, CD_MLOOPTANGENT, CD_FLAG_TEMPORARY);
+ }
+
+ /* Compute loop normals if needed. */
+ if (!CustomData_has_layer(&mesh->ldata, CD_NORMAL)) {
+ rna_Mesh_calc_normals_split(mesh, (float)M_PI);
+ }
+
+ BKE_mesh_loop_tangents(mesh, uvmap, r_looptangents, reports);
+}
+
+static void rna_Mesh_free_tangents(Mesh *mesh)
+{
+ CustomData_free_layers(&mesh->ldata, CD_MLOOPTANGENT, mesh->totloop);
+}
+
static void rna_Mesh_calc_smooth_groups(Mesh *mesh, int use_bitflags, int *r_poly_group_len,
int **r_poly_group, int *r_group_total)
{
@@ -141,6 +169,18 @@ void RNA_api_mesh(StructRNA *srna)
func = RNA_def_function(srna, "free_normals_split", "rna_Mesh_free_normals_split");
RNA_def_function_ui_description(func, "Free split vertex normals");
+ func = RNA_def_function(srna, "calc_tangents", "rna_Mesh_calc_tangents");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_function_ui_description(func,
+ "Compute tangents and bitangent signs, to be used together with the split normals "
+ "to get a complete tangent space for normal mapping "
+ "(split normals are also computed if not yet present)");
+ parm = RNA_def_string(func, "uvmap", "", MAX_CUSTOMDATA_LAYER_NAME, "",
+ "Name of the UV map to use for tangent space computation");
+
+ func = RNA_def_function(srna, "free_tangents", "rna_Mesh_free_tangents");
+ RNA_def_function_ui_description(func, "Free tangents");
+
func = RNA_def_function(srna, "calc_tessface", "ED_mesh_calc_tessface");
RNA_def_function_ui_description(func, "Calculate face tessellation (supports editmode too)");