Skip to content

Commit

Permalink
Added initial vertex colour support
Browse files Browse the repository at this point in the history
And verified by hand that they're read, at least from FBX.
  • Loading branch information
cwoffenden committed May 27, 2023
1 parent d41e870 commit 5738b7d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions inc/objvertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct ObjVertex
vec3 norm; /**< Normals (from the \c .obj file). */
vec3 tans; /**< Tangents (generated if needed). */
vec3 btan; /**< Bitangents (generated if needed). */
vec4 rgba; /**< Vertex colours (standard only in the FBX file). */
/**
* An alternative to storing the bitangents is to recreate them from:
* \code
Expand Down
1 change: 1 addition & 0 deletions inc/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ struct Vec4
T y;
T z;
T w;
Vec4() {}
Vec4& operator =(T const val) {
x = val;
y = val;
Expand Down
27 changes: 22 additions & 5 deletions src/objvertex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,22 @@ bool copyVec(const ufbx_vertex_vec3& src, size_t const idx, vec3& dst) {
}
return false;
}
/**
* \copydoc copyVec(const ufbx_vertex_vec2&,size_t,vec2&)
*/
bool copyVec(const ufbx_vertex_vec4& src, size_t const idx, vec4& dst) {
if (src.exists) {
ufbx_vec4& vec = src.values.data[src.indices.data[idx]];
dst.x = static_cast<float>(vec.x);
dst.y = static_cast<float>(vec.y);
dst.z = static_cast<float>(vec.z);
dst.w = static_cast<float>(vec.w);
return true;
} else {
dst = 0.0f;
}
return false;
}
}

//*****************************************************************************/
Expand Down Expand Up @@ -543,17 +559,18 @@ ObjVertex::ObjVertex(ufbx_mesh* fbx, size_t const idx) {
* Initial attempt at this: all vertex data are copied, zeroing if they
* don't exist (no effort has been made so far to generate missing data).
*
* Note: we're currently reading this but then ignoring any tangents (since
* at a first glance they weren't correct) and recreating them.
* Note: we're recreating tangents (1. because they have the wrong
* orientation and need correcting, and 2. so that we have the same
* MikkTSpace calculations throughout).
*
* TODO: extract (and support) tex1 from ufbx_uv_set_list
* TODO: add support for vertex_color
*/
impl::copyVec(fbx->vertex_position, idx, posn);
impl::copyVec(fbx->vertex_uv, idx, tex0);
impl::copyVec(fbx->vertex_normal, idx, norm);
impl::copyVec(fbx->vertex_tangent, idx, tans);
impl::copyVec(fbx->vertex_bitangent, idx, btan);
impl::copyVec(fbx->vertex_color, idx, rgba);
tans = 0.0f;
btan = 0.0f;
sign = 0.0f;
}

Expand Down

0 comments on commit 5738b7d

Please sign in to comment.