Comments (4)
Never Mind. I figure it out. I use blender to calculate the tangent vector which contain in the fbx file. I recommod to add a new option to calculate the tangent vector.
from ufbx.
Yeah I considered adding tangent calculation but it's actually very complicated to get right, and in practice most people will want to use mikktspace to stay compatible with other software.
from ufbx.
I highly recommend to add the method of tangent calculate. I try to use the mikktspace. Refer to https://www.turais.de/using-mikktspace-in-your-project/, I build the conection between mikktspace and ufbx_mesh. Here is my code.
`
#include "calc_mikktspace_tangent.h"
#include
#include <fmt/format.h>
CalcMikkTSpaceTangent::CalcMikkTSpaceTangent()
{
iface.m_getNumFaces = get_num_faces;
iface.m_getNumVerticesOfFace = get_num_vertices_of_face;
iface.m_getNormal = get_normal;
iface.m_getPosition = get_position;
iface.m_getTexCoord = get_tex_coords;
iface.m_setTSpaceBasic = set_tspace_basic;
context.m_pInterface = &iface;
}
void CalcMikkTSpaceTangent::calc(ufbx_mesh* mesh)
{
context.m_pUserData = mesh;
genTangSpaceDefault(&this->context);
}
int CalcMikkTSpaceTangent::get_vertex_index (const SMikkTSpaceContext* context, int iFace, int iVert)
{
ufbx_mesh* _mesh = static_cast<ufbx_mesh*> (context->m_pUserData);
auto face_size = get_num_vertices_of_face(context, iFace);
auto indices_index = (iFace * face_size) + iVert;
int index = _mesh->vertex_indices[indices_index];
return index;
}
int CalcMikkTSpaceTangent::get_num_faces (const SMikkTSpaceContext* context)
{
ufbx_mesh* _mesh = static_cast<ufbx_mesh*> (context->m_pUserData);
float f_size = (float)_mesh->num_indices / 3.f;
int i_size = (int)_mesh->num_indices / 3;
//assert((f_size - (float)i_size) == 0.f);
return i_size;
}
int CalcMikkTSpaceTangent::get_num_vertices_of_face (const SMikkTSpaceContext* context, int iFace)
{
return 3;
}
void CalcMikkTSpaceTangent::get_position (const SMikkTSpaceContext* context, float outpos[], int iFace, int iVert)
{
ufbx_mesh* _mesh = static_cast<ufbx_mesh*> (context->m_pUserData);
auto index = get_vertex_index(context, iFace, iVert);
auto vertex = _mesh->vertex_position[index];
outpos[0] = vertex.x;
outpos[1] = vertex.y;
outpos[2] = vertex.z;
}
void CalcMikkTSpaceTangent::get_normal (const SMikkTSpaceContext* context, float outnormal[], int iFace, int iVert)
{
ufbx_mesh* _mesh = static_cast<ufbx_mesh*> (context->m_pUserData);
auto index = get_vertex_index(context, iFace, iVert);
auto normal = _mesh->vertex_normal[index];
outnormal[0] = normal.x;
outnormal[1] = normal.y;
outnormal[2] = normal.z;
}
void CalcMikkTSpaceTangent::get_tex_coords (const SMikkTSpaceContext* context, float outuv[], int iFace, int iVert)
{
ufbx_mesh* _mesh = static_cast<ufbx_mesh*> (context->m_pUserData);
auto index = get_vertex_index(context, iFace, iVert);
auto uv = _mesh->vertex_uv[index];
outuv[0] = uv.x;
outuv[1] = uv.y;
}
void CalcMikkTSpaceTangent::set_tspace_basic (const SMikkTSpaceContext* context, const float tangentu[], float fSign, int iFace, int iVert)
{
ufbx_mesh* _mesh = static_cast<ufbx_mesh*> (context->m_pUserData);
auto index = get_vertex_index(context, iFace, iVert);
auto* tangent = &_mesh->vertex_tangent[index];
tangent->x = tangentu[0];
tangent->y = tangentu[1];
tangent->z = tangentu[2];
}
`
Here are two problem.
- The result didn't go well, the normal is total wrong.
- Only the fbx which had calculate the tangent in blender can override tangent. That why I think should add the support between the ufbx and mikktspace.
from ufbx.
Hmm, adding callbacks to external mikktspace would be an option for sure.
It looks like it doesn't support N-gons:
static int GenerateInitialVerticesIndexList(STriInfo pTriInfos[], int piTriList_out[], const SMikkTSpaceContext * pContext, const int iNrTrianglesIn)
{
int iTSpacesOffs = 0, f=0, t=0;
int iDstTriIndex = 0;
for (f=0; f<pContext->m_pInterface->m_getNumFaces(pContext); f++)
{
const int verts = pContext->m_pInterface->m_getNumVerticesOfFace(pContext, f);
if (verts!=3 && verts!=4) continue;
This will make integrating it a lot harder as ufbx would need to create some sort of temporary face mapping with triangulated N-gons.
from ufbx.
Related Issues (20)
- Fix .obj file scaling
- Re-add `ufbx_node.bone`
- Add `values_w` arrays to hash_scene
- ufbx_os does not use `extern "C"`
- Normalize `ufbx_matrix_for_normals()` HOT 2
- Add helper for finding baked node/element HOT 1
- Expose unit conversion transform in metadata
- Add geometry-based axis conversion
- Failed to load HOT 3
- result of ufbx_evaluate_transform HOT 17
- Documentation: Specify the result of `ufbx_evaluate_transform()`
- Double-check NURBS logic
- add texture HOT 1
- ufbx_os: Fix warnings
- Add support for detecting mesh winding HOT 2
- Baked animation transform HOT 3
- Indicate original order of nodes
- Add world transform evaluation
- Add fully deterministic resampling to ufbx_bake_anim()
- Support FBX export HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ufbx.