Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ufbx/_ufbx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ cdef extern from "ufbx_wrapper.h":
const float* ufbx_wrapper_mesh_get_vertex_bitangents(const ufbx_mesh *mesh, size_t *out_count)
const float* ufbx_wrapper_mesh_get_vertex_colors(const ufbx_mesh *mesh, size_t *out_count)
const uint32_t* ufbx_wrapper_mesh_get_indices(const ufbx_mesh *mesh, size_t *out_count)
const uint32_t* ufbx_wrapper_mesh_get_uv_indices(const ufbx_mesh *mesh, size_t *out_count)

# Mesh face data
size_t ufbx_wrapper_mesh_get_face_count(const ufbx_mesh *mesh)
Expand Down Expand Up @@ -2482,6 +2483,22 @@ cdef class Mesh(Element):
shape[0] = <np.npy_intp>count
return np.PyArray_SimpleNewFromData(1, shape, np.NPY_UINT32, <void*>data)

@property
def uv_indices(self):
"""UV indices as numpy array (N,)"""
if self._scene._closed:
raise RuntimeError("Scene is closed")

cdef size_t count = 0
cdef const uint32_t* data = ufbx_wrapper_mesh_get_uv_indices(self._mesh, &count)

if data == NULL or count == 0:
return None

cdef np.npy_intp shape[1]
shape[0] = <np.npy_intp>count
return np.PyArray_SimpleNewFromData(1, shape, np.NPY_UINT32, <void*>data)

@property
def materials(self):
"""Materials used by this mesh"""
Expand Down
10 changes: 10 additions & 0 deletions ufbx/src/ufbx_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,16 @@ const uint32_t* ufbx_wrapper_mesh_get_indices(const ufbx_mesh *mesh, size_t *out
return mesh->vertex_position.indices.data;
}

const uint32_t* ufbx_wrapper_mesh_get_uv_indices(const ufbx_mesh *mesh, size_t *out_count) {
if (!mesh || !mesh->vertex_uv.exists || !out_count) {
if (out_count) *out_count = 0;
return NULL;
}

*out_count = mesh->vertex_uv.indices.count;
return mesh->vertex_uv.indices.data;
}

// Mesh face data
size_t ufbx_wrapper_mesh_get_face_count(const ufbx_mesh *mesh) {
return mesh ? mesh->faces.count : 0;
Expand Down
1 change: 1 addition & 0 deletions ufbx/src/ufbx_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const float* ufbx_wrapper_mesh_get_vertex_tangents(const ufbx_mesh *mesh, size_t
const float* ufbx_wrapper_mesh_get_vertex_bitangents(const ufbx_mesh *mesh, size_t *out_count);
const float* ufbx_wrapper_mesh_get_vertex_colors(const ufbx_mesh *mesh, size_t *out_count);
const uint32_t* ufbx_wrapper_mesh_get_indices(const ufbx_mesh *mesh, size_t *out_count);
const uint32_t* ufbx_wrapper_mesh_get_uv_indices(const ufbx_mesh *mesh, size_t *out_count);

// Mesh face data
size_t ufbx_wrapper_mesh_get_face_count(const ufbx_mesh *mesh);
Expand Down