GithubHelp home page GithubHelp logo

nem0 / openfbx Goto Github PK

View Code? Open in Web Editor NEW
1.1K 37.0 126.0 3.91 MB

Lightweight open source FBX importer

License: MIT License

Lua 2.51% Batchfile 0.01% C++ 45.00% C 51.94% CMake 0.54%
fbx model loading animation morph

openfbx's Introduction

Discord Chat License build status

OpenFBX

Lightweight open source FBX importer. Used in Lumix Engine and Flax Engine. It's an almost full-featured importer. It can load geometry (with uvs, normals, tangents, colors), skeletons, animations, blend shapes, materials, textures, cameras and lights.

UFBX is similar project in C. Using libdeflate for decompression.

Use the library in your own project

Note: It's recommended to be familiar with fbx format to use this library, you can read about it more here.

  1. add files from src to your project
  2. use

See demo as an example how to use the library. See Lumix Engine as more advanced use case.

Alternatively, CMake support is provided by community but it's not supported by me - @nem0.

Compile demo project

  1. download source code
  2. execute projects/genie_vs19.bat
  3. open projects/tmp/vs2019/OpenFBX.sln in Visual Studio 2019
  4. compile and run

Demo is windows only. Library is multiplatform.

ofbx

openfbx's People

Contributors

alexaut avatar alexmollard avatar aras-p avatar asmaloney avatar bbugaev avatar cignoni avatar fran6co avatar jeongseok-meta avatar jmorton06 avatar kochol avatar kuranes avatar lnd3 avatar mafiesto4 avatar nem0 avatar nrz avatar percentcer avatar spexguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openfbx's Issues

Where can I found armature value ? (Question)

I try to find where is stored the armature value. Here is my fxb in ascii :
image
I try to obtain this -90.0000093346673 value.
I saw that the skin have the armature's name, so I have tested all its properties but nothing seems to be the right value.
image
Can you help me to find it ?

Here my ascii FBX :
HopeAnim1.zip
Here my binary FBX:
HopeAnim1.zip

signed long long for time value

Hi,

thank you for your library! I'm using it to open fbx scene in my android application and I hope to add a support for some features from motionbuilder.
I've just figured out that in AnimationCurve you are storing values in unsigned long long, which will give unpredictable result when converting time to seconds as real value should be in signed long long, for managing negative time values as well (some animation could have stance pose in -100 frame for example)

fbx file writes

Hi there,

Just wondering if file writes are on your list? The library as it stands is quite usable for imports but writing would also be incredible.

Thanks!

Vertices Not Indexed Properly?

Some vertices appear indexed improperly (a handful out of ~1k, so it's <1%?)

No triangulation going on. However, even so, the indexing code is hard to follow as I debug this issue. Is there any guidance you can give me for possible leads?

(Left: OpenFBX imported geometry, Right: same FBX imported into maya)
image

about animation

hello.My name is Long.
Question:I want to rewrite the json in the fbx.how could i do?
thx.

Question about change

There was a change in "minor fixes" that seems more than minor:

	UpVector_AxisX = 0,
	UpVector_AxisY = 1,
	UpVector_AxisZ = 2

This actually fixes a problem I was having, but I'm wondering what the background is on the change?

(I remember looking at the official API and it was using UpVector_AxisX = 1 which OpenFBX was before this change. It seemed to be giving me incorrect info.)

Memory Leak

Visual Studio reported memory leaks when I integrated OpenFBX into my hobby engine. Upon investigation, I've identified the problem.

Objects are allocated using Scene's m_allocator which releases the Object memory when a scene is destroyed, but doesn't call destructors, and therefore doesn't release memory that's allocated by objects outside of the allocator.

In particular ofbx.add() allocates GeometryImpl::NewVertex records with vanilla operator new, but because GeometryImpl's destructor is never called, these records are never deallocated.

One possible fix is to manually call object destructors in scene's destructor:

~Scene() override 
{
	for(auto ptr : m_all_objects)
		ptr->~Object();
}

I've confirmed that this fixes all outstanding memory leaks in the latest version, and Visual Studio has stopped complaining :)

Unused var or bug?

In parseTemplates():

if (subdef->id == "PropertyTemplate")
{
	DataView prop1 = def->first_property->value;
	DataView prop2 = subdef->first_property->value;
	std::string key((const char*)prop1.begin, prop1.end - prop1.begin);
	key += std::string((const char*)prop1.begin, prop1.end - prop1.begin);
	templates[key] = subdef;
}

Is prop2 supposed to be used or is it extraneous?

FrontAxis wrong ?

Hi !
I have a problem with the global settings of my FBX for the front axis.
bug
As you can see, the front axis was parsed with the value of 2. But the enum only contains values for 0 and 1.
Capture d’écran 2021-08-31 125048
If I see the documentation for the FBX I saw that they enum start with 1. But it is the same for the Up axis and I don't have a problem with it.
Capture d’écran 2021-08-31 124929
Can you help me ?

Request for animated example

Hi,

I would like to request that a comprehensive animation loading example be made available for loading animations. Following issue #71, attempts have been made to follow the Lumix engine example. Unfortunately, the lack of documentation has made loading fba animation files impossible. Documentation from FBXSDK did not help in this issue as openFBX != FBXSDK. The main issue for me is the loading of bones, animation bone offsets, frames and animated transforms. It would be appreciated if there was documentation on what type of animation openfbx is supporting and also provide either a doxygen or inline comments for the lumix engine's import example.

Thanks.

getRotationMatrix fall through in release build

In getRotationMatrix():

switch (order)
{
	default:
	case RotationOrder::SPHERIC_XYZ: assert(false);
	case RotationOrder::EULER_XYZ: return rz * ry * rx;

In a release build, the assert statement is compiled away and default and RotationOrder::SPHERIC_XYZ both fall through to the RotationOrder::EULER_XYZ case.

If this is the intent, then I would suggest a comment because it isn't clear. If it's not, then SPHERIC_XYZ probably needs an error for the user and then break;.

(Also the style of putting default at the top is non-idiomatic and will throw readers off. In this case it isn't needed anyways since all the enum values are covered.)

missing faces/indices

Hi I'm trying to load the next model messy tavern (I have converted the obj file with blender). which looks good using the windows 3d Visor app
2020-06-08

but after loading the file and creating the d3d12 stuff(my faces are in UINT16 so i had to drop the negative indexes) I see gaps in the faces of the model
2020-06-08 (1)
2020-06-08 (2)
2020-06-08 (3)

I'm not an expert in FBX parsing, but I think it's odd that some vertices are not referenced by the index buffer(ex: 2, 5, 8, etc..)

should I load those vertices myself in the index buffer? or it's a library issue?

Regards

Alignment error when using an ARM processor

All DataView::toX functions directly cast the pointer without taking alignment into account. This unaligned access will only have a performance penalty on x86 CPUs, however, on ARM CPUs this results in a crash due to the unaligned memory access.
https://github.com/nem0/OpenFBX/blob/master/src/ofbx.cpp#L304

Copying into a stack variable is one way to remove the unaligned access, not sure if it is the most performant way to fix this.

double result;
memcpy(&result, begin, sizeof(double));
return result;

connection property-property is missing

Hi,
I've found that there is no support for property references (property-property connection type), that could be in a file when, for example, someone forgot to kill character control rig components.
here is an example in ascii format

;NodeAttribute::, Model::Hips
C: "PP",738737744, "IK Reach Translation",842764320, "HipsEffector.IK Reach Translation"

and in code you are waiting for string, long, long
if (!isString(connection->first_property)
|| !isLong(connection->first_property->next)
|| !isLong(connection->first_property->next->next))
{
Error::s_message = "Invalid connection";
return false;
}

which don't suit well for PP connection type.
P.S. I've attached an example fbx.
move1.zip

how to use blendshapes

Hi, thanks for your project! A little question is that OpenFBX support blendshape, but the demo and the engine seems that haven't show hot to use blendshape. May you shed any light on how to use the blendshape in OpenFBX, thanks!

Number of vertex in FBX and OBJ are not equal

Hi, thank you for this lib,

I tested the conversion of a simple shape (a cube, 8 vertices) with this algorithm and i found that the number of vertices written in .obj file was 36, with multiple vertex replications. What's wrong?

I expected that .obj files contains only 8 vertices.

Compiler warning

OpenFBX-master\src\ofbx.cpp(1437,21): warning C4018: '<': signed/unsigned mismatch
and a few more similar

How to delete object from ofbx::load

Hi, it's unclear how a user of the API is meant to clean-up the object returned from ofbx::load?

I would delete but the destructor is protected. Am I missing something?

Thanks

Crash in parseObjects if FBX has no geometry

The importer crashes on importing animation fbx files, which have only skeleton and animations, but don't have mesh.

Here it tries to get the first value from parse_geom_jobs[0], but the array is empty.
(*job_processor)([](void* ptr){ ParseGeometryJob* job = (ParseGeometryJob*)ptr; job->is_error = parseGeometry(*job->element, job->triangulate, job->geom).isError(); }, job_user_ptr, &parse_geom_jobs[0], (u32)sizeof(parse_geom_jobs[0]), (u32)pars

A solution would be to wrap this code into this check:
if (!parse_geom_jobs.empty()) { .. }
Beside that Qt Creator and Visual Studio give tones of warnings about type conversions and other stuff.

Typo in ShapeImpl::postprocess making normals incorrectly parsed for blend shapes

I have found a small mistake in the code that made blend shape normals look ugly.

	vertices = geom->vertices;
	normals = geom->normals;


	Vec3* vr = &allocator.vec3_tmp[0];
	Vec3* nr = &allocator.vec3_tmp2[0];
	int* ir = &allocator.int_tmp[0];
	for (int i = 0, c = (int)allocator.int_tmp.size(); i < c; ++i)
	{
		int old_idx = ir[i];
		GeometryImpl::NewVertex* n = &geom->to_new_vertices[old_idx];
		if (n->index == -1) continue; // skip vertices which aren't indexed.
		while (n)
		{
			vertices[n->index] = vertices[n->index] + vr[i];
			normals[n->index] = vertices[n->index] + nr[i];   // <------------------------- line 2781, there should be 'normals' instead
			n = n->next;
		}
	}

P.S. This project is great!
Have a good day!

readProperty function question

Hey, thank you for making this lib :)

I was going through the code in the readProperty function and from what I understood (which can be completely wrong) the only values that we are getting from there are strings. Are there no other values that we can find there or am I missing something from the code ?

Just a thank you!

For taking the time to publish your work on this. My game engine currently uses Assimp to import assets, but as you probably know, it's far from flawless, and a lot of meshes/rigs simply don't work. This seems like a much cleaner solution!

<3

Add samples on how to parse fbx files into 3D mesh

Adding a sample inside the project that shows how to parse the information obtained by OpenFBX would be useful instead of showing how to make an OBJ file from the FBX file in main.
By following the OBJ->FBX sample code inside main.cpp I am getting these results:
image
Obviously, it is an indexing problem (on my end) but I can't figure out how to index the data provided without a sample of some kind to follow.

How to get SystemUnit?

I used this library in Echo Engine, It's a very easy used library. Thank you very much.
but I want to know how can I get Scene's System Unit by this library?

Native Fbx sdk did it like this

lScene->GetGlobalSettings().GetSystemUnit() == FbxSystemUnit::cm

in its documentation Scene Axis and Unit Conversion

But in Openfbx, GlobalSettings don't have a variable about SystemUnit.

struct GlobalSettings
{
	UpVector UpAxis = UpVector_AxisX;
	int UpAxisSign = 1;
	FrontVector FrontAxis = FrontVector_ParityOdd;
	int FrontAxisSign = 1;
	CoordSystem CoordAxis = CoordSystem_RightHanded;
	int CoordAxisSign = 1;
	int OriginalUpAxis = 0;
	int OriginalUpAxisSign = 1;
	float UnitScaleFactor = 1;
	float OriginalUnitScaleFactor = 1;
	double TimeSpanStart = 0L;
	double TimeSpanStop = 0L;
	FrameRate TimeMode = FrameRate_DEFAULT;
	float CustomFrameRate = -1.0f;
};

Is it possible to get provide of FBX ?

I would like to know the provision of my FBX to apply a correction for blenders files. (Scale and 90 degrees X rotation in importation of FBX format)
I don't see any option to do that. Is it possible ?

break before return

In parseObjects() around line 2849:

if (mat->textures[type])
{
	break; // This may happen for some models (eg. 2 normal maps in use)
	Error::s_message = "Invalid material";
	return false;
}

Unless the break is a mistake, everything after it is dead code and should be removed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.