Added openfbx to wrap folder

This commit is contained in:
Paolo Cignoni 2018-09-09 09:12:08 +02:00
parent 3dd1f38353
commit 5eb5363d01
8 changed files with 12060 additions and 0 deletions

42
wrap/openfbx/.clang-format Executable file
View File

@ -0,0 +1,42 @@
BasedOnStyle: LLVM
AlignAfterOpenBracket : false
AlignEscapedNewlinesLeft : true
AlignConsecutiveAssignments : false
AllowAllParametersOfDeclarationOnNextLine : false
AccessModifierOffset : -4
AllowShortCaseLabelsOnASingleLine : true
AllowShortFunctionsOnASingleLine : Inline
AllowShortIfStatementsOnASingleLine : true
AllowShortLoopsOnASingleLine : true
AlwaysBreakAfterDefinitionReturnType : None
BinPackArguments : false
BinPackParameters : false
BreakBeforeBraces : Allman
BreakConstructorInitializersBeforeComma : true
ColumnLimit : 120
ConstructorInitializerIndentWidth : 4
ConstructorInitializerAllOnOneLineOrOnePerLine : false
ContinuationIndentWidth : 4
IndentCaseLabels : true
IndentWidth : 4
KeepEmptyLinesAtTheStartOfBlocks : true
MaxEmptyLinesToKeep : 2
NamespaceIndentation : None
PenaltyBreakBeforeFirstCallParameter : 0
PenaltyReturnTypeOnItsOwnLine : 1000
PointerAlignment : Left
SpaceAfterCStyleCast : false
SpaceBeforeAssignmentOperators : true
SpaceBeforeParens : true
SpaceInEmptyParentheses : false
SpacesBeforeTrailingComments : 1
SpacesInAngles : false
SpacesInCStyleCastParentheses : false
SpacesInParentheses : false
SpacesInSquareBrackets : false
Standard : Cpp11
TabWidth : 4
UseTab : true

35
wrap/openfbx/.gitignore vendored Executable file
View File

@ -0,0 +1,35 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
projects/tmp/*
# Executables
*.out
*.app
runtime/imgui.ini

21
wrap/openfbx/LICENSE Executable file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Mikulas Florek
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

29
wrap/openfbx/README.md Executable file
View File

@ -0,0 +1,29 @@
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nem0/LumixEngine?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
# OpenFBX
Lightweight open source FBX importer. Used in [Lumix Engine](https://github.com/nem0/lumixengine). It's not a full-featured importer, but it suits all my needs. It can load geometry (with uvs, normals, tangents, colors), skeletons, animations, materials and textures.
Feel free to request new features. I will eventually try to add all missing fbx features.
## 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](http://help.autodesk.com/view/FBX/2017/ENU/?guid=__files_GUID_F194000D_5AD4_49C1_86CC_5DAC2CE64E97_htm).
1. add files from src to your project
2. use
See [demo](https://github.com/nem0/OpenFBX/blob/master/demo/main.cpp#L203) as an example how to use the library.
See [Lumix Engine](https://github.com/nem0/LumixEngine/blob/master/src/renderer/editor/import_asset_dialog.cpp#L504) as more advanced use case.
## Compile demo project
1. download source code
2. execute [projects/genie_vs15.bat](https://github.com/nem0/OpenFBX/blob/master/projects/genie_vs15.bat)
3. open projects/tmp/vs2015/OpenFBX.sln in Visual Studio 2015
4. compile and run
Demo is windows only. Library is multiplatform.
![ofbx](https://user-images.githubusercontent.com/153526/27876079-eea3c872-61b5-11e7-9fce-3a7c558fb0d2.png)

7241
wrap/openfbx/src/miniz.c Executable file

File diff suppressed because it is too large Load Diff

1296
wrap/openfbx/src/miniz.h Executable file

File diff suppressed because it is too large Load Diff

2950
wrap/openfbx/src/ofbx.cpp Executable file

File diff suppressed because it is too large Load Diff

446
wrap/openfbx/src/ofbx.h Executable file
View File

@ -0,0 +1,446 @@
#pragma once
namespace ofbx
{
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef long long i64;
static_assert(sizeof(u8) == 1, "u8 is not 1 byte");
static_assert(sizeof(u32) == 4, "u32 is not 4 bytes");
static_assert(sizeof(u64) == 8, "u64 is not 8 bytes");
static_assert(sizeof(i64) == 8, "i64 is not 8 bytes");
struct Vec2
{
double x, y;
};
struct Vec3
{
double x, y, z;
};
struct Vec4
{
double x, y, z, w;
};
struct Matrix
{
double m[16]; // last 4 are translation
};
struct Quat
{
double x, y, z, w;
};
struct Color
{
float r, g, b;
};
struct DataView
{
const u8* begin = nullptr;
const u8* end = nullptr;
bool is_binary = true;
bool operator!=(const char* rhs) const { return !(*this == rhs); }
bool operator==(const char* rhs) const;
u64 toU64() const;
i64 toI64() const;
int toInt() const;
u32 toU32() const;
double toDouble() const;
float toFloat() const;
template <int N>
void toString(char(&out)[N]) const
{
char* cout = out;
const u8* cin = begin;
while (cin != end && cout - out < N - 1)
{
*cout = (char)*cin;
++cin;
++cout;
}
*cout = '\0';
}
};
struct IElementProperty
{
enum Type : unsigned char
{
LONG = 'L',
INTEGER = 'I',
STRING = 'S',
FLOAT = 'F',
DOUBLE = 'D',
ARRAY_DOUBLE = 'd',
ARRAY_INT = 'i',
ARRAY_LONG = 'l',
ARRAY_FLOAT = 'f'
};
virtual ~IElementProperty() {}
virtual Type getType() const = 0;
virtual IElementProperty* getNext() const = 0;
virtual DataView getValue() const = 0;
virtual int getCount() const = 0;
virtual bool getValues(double* values, int max_size) const = 0;
virtual bool getValues(int* values, int max_size) const = 0;
virtual bool getValues(float* values, int max_size) const = 0;
virtual bool getValues(u64* values, int max_size) const = 0;
virtual bool getValues(i64* values, int max_size) const = 0;
};
struct IElement
{
virtual IElement* getFirstChild() const = 0;
virtual IElement* getSibling() const = 0;
virtual DataView getID() const = 0;
virtual IElementProperty* getFirstProperty() const = 0;
};
enum class RotationOrder {
EULER_XYZ,
EULER_XZY,
EULER_YZX,
EULER_YXZ,
EULER_ZXY,
EULER_ZYX,
SPHERIC_XYZ // Currently unsupported. Treated as EULER_XYZ.
};
struct AnimationCurveNode;
struct AnimationLayer;
struct Scene;
struct IScene;
struct Object
{
enum class Type
{
ROOT,
GEOMETRY,
MATERIAL,
MESH,
TEXTURE,
LIMB_NODE,
NULL_NODE,
NODE_ATTRIBUTE,
CLUSTER,
SKIN,
ANIMATION_STACK,
ANIMATION_LAYER,
ANIMATION_CURVE,
ANIMATION_CURVE_NODE
};
Object(const Scene& _scene, const IElement& _element);
virtual ~Object() {}
virtual Type getType() const = 0;
const IScene& getScene() const;
Object* resolveObjectLink(int idx) const;
Object* resolveObjectLink(Type type, const char* property, int idx) const;
Object* resolveObjectLinkReverse(Type type) const;
Object* getParent() const;
RotationOrder getRotationOrder() const;
Vec3 getRotationOffset() const;
Vec3 getRotationPivot() const;
Vec3 getPostRotation() const;
Vec3 getScalingOffset() const;
Vec3 getScalingPivot() const;
Vec3 getPreRotation() const;
Vec3 getLocalTranslation() const;
Vec3 getLocalRotation() const;
Vec3 getLocalScaling() const;
Matrix getGlobalTransform() const;
Matrix getLocalTransform() const;
Matrix evalLocal(const Vec3& translation, const Vec3& rotation) const;
Matrix evalLocal(const Vec3& translation, const Vec3& rotation, const Vec3& scaling) const;
bool isNode() const { return is_node; }
template <typename T> T* resolveObjectLink(int idx) const
{
return static_cast<T*>(resolveObjectLink(T::s_type, nullptr, idx));
}
u64 id;
char name[128];
const IElement& element;
const Object* node_attribute;
protected:
bool is_node;
const Scene& scene;
};
struct Texture : Object
{
enum TextureType
{
DIFFUSE,
NORMAL,
COUNT
};
static const Type s_type = Type::TEXTURE;
Texture(const Scene& _scene, const IElement& _element);
virtual DataView getFileName() const = 0;
virtual DataView getRelativeFileName() const = 0;
};
struct Material : Object
{
static const Type s_type = Type::MATERIAL;
Material(const Scene& _scene, const IElement& _element);
virtual Color getDiffuseColor() const = 0;
virtual const Texture* getTexture(Texture::TextureType type) const = 0;
};
struct Cluster : Object
{
static const Type s_type = Type::CLUSTER;
Cluster(const Scene& _scene, const IElement& _element);
virtual const int* getIndices() const = 0;
virtual int getIndicesCount() const = 0;
virtual const double* getWeights() const = 0;
virtual int getWeightsCount() const = 0;
virtual Matrix getTransformMatrix() const = 0;
virtual Matrix getTransformLinkMatrix() const = 0;
virtual const Object* getLink() const = 0;
};
struct Skin : Object
{
static const Type s_type = Type::SKIN;
Skin(const Scene& _scene, const IElement& _element);
virtual int getClusterCount() const = 0;
virtual const Cluster* getCluster(int idx) const = 0;
};
struct NodeAttribute : Object
{
static const Type s_type = Type::NODE_ATTRIBUTE;
NodeAttribute(const Scene& _scene, const IElement& _element);
virtual DataView getAttributeType() const = 0;
};
struct Geometry : Object
{
static const Type s_type = Type::GEOMETRY;
static const int s_uvs_max = 4;
Geometry(const Scene& _scene, const IElement& _element);
virtual const Vec3* getVertices() const = 0;
virtual int getVertexCount() const = 0;
virtual const Vec3* getNormals() const = 0;
virtual const Vec2* getUVs(int index = 0) const = 0;
virtual const Vec4* getColors() const = 0;
virtual const Vec3* getTangents() const = 0;
virtual const Skin* getSkin() const = 0;
virtual const int* getMaterials() const = 0;
};
struct Mesh : Object
{
static const Type s_type = Type::MESH;
Mesh(const Scene& _scene, const IElement& _element);
virtual const Geometry* getGeometry() const = 0;
virtual Matrix getGeometricMatrix() const = 0;
virtual const Material* getMaterial(int idx) const = 0;
virtual int getMaterialCount() const = 0;
};
struct AnimationStack : Object
{
static const Type s_type = Type::ANIMATION_STACK;
AnimationStack(const Scene& _scene, const IElement& _element);
virtual const AnimationLayer* getLayer(int index) const = 0;
};
struct AnimationLayer : Object
{
static const Type s_type = Type::ANIMATION_LAYER;
AnimationLayer(const Scene& _scene, const IElement& _element);
virtual const AnimationCurveNode* getCurveNode(int index) const = 0;
virtual const AnimationCurveNode* getCurveNode(const Object& bone, const char* property) const = 0;
};
struct AnimationCurve : Object
{
static const Type s_type = Type::ANIMATION_CURVE;
AnimationCurve(const Scene& _scene, const IElement& _element);
virtual int getKeyCount() const = 0;
virtual const i64* getKeyTime() const = 0;
virtual const float* getKeyValue() const = 0;
};
struct AnimationCurveNode : Object
{
static const Type s_type = Type::ANIMATION_CURVE_NODE;
AnimationCurveNode(const Scene& _scene, const IElement& _element);
virtual Vec3 getNodeLocalTransform(double time) const = 0;
virtual const Object* getBone() const = 0;
};
struct TakeInfo
{
DataView name;
DataView filename;
double local_time_from;
double local_time_to;
double reference_time_from;
double reference_time_to;
};
// Specifies which canonical axis represents up in the system (typically Y or Z).
enum UpVector
{
UpVector_AxisX = 1,
UpVector_AxisY = 2,
UpVector_AxisZ = 3
};
// Vector with origin at the screen pointing toward the camera.
enum FrontVector
{
FrontVector_ParityEven = 1,
FrontVector_ParityOdd = 2
};
// Specifies the third vector of the system.
enum CoordSystem
{
CoordSystem_RightHanded = 0,
CoordSystem_LeftHanded = 1
};
// http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/index.html?url=cpp_ref/class_fbx_time.html,topicNumber=cpp_ref_class_fbx_time_html29087af6-8c2c-4e9d-aede-7dc5a1c2436c,hash=a837590fd5310ff5df56ffcf7c394787e
enum FrameRate
{
FrameRate_DEFAULT = 0,
FrameRate_120 = 1,
FrameRate_100 = 2,
FrameRate_60 = 3,
FrameRate_50 = 4,
FrameRate_48 = 5,
FrameRate_30 = 6,
FrameRate_30_DROP = 7,
FrameRate_NTSC_DROP_FRAME = 8,
FrameRate_NTSC_FULL_FRAME = 9,
FrameRate_PAL = 10,
FrameRate_CINEMA = 11,
FrameRate_1000 = 12,
FrameRate_CINEMA_ND = 13,
FrameRate_CUSTOM = 14,
};
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;
u64 TimeSpanStart = 0L;
u64 TimeSpanStop = 0L;
FrameRate TimeMode = FrameRate_DEFAULT;
float CustomFrameRate = -1.0f;
};
struct IScene
{
virtual void destroy() = 0;
virtual const IElement* getRootElement() const = 0;
virtual const Object* getRoot() const = 0;
virtual const TakeInfo* getTakeInfo(const char* name) const = 0;
virtual int getMeshCount() const = 0;
virtual float getSceneFrameRate() const = 0;
virtual const GlobalSettings* getGlobalSettings() const = 0;
virtual const Mesh* getMesh(int index) const = 0;
virtual int getAnimationStackCount() const = 0;
virtual const AnimationStack* getAnimationStack(int index) const = 0;
virtual const Object *const * getAllObjects() const = 0;
virtual int getAllObjectCount() const = 0;
protected:
virtual ~IScene() {}
};
IScene* load(const u8* data, int size);
const char* getError();
} // namespace ofbx