1
1
#include " stdio.h"
2
- #include " string .h"
2
+ #include " mikktspace .h"
3
3
4
4
#ifdef _WIN32
5
5
#define EXPORT extern " C" __declspec( dllexport )
6
6
#else
7
7
#define EXPORT extern " C" __attribute__ ((visibility (" default" )))
8
8
#endif
9
9
10
- #include " blender_dna/DNA_mesh_types.h"
11
- #include " blender_dna/DNA_meshdata_types.h"
12
-
13
- // blenkernel/intern/customdata.cc
14
-
15
- int CustomData_get_active_layer_index (const CustomData *data, int type)
16
- {
17
- const int layer_index = data->typemap [type];
18
- // BLI_assert(customdata_typemap_is_valid(data));
19
- return (layer_index != -1 ) ? layer_index + data->layers [layer_index].active : -1 ;
20
- }
21
-
22
- void *CustomData_get_layer (const CustomData *data, int type)
23
- {
24
- /* get the layer index of the active layer of type */
25
- int layer_index = CustomData_get_active_layer_index (data, type);
26
- if (layer_index == -1 ) {
27
- return nullptr ;
28
- }
29
-
30
- return data->layers [layer_index].data ;
31
- }
32
-
33
- int CustomData_get_layer_index (const CustomData *data, int type)
34
- {
35
- // BLI_assert(customdata_typemap_is_valid(data));
36
- return data->typemap [type];
37
- }
38
-
39
- int CustomData_get_layer_index_n (const struct CustomData *data, int type, int n)
40
- {
41
- // BLI_assert(n >= 0);
42
- int i = CustomData_get_layer_index (data, type);
43
-
44
- if (i != -1 ) {
45
- // BLI_assert(i + n < data->totlayer);
46
- i = (data->layers [i + n].type == type) ? (i + n) : (-1 );
47
- }
48
-
49
- return i;
50
- }
51
-
52
- #define STREQ (a, b ) (strcmp(a, b) == 0 )
53
-
54
- int CustomData_get_named_layer_index (const CustomData *data, const int type, const char *name)
55
- {
56
- for (int i = 0 ; i < data->totlayer ; i++) {
57
- if (data->layers [i].type == type) {
58
- if (STREQ (data->layers [i].name , name)) {
59
- return i;
60
- }
61
- }
62
- }
63
-
64
- return -1 ;
65
- }
66
-
67
- void *CustomData_get_layer_named (const CustomData *data, const int type, const char *name)
68
- {
69
- int layer_index = CustomData_get_named_layer_index (data, type, name);
70
- if (layer_index == -1 ) {
71
- return nullptr ;
72
- }
73
-
74
- return data->layers [layer_index].data ;
75
- }
76
-
77
- void *CustomData_get_layer_n (const CustomData *data, int type, int n)
78
- {
79
- /* get the layer index of the active layer of type */
80
- int layer_index = CustomData_get_layer_index_n (data, type, n);
81
- if (layer_index == -1 ) {
82
- return nullptr ;
83
- }
84
-
85
- return data->layers [layer_index].data ;
86
- }
87
-
88
- // CBlenderMalt API
89
-
90
10
EXPORT void retrieve_mesh_data (
91
11
float * in_positions,
92
12
int * in_loop_verts, int loop_count,
@@ -113,10 +33,74 @@ EXPORT void retrieve_mesh_data(
113
33
}
114
34
}
115
35
116
- EXPORT float * mesh_tangents_ptr (void * in_mesh)
36
+ EXPORT bool mesh_tangents (
37
+ int * in_indices, int index_len,
38
+ float * in_positions, float * in_normals, float * in_uvs,
39
+ float * out_tangents)
117
40
{
118
- Mesh* mesh = (Mesh*)in_mesh;
119
- float * ptr = (float *)CustomData_get_layer (&mesh->corner_data , CD_MLOOPTANGENT);
120
-
121
- return ptr;
41
+ struct MData
42
+ {
43
+ int * indices;
44
+ int index_len;
45
+ float * positions;
46
+ float * normals;
47
+ float * uvs;
48
+ float * tangents;
49
+ };
50
+
51
+ MData data = {
52
+ in_indices,
53
+ index_len,
54
+ in_positions,
55
+ in_normals,
56
+ in_uvs,
57
+ out_tangents,
58
+ };
59
+
60
+ SMikkTSpaceInterface mti = {0 };
61
+ mti.m_getNumFaces = [](const SMikkTSpaceContext * pContext){
62
+ return ((MData*)pContext->m_pUserData )->index_len / 3 ;
63
+ };
64
+
65
+ mti.m_getNumVerticesOfFace = [](const SMikkTSpaceContext * pContext, const int iFace){
66
+ return 3 ;
67
+ };
68
+
69
+ mti.m_getPosition = [](const SMikkTSpaceContext * pContext, float fvPosOut[], const int iFace, const int iVert){
70
+ MData* m = (MData*)pContext->m_pUserData ;
71
+ int i = iFace * 3 + iVert;
72
+ fvPosOut[0 ] = m->positions [m->indices [i] * 3 + 0 ];
73
+ fvPosOut[1 ] = m->positions [m->indices [i] * 3 + 1 ];
74
+ fvPosOut[2 ] = m->positions [m->indices [i] * 3 + 2 ];
75
+ };
76
+
77
+ mti.m_getNormal = [](const SMikkTSpaceContext * pContext, float fvNormOut[], const int iFace, const int iVert){
78
+ MData* m = (MData*)pContext->m_pUserData ;
79
+ int i = iFace * 3 + iVert;
80
+ fvNormOut[0 ] = m->normals [m->indices [i] * 3 + 0 ];
81
+ fvNormOut[1 ] = m->normals [m->indices [i] * 3 + 1 ];
82
+ fvNormOut[2 ] = m->normals [m->indices [i] * 3 + 2 ];
83
+ };
84
+
85
+ mti.m_getTexCoord = [](const SMikkTSpaceContext * pContext, float fvTexcOut[], const int iFace, const int iVert){
86
+ MData* m = (MData*)pContext->m_pUserData ;
87
+ int i = iFace * 3 + iVert;
88
+ fvTexcOut[0 ] = m->uvs [m->indices [i] * 2 + 0 ];
89
+ fvTexcOut[1 ] = m->uvs [m->indices [i] * 2 + 1 ];
90
+ };
91
+
92
+ mti.m_setTSpaceBasic = [](const SMikkTSpaceContext * pContext, const float fvTangent[], const float fSign , const int iFace, const int iVert){
93
+ MData* m = (MData*)pContext->m_pUserData ;
94
+ int i = iFace * 3 + iVert;
95
+ m->tangents [m->indices [i] * 4 + 0 ] = fvTangent[0 ];
96
+ m->tangents [m->indices [i] * 4 + 1 ] = fvTangent[1 ];
97
+ m->tangents [m->indices [i] * 4 + 2 ] = fvTangent[2 ];
98
+ m->tangents [m->indices [i] * 4 + 3 ] = fSign ;
99
+ };
100
+
101
+ SMikkTSpaceContext mtc;
102
+ mtc.m_pInterface = &mti;
103
+ mtc.m_pUserData = &data;
104
+
105
+ return genTangSpaceDefault (&mtc);
122
106
}
0 commit comments