mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-08-14 01:15:56 +08:00
Added uvs mapping
This commit is contained in:
parent
9d02e1cd75
commit
64dbf0f3ef
Binary file not shown.
@ -15,7 +15,9 @@ class Drc2PyMesh(ctypes.Structure):
|
|||||||
("vertices_num", ctypes.c_uint),
|
("vertices_num", ctypes.c_uint),
|
||||||
("vertices", ctypes.POINTER(ctypes.c_float)),
|
("vertices", ctypes.POINTER(ctypes.c_float)),
|
||||||
("normals_num", ctypes.c_uint),
|
("normals_num", ctypes.c_uint),
|
||||||
("normals", ctypes.POINTER(ctypes.c_float))
|
("normals", ctypes.POINTER(ctypes.c_float)),
|
||||||
|
("uvs_num", ctypes.c_uint),
|
||||||
|
("uvs", ctypes.POINTER(ctypes.c_float))
|
||||||
]
|
]
|
||||||
|
|
||||||
# TODO: Add integration for UNIX
|
# TODO: Add integration for UNIX
|
||||||
@ -67,6 +69,10 @@ class Draco:
|
|||||||
result.normals_len = mesh.normals_num * 3
|
result.normals_len = mesh.normals_num * 3
|
||||||
result.normals_num = mesh.normals_num
|
result.normals_num = mesh.normals_num
|
||||||
|
|
||||||
|
result.uvs = mesh.uvs[0:mesh.uvs_num * 3]
|
||||||
|
result.uvs_len = mesh.uvs_num * 3
|
||||||
|
result.uvs_num = mesh.uvs_num
|
||||||
|
|
||||||
# Free memory allocated by the lib
|
# Free memory allocated by the lib
|
||||||
self.drc_free(ctypes.byref(mesh_ptr))
|
self.drc_free(ctypes.byref(mesh_ptr))
|
||||||
mesh_ptr = None
|
mesh_ptr = None
|
||||||
|
@ -27,6 +27,10 @@ class DracoTest(unittest.TestCase):
|
|||||||
self.assertEqual(0, mesh.normals_num, 'Number of normals')
|
self.assertEqual(0, mesh.normals_num, 'Number of normals')
|
||||||
self.assertEqual(0, mesh.normals_len,'Length of normals array precalculated')
|
self.assertEqual(0, mesh.normals_len,'Length of normals array precalculated')
|
||||||
self.assertEqual(0, len(mesh.normals),'Length of normals array by len')
|
self.assertEqual(0, len(mesh.normals),'Length of normals array by len')
|
||||||
|
# Uvs check
|
||||||
|
self.assertEqual(0, mesh.normals_num, 'Number of uvs')
|
||||||
|
self.assertEqual(0, mesh.normals_len,'Length of uvs array precalculated')
|
||||||
|
self.assertEqual(0, len(mesh.normals),'Length of uvs array by len')
|
||||||
|
|
||||||
def test_unexistent_drc(self):
|
def test_unexistent_drc(self):
|
||||||
self.assertRaises(Exception, self.drc.decode, 'unexistent.drc')
|
self.assertRaises(Exception, self.drc.decode, 'unexistent.drc')
|
||||||
|
@ -60,7 +60,6 @@ namespace draco {
|
|||||||
int num_normals = drc_mesh->num_points();
|
int num_normals = drc_mesh->num_points();
|
||||||
out_mesh->normals = new float[num_normals];
|
out_mesh->normals = new float[num_normals];
|
||||||
out_mesh->normals_num = num_normals;
|
out_mesh->normals_num = num_normals;
|
||||||
//out_mesh->has_normals = true;
|
|
||||||
|
|
||||||
for (int i = 0; i < num_normals; i++) {
|
for (int i = 0; i < num_normals; i++) {
|
||||||
draco::PointIndex pi(i);
|
draco::PointIndex pi(i);
|
||||||
@ -74,7 +73,32 @@ namespace draco {
|
|||||||
out_mesh->normals[i * 3 + 1] = out_normal[1];
|
out_mesh->normals[i * 3 + 1] = out_normal[1];
|
||||||
out_mesh->normals[i * 3 + 2] = out_normal[2];
|
out_mesh->normals[i * 3 + 2] = out_normal[2];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void decode_uvs(std::unique_ptr<draco::Mesh> &drc_mesh, Drc2PyMesh* out_mesh) {
|
||||||
|
const auto uv_att = drc_mesh->GetNamedAttribute(draco::GeometryAttribute::TEX_COORD);
|
||||||
|
if (uv_att == nullptr) {
|
||||||
|
out_mesh->uvs = new float[0];
|
||||||
|
out_mesh->uvs_num = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int num_uvs = drc_mesh->num_points();
|
||||||
|
out_mesh->normals = new float[num_uvs * 2];
|
||||||
|
out_mesh->normals_num = num_uvs;
|
||||||
|
|
||||||
|
for (int i = 0; i < num_uvs; i++) {
|
||||||
|
draco::PointIndex pi(i);
|
||||||
|
const draco::AttributeValueIndex val_index = uv_att->mapped_index(pi);
|
||||||
|
|
||||||
|
float out_uv[3];
|
||||||
|
bool is_ok = uv_att->ConvertValue<float, 3>(val_index, out_uv);
|
||||||
|
if (!is_ok) return;
|
||||||
|
|
||||||
|
out_mesh->uvs[i * 3 + 0] = out_uv[0];
|
||||||
|
out_mesh->uvs[i * 3 + 1] = out_uv[1];
|
||||||
|
out_mesh->uvs[i * 3 + 2] = out_uv[2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drc2py_free(Drc2PyMesh **mesh_ptr) {
|
void drc2py_free(Drc2PyMesh **mesh_ptr) {
|
||||||
|
@ -36,13 +36,17 @@ namespace draco {
|
|||||||
vertices_num(0),
|
vertices_num(0),
|
||||||
vertices(nullptr),
|
vertices(nullptr),
|
||||||
normals_num(0),
|
normals_num(0),
|
||||||
normals(nullptr) {}
|
normals(nullptr),
|
||||||
|
uvs_num(0),
|
||||||
|
uvs(nullptr) {}
|
||||||
int faces_num;
|
int faces_num;
|
||||||
int* faces;
|
int* faces;
|
||||||
int vertices_num;
|
int vertices_num;
|
||||||
float* vertices;
|
float* vertices;
|
||||||
int normals_num;
|
int normals_num;
|
||||||
float* normals;
|
float* normals;
|
||||||
|
int uvs_num;
|
||||||
|
float* uvs;
|
||||||
};
|
};
|
||||||
|
|
||||||
EXPORT_API int drc2py_decode(char *data, unsigned int length, Drc2PyMesh **res_mesh);
|
EXPORT_API int drc2py_decode(char *data, unsigned int length, Drc2PyMesh **res_mesh);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user