Skip to content

Commit

Permalink
Merge branch 'Development' into node-groups
Browse files Browse the repository at this point in the history
  • Loading branch information
pragma37 committed Jul 20, 2024
2 parents 4c63ad1 + d92263d commit c88fa73
Show file tree
Hide file tree
Showing 20 changed files with 2,161 additions and 3,107 deletions.
12 changes: 0 additions & 12 deletions .github/FUNDING.yml

This file was deleted.

4 changes: 1 addition & 3 deletions .github/workflows/BlenderMalt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ jobs:
body: |
[**BlenderMalt-Windows.zip**](https://github.com/${{github.repository}}/releases/download/${{env.BRANCH_NAME}}-latest/BlenderMalt-Windows.zip)
[**BlenderMalt-Linux.zip**](https://github.com/${{github.repository}}/releases/download/${{env.BRANCH_NAME}}-latest/BlenderMalt-Linux.zip)
*(Requires Blender 4.1)*
- name: Rollback Tagged Release
uses: author/action-rollback@stable
Expand All @@ -56,7 +55,6 @@ jobs:
[**BlenderMalt-Windows.zip**](https://github.com/${{github.repository}}/releases/download/${{github.ref_name}}/BlenderMalt-Windows.zip)
[**BlenderMalt-Linux.zip**](https://github.com/${{github.repository}}/releases/download/${{github.ref_name}}/BlenderMalt-Linux.zip)
*(Requires Blender 4.1)*
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
Expand Down
156 changes: 70 additions & 86 deletions BlenderMalt/CBlenderMalt/CBlenderMalt.cpp
Original file line number Diff line number Diff line change
@@ -1,92 +1,12 @@
#include "stdio.h"
#include "string.h"
#include "mikktspace.h"

#ifdef _WIN32
#define EXPORT extern "C" __declspec( dllexport )
#else
#define EXPORT extern "C" __attribute__ ((visibility ("default")))
#endif

#include "blender_dna/DNA_mesh_types.h"
#include "blender_dna/DNA_meshdata_types.h"

//blenkernel/intern/customdata.cc

int CustomData_get_active_layer_index(const CustomData *data, int type)
{
const int layer_index = data->typemap[type];
//BLI_assert(customdata_typemap_is_valid(data));
return (layer_index != -1) ? layer_index + data->layers[layer_index].active : -1;
}

void *CustomData_get_layer(const CustomData *data, int type)
{
/* get the layer index of the active layer of type */
int layer_index = CustomData_get_active_layer_index(data, type);
if (layer_index == -1) {
return nullptr;
}

return data->layers[layer_index].data;
}

int CustomData_get_layer_index(const CustomData *data, int type)
{
//BLI_assert(customdata_typemap_is_valid(data));
return data->typemap[type];
}

int CustomData_get_layer_index_n(const struct CustomData *data, int type, int n)
{
//BLI_assert(n >= 0);
int i = CustomData_get_layer_index(data, type);

if (i != -1) {
//BLI_assert(i + n < data->totlayer);
i = (data->layers[i + n].type == type) ? (i + n) : (-1);
}

return i;
}

#define STREQ(a, b) (strcmp(a, b) == 0)

int CustomData_get_named_layer_index(const CustomData *data, const int type, const char *name)
{
for (int i = 0; i < data->totlayer; i++) {
if (data->layers[i].type == type) {
if (STREQ(data->layers[i].name, name)) {
return i;
}
}
}

return -1;
}

void *CustomData_get_layer_named(const CustomData *data, const int type, const char *name)
{
int layer_index = CustomData_get_named_layer_index(data, type, name);
if (layer_index == -1) {
return nullptr;
}

return data->layers[layer_index].data;
}

void *CustomData_get_layer_n(const CustomData *data, int type, int n)
{
/* get the layer index of the active layer of type */
int layer_index = CustomData_get_layer_index_n(data, type, n);
if (layer_index == -1) {
return nullptr;
}

return data->layers[layer_index].data;
}

// CBlenderMalt API

EXPORT void retrieve_mesh_data(
float* in_positions,
int* in_loop_verts, int loop_count,
Expand All @@ -113,10 +33,74 @@ EXPORT void retrieve_mesh_data(
}
}

EXPORT float* mesh_tangents_ptr(void* in_mesh)
EXPORT bool mesh_tangents(
int* in_indices, int index_len,
float* in_positions, float* in_normals, float* in_uvs,
float* out_tangents)
{
Mesh* mesh = (Mesh*)in_mesh;
float* ptr = (float*)CustomData_get_layer(&mesh->corner_data, CD_MLOOPTANGENT);

return ptr;
struct MData
{
int* indices;
int index_len;
float* positions;
float* normals;
float* uvs;
float* tangents;
};

MData data = {
in_indices,
index_len,
in_positions,
in_normals,
in_uvs,
out_tangents,
};

SMikkTSpaceInterface mti = {0};
mti.m_getNumFaces = [](const SMikkTSpaceContext * pContext){
return ((MData*)pContext->m_pUserData)->index_len / 3;
};

mti.m_getNumVerticesOfFace = [](const SMikkTSpaceContext * pContext, const int iFace){
return 3;
};

mti.m_getPosition = [](const SMikkTSpaceContext * pContext, float fvPosOut[], const int iFace, const int iVert){
MData* m = (MData*)pContext->m_pUserData;
int i = iFace * 3 + iVert;
fvPosOut[0] = m->positions[m->indices[i] * 3 + 0];
fvPosOut[1] = m->positions[m->indices[i] * 3 + 1];
fvPosOut[2] = m->positions[m->indices[i] * 3 + 2];
};

mti.m_getNormal = [](const SMikkTSpaceContext * pContext, float fvNormOut[], const int iFace, const int iVert){
MData* m = (MData*)pContext->m_pUserData;
int i = iFace * 3 + iVert;
fvNormOut[0] = m->normals[m->indices[i] * 3 + 0];
fvNormOut[1] = m->normals[m->indices[i] * 3 + 1];
fvNormOut[2] = m->normals[m->indices[i] * 3 + 2];
};

mti.m_getTexCoord = [](const SMikkTSpaceContext * pContext, float fvTexcOut[], const int iFace, const int iVert){
MData* m = (MData*)pContext->m_pUserData;
int i = iFace * 3 + iVert;
fvTexcOut[0] = m->uvs[m->indices[i] * 2 + 0];
fvTexcOut[1] = m->uvs[m->indices[i] * 2 + 1];
};

mti.m_setTSpaceBasic = [](const SMikkTSpaceContext * pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert){
MData* m = (MData*)pContext->m_pUserData;
int i = iFace * 3 + iVert;
m->tangents[m->indices[i] * 4 + 0] = fvTangent[0];
m->tangents[m->indices[i] * 4 + 1] = fvTangent[1];
m->tangents[m->indices[i] * 4 + 2] = fvTangent[2];
m->tangents[m->indices[i] * 4 + 3] = fSign;
};

SMikkTSpaceContext mtc;
mtc.m_pInterface = &mti;
mtc.m_pUserData = &data;

return genTangSpaceDefault(&mtc);
}
3 changes: 1 addition & 2 deletions BlenderMalt/CBlenderMalt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ project(CBlenderMalt)
SET(CMAKE_BUILD_TYPE Release)
SET(BUILD_SHARED_LIBS ON)

add_library(CBlenderMalt CBlenderMalt.cpp)
add_library(CBlenderMalt CBlenderMalt.cpp mikktspace.c)
target_include_directories(CBlenderMalt PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/blender_dna)

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

10 changes: 7 additions & 3 deletions BlenderMalt/CBlenderMalt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
]
retrieve_mesh_data.restype = None

mesh_tangents_ptr = CBlenderMalt['mesh_tangents_ptr']
mesh_tangents_ptr.argtypes = [ctypes.c_void_p]
mesh_tangents_ptr.restype = ctypes.POINTER(ctypes.c_float)
mesh_tangents = CBlenderMalt['mesh_tangents']
mesh_tangents.argtypes = [
ctypes.POINTER(ctypes.c_int), ctypes.c_int,
ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float)
]
mesh_tangents.restype = ctypes.c_bool
74 changes: 0 additions & 74 deletions BlenderMalt/CBlenderMalt/blender_dna/BLI_sys_types.h

This file was deleted.

Loading

0 comments on commit c88fa73

Please sign in to comment.