gmio_amf: only one function for mesh element metadata
This commit is contained in:
parent
26f05688d9
commit
3952c8e0ee
@ -202,9 +202,14 @@ enum gmio_amf_mesh_element {
|
|||||||
|
|
||||||
/*! Index of an element(vertex, edge or volume) within a mesh */
|
/*! Index of an element(vertex, edge or volume) within a mesh */
|
||||||
struct gmio_amf_object_mesh_element_index {
|
struct gmio_amf_object_mesh_element_index {
|
||||||
uint32_t object_index; /*!< Index of the object that owns the mesh */
|
/*! Index of the object that owns the mesh */
|
||||||
uint32_t mesh_index; /*!< Index of the mesh that owns element */
|
uint32_t object_index;
|
||||||
uint32_t value; /*!< Index of the inner element */
|
/*! Index of the mesh that owns element */
|
||||||
|
uint32_t mesh_index;
|
||||||
|
/*! Index of the inner element */
|
||||||
|
uint32_t value;
|
||||||
|
/*! Type of the inner element */
|
||||||
|
enum gmio_amf_mesh_element element_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! Provides an interface for accessing the underlying(hidden) user AMF data
|
/*! Provides an interface for accessing the underlying(hidden) user AMF data
|
||||||
@ -257,7 +262,7 @@ struct gmio_amf_document {
|
|||||||
* \c material element
|
* \c material element
|
||||||
*
|
*
|
||||||
* Function not required(can be set to \c NULL) if there is no material
|
* Function not required(can be set to \c NULL) if there is no material
|
||||||
* composite in the document to write */
|
* composite in the document */
|
||||||
void (*func_get_material_composite)(
|
void (*func_get_material_composite)(
|
||||||
const void* cookie,
|
const void* cookie,
|
||||||
uint32_t material_index,
|
uint32_t material_index,
|
||||||
@ -268,7 +273,7 @@ struct gmio_amf_document {
|
|||||||
* \c constellation element
|
* \c constellation element
|
||||||
*
|
*
|
||||||
* Function not required(can be set to \c NULL) if there is no
|
* Function not required(can be set to \c NULL) if there is no
|
||||||
* constellation in the document to write */
|
* constellation in the document */
|
||||||
void (*func_get_constellation_instance)(
|
void (*func_get_constellation_instance)(
|
||||||
const void* cookie,
|
const void* cookie,
|
||||||
uint32_t constellation_index,
|
uint32_t constellation_index,
|
||||||
@ -284,7 +289,6 @@ struct gmio_amf_document {
|
|||||||
|
|
||||||
/*! Function that retrieves the i-th sub-element of a \c mesh element
|
/*! Function that retrieves the i-th sub-element of a \c mesh element
|
||||||
*
|
*
|
||||||
* \p element is the type of the sub-element of interest.\n
|
|
||||||
* \p element_index is the index of the sub-element within the \c mesh
|
* \p element_index is the index of the sub-element within the \c mesh
|
||||||
* element.\n
|
* element.\n
|
||||||
* The domain of this index(ie. \c value field) depends on \p element :
|
* The domain of this index(ie. \c value field) depends on \p element :
|
||||||
@ -296,12 +300,10 @@ struct gmio_amf_document {
|
|||||||
*/
|
*/
|
||||||
void (*func_get_object_mesh_element)(
|
void (*func_get_object_mesh_element)(
|
||||||
const void* cookie,
|
const void* cookie,
|
||||||
enum gmio_amf_mesh_element element,
|
|
||||||
const struct gmio_amf_object_mesh_element_index* element_index,
|
const struct gmio_amf_object_mesh_element_index* element_index,
|
||||||
void* ptr_element);
|
void* ptr_element);
|
||||||
|
|
||||||
/*! Function that retrieves the i-th \c triangle within a mesh \c volume
|
/*! Function that retrieves the i-th \c triangle within a mesh \c volume */
|
||||||
* element */
|
|
||||||
void (*func_get_object_mesh_volume_triangle)(
|
void (*func_get_object_mesh_volume_triangle)(
|
||||||
const void* cookie,
|
const void* cookie,
|
||||||
const struct gmio_amf_object_mesh_element_index* volume_index,
|
const struct gmio_amf_object_mesh_element_index* volume_index,
|
||||||
@ -324,7 +326,7 @@ struct gmio_amf_document {
|
|||||||
* CONSTELLATION | <tt> [0 .. constellation_count[ </tt> | gmio_amf_constellation
|
* CONSTELLATION | <tt> [0 .. constellation_count[ </tt> | gmio_amf_constellation
|
||||||
*
|
*
|
||||||
* Function not required(can be set to \c NULL) if there is no metadata in
|
* Function not required(can be set to \c NULL) if there is no metadata in
|
||||||
* the document to write */
|
* the document */
|
||||||
void (*func_get_document_element_metadata)(
|
void (*func_get_document_element_metadata)(
|
||||||
const void* cookie,
|
const void* cookie,
|
||||||
enum gmio_amf_document_element element,
|
enum gmio_amf_document_element element,
|
||||||
@ -332,25 +334,14 @@ struct gmio_amf_document {
|
|||||||
uint32_t metadata_index,
|
uint32_t metadata_index,
|
||||||
struct gmio_amf_metadata* ptr_metadata);
|
struct gmio_amf_metadata* ptr_metadata);
|
||||||
|
|
||||||
/*! Optional function that retrieves the i-th metadata assigned to a mesh
|
/*! Optional function that retrieves the i-th metadata attached to a mesh
|
||||||
* vertex
|
* element(only vertex or volume)
|
||||||
*
|
*
|
||||||
* Function not required(can be set to \c NULL) if there is no mesh vertex
|
* Function not required(can be set to \c NULL) if there is no metadata
|
||||||
* metadata in the document to write */
|
* for all mesh elements */
|
||||||
void (*func_get_object_mesh_vertex_metadata)(
|
void (*func_get_object_mesh_element_metadata)(
|
||||||
const void* cookie,
|
const void* cookie,
|
||||||
const struct gmio_amf_object_mesh_element_index* vertex_index,
|
const struct gmio_amf_object_mesh_element_index* mesh_element_index,
|
||||||
uint32_t metadata_index,
|
|
||||||
struct gmio_amf_metadata* ptr_metadata);
|
|
||||||
|
|
||||||
/*! Optional function that retrieves the i-th metadata assigned to a mesh
|
|
||||||
* volume
|
|
||||||
*
|
|
||||||
* Function not required(can be set to \c NULL) if there is no mesh volume
|
|
||||||
* metadata in the document to write */
|
|
||||||
void (*func_get_object_mesh_volume_metadata)(
|
|
||||||
const void* cookie,
|
|
||||||
const struct gmio_amf_object_mesh_element_index* volume_index,
|
|
||||||
uint32_t metadata_index,
|
uint32_t metadata_index,
|
||||||
struct gmio_amf_metadata* ptr_metadata);
|
struct gmio_amf_metadata* ptr_metadata);
|
||||||
};
|
};
|
||||||
|
@ -73,13 +73,9 @@ enum gmio_amf_error
|
|||||||
* is \c NULL while some gmio_amf_material::composite_count > 0 */
|
* is \c NULL while some gmio_amf_material::composite_count > 0 */
|
||||||
GMIO_AMF_ERROR_NULL_FUNC_GET_MATERIAL_COMPOSITE,
|
GMIO_AMF_ERROR_NULL_FUNC_GET_MATERIAL_COMPOSITE,
|
||||||
|
|
||||||
/*! Function pointer gmio_amf_document::func_get_object_mesh_vertex_metadata
|
/*! Function pointer gmio_amf_document::func_get_object_mesh_element_metadata
|
||||||
* is \c NULL while some gmio_amf_vertex::metadata_count > 0 */
|
* is \c NULL while some metadata is attached to a mesh element */
|
||||||
GMIO_AMF_ERROR_NULL_FUNC_GET_OBJECT_MESH_VERTEX_METADATA,
|
GMIO_AMF_ERROR_NULL_FUNC_GET_OBJECT_MESH_ELEMENT_METADATA
|
||||||
|
|
||||||
/*! Function pointer gmio_amf_document::func_get_object_mesh_volume_metadata
|
|
||||||
* is \c NULL while some gmio_amf_volume::metadata_count > 0 */
|
|
||||||
GMIO_AMF_ERROR_NULL_FUNC_GET_OBJECT_MESH_VOLUME_METADATA
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! @} */
|
/*! @} */
|
||||||
|
@ -274,6 +274,26 @@ static void gmio_amf_write_texmap(
|
|||||||
gmio_ostringstream_write_chararray(sstream, "</texmap>\n");
|
gmio_ostringstream_write_chararray(sstream, "</texmap>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool gmio_amf_write_mesh_object_element_metadata(
|
||||||
|
struct gmio_amf_wcontext* context,
|
||||||
|
const struct gmio_amf_object_mesh_element_index* mesh_element_index,
|
||||||
|
uint32_t metadata_count)
|
||||||
|
{
|
||||||
|
const struct gmio_amf_document* doc = context->document;
|
||||||
|
if (doc->func_get_object_mesh_element_metadata == NULL) {
|
||||||
|
return gmio_amf_wcontext_set_error(
|
||||||
|
context,
|
||||||
|
GMIO_AMF_ERROR_NULL_FUNC_GET_OBJECT_MESH_ELEMENT_METADATA);
|
||||||
|
}
|
||||||
|
struct gmio_amf_metadata metadata = {0};
|
||||||
|
for (uint32_t imeta = 0; imeta < metadata_count; ++imeta) {
|
||||||
|
doc->func_get_object_mesh_element_metadata(
|
||||||
|
doc->cookie, mesh_element_index, imeta, &metadata);
|
||||||
|
gmio_amf_write_metadata(&context->sstream, &metadata);
|
||||||
|
}
|
||||||
|
return gmio_no_error(context->error);
|
||||||
|
}
|
||||||
|
|
||||||
/* Writes gmio_amf_mesh to stream */
|
/* Writes gmio_amf_mesh to stream */
|
||||||
static bool gmio_amf_write_mesh(
|
static bool gmio_amf_write_mesh(
|
||||||
struct gmio_amf_wcontext* context,
|
struct gmio_amf_wcontext* context,
|
||||||
@ -287,13 +307,13 @@ static bool gmio_amf_write_mesh(
|
|||||||
const struct gmio_ostringstream_format_float* f64_format =
|
const struct gmio_ostringstream_format_float* f64_format =
|
||||||
&context->f64_format;
|
&context->f64_format;
|
||||||
/* Write mesh <vertices> element */
|
/* Write mesh <vertices> element */
|
||||||
|
mesh_elt_index.element_type = GMIO_AMF_MESH_ELEMENT_VERTEX;
|
||||||
struct gmio_amf_vertex vertex = {0};
|
struct gmio_amf_vertex vertex = {0};
|
||||||
gmio_ostringstream_write_chararray(sstream, "<mesh>\n<vertices>\n");
|
gmio_ostringstream_write_chararray(sstream, "<mesh>\n<vertices>\n");
|
||||||
for (uint32_t ivert = 0; ivert < mesh->vertex_count; ++ivert) {
|
for (uint32_t ivert = 0; ivert < mesh->vertex_count; ++ivert) {
|
||||||
mesh_elt_index.value = ivert;
|
mesh_elt_index.value = ivert;
|
||||||
doc->func_get_object_mesh_element(
|
doc->func_get_object_mesh_element(
|
||||||
doc->cookie,
|
doc->cookie, &mesh_elt_index, &vertex);
|
||||||
GMIO_AMF_MESH_ELEMENT_VERTEX, &mesh_elt_index, &vertex);
|
|
||||||
/* Write <coordinates> element */
|
/* Write <coordinates> element */
|
||||||
gmio_ostringstream_write_chararray(sstream, "<vertex><coordinates>");
|
gmio_ostringstream_write_chararray(sstream, "<vertex><coordinates>");
|
||||||
gmio_ostringstream_write_chararray(sstream, "<x>");
|
gmio_ostringstream_write_chararray(sstream, "<x>");
|
||||||
@ -318,17 +338,10 @@ static bool gmio_amf_write_mesh(
|
|||||||
}
|
}
|
||||||
/* Write <metadata> elements */
|
/* Write <metadata> elements */
|
||||||
if (vertex.metadata_count > 0) {
|
if (vertex.metadata_count > 0) {
|
||||||
if (doc->func_get_object_mesh_vertex_metadata == NULL) {
|
gmio_amf_write_mesh_object_element_metadata(
|
||||||
return gmio_amf_wcontext_set_error(
|
context, &mesh_elt_index, vertex.metadata_count);
|
||||||
context,
|
if (gmio_error(context->error))
|
||||||
GMIO_AMF_ERROR_NULL_FUNC_GET_OBJECT_MESH_VERTEX_METADATA);
|
return false;
|
||||||
}
|
|
||||||
struct gmio_amf_metadata metadata = {0};
|
|
||||||
for (uint32_t imeta = 0; imeta < vertex.metadata_count; ++imeta) {
|
|
||||||
doc->func_get_object_mesh_vertex_metadata(
|
|
||||||
doc->cookie, &mesh_elt_index, imeta, &metadata);
|
|
||||||
gmio_amf_write_metadata(sstream, &metadata);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
gmio_ostringstream_write_chararray(sstream, "</vertex>\n");
|
gmio_ostringstream_write_chararray(sstream, "</vertex>\n");
|
||||||
gmio_amf_wcontext_incr_task_progress(context);
|
gmio_amf_wcontext_incr_task_progress(context);
|
||||||
@ -337,12 +350,12 @@ static bool gmio_amf_write_mesh(
|
|||||||
}
|
}
|
||||||
/* Write mesh vertices <edge> elements */
|
/* Write mesh vertices <edge> elements */
|
||||||
if (mesh->edge_count > 0) {
|
if (mesh->edge_count > 0) {
|
||||||
|
mesh_elt_index.element_type = GMIO_AMF_MESH_ELEMENT_EDGE;
|
||||||
struct gmio_amf_edge edge = {0};
|
struct gmio_amf_edge edge = {0};
|
||||||
for (uint32_t iedge = 0; iedge < mesh->edge_count; ++iedge) {
|
for (uint32_t iedge = 0; iedge < mesh->edge_count; ++iedge) {
|
||||||
mesh_elt_index.value = iedge;
|
mesh_elt_index.value = iedge;
|
||||||
doc->func_get_object_mesh_element(
|
doc->func_get_object_mesh_element(
|
||||||
doc->cookie,
|
doc->cookie, &mesh_elt_index, &edge);
|
||||||
GMIO_AMF_MESH_ELEMENT_EDGE, &mesh_elt_index, &edge);
|
|
||||||
gmio_ostringstream_write_chararray(sstream, "<edge><v1>");
|
gmio_ostringstream_write_chararray(sstream, "<edge><v1>");
|
||||||
gmio_ostringstream_write_u32(sstream, edge.v1);
|
gmio_ostringstream_write_u32(sstream, edge.v1);
|
||||||
gmio_ostringstream_write_chararray(sstream, "</v1><dx1>");
|
gmio_ostringstream_write_chararray(sstream, "</v1><dx1>");
|
||||||
@ -368,12 +381,12 @@ static bool gmio_amf_write_mesh(
|
|||||||
gmio_ostringstream_write_chararray(sstream, "</vertices>\n");
|
gmio_ostringstream_write_chararray(sstream, "</vertices>\n");
|
||||||
/* Write mesh <volume> elements */
|
/* Write mesh <volume> elements */
|
||||||
if (mesh->volume_count > 0) {
|
if (mesh->volume_count > 0) {
|
||||||
|
mesh_elt_index.element_type = GMIO_AMF_MESH_ELEMENT_VOLUME;
|
||||||
struct gmio_amf_volume volume = {0};
|
struct gmio_amf_volume volume = {0};
|
||||||
for (uint32_t ivol = 0; ivol < mesh->volume_count; ++ivol) {
|
for (uint32_t ivol = 0; ivol < mesh->volume_count; ++ivol) {
|
||||||
mesh_elt_index.value = ivol;
|
mesh_elt_index.value = ivol;
|
||||||
doc->func_get_object_mesh_element(
|
doc->func_get_object_mesh_element(
|
||||||
doc->cookie,
|
doc->cookie, &mesh_elt_index, &volume);
|
||||||
GMIO_AMF_MESH_ELEMENT_VOLUME, &mesh_elt_index, &volume);
|
|
||||||
/* Write <volume ...> element begin */
|
/* Write <volume ...> element begin */
|
||||||
gmio_ostringstream_write_chararray(sstream, "<volume");
|
gmio_ostringstream_write_chararray(sstream, "<volume");
|
||||||
gmio_ostringstream_write_xmlattr_u32(
|
gmio_ostringstream_write_xmlattr_u32(
|
||||||
@ -389,17 +402,10 @@ static bool gmio_amf_write_mesh(
|
|||||||
gmio_ostringstream_write_chararray(sstream, ">\n");
|
gmio_ostringstream_write_chararray(sstream, ">\n");
|
||||||
/* Write volume <metadata> elements */
|
/* Write volume <metadata> elements */
|
||||||
if (volume.metadata_count > 0) {
|
if (volume.metadata_count > 0) {
|
||||||
if (doc->func_get_object_mesh_volume_metadata == NULL) {
|
gmio_amf_write_mesh_object_element_metadata(
|
||||||
return gmio_amf_wcontext_set_error(
|
context, &mesh_elt_index, volume.metadata_count);
|
||||||
context,
|
if (gmio_error(context->error))
|
||||||
GMIO_AMF_ERROR_NULL_FUNC_GET_OBJECT_MESH_VOLUME_METADATA);
|
return false;
|
||||||
}
|
|
||||||
struct gmio_amf_metadata metadata = {0};
|
|
||||||
for (uint32_t imeta = 0; imeta < volume.metadata_count; ++imeta) {
|
|
||||||
doc->func_get_object_mesh_volume_metadata(
|
|
||||||
doc->cookie, &mesh_elt_index, imeta, &metadata);
|
|
||||||
gmio_amf_write_metadata(sstream, &metadata);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* Write volume <color> element */
|
/* Write volume <color> element */
|
||||||
if (volume.has_color)
|
if (volume.has_color)
|
||||||
@ -477,8 +483,8 @@ static bool gmio_amf_write_root_objects(struct gmio_amf_wcontext* context)
|
|||||||
if (object.mesh_count > 0) {
|
if (object.mesh_count > 0) {
|
||||||
struct gmio_amf_mesh mesh = {0};
|
struct gmio_amf_mesh mesh = {0};
|
||||||
for (uint32_t imesh = 0; imesh < object.mesh_count; ++imesh) {
|
for (uint32_t imesh = 0; imesh < object.mesh_count; ++imesh) {
|
||||||
struct gmio_amf_object_mesh_element_index base_mesh_elt_index;
|
|
||||||
doc->func_get_object_mesh(doc->cookie, iobj, imesh, &mesh);
|
doc->func_get_object_mesh(doc->cookie, iobj, imesh, &mesh);
|
||||||
|
struct gmio_amf_object_mesh_element_index base_mesh_elt_index;
|
||||||
base_mesh_elt_index.object_index = iobj;
|
base_mesh_elt_index.object_index = iobj;
|
||||||
base_mesh_elt_index.mesh_index = imesh;
|
base_mesh_elt_index.mesh_index = imesh;
|
||||||
base_mesh_elt_index.value = 0;
|
base_mesh_elt_index.value = 0;
|
||||||
@ -766,6 +772,7 @@ static intmax_t gmio_amf_task_progress_max(const struct gmio_amf_document* doc)
|
|||||||
progress_max += mesh.vertex_count;
|
progress_max += mesh.vertex_count;
|
||||||
progress_max += mesh.edge_count;
|
progress_max += mesh.edge_count;
|
||||||
struct gmio_amf_object_mesh_element_index mesh_elt_index;
|
struct gmio_amf_object_mesh_element_index mesh_elt_index;
|
||||||
|
mesh_elt_index.element_type = GMIO_AMF_MESH_ELEMENT_VOLUME;
|
||||||
mesh_elt_index.object_index = iobj;
|
mesh_elt_index.object_index = iobj;
|
||||||
mesh_elt_index.mesh_index = imesh;
|
mesh_elt_index.mesh_index = imesh;
|
||||||
mesh_elt_index.value = 0;
|
mesh_elt_index.value = 0;
|
||||||
@ -773,10 +780,7 @@ static intmax_t gmio_amf_task_progress_max(const struct gmio_amf_document* doc)
|
|||||||
struct gmio_amf_volume volume = {0};
|
struct gmio_amf_volume volume = {0};
|
||||||
mesh_elt_index.value = ivol;
|
mesh_elt_index.value = ivol;
|
||||||
doc->func_get_object_mesh_element(
|
doc->func_get_object_mesh_element(
|
||||||
doc->cookie,
|
doc->cookie, &mesh_elt_index, &volume);
|
||||||
GMIO_AMF_MESH_ELEMENT_VOLUME,
|
|
||||||
&mesh_elt_index,
|
|
||||||
&volume);
|
|
||||||
progress_max += volume.triangle_count;
|
progress_max += volume.triangle_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,9 +63,9 @@ GMIO_C_LINKAGE_BEGIN
|
|||||||
* \sa gmio_amf_write_file()
|
* \sa gmio_amf_write_file()
|
||||||
*/
|
*/
|
||||||
GMIO_API int gmio_amf_write(
|
GMIO_API int gmio_amf_write(
|
||||||
struct gmio_stream* stream,
|
struct gmio_stream* stream,
|
||||||
const struct gmio_amf_document* doc,
|
const struct gmio_amf_document* doc,
|
||||||
const struct gmio_amf_write_options* opts);
|
const struct gmio_amf_write_options* opts);
|
||||||
|
|
||||||
/*! Writes AMF document to stream
|
/*! Writes AMF document to stream
|
||||||
*
|
*
|
||||||
@ -86,9 +86,9 @@ GMIO_API int gmio_amf_write(
|
|||||||
* \sa gmio_amf_write(), gmio_stream_stdio(FILE*)
|
* \sa gmio_amf_write(), gmio_stream_stdio(FILE*)
|
||||||
*/
|
*/
|
||||||
GMIO_API int gmio_amf_write_file(
|
GMIO_API int gmio_amf_write_file(
|
||||||
const char* filepath,
|
const char* filepath,
|
||||||
const struct gmio_amf_document* doc,
|
const struct gmio_amf_document* doc,
|
||||||
const struct gmio_amf_write_options* opts);
|
const struct gmio_amf_write_options* opts);
|
||||||
|
|
||||||
GMIO_C_LINKAGE_END
|
GMIO_C_LINKAGE_END
|
||||||
|
|
||||||
|
@ -124,12 +124,11 @@ static void __tamf__get_object_mesh(
|
|||||||
|
|
||||||
static void __tamf__get_object_mesh_element(
|
static void __tamf__get_object_mesh_element(
|
||||||
const void* cookie,
|
const void* cookie,
|
||||||
enum gmio_amf_mesh_element element,
|
|
||||||
const struct gmio_amf_object_mesh_element_index* element_index,
|
const struct gmio_amf_object_mesh_element_index* element_index,
|
||||||
void* ptr_element)
|
void* ptr_element)
|
||||||
{
|
{
|
||||||
const struct __tamf__document* doc = (const struct __tamf__document*)cookie;
|
const struct __tamf__document* doc = (const struct __tamf__document*)cookie;
|
||||||
switch (element) {
|
switch (element_index->element_type) {
|
||||||
case GMIO_AMF_MESH_ELEMENT_VERTEX: {
|
case GMIO_AMF_MESH_ELEMENT_VERTEX: {
|
||||||
struct gmio_amf_vertex* ptr_vertex = (struct gmio_amf_vertex*)ptr_element;
|
struct gmio_amf_vertex* ptr_vertex = (struct gmio_amf_vertex*)ptr_element;
|
||||||
ptr_vertex->coords = doc->mesh.vec_vertex[element_index->value];
|
ptr_vertex->coords = doc->mesh.vec_vertex[element_index->value];
|
||||||
|
Loading…
Reference in New Issue
Block a user