Skip to content

Commit

Permalink
Blender 4.1 update
Browse files Browse the repository at this point in the history
  • Loading branch information
pragma37 committed Mar 28, 2024
1 parent 07d3d6e commit 0d917fe
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 208 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/BlenderMalt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
[**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.0)*
*(Requires Blender 4.1)*
- name: Rollback Tagged Release
uses: author/action-rollback@stable
Expand All @@ -56,7 +56,7 @@ 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.0)*
*(Requires Blender 4.1)*
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
Expand All @@ -77,7 +77,7 @@ jobs:

- uses: actions/setup-python@v2
with:
python-version: '3.10'
python-version: '3.11'

- name: setup_blender_addon.py
run: python setup_blender_addon.py --copy-modules
Expand Down
64 changes: 16 additions & 48 deletions BlenderMalt/CBlenderMalt/CBlenderMalt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,68 +87,36 @@ void *CustomData_get_layer_n(const CustomData *data, int type, int n)

// CBlenderMalt API

EXPORT void retrieve_mesh_data(void* in_mesh, void* in_loop_tris, int* in_loop_tri_polys, int loop_tri_count,
float* out_positions, float* out_normals, unsigned int** out_indices, unsigned int* out_index_lengths)
EXPORT void retrieve_mesh_data(
float* in_positions,
int* in_loop_verts, int loop_count,
int* in_loop_tris,
int* in_loop_tri_polys, int loop_tri_count,
int* in_mat_indices,
float* out_positions, unsigned int** out_indices, unsigned int* out_index_lengths)
{
Mesh* mesh = (Mesh*)in_mesh;
MLoopTri* loop_tris = (MLoopTri*)in_loop_tris;

int* loop_verts = (int*)CustomData_get_layer_named(&mesh->loop_data, CD_PROP_INT32, ".corner_vert");
float* positions = (float*)CustomData_get_layer_named(&mesh->vert_data, CD_PROP_FLOAT3, "position");
float* normals = (float*)CustomData_get_layer(&mesh->loop_data, CD_NORMAL);
int* mat_indices = (int*)CustomData_get_layer_named(&mesh->face_data, CD_PROP_INT32, "material_index");

for(int i = 0; i < mesh->totloop; i++)
for(int i = 0; i < loop_count; i++)
{
out_positions[i*3+0] = positions[loop_verts[i]*3+0];
out_positions[i*3+1] = positions[loop_verts[i]*3+1];
out_positions[i*3+2] = positions[loop_verts[i]*3+2];
out_positions[i*3+0] = in_positions[in_loop_verts[i]*3+0];
out_positions[i*3+1] = in_positions[in_loop_verts[i]*3+1];
out_positions[i*3+2] = in_positions[in_loop_verts[i]*3+2];
}

memcpy(out_normals, normals, mesh->totloop * sizeof(float) * 3);

unsigned int* mat_i = out_index_lengths;

for(int i = 0; i < loop_tri_count; i++)
{
int mat = mat_indices ? mat_indices[in_loop_tri_polys[i]] : 0;
out_indices[mat][mat_i[mat]++] = loop_tris[i].tri[0];
out_indices[mat][mat_i[mat]++] = loop_tris[i].tri[1];
out_indices[mat][mat_i[mat]++] = loop_tris[i].tri[2];
int mat = in_mat_indices ? in_mat_indices[in_loop_tri_polys[i]] : 0;
out_indices[mat][mat_i[mat]++] = in_loop_tris[i*3+0];
out_indices[mat][mat_i[mat]++] = in_loop_tris[i*3+1];
out_indices[mat][mat_i[mat]++] = in_loop_tris[i*3+2];
}
}

EXPORT float* mesh_tangents_ptr(void* in_mesh)
{
Mesh* mesh = (Mesh*)in_mesh;
float* ptr = (float*)CustomData_get_layer(&mesh->loop_data, CD_MLOOPTANGENT);
float* ptr = (float*)CustomData_get_layer(&mesh->corner_data, CD_MLOOPTANGENT);

return ptr;
}

EXPORT void pack_tangents(float* in_tangents, float* in_bitangent_signs, int loop_count, float* out_tangents)
{
for(int i = 0; i < loop_count; i++)
{
out_tangents[i*4+0] = in_tangents[i*3+0];
out_tangents[i*4+1] = in_tangents[i*3+1];
out_tangents[i*4+2] = in_tangents[i*3+2];
out_tangents[i*4+3] = in_bitangent_signs[i];
}
}

EXPORT bool has_flat_polys(void* in_mesh, int polys_count)
{
Mesh* mesh = (Mesh*)in_mesh;
const bool *sharp_faces = (bool*)CustomData_get_layer_named(&mesh->face_data, CD_PROP_BOOL, "sharp_face");

for(int i = 0; i < polys_count; i++)
{
if(sharp_faces[i])
{
return true;
}
}

return false;
}
17 changes: 6 additions & 11 deletions BlenderMalt/CBlenderMalt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@

retrieve_mesh_data = CBlenderMalt['retrieve_mesh_data']
retrieve_mesh_data.argtypes = [
ctypes.c_void_p, ctypes.c_void_p, ctypes.POINTER(ctypes.c_int), ctypes.c_int,
ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(ctypes.c_uint32)
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_int), ctypes.c_int,
ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_int), ctypes.c_int,
ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_void_p), ctypes.POINTER(ctypes.c_uint32)
]
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)

pack_tangents = CBlenderMalt['pack_tangents']
pack_tangents.argtypes = [ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float), ctypes.c_int, ctypes.POINTER(ctypes.c_float)]
pack_tangents.restype = None

has_flat_polys = CBlenderMalt['has_flat_polys']
has_flat_polys.argtypes = [ctypes.c_void_p, ctypes.c_int]
has_flat_polys.restype = ctypes.c_bool
29 changes: 21 additions & 8 deletions BlenderMalt/CBlenderMalt/blender_dna/DNA_ID.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,35 @@ typedef struct IDPropertyUIData {
char _pad[4];
} IDPropertyUIData;

/* DNA version of #EnumPropertyItem. */
typedef struct IDPropertyUIDataEnumItem {
/* Unique identifier, used for string lookup. */
char *identifier;
/* UI name of the item. */
char *name;
/* Optional description. */
char *description;
/* Unique integer value, should never change. */
int value;
/* Optional icon. */
int icon;
} IDPropertyUIDataEnumItem;

/* IDP_UI_DATA_TYPE_INT */
typedef struct IDPropertyUIDataInt {
IDPropertyUIData base;
int *default_array; /* Only for array properties. */
int default_array_len;
char _pad[4];

int min;
int max;
int soft_min;
int soft_max;
int step;
int default_value;

int enum_items_num;
IDPropertyUIDataEnumItem *enum_items;
} IDPropertyUIDataInt;

/** For #IDP_UI_DATA_TYPE_BOOLEAN Use `int8_t` because DNA does not support `bool`. */
Expand Down Expand Up @@ -477,7 +493,7 @@ typedef struct ID {
* A session-wide unique identifier for a given ID, that remain the same across potential
* re-allocations (e.g. due to undo/redo steps).
*/
unsigned int session_uuid;
unsigned int session_uid;

IDProperty *properties;

Expand Down Expand Up @@ -679,9 +695,6 @@ typedef struct PreviewImage {
(!ID_IS_OVERRIDE_LIBRARY_REAL(_id) || \
((ID *)(_id))->override_library->hierarchy_root == ((ID *)(_id)))

#define ID_IS_OVERRIDE_LIBRARY_TEMPLATE(_id) \
(((ID *)(_id))->override_library != NULL && ((ID *)(_id))->override_library->reference == NULL)

#define ID_IS_ASSET(_id) (((const ID *)(_id))->asset_data != NULL)

/* Check whether datablock type is covered by copy-on-write. */
Expand Down Expand Up @@ -901,7 +914,7 @@ enum {
* processing, because it is a 'NO_UNDO' type of ID.
*
* \note: Also means that such ID does not need to be lib-linked during undo readfile process. It
* does need to be relinked in a different way however, doing a `session_uuid`-based lookup into
* does need to be relinked in a different way however, doing a `session_uid`-based lookup into
* the newly read main database.
*
* RESET_AFTER_USE
Expand All @@ -928,12 +941,12 @@ enum {
* RESET_NEVER
*
* Don't allow assigning this to non-temporary members (since it's likely to cause errors).
* When set #ID.session_uuid isn't initialized, since the data isn't part of the session.
* When set #ID.session_uid isn't initialized, since the data isn't part of the session.
*/
LIB_TAG_TEMP_MAIN = 1 << 20,
/** General ID management info, for freeing or copying behavior e.g. */
/**
* ID is not listed/stored in Main database.
* ID is not listed/stored in any #Main database.
*
* RESET_NEVER
*/
Expand Down
50 changes: 30 additions & 20 deletions BlenderMalt/CBlenderMalt/blender_dna/DNA_customdata_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,24 @@ typedef struct CustomDataExternal {
} CustomDataExternal;

/**
* Structure which stores custom element data associated with mesh elements
* (vertices, edges or faces). The custom data is organized into a series of
* layers, each with a data type (e.g. MTFace, MDeformVert, etc.).
* #CustomData stores an arbitrary number of typed data "layers" for multiple elements.
* The layers are typically geometry attributes, and the elements are typically geometry
* elements like vertices, edges, or curves.
*
* Each layer has a type, often with certain semantics beyond the type of the raw data. However,
* a subset of the layer types are exposed as attributes and accessed with a higher level API
* built around #AttributeAccessor.
*
* For #BMesh, #CustomData is adapted to store the data from all layers in a single "block" which
* is allocated for each element. Each layer's data is stored at a certain offset into every
* block's data.
*/
typedef struct CustomData {
/** CustomDataLayers, ordered by type. */
/** Layers ordered by type. */
CustomDataLayer *layers;
/**
* runtime only! - maps types to indices of first layer of that type,
* MUST be >= CD_NUMTYPES, but we can't use a define here.
* Correct size is ensured in CustomData_update_typemap assert().
* Runtime only map from types to indices of first layer of that type,
* Correct size of #CD_NUMTYPES is ensured by CustomData_update_typemap.
*/
int typemap[53];
/** Number of layers, size of layers array. */
Expand All @@ -92,19 +99,19 @@ typedef struct CustomData {
CustomDataExternal *external;
} CustomData;

/** #CustomData.type */
/** #CustomDataLayer.type */
typedef enum eCustomDataType {
/* Used by GLSL attributes in the cases when we need a delayed CD type
* assignment (in the cases when we don't know in advance which layer
* we are addressing).
/**
* Used by GPU attributes in the cases when we don't know which layer
* we are addressing in advance.
*/
CD_AUTO_FROM_NAME = -1,

#ifdef DNA_DEPRECATED_ALLOW
CD_MVERT = 0,
CD_MSTICKY = 1,
#endif
CD_MDEFORMVERT = 2, /* Array of `MDeformVert`. */
CD_MDEFORMVERT = 2, /* Array of #MDeformVert. */
#ifdef DNA_DEPRECATED_ALLOW
CD_MEDGE = 3,
#endif
Expand All @@ -113,8 +120,8 @@ typedef enum eCustomDataType {
CD_MCOL = 6,
CD_ORIGINDEX = 7,
/**
* Used for derived face corner normals on mesh `ldata`, since currently they are not computed
* lazily. Derived vertex and polygon normals are stored in #Mesh_Runtime.
* Used as temporary storage for some areas that support interpolating custom normals.
* Using a separate type from generic 3D vectors is a simple way of keeping values normalized.
*/
CD_NORMAL = 8,
#ifdef DNA_DEPRECATED_ALLOW
Expand All @@ -132,8 +139,8 @@ typedef enum eCustomDataType {
CD_PROP_BYTE_COLOR = 17,
CD_TANGENT = 18,
CD_MDISPS = 19,
CD_PREVIEW_MCOL = 20, /* For displaying weight-paint colors. */
/* CD_ID_MCOL = 21, */
/* CD_PREVIEW_MCOL = 20, */ /* UNUSED */
/* CD_ID_MCOL = 21, */
/* CD_TEXTURE_MLOOPCOL = 22, */ /* UNUSED */
CD_CLOTH_ORCO = 23,
/* CD_RECAST = 24, */ /* UNUSED */
Expand All @@ -149,10 +156,12 @@ typedef enum eCustomDataType {
CD_CREASE = 30,
#endif
CD_ORIGSPACE_MLOOP = 31,
CD_PREVIEW_MLOOPCOL = 32,
/* CD_PREVIEW_MLOOPCOL = 32, */ /* UNUSED */
CD_BM_ELEM_PYPTR = 33,

#ifdef DNA_DEPRECATED_ALLOW
CD_PAINT_MASK = 34,
#endif
CD_GRID_PAINT_MASK = 35,
CD_MVERT_SKIN = 36,
CD_FREESTYLE_EDGE = 37,
Expand Down Expand Up @@ -182,6 +191,10 @@ typedef enum eCustomDataType {
CD_NUMTYPES = 53,
} eCustomDataType;

#ifdef __cplusplus
using eCustomDataMask = uint64_t;
#endif

/* Bits for eCustomDataMask */
#define CD_MASK_MDEFORMVERT (1 << CD_MDEFORMVERT)
#define CD_MASK_MFACE (1 << CD_MFACE)
Expand All @@ -197,16 +210,13 @@ typedef enum eCustomDataType {
#define CD_MASK_PROP_BYTE_COLOR (1 << CD_PROP_BYTE_COLOR)
#define CD_MASK_TANGENT (1 << CD_TANGENT)
#define CD_MASK_MDISPS (1 << CD_MDISPS)
#define CD_MASK_PREVIEW_MCOL (1 << CD_PREVIEW_MCOL)
#define CD_MASK_CLOTH_ORCO (1 << CD_CLOTH_ORCO)

#define CD_MASK_SHAPE_KEYINDEX (1 << CD_SHAPE_KEYINDEX)
#define CD_MASK_SHAPEKEY (1 << CD_SHAPEKEY)
#define CD_MASK_ORIGSPACE_MLOOP (1LL << CD_ORIGSPACE_MLOOP)
#define CD_MASK_PREVIEW_MLOOPCOL (1LL << CD_PREVIEW_MLOOPCOL)
#define CD_MASK_BM_ELEM_PYPTR (1LL << CD_BM_ELEM_PYPTR)

#define CD_MASK_PAINT_MASK (1LL << CD_PAINT_MASK)
#define CD_MASK_GRID_PAINT_MASK (1LL << CD_GRID_PAINT_MASK)
#define CD_MASK_MVERT_SKIN (1LL << CD_MVERT_SKIN)
#define CD_MASK_FREESTYLE_EDGE (1LL << CD_FREESTYLE_EDGE)
Expand Down
3 changes: 1 addition & 2 deletions BlenderMalt/CBlenderMalt/blender_dna/DNA_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ template<class T> class ShallowDataConstRef {
const T &ref_;
};

class ShallowZeroInitializeTag {
};
class ShallowZeroInitializeTag {};

} // namespace blender::dna::internal

Expand Down
Loading

0 comments on commit 0d917fe

Please sign in to comment.