Skip to content

Commit c88fa73

Browse files
committed
Merge branch 'Development' into node-groups
2 parents 4c63ad1 + d92263d commit c88fa73

20 files changed

+2161
-3107
lines changed

.github/FUNDING.yml

-12
This file was deleted.

.github/workflows/BlenderMalt.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ jobs:
3232
body: |
3333
[**BlenderMalt-Windows.zip**](https://github.com/${{github.repository}}/releases/download/${{env.BRANCH_NAME}}-latest/BlenderMalt-Windows.zip)
3434
[**BlenderMalt-Linux.zip**](https://github.com/${{github.repository}}/releases/download/${{env.BRANCH_NAME}}-latest/BlenderMalt-Linux.zip)
35-
36-
*(Requires Blender 4.1)*
35+
3736
3837
- name: Rollback Tagged Release
3938
uses: author/action-rollback@stable
@@ -56,7 +55,6 @@ jobs:
5655
[**BlenderMalt-Windows.zip**](https://github.com/${{github.repository}}/releases/download/${{github.ref_name}}/BlenderMalt-Windows.zip)
5756
[**BlenderMalt-Linux.zip**](https://github.com/${{github.repository}}/releases/download/${{github.ref_name}}/BlenderMalt-Linux.zip)
5857
59-
*(Requires Blender 4.1)*
6058
6159
outputs:
6260
upload_url: ${{ steps.create_release.outputs.upload_url }}
+70-86
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,12 @@
11
#include "stdio.h"
2-
#include "string.h"
2+
#include "mikktspace.h"
33

44
#ifdef _WIN32
55
#define EXPORT extern "C" __declspec( dllexport )
66
#else
77
#define EXPORT extern "C" __attribute__ ((visibility ("default")))
88
#endif
99

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-
9010
EXPORT void retrieve_mesh_data(
9111
float* in_positions,
9212
int* in_loop_verts, int loop_count,
@@ -113,10 +33,74 @@ EXPORT void retrieve_mesh_data(
11333
}
11434
}
11535

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)
11740
{
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);
122106
}

BlenderMalt/CBlenderMalt/CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ project(CBlenderMalt)
88
SET(CMAKE_BUILD_TYPE Release)
99
SET(BUILD_SHARED_LIBS ON)
1010

11-
add_library(CBlenderMalt CBlenderMalt.cpp)
11+
add_library(CBlenderMalt CBlenderMalt.cpp mikktspace.c)
1212
target_include_directories(CBlenderMalt PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/blender_dna)
1313

1414
install(TARGETS CBlenderMalt CONFIGURATIONS Release DESTINATION ${PROJECT_SOURCE_DIR})
15-

BlenderMalt/CBlenderMalt/__init__.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
]
2424
retrieve_mesh_data.restype = None
2525

26-
mesh_tangents_ptr = CBlenderMalt['mesh_tangents_ptr']
27-
mesh_tangents_ptr.argtypes = [ctypes.c_void_p]
28-
mesh_tangents_ptr.restype = ctypes.POINTER(ctypes.c_float)
26+
mesh_tangents = CBlenderMalt['mesh_tangents']
27+
mesh_tangents.argtypes = [
28+
ctypes.POINTER(ctypes.c_int), ctypes.c_int,
29+
ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
30+
ctypes.POINTER(ctypes.c_float)
31+
]
32+
mesh_tangents.restype = ctypes.c_bool

BlenderMalt/CBlenderMalt/blender_dna/BLI_sys_types.h

-74
This file was deleted.

0 commit comments

Comments
 (0)