├── .gitignore ├── AUTHORS ├── CC-LICENSE ├── CHANGES ├── LICENSE ├── README.md ├── build ├── vs2012 │ ├── fbx-conv.sln │ ├── fbx-conv.vcxproj │ └── fbx-conv.vcxproj.filters └── xcode3 │ └── fbx-conv.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── fbx-conv.xccheckout ├── generate_makefile ├── generate_vs2010.bat ├── generate_xcode ├── libs ├── libpng │ ├── LICENSE.txt │ ├── include │ │ ├── png.h │ │ ├── pngconf.h │ │ └── pngpriv.h │ ├── lib │ │ ├── android │ │ │ └── arm │ │ │ │ └── libpng.a │ │ ├── ios │ │ │ ├── armv7 │ │ │ │ └── libpng.a │ │ │ └── i386 │ │ │ │ └── libpng.a │ │ ├── linux │ │ │ ├── x64 │ │ │ │ └── libpng.a │ │ │ └── x86 │ │ │ │ └── libpng.a │ │ ├── macosx │ │ │ └── libpng.a │ │ └── windows │ │ │ ├── x64 │ │ │ └── libpng14.lib │ │ │ └── x86 │ │ │ └── libpng14.lib │ └── version.txt └── zlib │ ├── LICENSE.txt │ ├── include │ ├── crc32.h │ ├── deflate.h │ ├── gzguts.h │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.h │ ├── inftrees.h │ ├── trees.h │ ├── zconf.h │ ├── zlib.h │ └── zutil.h │ ├── lib │ ├── android │ │ └── arm │ │ │ └── libzlib.a │ ├── linux │ │ ├── x64 │ │ │ └── libz.a │ │ └── x86 │ │ │ └── libz.a │ ├── macosx │ │ └── libz.a │ └── windows │ │ ├── x64 │ │ └── zlib.lib │ │ └── x86 │ │ └── zlib.lib │ └── version.txt ├── premake.lua ├── samples ├── 3dsmax │ ├── animation.FBX │ ├── animation_bin.FBX │ ├── mineShaftWall001.png │ ├── redSpec.fbx │ ├── redSpec_bin.fbx │ ├── textured.FBX │ └── textured_bin.FBX ├── Knight.png ├── attribution.txt ├── blender │ ├── WoodenBoxOpen02.fbx │ ├── cube-single-bone.blend │ ├── cube-single-bone.fbx │ ├── cube-single-bone.g3dj │ ├── cube-two-bones.blend │ ├── cube-two-bones.blend1 │ ├── cube-two-bones.blend2 │ ├── cube-two-bones.fbx │ ├── cube-two-bones.g3dj │ ├── cube.dae │ ├── cube.fbx │ ├── cube.g3dj │ ├── cube.mtl │ ├── cube.obj │ ├── cubes.blend │ ├── cubes.blend1 │ ├── cubes.blend2 │ ├── cubes.fbx │ └── fighter.blend ├── knight.fbx └── softimage │ ├── bump.png │ ├── checkboard.png │ ├── checkboard1.png │ ├── cube_anim.fbx │ ├── cube_anim.g3dj │ ├── cube_anim_2clips.fbx │ ├── cube_anim_2clips_ascii.fbx │ ├── cube_anim_linear.fbx │ ├── cube_multi_uv.fbx │ ├── cube_single_uv.fbx │ ├── cube_single_uv_bump.fbx │ ├── cube_single_uv_flipped.fbx │ ├── cube_single_uv_multi_material.fbx │ ├── head.fbx │ ├── head.g3dj │ ├── head2.fbx │ ├── head2.g3dj │ ├── head_color.png │ ├── head_parented.fbx │ └── head_parented.g3dj └── src ├── FbxConv.h ├── FbxConvCommand.h ├── Settings.h ├── json ├── BaseJSONWriter.h ├── JSONWriter.h ├── UBJSON.h └── UBJSONWriter.h ├── log ├── codes.h ├── log.h └── messages.h ├── main.cpp ├── modeldata ├── Animation.h ├── Attributes.h ├── C3BFile.cpp ├── C3BFile.h ├── FileIO.cpp ├── FileIO.h ├── Keyframe.h ├── Material.h ├── Mesh.h ├── MeshPart.h ├── Model.h ├── Node.h ├── NodeAnimation.h ├── NodePart.h ├── Reference.cpp ├── Reference.h ├── ReferenceTable.cpp ├── ReferenceTable.h ├── Serialization.cpp └── WriteBinnary.cpp └── readers ├── FbxConverter.h ├── FbxMeshInfo.h ├── Reader.h ├── matrix3.h └── util.h /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | ipch/ 3 | Debug/ 4 | Release/ 5 | build/ 6 | *.*sdf 7 | *.suo 8 | *.user 9 | /*.exe 10 | /*.idb 11 | /*.ilk 12 | /*.pdb 13 | /fbx-conv 14 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of the AUTHORS of fbx-conv 2 | # for copyright purposes. 3 | # This file is distinct from the CONTRIBUTORS files. 4 | # See the latter for an explanation. 5 | 6 | # Names should be added to this file as 7 | # Name or Organization 8 | # The email address is not required for organizations. 9 | Mario Zechner 10 | Nathan Sweet 11 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | [0.7] 2 | [NEW] calculate the origin position rotation and scale when the model is single node(don’t have child node). 3 | NOTE: your single node mode may have some change after you use the new fbx-conv 4 | [NEW] add command -p, export “tangent” and “binormal” data 5 | 6 | [0.6] 7 | [NEW] aabb export 8 | [NEW] add -p parameter for normal-map 9 | [NEW] split mesh when it contains more indices than the specified maximum 10 | [FIX] calculate animation length use the end frame 11 | [0.5] 12 | [NEW] separate export data about model and animation(-l or -j). 13 | [NEW] optimize read animation. 14 | [FIX] fix bug about the file path include “.” 15 | [FIX] fix log crash. 16 | [0.4] 17 | [NEW] add compression parameter -c 18 | [NEW] can export transparent channel 19 | [FIX] modify export frame segment bug, you should export animation begin as 0 frame 20 | [FIX] fix material-component export bug 21 | [0.3] 22 | [NEW] export new file format that depends on libgdx's file structure 23 | [NEW] complex FBX model support. 24 | [NEW] Useful for Reskin. 25 | [NEW] multiple meshes and multiple materials support 26 | [FIX] animation has 0 Frame export problem 27 | [0.1] 28 | [NEW] modify for cocos2d-x 3d 29 | [NEW] support simple model to export 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | fbx-conv 2 | ======== 3 | fbx-conv can convert some middle format (such as fbx, blend, obj, etc) to .c3b or .c3t which are used by cocos2d-x. 4 | 5 | Precompiled Binaries 6 | ==================== 7 | You can download the precompiled binaries from https://github.com/cocos2d/cocos2d-x-3rd-party-libs-bin/. 8 | 9 | Building 10 | ======== 11 | You'll need an installation of the FBX SDK 2014. Once installed, set the 12 | FBX_SDK_ROOT to the directory where you installed the FBX SDK. Then run the project which you want at "build/xxxx/" 13 | . These we generate Visual Studio and XCode project. 14 | 15 | Command-line USAGE: 16 | ======== 17 | 18 | * Windows - `fbx-conv.exe [options] ` 19 | * Mac - `fbx-conv [options] ` 20 | 21 | ###Options/flags 22 | * **`-?`** -Display help information. 23 | * **`-f`** -Flip the V texture coordinates. 24 | * **`-m `** -The maximum amount of vertices or indices a mesh may contain (default: 32k) 25 | * **`-n `** -The maximum amount of bones a nodepart can contain (default: 40) 26 | * **`-v`** -Verbose: print additional progress information 27 | * **`-g`** -Whether you need to merge the same mesh which have the same vertex attribute 28 | * **`-a`** -Export c3b(binary) and c3t(text) 29 | * **`-b`** -Export c3b(binary) 30 | * **`-t`** -Export c3t(text) 31 | * **`-c `** -The compression level: 0 , 1 (default: 0) 32 | * **`-l`** -Export model data only. 33 | * **`-j`** -Export animation data only. 34 | 35 | ###Example 36 | `fbx-conv -a boss.FBX` 37 | 38 | Note: 39 | ======== 40 | 1. Model need to have a material. 41 | 2. contain only one skeleton. 42 | 43 | Thanks 44 | ======== 45 | Special thanks to libgdx fbx-conv, We used their code and do some change. 46 | 47 | 48 | -------------------------------------------------------------------------------- /build/vs2012/fbx-conv.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fbx-conv", "fbx-conv.vcxproj", "{92B3746B-795A-B346-B6B2-8265879D5E12}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {92B3746B-795A-B346-B6B2-8265879D5E12}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {92B3746B-795A-B346-B6B2-8265879D5E12}.Debug|Win32.Build.0 = Debug|Win32 14 | {92B3746B-795A-B346-B6B2-8265879D5E12}.Release|Win32.ActiveCfg = Release|Win32 15 | {92B3746B-795A-B346-B6B2-8265879D5E12}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /build/vs2012/fbx-conv.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {50804E0A-F27D-4A45-85B0-19C85A29C407} 6 | 7 | 8 | {92EAFDCC-A0CF-C34D-85AD-A6C2BB9CB008} 9 | 10 | 11 | {965827AA-3D59-0B4C-A0F5-89971437A548} 12 | 13 | 14 | {CA621585-48B0-D942-B41C-B57F2FDB4C6E} 15 | 16 | 17 | {6850282C-8EB7-BE41-8139-CB501FCFD3FF} 18 | 19 | 20 | 21 | 22 | src 23 | 24 | 25 | src 26 | 27 | 28 | src 29 | 30 | 31 | src\json 32 | 33 | 34 | src\json 35 | 36 | 37 | src\json 38 | 39 | 40 | src\json 41 | 42 | 43 | src\log 44 | 45 | 46 | src\log 47 | 48 | 49 | src\log 50 | 51 | 52 | src\modeldata 53 | 54 | 55 | src\modeldata 56 | 57 | 58 | src\modeldata 59 | 60 | 61 | src\modeldata 62 | 63 | 64 | src\modeldata 65 | 66 | 67 | src\modeldata 68 | 69 | 70 | src\modeldata 71 | 72 | 73 | src\modeldata 74 | 75 | 76 | src\modeldata 77 | 78 | 79 | src\modeldata 80 | 81 | 82 | src\readers 83 | 84 | 85 | src\readers 86 | 87 | 88 | src\readers 89 | 90 | 91 | src\readers 92 | 93 | 94 | src\readers 95 | 96 | 97 | src\modeldata 98 | 99 | 100 | src\modeldata 101 | 102 | 103 | src\modeldata 104 | 105 | 106 | src\modeldata 107 | 108 | 109 | 110 | 111 | src 112 | 113 | 114 | src\modeldata 115 | 116 | 117 | src\modeldata 118 | 119 | 120 | src\modeldata 121 | 122 | 123 | src\modeldata 124 | 125 | 126 | src\modeldata 127 | 128 | 129 | src\modeldata 130 | 131 | 132 | -------------------------------------------------------------------------------- /build/xcode3/fbx-conv.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /build/xcode3/fbx-conv.xcodeproj/project.xcworkspace/xcshareddata/fbx-conv.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 8523B213-BF4E-455A-A71A-C2972B75E98A 9 | IDESourceControlProjectName 10 | fbx-conv 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 895B8B25-27D9-4F5B-99A0-2B1639703AA2 14 | ssh://github.com/lvlonggame/fbx-conv.git 15 | 16 | IDESourceControlProjectPath 17 | build/xcode3/fbx-conv.xcodeproj/project.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 895B8B25-27D9-4F5B-99A0-2B1639703AA2 21 | ../../../.. 22 | 23 | IDESourceControlProjectURL 24 | ssh://github.com/lvlonggame/fbx-conv.git 25 | IDESourceControlProjectVersion 26 | 110 27 | IDESourceControlProjectWCCIdentifier 28 | 895B8B25-27D9-4F5B-99A0-2B1639703AA2 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 895B8B25-27D9-4F5B-99A0-2B1639703AA2 36 | IDESourceControlWCCName 37 | fbx-conv-master 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /generate_makefile: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd "$(dirname "$0")" 3 | type premake4 >/dev/null 2>&1 || 4 | { 5 | echo >&2 "'premake4' not found in your path."; 6 | echo >&2 "Premake can be downloaded from http://industriousone.com/premake/"; 7 | exit 1; 8 | } 9 | premake4 --file=premake.lua gmake 10 | -------------------------------------------------------------------------------- /generate_vs2010.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | for %%X in (premake4.exe) do (set FOUND=%%~$PATH:X) 3 | if not defined FOUND ( 4 | echo 'premake4' not found in your path. 5 | echo Premake can be downloaded from http://industriousone.com/premake/ 6 | exit /b 7 | ) 8 | 9 | premake4 --file=premake.lua vs2010 10 | -------------------------------------------------------------------------------- /generate_xcode: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd "$(dirname "$0")" 3 | type premake4 >/dev/null 2>&1 || 4 | { 5 | echo >&2 "'premake4' not found in your path."; 6 | echo >&2 "Premake can be downloaded from http://industriousone.com/premake/"; 7 | exit 1; 8 | } 9 | premake4 --file=premake.lua xcode3 10 | -------------------------------------------------------------------------------- /libs/libpng/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | This copy of the libpng notices is provided for your convenience. In case of 3 | any discrepancy between this copy and the notices in the file png.h that is 4 | included in the libpng distribution, the latter shall prevail. 5 | 6 | COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: 7 | 8 | If you modify libpng you may insert additional notices immediately following 9 | this sentence. 10 | 11 | This code is released under the libpng license. 12 | 13 | libpng versions 1.2.6, August 15, 2004, through 1.4.8, July 7, 2011, are 14 | Copyright (c) 2004, 2006-2010 Glenn Randers-Pehrson, and are 15 | distributed according to the same disclaimer and license as libpng-1.2.5 16 | with the following individual added to the list of Contributing Authors 17 | 18 | Cosmin Truta 19 | 20 | libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are 21 | Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are 22 | distributed according to the same disclaimer and license as libpng-1.0.6 23 | with the following individuals added to the list of Contributing Authors 24 | 25 | Simon-Pierre Cadieux 26 | Eric S. Raymond 27 | Gilles Vollant 28 | 29 | and with the following additions to the disclaimer: 30 | 31 | There is no warranty against interference with your enjoyment of the 32 | library or against infringement. There is no warranty that our 33 | efforts or the library will fulfill any of your particular purposes 34 | or needs. This library is provided with all faults, and the entire 35 | risk of satisfactory quality, performance, accuracy, and effort is with 36 | the user. 37 | 38 | libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are 39 | Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are 40 | distributed according to the same disclaimer and license as libpng-0.96, 41 | with the following individuals added to the list of Contributing Authors: 42 | 43 | Tom Lane 44 | Glenn Randers-Pehrson 45 | Willem van Schaik 46 | 47 | libpng versions 0.89, June 1996, through 0.96, May 1997, are 48 | Copyright (c) 1996, 1997 Andreas Dilger 49 | Distributed according to the same disclaimer and license as libpng-0.88, 50 | with the following individuals added to the list of Contributing Authors: 51 | 52 | John Bowler 53 | Kevin Bracey 54 | Sam Bushell 55 | Magnus Holmgren 56 | Greg Roelofs 57 | Tom Tanner 58 | 59 | libpng versions 0.5, May 1995, through 0.88, January 1996, are 60 | Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. 61 | 62 | For the purposes of this copyright and license, "Contributing Authors" 63 | is defined as the following set of individuals: 64 | 65 | Andreas Dilger 66 | Dave Martindale 67 | Guy Eric Schalnat 68 | Paul Schmidt 69 | Tim Wegner 70 | 71 | The PNG Reference Library is supplied "AS IS". The Contributing Authors 72 | and Group 42, Inc. disclaim all warranties, expressed or implied, 73 | including, without limitation, the warranties of merchantability and of 74 | fitness for any purpose. The Contributing Authors and Group 42, Inc. 75 | assume no liability for direct, indirect, incidental, special, exemplary, 76 | or consequential damages, which may result from the use of the PNG 77 | Reference Library, even if advised of the possibility of such damage. 78 | 79 | Permission is hereby granted to use, copy, modify, and distribute this 80 | source code, or portions hereof, for any purpose, without fee, subject 81 | to the following restrictions: 82 | 83 | 1. The origin of this source code must not be misrepresented. 84 | 85 | 2. Altered versions must be plainly marked as such and must not 86 | be misrepresented as being the original source. 87 | 88 | 3. This Copyright notice may not be removed or altered from any 89 | source or altered source distribution. 90 | 91 | The Contributing Authors and Group 42, Inc. specifically permit, without 92 | fee, and encourage the use of this source code as a component to 93 | supporting the PNG file format in commercial products. If you use this 94 | source code in a product, acknowledgment is not required but would be 95 | appreciated. 96 | 97 | 98 | A "png_get_copyright" function is available, for convenient use in "about" 99 | boxes and the like: 100 | 101 | printf("%s",png_get_copyright(NULL)); 102 | 103 | Also, the PNG logo (in PNG format, of course) is supplied in the 104 | files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). 105 | 106 | Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a 107 | certification mark of the Open Source Initiative. 108 | 109 | Glenn Randers-Pehrson 110 | glennrp at users.sourceforge.net 111 | July 7, 2011 112 | -------------------------------------------------------------------------------- /libs/libpng/lib/android/arm/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/libpng/lib/android/arm/libpng.a -------------------------------------------------------------------------------- /libs/libpng/lib/ios/armv7/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/libpng/lib/ios/armv7/libpng.a -------------------------------------------------------------------------------- /libs/libpng/lib/ios/i386/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/libpng/lib/ios/i386/libpng.a -------------------------------------------------------------------------------- /libs/libpng/lib/linux/x64/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/libpng/lib/linux/x64/libpng.a -------------------------------------------------------------------------------- /libs/libpng/lib/linux/x86/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/libpng/lib/linux/x86/libpng.a -------------------------------------------------------------------------------- /libs/libpng/lib/macosx/libpng.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/libpng/lib/macosx/libpng.a -------------------------------------------------------------------------------- /libs/libpng/lib/windows/x64/libpng14.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/libpng/lib/windows/x64/libpng14.lib -------------------------------------------------------------------------------- /libs/libpng/lib/windows/x86/libpng14.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/libpng/lib/windows/x86/libpng14.lib -------------------------------------------------------------------------------- /libs/libpng/version.txt: -------------------------------------------------------------------------------- 1 | 1.4.8 -------------------------------------------------------------------------------- /libs/zlib/LICENSE.txt: -------------------------------------------------------------------------------- 1 | See license in include/zlib.h -------------------------------------------------------------------------------- /libs/zlib/include/gzguts.h: -------------------------------------------------------------------------------- 1 | /* gzguts.h -- zlib internal header definitions for gz* operations 2 | * Copyright (C) 2004, 2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #ifdef _LARGEFILE64_SOURCE 7 | # ifndef _LARGEFILE_SOURCE 8 | # define _LARGEFILE_SOURCE 1 9 | # endif 10 | # ifdef _FILE_OFFSET_BITS 11 | # undef _FILE_OFFSET_BITS 12 | # endif 13 | #endif 14 | 15 | #if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) 16 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 17 | #else 18 | # define ZLIB_INTERNAL 19 | #endif 20 | 21 | #include 22 | #include "zlib.h" 23 | #ifdef STDC 24 | # include 25 | # include 26 | # include 27 | #endif 28 | #include 29 | 30 | #ifdef NO_DEFLATE /* for compatibility with old definition */ 31 | # define NO_GZCOMPRESS 32 | #endif 33 | 34 | #ifdef _MSC_VER 35 | # include 36 | # define vsnprintf _vsnprintf 37 | #endif 38 | 39 | #ifndef local 40 | # define local static 41 | #endif 42 | /* compile with -Dlocal if your debugger can't find static symbols */ 43 | 44 | /* gz* functions always use library allocation functions */ 45 | #ifndef STDC 46 | extern voidp malloc OF((uInt size)); 47 | extern void free OF((voidpf ptr)); 48 | #endif 49 | 50 | /* get errno and strerror definition */ 51 | #if defined UNDER_CE 52 | # include 53 | # define zstrerror() gz_strwinerror((DWORD)GetLastError()) 54 | #else 55 | # ifdef STDC 56 | # include 57 | # define zstrerror() strerror(errno) 58 | # else 59 | # define zstrerror() "stdio error (consult errno)" 60 | # endif 61 | #endif 62 | 63 | /* provide prototypes for these when building zlib without LFS */ 64 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 65 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); 66 | ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); 67 | ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); 68 | ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); 69 | #endif 70 | 71 | /* default i/o buffer size -- double this for output when reading */ 72 | #define GZBUFSIZE 8192 73 | 74 | /* gzip modes, also provide a little integrity check on the passed structure */ 75 | #define GZ_NONE 0 76 | #define GZ_READ 7247 77 | #define GZ_WRITE 31153 78 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ 79 | 80 | /* values for gz_state how */ 81 | #define LOOK 0 /* look for a gzip header */ 82 | #define COPY 1 /* copy input directly */ 83 | #define GZIP 2 /* decompress a gzip stream */ 84 | 85 | /* internal gzip file state data structure */ 86 | typedef struct { 87 | /* used for both reading and writing */ 88 | int mode; /* see gzip modes above */ 89 | int fd; /* file descriptor */ 90 | char *path; /* path or fd for error messages */ 91 | z_off64_t pos; /* current position in uncompressed data */ 92 | unsigned size; /* buffer size, zero if not allocated yet */ 93 | unsigned want; /* requested buffer size, default is GZBUFSIZE */ 94 | unsigned char *in; /* input buffer */ 95 | unsigned char *out; /* output buffer (double-sized when reading) */ 96 | unsigned char *next; /* next output data to deliver or write */ 97 | /* just for reading */ 98 | unsigned have; /* amount of output data unused at next */ 99 | int eof; /* true if end of input file reached */ 100 | z_off64_t start; /* where the gzip data started, for rewinding */ 101 | z_off64_t raw; /* where the raw data started, for seeking */ 102 | int how; /* 0: get header, 1: copy, 2: decompress */ 103 | int direct; /* true if last read direct, false if gzip */ 104 | /* just for writing */ 105 | int level; /* compression level */ 106 | int strategy; /* compression strategy */ 107 | /* seek request */ 108 | z_off64_t skip; /* amount to skip (already rewound if backwards) */ 109 | int seek; /* true if seek request pending */ 110 | /* error information */ 111 | int err; /* error code */ 112 | char *msg; /* error message */ 113 | /* zlib inflate or deflate stream */ 114 | z_stream strm; /* stream structure in-place (not a pointer) */ 115 | } gz_state; 116 | typedef gz_state FAR *gz_statep; 117 | 118 | /* shared functions */ 119 | void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); 120 | #if defined UNDER_CE 121 | char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); 122 | #endif 123 | 124 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t 125 | value -- needed when comparing unsigned to z_off64_t, which is signed 126 | (possible z_off64_t types off_t, off64_t, and long are all signed) */ 127 | #ifdef INT_MAX 128 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) 129 | #else 130 | unsigned ZLIB_INTERNAL gz_intmax OF((void)); 131 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) 132 | #endif 133 | -------------------------------------------------------------------------------- /libs/zlib/include/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /libs/zlib/include/inffixed.h: -------------------------------------------------------------------------------- 1 | /* inffixed.h -- table for decoding fixed codes 2 | * Generated automatically by makefixed(). 3 | */ 4 | 5 | /* WARNING: this file should *not* be used by applications. It 6 | is part of the implementation of the compression library and 7 | is subject to change. Applications should only use zlib.h. 8 | */ 9 | 10 | static const code lenfix[512] = { 11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, 12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, 13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, 14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, 15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, 16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, 17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, 18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, 19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, 20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, 21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, 22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, 23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, 24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, 25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, 26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, 27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, 28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, 29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, 30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, 31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, 32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, 33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, 34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, 35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, 36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, 37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, 38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, 39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, 40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, 41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, 42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, 43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, 44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, 45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, 46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, 47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, 48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, 49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, 50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, 51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, 52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, 53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, 54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, 55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, 56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, 57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, 58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, 59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, 60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, 61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, 62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, 63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, 64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, 65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, 66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, 67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, 68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, 69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, 70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, 71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, 72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, 73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, 74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, 75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, 76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, 77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, 78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, 79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, 80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, 81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, 82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, 83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, 84 | {0,9,255} 85 | }; 86 | 87 | static const code distfix[32] = { 88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, 89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, 90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, 91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, 92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, 93 | {22,5,193},{64,5,0} 94 | }; 95 | -------------------------------------------------------------------------------- /libs/zlib/include/inflate.h: -------------------------------------------------------------------------------- 1 | /* inflate.h -- internal inflate state definition 2 | * Copyright (C) 1995-2009 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* define NO_GZIP when compiling if you want to disable gzip header and 12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in 13 | the crc code when it is not needed. For shared libraries, gzip decoding 14 | should be left enabled. */ 15 | #ifndef NO_GZIP 16 | # define GUNZIP 17 | #endif 18 | 19 | /* Possible inflate modes between inflate() calls */ 20 | typedef enum { 21 | HEAD, /* i: waiting for magic header */ 22 | FLAGS, /* i: waiting for method and flags (gzip) */ 23 | TIME, /* i: waiting for modification time (gzip) */ 24 | OS, /* i: waiting for extra flags and operating system (gzip) */ 25 | EXLEN, /* i: waiting for extra length (gzip) */ 26 | EXTRA, /* i: waiting for extra bytes (gzip) */ 27 | NAME, /* i: waiting for end of file name (gzip) */ 28 | COMMENT, /* i: waiting for end of comment (gzip) */ 29 | HCRC, /* i: waiting for header crc (gzip) */ 30 | DICTID, /* i: waiting for dictionary check value */ 31 | DICT, /* waiting for inflateSetDictionary() call */ 32 | TYPE, /* i: waiting for type bits, including last-flag bit */ 33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */ 34 | STORED, /* i: waiting for stored size (length and complement) */ 35 | COPY_, /* i/o: same as COPY below, but only first time in */ 36 | COPY, /* i/o: waiting for input or output to copy stored block */ 37 | TABLE, /* i: waiting for dynamic block table lengths */ 38 | LENLENS, /* i: waiting for code length code lengths */ 39 | CODELENS, /* i: waiting for length/lit and distance code lengths */ 40 | LEN_, /* i: same as LEN below, but only first time in */ 41 | LEN, /* i: waiting for length/lit/eob code */ 42 | LENEXT, /* i: waiting for length extra bits */ 43 | DIST, /* i: waiting for distance code */ 44 | DISTEXT, /* i: waiting for distance extra bits */ 45 | MATCH, /* o: waiting for output space to copy string */ 46 | LIT, /* o: waiting for output space to write literal */ 47 | CHECK, /* i: waiting for 32-bit check value */ 48 | LENGTH, /* i: waiting for 32-bit length (gzip) */ 49 | DONE, /* finished check, done -- remain here until reset */ 50 | BAD, /* got a data error -- remain here until reset */ 51 | MEM, /* got an inflate() memory error -- remain here until reset */ 52 | SYNC /* looking for synchronization bytes to restart inflate() */ 53 | } inflate_mode; 54 | 55 | /* 56 | State transitions between above modes - 57 | 58 | (most modes can go to BAD or MEM on error -- not shown for clarity) 59 | 60 | Process header: 61 | HEAD -> (gzip) or (zlib) or (raw) 62 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> 63 | HCRC -> TYPE 64 | (zlib) -> DICTID or TYPE 65 | DICTID -> DICT -> TYPE 66 | (raw) -> TYPEDO 67 | Read deflate blocks: 68 | TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK 69 | STORED -> COPY_ -> COPY -> TYPE 70 | TABLE -> LENLENS -> CODELENS -> LEN_ 71 | LEN_ -> LEN 72 | Read deflate codes in fixed or dynamic block: 73 | LEN -> LENEXT or LIT or TYPE 74 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN 75 | LIT -> LEN 76 | Process trailer: 77 | CHECK -> LENGTH -> DONE 78 | */ 79 | 80 | /* state maintained between inflate() calls. Approximately 10K bytes. */ 81 | struct inflate_state { 82 | inflate_mode mode; /* current inflate mode */ 83 | int last; /* true if processing last block */ 84 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ 85 | int havedict; /* true if dictionary provided */ 86 | int flags; /* gzip header method and flags (0 if zlib) */ 87 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ 88 | unsigned long check; /* protected copy of check value */ 89 | unsigned long total; /* protected copy of output count */ 90 | gz_headerp head; /* where to save gzip header information */ 91 | /* sliding window */ 92 | unsigned wbits; /* log base 2 of requested window size */ 93 | unsigned wsize; /* window size or zero if not using window */ 94 | unsigned whave; /* valid bytes in the window */ 95 | unsigned wnext; /* window write index */ 96 | unsigned char FAR *window; /* allocated sliding window, if needed */ 97 | /* bit accumulator */ 98 | unsigned long hold; /* input bit accumulator */ 99 | unsigned bits; /* number of bits in "in" */ 100 | /* for string and stored block copying */ 101 | unsigned length; /* literal or length of data to copy */ 102 | unsigned offset; /* distance back to copy string from */ 103 | /* for table and code decoding */ 104 | unsigned extra; /* extra bits needed */ 105 | /* fixed and dynamic code tables */ 106 | code const FAR *lencode; /* starting table for length/literal codes */ 107 | code const FAR *distcode; /* starting table for distance codes */ 108 | unsigned lenbits; /* index bits for lencode */ 109 | unsigned distbits; /* index bits for distcode */ 110 | /* dynamic table building */ 111 | unsigned ncode; /* number of code length code lengths */ 112 | unsigned nlen; /* number of length code lengths */ 113 | unsigned ndist; /* number of distance code lengths */ 114 | unsigned have; /* number of code lengths in lens[] */ 115 | code FAR *next; /* next available space in codes[] */ 116 | unsigned short lens[320]; /* temporary storage for code lengths */ 117 | unsigned short work[288]; /* work area for code table building */ 118 | code codes[ENOUGH]; /* space for code tables */ 119 | int sane; /* if false, allow invalid distance too far */ 120 | int back; /* bits back of last unprocessed length/lit */ 121 | unsigned was; /* initial length of match */ 122 | }; 123 | -------------------------------------------------------------------------------- /libs/zlib/include/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2005, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Structure for decoding tables. Each entry provides either the 12 | information needed to do the operation requested by the code that 13 | indexed that table entry, or it provides a pointer to another 14 | table that indexes more bits of the code. op indicates whether 15 | the entry is a pointer to another table, a literal, a length or 16 | distance, an end-of-block, or an invalid code. For a table 17 | pointer, the low four bits of op is the number of index bits of 18 | that table. For a length or distance, the low four bits of op 19 | is the number of extra bits to get after the code. bits is 20 | the number of bits in this code or part of the code to drop off 21 | of the bit buffer. val is the actual byte to output in the case 22 | of a literal, the base length or distance, or the offset from 23 | the current table to the next table. Each entry is four bytes. */ 24 | typedef struct { 25 | unsigned char op; /* operation, extra bits, table bits */ 26 | unsigned char bits; /* bits in this part of the code */ 27 | unsigned short val; /* offset in table or code value */ 28 | } code; 29 | 30 | /* op values as set by inflate_table(): 31 | 00000000 - literal 32 | 0000tttt - table link, tttt != 0 is the number of table index bits 33 | 0001eeee - length or distance, eeee is the number of extra bits 34 | 01100000 - end of block 35 | 01000000 - invalid code 36 | */ 37 | 38 | /* Maximum size of the dynamic table. The maximum number of code structures is 39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance 40 | codes. These values were found by exhaustive searches using the program 41 | examples/enough.c found in the zlib distribtution. The arguments to that 42 | program are the number of symbols, the initial root table size, and the 43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes 44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592. 45 | The initial root table size (9 or 6) is found in the fifth argument of the 46 | inflate_table() calls in inflate.c and infback.c. If the root table size is 47 | changed, then these maximum sizes would be need to be recalculated and 48 | updated. */ 49 | #define ENOUGH_LENS 852 50 | #define ENOUGH_DISTS 592 51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) 52 | 53 | /* Type of code to build for inflate_table() */ 54 | typedef enum { 55 | CODES, 56 | LENS, 57 | DISTS 58 | } codetype; 59 | 60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, 61 | unsigned codes, code FAR * FAR *table, 62 | unsigned FAR *bits, unsigned short FAR *work)); 63 | -------------------------------------------------------------------------------- /libs/zlib/include/trees.h: -------------------------------------------------------------------------------- 1 | /* header created automatically with -DGEN_TREES_H */ 2 | 3 | local const ct_data static_ltree[L_CODES+2] = { 4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, 5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, 6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, 7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, 8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, 9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, 10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, 11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, 12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, 13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, 14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, 15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, 16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, 17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, 18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, 19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, 20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, 21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, 22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, 23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, 24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, 25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, 26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, 27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, 28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, 29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, 30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, 31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, 32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, 33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, 34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, 35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, 36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, 37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, 38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, 39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, 40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, 41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, 42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, 43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, 44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, 45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, 46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, 47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, 48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, 49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, 50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, 51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, 52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, 53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, 54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, 55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, 56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, 57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, 58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, 59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, 60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, 61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} 62 | }; 63 | 64 | local const ct_data static_dtree[D_CODES] = { 65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, 66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, 67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, 68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, 69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, 70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} 71 | }; 72 | 73 | const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { 74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, 87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 100 | }; 101 | 102 | const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { 103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, 104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, 109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 116 | }; 117 | 118 | local const int base_length[LENGTH_CODES] = { 119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 120 | 64, 80, 96, 112, 128, 160, 192, 224, 0 121 | }; 122 | 123 | local const int base_dist[D_CODES] = { 124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 127 | }; 128 | 129 | -------------------------------------------------------------------------------- /libs/zlib/include/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2010 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id$ */ 12 | 13 | #ifndef ZUTIL_H 14 | #define ZUTIL_H 15 | 16 | #if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) 17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) 18 | #else 19 | # define ZLIB_INTERNAL 20 | #endif 21 | 22 | #include "zlib.h" 23 | 24 | #ifdef STDC 25 | # if !(defined(_WIN32_WCE) && defined(_MSC_VER)) 26 | # include 27 | # endif 28 | # include 29 | # include 30 | #endif 31 | 32 | #ifndef local 33 | # define local static 34 | #endif 35 | /* compile with -Dlocal if your debugger can't find static symbols */ 36 | 37 | typedef unsigned char uch; 38 | typedef uch FAR uchf; 39 | typedef unsigned short ush; 40 | typedef ush FAR ushf; 41 | typedef unsigned long ulg; 42 | 43 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ 44 | /* (size given to avoid silly warnings with Visual C++) */ 45 | 46 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 47 | 48 | #define ERR_RETURN(strm,err) \ 49 | return (strm->msg = (char*)ERR_MSG(err), (err)) 50 | /* To be used only when the state is known to be valid */ 51 | 52 | /* common constants */ 53 | 54 | #ifndef DEF_WBITS 55 | # define DEF_WBITS MAX_WBITS 56 | #endif 57 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 58 | 59 | #if MAX_MEM_LEVEL >= 8 60 | # define DEF_MEM_LEVEL 8 61 | #else 62 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 63 | #endif 64 | /* default memLevel */ 65 | 66 | #define STORED_BLOCK 0 67 | #define STATIC_TREES 1 68 | #define DYN_TREES 2 69 | /* The three kinds of block type */ 70 | 71 | #define MIN_MATCH 3 72 | #define MAX_MATCH 258 73 | /* The minimum and maximum match lengths */ 74 | 75 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 76 | 77 | /* target dependencies */ 78 | 79 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) 80 | # define OS_CODE 0x00 81 | # if defined(__TURBOC__) || defined(__BORLANDC__) 82 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 83 | /* Allow compilation with ANSI keywords only enabled */ 84 | void _Cdecl farfree( void *block ); 85 | void *_Cdecl farmalloc( unsigned long nbytes ); 86 | # else 87 | # include 88 | # endif 89 | # else /* MSC or DJGPP */ 90 | # include 91 | # endif 92 | #endif 93 | 94 | #ifdef AMIGA 95 | # define OS_CODE 0x01 96 | #endif 97 | 98 | #if defined(VAXC) || defined(VMS) 99 | # define OS_CODE 0x02 100 | # define F_OPEN(name, mode) \ 101 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 102 | #endif 103 | 104 | #if defined(ATARI) || defined(atarist) 105 | # define OS_CODE 0x05 106 | #endif 107 | 108 | #ifdef OS2 109 | # define OS_CODE 0x06 110 | # ifdef M_I86 111 | # include 112 | # endif 113 | #endif 114 | 115 | #if defined(MACOS) || defined(TARGET_OS_MAC) 116 | # define OS_CODE 0x07 117 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 118 | # include /* for fdopen */ 119 | # else 120 | # ifndef fdopen 121 | # define fdopen(fd,mode) NULL /* No fdopen() */ 122 | # endif 123 | # endif 124 | #endif 125 | 126 | #ifdef TOPS20 127 | # define OS_CODE 0x0a 128 | #endif 129 | 130 | #ifdef WIN32 131 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ 132 | # define OS_CODE 0x0b 133 | # endif 134 | #endif 135 | 136 | #ifdef __50SERIES /* Prime/PRIMOS */ 137 | # define OS_CODE 0x0f 138 | #endif 139 | 140 | #if defined(_BEOS_) || defined(RISCOS) 141 | # define fdopen(fd,mode) NULL /* No fdopen() */ 142 | #endif 143 | 144 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX 145 | # if defined(_WIN32_WCE) 146 | # define fdopen(fd,mode) NULL /* No fdopen() */ 147 | # ifndef _PTRDIFF_T_DEFINED 148 | typedef int ptrdiff_t; 149 | # define _PTRDIFF_T_DEFINED 150 | # endif 151 | # else 152 | # define fdopen(fd,type) _fdopen(fd,type) 153 | # endif 154 | #endif 155 | 156 | #if defined(__BORLANDC__) 157 | #pragma warn -8004 158 | #pragma warn -8008 159 | #pragma warn -8066 160 | #endif 161 | 162 | /* provide prototypes for these when building zlib without LFS */ 163 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 164 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); 165 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); 166 | #endif 167 | 168 | /* common defaults */ 169 | 170 | #ifndef OS_CODE 171 | # define OS_CODE 0x03 /* assume Unix */ 172 | #endif 173 | 174 | #ifndef F_OPEN 175 | # define F_OPEN(name, mode) fopen((name), (mode)) 176 | #endif 177 | 178 | /* functions */ 179 | 180 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) 181 | # ifndef HAVE_VSNPRINTF 182 | # define HAVE_VSNPRINTF 183 | # endif 184 | #endif 185 | #if defined(__CYGWIN__) 186 | # ifndef HAVE_VSNPRINTF 187 | # define HAVE_VSNPRINTF 188 | # endif 189 | #endif 190 | #ifndef HAVE_VSNPRINTF 191 | # ifdef MSDOS 192 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), 193 | but for now we just assume it doesn't. */ 194 | # define NO_vsnprintf 195 | # endif 196 | # ifdef __TURBOC__ 197 | # define NO_vsnprintf 198 | # endif 199 | # ifdef WIN32 200 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ 201 | # if !defined(vsnprintf) && !defined(NO_vsnprintf) 202 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) 203 | # define vsnprintf _vsnprintf 204 | # endif 205 | # endif 206 | # endif 207 | # ifdef __SASC 208 | # define NO_vsnprintf 209 | # endif 210 | #endif 211 | #ifdef VMS 212 | # define NO_vsnprintf 213 | #endif 214 | 215 | #if defined(pyr) 216 | # define NO_MEMCPY 217 | #endif 218 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 219 | /* Use our own functions for small and medium model with MSC <= 5.0. 220 | * You may have to use the same strategy for Borland C (untested). 221 | * The __SC__ check is for Symantec. 222 | */ 223 | # define NO_MEMCPY 224 | #endif 225 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 226 | # define HAVE_MEMCPY 227 | #endif 228 | #ifdef HAVE_MEMCPY 229 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 230 | # define zmemcpy _fmemcpy 231 | # define zmemcmp _fmemcmp 232 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 233 | # else 234 | # define zmemcpy memcpy 235 | # define zmemcmp memcmp 236 | # define zmemzero(dest, len) memset(dest, 0, len) 237 | # endif 238 | #else 239 | void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 240 | int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 241 | void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); 242 | #endif 243 | 244 | /* Diagnostic functions */ 245 | #ifdef DEBUG 246 | # include 247 | extern int ZLIB_INTERNAL z_verbose; 248 | extern void ZLIB_INTERNAL z_error OF((char *m)); 249 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 250 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 251 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 252 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 253 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 254 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 255 | #else 256 | # define Assert(cond,msg) 257 | # define Trace(x) 258 | # define Tracev(x) 259 | # define Tracevv(x) 260 | # define Tracec(c,x) 261 | # define Tracecv(c,x) 262 | #endif 263 | 264 | 265 | voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, 266 | unsigned size)); 267 | void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); 268 | 269 | #define ZALLOC(strm, items, size) \ 270 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 271 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 272 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 273 | 274 | #endif /* ZUTIL_H */ 275 | -------------------------------------------------------------------------------- /libs/zlib/lib/android/arm/libzlib.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/zlib/lib/android/arm/libzlib.a -------------------------------------------------------------------------------- /libs/zlib/lib/linux/x64/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/zlib/lib/linux/x64/libz.a -------------------------------------------------------------------------------- /libs/zlib/lib/linux/x86/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/zlib/lib/linux/x86/libz.a -------------------------------------------------------------------------------- /libs/zlib/lib/macosx/libz.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/zlib/lib/macosx/libz.a -------------------------------------------------------------------------------- /libs/zlib/lib/windows/x64/zlib.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/zlib/lib/windows/x64/zlib.lib -------------------------------------------------------------------------------- /libs/zlib/lib/windows/x86/zlib.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/libs/zlib/lib/windows/x86/zlib.lib -------------------------------------------------------------------------------- /libs/zlib/version.txt: -------------------------------------------------------------------------------- 1 | 1.2.5 -------------------------------------------------------------------------------- /premake.lua: -------------------------------------------------------------------------------- 1 | -- TODO: Because there are a few remaining things ... 2 | -- 1. x86/x64 switching 3 | -- 2. clean this file up because I'm sure it could be organized better 4 | -- 3. consider maybe switching to CMake because of the ugly hack below 5 | -- 6 | -- NOTE: I am intentionally leaving out a "windows+gmake" configuration 7 | -- as trying to compile against the FBX SDK using MinGW results in 8 | -- compile errors. Some quick googling seems to indicate MinGW is 9 | -- not supported by the FBX SDK? 10 | -- If you try to use this script to build with MinGW you will end 11 | -- up with a Makefile that has god knows what in it 12 | 13 | FBX_SDK_ROOT = os.getenv("FBX_SDK_ROOT") 14 | if not FBX_SDK_ROOT then 15 | printf("ERROR: Environment variable FBX_SDK_ROOT is not set.") 16 | printf("Set it to something like: C:\\Program Files\\Autodesk\\FBX\\FBX SDK\\2013.3") 17 | os.exit() 18 | end 19 | 20 | -- avert your eyes children! 21 | if string.find(_ACTION, "xcode") then 22 | -- TODO: i'm sure we could do some string search+replace trickery to make 23 | -- this more general-purpose 24 | -- take care of the most common case where the FBX SDK is installed to the 25 | -- default location and part of the path contains a space 26 | -- god help you if you install the FBX SDK using a totally different path 27 | -- that contains a space AND you want to use Xcode 28 | -- Premake + Xcode combined fuck this up so badly making it nigh-impossible 29 | -- to do any kind of _proper_ path escaping here (I wasted an hour on this) 30 | -- (maybe I should have used CMake ....) 31 | FBX_SDK_ROOT = string.gsub(FBX_SDK_ROOT, "FBX SDK", "'FBX SDK'") 32 | end 33 | -- ok, you can look again 34 | 35 | BUILD_DIR = "build" 36 | if _ACTION == "clean" then 37 | os.rmdir(BUILD_DIR) 38 | end 39 | 40 | solution "fbx-conv" 41 | configurations { "Debug", "Release" } 42 | location (BUILD_DIR .. "/" .. _ACTION) 43 | 44 | project "fbx-conv" 45 | --- GENERAL STUFF FOR ALL PLATFORMS -------------------------------- 46 | kind "ConsoleApp" 47 | language "C++" 48 | location (BUILD_DIR .. "/" .. _ACTION) 49 | files { 50 | "./src/**.c*", 51 | "./src/**.h", 52 | } 53 | includedirs { 54 | (FBX_SDK_ROOT .. "/include"), 55 | "./libs/libpng/include", 56 | "./libs/zlib/include", 57 | } 58 | defines { 59 | "FBXSDK_NEW_API", 60 | } 61 | --- debugdir "." 62 | 63 | configuration "Debug" 64 | defines { 65 | "DEBUG", 66 | } 67 | flags { "Symbols" } 68 | 69 | configuration "Release" 70 | defines { 71 | "NDEBUG", 72 | } 73 | flags { "Optimize" } 74 | 75 | --- VISUAL STUDIO -------------------------------------------------- 76 | configuration "vs*" 77 | flags { 78 | "NoPCH", 79 | "NoMinimalRebuild" 80 | } 81 | buildoptions { "/MP" } 82 | defines { 83 | "_CRT_SECURE_NO_WARNINGS", 84 | "_CRT_NONSTDC_NO_WARNINGS" 85 | } 86 | libdirs { 87 | (FBX_SDK_ROOT .. "/lib/vs2010/x86"), 88 | "./libs/libpng/lib/windows/x86", 89 | "./libs/zlib/lib/windows/x86", 90 | } 91 | links { 92 | "libpng14", 93 | "zlib", 94 | "libfbxsdk-md", 95 | } 96 | 97 | configuration { "vs*", "Debug" } 98 | libdirs { 99 | (FBX_SDK_ROOT .. "/lib/vs2010/x86/debug"), 100 | } 101 | 102 | configuration { "vs*", "Release" } 103 | libdirs { 104 | (FBX_SDK_ROOT .. "/lib/vs2010/x86/release"), 105 | } 106 | 107 | --- LINUX ---------------------------------------------------------- 108 | configuration { "linux" } 109 | kind "ConsoleApp" 110 | buildoptions { "-Wall" } 111 | -- TODO: while using x64 will likely be fine for most people nowadays, 112 | -- we still need to make this configurable 113 | libdirs { 114 | "./libs/libpng/lib/linux/x64", 115 | "./libs/zlib/lib/linux/x64", 116 | } 117 | 118 | linkoptions {"-Wl,--no-as-needed"} 119 | 120 | links { 121 | "png", 122 | "z", 123 | "pthread", 124 | "fbxsdk", 125 | "dl", 126 | } 127 | 128 | configuration { "linux", "Debug" } 129 | libdirs { 130 | (FBX_SDK_ROOT .. "/lib/gcc4/x64/debug"), 131 | } 132 | 133 | configuration { "linux", "Release" } 134 | libdirs { 135 | (FBX_SDK_ROOT .. "/lib/gcc4/x64/release"), 136 | } 137 | 138 | --- MAC ------------------------------------------------------------ 139 | configuration { "macosx" } 140 | kind "ConsoleApp" 141 | buildoptions { "-Wall" } 142 | libdirs { 143 | (FBX_SDK_ROOT .. "/lib/clang/ub"), 144 | "./libs/libpng/lib/macosx", 145 | "./libs/zlib/lib/macosx", 146 | } 147 | links { 148 | "png", 149 | "z", 150 | "CoreFoundation.framework", 151 | "fbxsdk", 152 | } 153 | 154 | configuration { "macosx", "Debug" } 155 | libdirs { 156 | (FBX_SDK_ROOT .. "/lib/clang/ub/debug"), 157 | } 158 | 159 | configuration { "macosx", "Release" } 160 | libdirs { 161 | (FBX_SDK_ROOT .. "/lib/clang/ub/release"), 162 | } 163 | -------------------------------------------------------------------------------- /samples/3dsmax/mineShaftWall001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/3dsmax/mineShaftWall001.png -------------------------------------------------------------------------------- /samples/3dsmax/redSpec_bin.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/3dsmax/redSpec_bin.fbx -------------------------------------------------------------------------------- /samples/3dsmax/textured_bin.FBX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/3dsmax/textured_bin.FBX -------------------------------------------------------------------------------- /samples/Knight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/Knight.png -------------------------------------------------------------------------------- /samples/attribution.txt: -------------------------------------------------------------------------------- 1 | air fighter 2 | ----------- 3 | http://opengameart.org/content/low-spec-airspace-fighter -------------------------------------------------------------------------------- /samples/blender/cube-single-bone.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/blender/cube-single-bone.blend -------------------------------------------------------------------------------- /samples/blender/cube-single-bone.g3dj: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "1.0", 3 | "meshes" : [ 4 | { 5 | "id" : "Cube_Mesh", 6 | "attributes" : [ 7 | "POSITION","NORMAL","BLENDWEIGHTS","BLENDINDICES" 8 | ], 9 | "vertices" : [ 10 | -0.236371,-0.236371,-0.236371,-0.577349,-0.577349,-0.577349,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.236371,0.236371,-0.236371,0.577349,0.577349,-0.577349,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.236371,-0.236371,-0.236371,0.577349,-0.577349,-0.577349,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,-0.236371,0.236371,-0.236371,-0.577349,0.577349,-0.577349,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,-0.236371,0.236371,0.236371,-0.577349,0.577349,0.577349,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,-0.236371,-0.236371,0.236371,-0.577349,-0.577349,0.577349,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.236371,0.236371,0.236371,0.577349,0.577349,0.577349,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.236371,-0.236371,0.236371,0.577349,-0.577349,0.577349,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 11 | ], 12 | "parts" : [ 13 | { 14 | "id" : "part0", 15 | "type" : "TRIANGLES", 16 | "indices" : [ 17 | 0,1,2,1,0,3,4,5,6,6,5,7,7,1,6,1,7,2,5,2,7,2,5,0,4,0,5,0,4,3,4,6,3,6,1,3 18 | ] 19 | } 20 | ] 21 | } 22 | ], 23 | "materials" : [ 24 | { 25 | "id" : "Material", 26 | "type" : "LAMBERT", 27 | "diffuse" : [0.800000,0.800000,0.800000], 28 | "ambient" : [0.0,0.0,0.0], 29 | "emissive" : [0.800000,0.800000,0.800000], 30 | "opacity" : 1.000000 31 | } 32 | ], 33 | "nodes" : [ 34 | { 35 | "id" : "Armature", 36 | "isBone" : "true", 37 | "translation" : [0.0,0.0,0.0], 38 | "rotation" : [-0.707107,0.0,0.0,0.707107], 39 | "scale" : [1.0,1.0,1.0], 40 | "children" : [ 41 | { 42 | "id" : "Bone", 43 | "isBone" : "true", 44 | "translation" : [0.0,0.0,0.0], 45 | "rotation" : [0.500000,-0.500000,0.500000,0.500000], 46 | "scale" : [1.0,1.0,1.0] 47 | } 48 | ] 49 | }, 50 | { 51 | "id" : "Cube", 52 | "isBone" : "false", 53 | "translation" : [0.0,0.0,0.0], 54 | "rotation" : [0.0,0.0,0.0,1.0], 55 | "scale" : [1.0,1.0,1.0], 56 | "mesh" : "Cube_Mesh", 57 | "materials" : [ 58 | { 59 | "meshpartid" : "part0", 60 | "materialid" : "Material" 61 | } 62 | ] 63 | } 64 | ], 65 | "animations" : [ 66 | { 67 | "id" : "Default Take", 68 | "bones" : [ 69 | { 70 | "boneId" : "Armature", 71 | "keyframes" : [ 72 | { 73 | "keytime" : 0.000000, 74 | "translation" : [0.0,0.0,0.0], 75 | "rotation" : [-0.707107,0.0,0.0,0.707107], 76 | "scale" : [1.0,1.0,1.0] 77 | } 78 | ] 79 | }, 80 | { 81 | "boneId" : "Bone", 82 | "keyframes" : [ 83 | { 84 | "keytime" : 0.000000, 85 | "translation" : [0.0,0.0,0.0], 86 | "rotation" : [0.500000,-0.500000,0.500000,0.500000], 87 | "scale" : [1.0,1.0,1.0] 88 | } 89 | ] 90 | } 91 | ] 92 | } 93 | ] 94 | } -------------------------------------------------------------------------------- /samples/blender/cube-two-bones.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/blender/cube-two-bones.blend -------------------------------------------------------------------------------- /samples/blender/cube-two-bones.blend1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/blender/cube-two-bones.blend1 -------------------------------------------------------------------------------- /samples/blender/cube-two-bones.blend2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/blender/cube-two-bones.blend2 -------------------------------------------------------------------------------- /samples/blender/cube-two-bones.g3dj: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "1.0", 3 | "meshes" : [ 4 | { 5 | "id" : "Cube_Mesh", 6 | "attributes" : [ 7 | "POSITION","NORMAL","BLENDWEIGHTS","BLENDINDICES" 8 | ], 9 | "vertices" : [ 10 | 1.0,-1.0,-1.0,0.577349,-0.577349,-0.577349,1.0,0.0,0.0,0.0,5.000000,0.0,0.0,0.0,-0.999999,1.0,-1.0,-0.577349,0.577349,-0.577349,1.0,0.0,0.0,0.0,5.000000,0.0,0.0,0.0,1.0,1.0,-1.0,0.577349,0.577349,-0.577349,1.0,0.0,0.0,0.0,5.000000,0.0,0.0,0.0,-1.0,-1.0,-1.0,-0.577349,-0.577349,-0.577349,1.0,0.0,0.0,0.0,5.000000,0.0,0.0,0.0,-1.0,1.0,1.0,-0.577349,0.577349,0.577349,1.0,0.0,0.0,0.0,5.000000,0.0,0.0,0.0,-1.0,-1.0,1.0,-0.577349,-0.577349,0.577349,1.0,0.0,0.0,0.0,5.000000,0.0,0.0,0.0,1.0,0.999999,1.0,0.577349,0.577349,0.577349,1.0,0.0,0.0,0.0,5.000000,0.0,0.0,0.0,1.0,-1.000001,1.0,0.577349,-0.577349,0.577349,1.0,0.0,0.0,0.0,5.000000,0.0,0.0,0.0 11 | ], 12 | "parts" : [ 13 | { 14 | "id" : "part0", 15 | "type" : "TRIANGLES", 16 | "indices" : [ 17 | 0,1,2,1,0,3,4,5,6,6,5,7,6,0,2,0,6,7,5,0,7,0,5,3,4,3,5,3,4,1,4,6,1,6,2,1 18 | ] 19 | } 20 | ] 21 | } 22 | ], 23 | "materials" : [ 24 | { 25 | "id" : "Material", 26 | "type" : "LAMBERT", 27 | "diffuse" : [0.800000,0.800000,0.800000], 28 | "ambient" : [0.0,0.0,0.0], 29 | "emissive" : [0.800000,0.800000,0.800000], 30 | "opacity" : 1.000000 31 | } 32 | ], 33 | "nodes" : [ 34 | { 35 | "id" : "Armature", 36 | "isBone" : "true", 37 | "translation" : [0.0,0.0,0.0], 38 | "rotation" : [-0.707107,0.0,0.0,0.707107], 39 | "scale" : [1.0,1.0,1.0], 40 | "children" : [ 41 | { 42 | "id" : "Bone", 43 | "isBone" : "true", 44 | "translation" : [0.0,0.0,0.0], 45 | "rotation" : [0.500000,-0.500000,0.500000,0.500000], 46 | "scale" : [1.0,1.0,1.0], 47 | "children" : [ 48 | { 49 | "id" : "Bone_001", 50 | "isBone" : "true", 51 | "translation" : [1.0,0.000000,0.0], 52 | "rotation" : [-0.000000,0.707107,0.000000,0.707107], 53 | "scale" : [1.0,1.0,1.0] 54 | }, 55 | { 56 | "id" : "Bone_002", 57 | "isBone" : "true", 58 | "translation" : [1.0,0.000000,0.0], 59 | "rotation" : [0.000000,-0.707107,0.000000,0.707107], 60 | "scale" : [1.0,1.0,1.0], 61 | "children" : [ 62 | { 63 | "id" : "Bone_003", 64 | "isBone" : "true", 65 | "translation" : [2.339790,0.000000,-0.000000], 66 | "rotation" : [1.0,0.000000,0.000000,-0.000000], 67 | "scale" : [1.0,1.0,1.0] 68 | } 69 | ] 70 | }, 71 | { 72 | "id" : "Bone_004", 73 | "isBone" : "true", 74 | "translation" : [1.0,0.000000,0.0], 75 | "rotation" : [0.500000,-0.500000,-0.500000,0.500000], 76 | "scale" : [1.0,1.0,1.0], 77 | "children" : [ 78 | { 79 | "id" : "Bone_005", 80 | "isBone" : "true", 81 | "translation" : [2.633632,0.000000,0.000000], 82 | "rotation" : [1.0,0.000000,-0.000000,-0.000000], 83 | "scale" : [1.000000,1.0,1.0] 84 | } 85 | ] 86 | } 87 | ] 88 | } 89 | ] 90 | }, 91 | { 92 | "id" : "Camera", 93 | "isBone" : "false", 94 | "translation" : [7.481132,5.343665,6.507640], 95 | "rotation" : [-0.210611,0.905240,-0.089282,0.358067], 96 | "scale" : [1.0,1.000000,1.0] 97 | }, 98 | { 99 | "id" : "Cube", 100 | "isBone" : "false", 101 | "translation" : [4.731989,0.599482,0.615188], 102 | "rotation" : [0.0,0.0,0.0,1.0], 103 | "scale" : [1.0,1.0,1.0], 104 | "mesh" : "Cube_Mesh", 105 | "materials" : [ 106 | { 107 | "meshpartid" : "part0", 108 | "materialid" : "Material" 109 | } 110 | ] 111 | }, 112 | { 113 | "id" : "Lamp", 114 | "isBone" : "false", 115 | "translation" : [4.076245,5.903862,-1.005454], 116 | "rotation" : [0.169076,0.755880,-0.272171,0.570948], 117 | "scale" : [1.000000,1.000000,1.0] 118 | } 119 | ], 120 | "animations" : [ 121 | { 122 | "id" : "Default Take", 123 | "bones" : [ 124 | { 125 | "boneId" : "Lamp", 126 | "keyframes" : [ 127 | { 128 | "keytime" : 0.000000, 129 | "translation" : [4.076245,5.903862,-1.005454], 130 | "rotation" : [0.169076,0.755880,-0.272171,0.570947], 131 | "scale" : [1.000000,1.000000,1.000000] 132 | } 133 | ] 134 | }, 135 | { 136 | "boneId" : "Camera", 137 | "keyframes" : [ 138 | { 139 | "keytime" : 0.000000, 140 | "translation" : [7.481132,5.343665,6.507640], 141 | "rotation" : [-0.210611,0.905240,-0.089282,0.358067], 142 | "scale" : [1.0,1.000000,1.0] 143 | } 144 | ] 145 | }, 146 | { 147 | "boneId" : "Armature", 148 | "keyframes" : [ 149 | { 150 | "keytime" : 0.000000, 151 | "translation" : [0.0,0.0,0.0], 152 | "rotation" : [-0.707107,0.0,0.0,0.707107], 153 | "scale" : [1.0,1.0,1.0] 154 | } 155 | ] 156 | }, 157 | { 158 | "boneId" : "Bone", 159 | "keyframes" : [ 160 | { 161 | "keytime" : 0.000000, 162 | "translation" : [0.0,0.0,0.0], 163 | "rotation" : [0.500000,-0.500000,0.500000,0.500000], 164 | "scale" : [1.0,1.0,1.0] 165 | } 166 | ] 167 | }, 168 | { 169 | "boneId" : "Bone_001", 170 | "keyframes" : [ 171 | { 172 | "keytime" : 0.000000, 173 | "translation" : [1.0,0.000000,0.0], 174 | "rotation" : [-0.000000,0.707107,0.000000,0.707107], 175 | "scale" : [1.0,1.0,1.0] 176 | } 177 | ] 178 | }, 179 | { 180 | "boneId" : "Bone_002", 181 | "keyframes" : [ 182 | { 183 | "keytime" : 0.000000, 184 | "translation" : [1.0,0.000000,0.0], 185 | "rotation" : [0.000000,-0.707107,0.000000,0.707107], 186 | "scale" : [1.0,1.0,1.0] 187 | } 188 | ] 189 | }, 190 | { 191 | "boneId" : "Bone_003", 192 | "keyframes" : [ 193 | { 194 | "keytime" : 0.000000, 195 | "translation" : [2.339790,0.000000,-0.000000], 196 | "rotation" : [1.0,0.000000,0.000000,0.000000], 197 | "scale" : [1.0,1.0,1.0] 198 | } 199 | ] 200 | }, 201 | { 202 | "boneId" : "Bone_004", 203 | "keyframes" : [ 204 | { 205 | "keytime" : 0.000000, 206 | "translation" : [1.0,0.000000,0.0], 207 | "rotation" : [0.500000,-0.500000,-0.500000,0.500000], 208 | "scale" : [1.0,1.0,1.0] 209 | } 210 | ] 211 | }, 212 | { 213 | "boneId" : "Bone_005", 214 | "keyframes" : [ 215 | { 216 | "keytime" : 0.000000, 217 | "translation" : [2.633632,0.000000,0.000000], 218 | "rotation" : [1.0,0.000000,0.000000,0.000000], 219 | "scale" : [1.000000,1.0,1.0] 220 | } 221 | ] 222 | } 223 | ] 224 | } 225 | ] 226 | } -------------------------------------------------------------------------------- /samples/blender/cube.dae: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Blender User 6 | Blender 2.64.0 r51232 7 | 8 | 2012-11-18T15:44:31 9 | 2012-11-18T15:44:31 10 | 11 | Z_UP 12 | 13 | 14 | 15 | 16 | 17 | 18 | 49.13434 19 | 1.777778 20 | 0.1 21 | 100 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 1 1 1 32 | 1 33 | 0 34 | 0.00111109 35 | 36 | 37 | 38 | 39 | 0.000999987 40 | 0 41 | 1 42 | 1 43 | 1 44 | 1 45 | 1 46 | 2 47 | 0 48 | 1 49 | 1 50 | 1 51 | 1 52 | 1 53 | 0 54 | 2880 55 | 2 56 | 30.002 57 | 1.000799 58 | 0.04999995 59 | 29.99998 60 | 1 61 | 2 62 | 0 63 | 0 64 | 1 65 | 1 66 | 1 67 | 1 68 | 8192 69 | 1 70 | 1 71 | 0 72 | 1 73 | 1 74 | 1 75 | 3 76 | 0 77 | 0 78 | 0 79 | 0 80 | 45 81 | 0 82 | 1 83 | 1 84 | 1 85 | 3 86 | 0.15 87 | 75 88 | 1 89 | 1 90 | 0 91 | 1 92 | 1 93 | 0 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 0 0 0 1 106 | 107 | 108 | 0 0 0 1 109 | 110 | 111 | 0.64 0.64 0.64 1 112 | 113 | 114 | 0.5 0.5 0.5 1 115 | 116 | 117 | 50 118 | 119 | 120 | 1 121 | 122 | 123 | 124 | 125 | 126 | 1 127 | 128 | 129 | 130 | 1 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 1 1 -1 1 -1 -1 -1 -0.9999998 -1 -0.9999997 1 -1 1 0.9999995 1 0.9999994 -1.000001 1 -1 -0.9999997 1 -1 1 1 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 0 0 -1 0 0 1 1 -2.83122e-7 0 -2.83122e-7 -1 0 -1 2.23517e-7 -1.3411e-7 2.38419e-7 1 2.08616e-7 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 4 4 4 4 4 4 168 |

0 0 1 0 2 0 3 0 4 1 7 1 6 1 5 1 0 2 4 2 5 2 1 2 1 3 5 3 6 3 2 3 2 4 6 4 7 4 3 4 4 5 0 5 3 5 7 5

169 |
170 |
171 | 1 172 |
173 |
174 | 175 | 176 | 177 | 7.481132 -6.50764 5.343665 178 | 0 0 1 46.69195 179 | 0 1 0 0.619768 180 | 1 0 0 63.5593 181 | 1 1 1 182 | 183 | 184 | 185 | 4.076245 1.005454 5.903862 186 | 0 0 1 106.9363 187 | 0 1 0 3.163708 188 | 1 0 0 37.26105 189 | 1 1 1 190 | 191 | 192 | 193 | 0 0 0 194 | 0 0 1 0 195 | 0 1 0 0 196 | 1 0 0 0 197 | 1 1 1 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 |
-------------------------------------------------------------------------------- /samples/blender/cube.g3dj: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "1.0", 3 | "meshes" : [ 4 | { 5 | "id" : "Cube_Mesh", 6 | "attributes" : [ 7 | "POSITION","NORMAL" 8 | ], 9 | "vertices" : [ 10 | -1.0,-1.0,-1.0,-0.577349,-0.577349,-0.577349,1.0,1.0,-1.0,0.577349,0.577349,-0.577349,1.0,-1.0,-1.0,0.577349,-0.577349,-0.577349,-1.0,1.0,-1.0,-0.577349,0.577349,-0.577349,-1.0,1.0,1.0,-0.577349,0.577349,0.577349,-1.0,-1.0,1.0,-0.577349,-0.577349,0.577349,1.0,0.999999,1.0,0.577349,0.577349,0.577349,0.999999,-1.000001,1.0,0.577349,-0.577349,0.577349 11 | ], 12 | "parts" : [ 13 | { 14 | "id" : "part0", 15 | "type" : "TRIANGLES", 16 | "indices" : [ 17 | 0,1,2,1,0,3,4,5,6,6,5,7,6,2,1,2,6,7,7,0,2,0,7,5,4,0,5,0,4,3,4,6,3,6,1,3 18 | ] 19 | } 20 | ] 21 | } 22 | ], 23 | "materials" : [ 24 | { 25 | "id" : "Material", 26 | "type" : "LAMBERT", 27 | "diffuse" : [0.800000,0.800000,0.800000], 28 | "ambient" : [0.0,0.0,0.0], 29 | "emissive" : [0.800000,0.800000,0.800000], 30 | "opacity" : 1.000000 31 | } 32 | ], 33 | "nodes" : [ 34 | { 35 | "id" : "Camera", 36 | "isBone" : "false", 37 | "translation" : [7.481132,5.343665,6.507640], 38 | "rotation" : [-0.210611,0.905240,-0.089282,0.358067], 39 | "scale" : [1.0,1.000000,1.0] 40 | }, 41 | { 42 | "id" : "Cube", 43 | "isBone" : "false", 44 | "translation" : [0.0,0.0,0.0], 45 | "rotation" : [-0.707107,0.0,0.0,0.707107], 46 | "scale" : [1.0,1.0,1.0], 47 | "mesh" : "Cube_Mesh", 48 | "materials" : [ 49 | { 50 | "meshpartid" : "part0", 51 | "materialid" : "Material" 52 | } 53 | ] 54 | }, 55 | { 56 | "id" : "Lamp", 57 | "isBone" : "false", 58 | "translation" : [4.076245,5.903862,-1.005454], 59 | "rotation" : [0.169076,0.755880,-0.272171,0.570948], 60 | "scale" : [1.000000,1.0,1.000000] 61 | } 62 | ], 63 | "animations" : [ 64 | { 65 | "id" : "Default Take", 66 | "bones" : [ 67 | { 68 | "boneId" : "Cube", 69 | "keyframes" : [ 70 | { 71 | "keytime" : 0.000000, 72 | "translation" : [0.0,0.0,0.0], 73 | "rotation" : [-0.707107,0.0,0.0,0.707107], 74 | "scale" : [1.0,1.0,1.0] 75 | } 76 | ] 77 | }, 78 | { 79 | "boneId" : "Lamp", 80 | "keyframes" : [ 81 | { 82 | "keytime" : 0.000000, 83 | "translation" : [4.076245,5.903862,-1.005454], 84 | "rotation" : [0.169076,0.755880,-0.272171,0.570947], 85 | "scale" : [1.000000,1.0,1.000000] 86 | } 87 | ] 88 | }, 89 | { 90 | "boneId" : "Camera", 91 | "keyframes" : [ 92 | { 93 | "keytime" : 0.000000, 94 | "translation" : [7.481132,5.343665,6.507640], 95 | "rotation" : [-0.210611,0.905240,-0.089282,0.358067], 96 | "scale" : [1.0,1.000000,1.0] 97 | } 98 | ] 99 | } 100 | ] 101 | } 102 | ] 103 | } -------------------------------------------------------------------------------- /samples/blender/cube.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'None' 2 | # Material Count: 1 3 | newmtl Material 4 | Ns 96.078431 5 | Ka 0.000000 0.000000 0.000000 6 | Kd 0.640000 0.640000 0.640000 7 | Ks 0.500000 0.500000 0.500000 8 | Ni 1.000000 9 | d 1.000000 10 | illum 2 11 | 12 | 13 | -------------------------------------------------------------------------------- /samples/blender/cube.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.64 (sub 0) OBJ File: '' 2 | # www.blender.org 3 | mtllib cube.mtl 4 | o Cube 5 | v 1.000000 -1.000000 -1.000000 6 | v 1.000000 -1.000000 1.000000 7 | v -1.000000 -1.000000 1.000000 8 | v -1.000000 -1.000000 -1.000000 9 | v 1.000000 1.000000 -0.999999 10 | v 0.999999 1.000000 1.000001 11 | v -1.000000 1.000000 1.000000 12 | v -1.000000 1.000000 -1.000000 13 | vn 0.000000 -1.000000 0.000000 14 | vn 0.000000 1.000000 0.000000 15 | vn 1.000000 0.000000 0.000000 16 | vn -0.000000 -0.000000 1.000000 17 | vn -1.000000 -0.000000 -0.000000 18 | vn 0.000000 0.000000 -1.000000 19 | usemtl Material 20 | s off 21 | f 1//1 2//1 3//1 4//1 22 | f 5//2 8//2 7//2 6//2 23 | f 1//3 5//3 6//3 2//3 24 | f 2//4 6//4 7//4 3//4 25 | f 3//5 7//5 8//5 4//5 26 | f 5//6 1//6 4//6 8//6 27 | -------------------------------------------------------------------------------- /samples/blender/cubes.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/blender/cubes.blend -------------------------------------------------------------------------------- /samples/blender/cubes.blend1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/blender/cubes.blend1 -------------------------------------------------------------------------------- /samples/blender/cubes.blend2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/blender/cubes.blend2 -------------------------------------------------------------------------------- /samples/blender/fighter.blend: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/blender/fighter.blend -------------------------------------------------------------------------------- /samples/softimage/bump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/softimage/bump.png -------------------------------------------------------------------------------- /samples/softimage/checkboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/softimage/checkboard.png -------------------------------------------------------------------------------- /samples/softimage/checkboard1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/softimage/checkboard1.png -------------------------------------------------------------------------------- /samples/softimage/cube_anim.g3dj: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "1.0", 3 | "meshes" : [ 4 | { 5 | "id" : "cubeanim:cube_Mesh", 6 | "attributes" : [ 7 | "POSITION","NORMAL","TEXCOORD0","BLENDWEIGHTS","BLENDINDICES" 8 | ], 9 | "vertices" : [ 10 | 0.0,-2.259414,-2.259414,0.0,0.0,-1.0,0.582997,0.456003,0.500033,0.499967,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,-2.259414,-2.259414,0.0,0.0,-1.0,0.582997,0.168971,0.066419,0.933581,0.0,0.0,0.0,1.0,0.0,0.0,0.0,2.259414,-2.259414,0.0,0.0,-1.0,0.827052,0.456003,0.500111,0.499889,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,2.259414,-2.259414,0.0,0.0,-1.0,0.827052,0.168971,0.067801,0.932199,0.0,0.0,0.0,1.0,0.0,0.0,0.0,-2.259414,2.259414,0.0,-1.0,0.0,0.253258,0.705932,0.500033,0.499967,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,-2.259414,2.259414,0.0,-1.0,0.0,0.253258,0.418900,0.066419,0.933581,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,-2.259414,-2.259414,0.0,-1.0,0.0,0.497313,0.418900,0.066419,0.933581,0.0,0.0,0.0,1.0,0.0,0.0,0.0,-2.259414,-2.259414,0.0,-1.0,0.0,0.497313,0.705932,0.500033,0.499967,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,2.259414,2.259414,-1.0,0.0,0.0,0.753117,0.748774,0.067801,0.932199,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,-2.259414,-2.259414,-1.0,0.0,0.0,0.997172,0.992829,0.066419,0.933581,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,-2.259414,2.259414,-1.0,0.0,0.0,0.753117,0.992829,0.066419,0.933581,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,2.259414,-2.259414,-1.0,0.0,0.0,0.997172,0.748774,0.067801,0.932199,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,-2.259414,-2.259414,0.0,0.0,-1.0,0.582997,0.743034,0.932057,0.067943,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,2.259414,-2.259414,0.0,0.0,-1.0,0.827052,0.743034,0.938571,0.061429,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,-2.259414,2.259414,0.0,-1.0,0.0,0.253258,0.992964,0.932057,0.067943,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,-2.259414,-2.259414,0.0,-1.0,0.0,0.497313,0.992964,0.932057,0.067943,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,2.259414,2.259414,1.0,0.0,0.0,0.503187,0.992829,0.938571,0.061429,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,-2.259414,2.259414,1.0,0.0,0.0,0.503187,0.748774,0.932057,0.067943,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,-2.259414,-2.259414,1.0,0.0,0.0,0.747243,0.748774,0.932057,0.067943,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,2.259414,-2.259414,1.0,0.0,0.0,0.747243,0.992829,0.938571,0.061429,0.0,0.0,0.0,1.0,0.0,0.0,0.0,2.259414,2.259414,0.0,1.0,0.0,0.003328,0.705932,0.500111,0.499889,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,2.259414,-2.259414,0.0,1.0,0.0,0.247384,0.992964,0.067801,0.932199,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,2.259414,2.259414,0.0,1.0,0.0,0.003328,0.992964,0.067801,0.932199,0.0,0.0,0.0,1.0,0.0,0.0,0.0,2.259414,-2.259414,0.0,1.0,0.0,0.247384,0.705932,0.500111,0.499889,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,2.259414,2.259414,0.0,1.0,0.0,0.003328,0.418900,0.938571,0.061429,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,2.259414,-2.259414,0.0,1.0,0.0,0.247384,0.418900,0.938571,0.061429,0.0,0.0,0.0,1.0,0.0,0.0,0.0,2.259414,2.259414,0.0,0.0,1.0,0.290226,0.413161,0.500111,0.499889,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,2.259414,2.259414,0.0,0.0,1.0,0.003194,0.413161,0.067801,0.932199,0.0,0.0,0.0,1.0,0.0,0.0,-5.314565,-2.259414,2.259414,0.0,0.0,1.0,0.003194,0.169105,0.066419,0.933581,0.0,0.0,0.0,1.0,0.0,0.0,0.0,-2.259414,2.259414,0.0,0.0,1.0,0.290226,0.169105,0.500033,0.499967,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,2.259414,2.259414,0.0,0.0,1.0,0.577257,0.413161,0.938571,0.061429,0.0,0.0,0.0,1.0,0.0,0.0,5.314565,-2.259414,2.259414,0.0,0.0,1.0,0.577257,0.169105,0.932057,0.067943,0.0,0.0,0.0,1.0,0.0,0.0 11 | ], 12 | "parts" : [ 13 | { 14 | "id" : "part0", 15 | "type" : "TRIANGLES", 16 | "indices" : [ 17 | 0,1,2,1,3,2,4,5,6,4,6,7,8,9,10,9,8,11,12,0,13,0,2,13,14,4,7,14,7,15,16,17,18,16,18,19,20,21,22,21,20,23,24,23,20,23,24,25,26,27,28,26,28,29,30,26,29,30,29,31 18 | ] 19 | } 20 | ] 21 | } 22 | ], 23 | "materials" : [ 24 | { 25 | "id" : "Material_1", 26 | "type" : "PHONG", 27 | "diffuse" : [0.700000,0.700000,0.700000], 28 | "ambient" : [0.300000,0.300000,0.300000], 29 | "emissive" : [1.0,1.0,1.0], 30 | "opacity" : 0.000000, 31 | "specular" : [1.0,1.0,1.0], 32 | "shininess" : 50.000000, 33 | "textures" : [ 34 | { 35 | "id" : "cube", 36 | "filename" : "checkboard.png", 37 | "uvtranslation" : [0.0,0.0], 38 | "uvscaling" : [1.0,1.0], 39 | "type" : "STANDARD" 40 | } 41 | ] 42 | } 43 | ], 44 | "nodes" : [ 45 | { 46 | "id" : "cubeanim:cubeanim", 47 | "translation" : [0.0,0.0,0.0], 48 | "rotation" : [0.0,0.0,0.0,1.0], 49 | "scale" : [1.0,1.0,1.0], 50 | "children" : [ 51 | { 52 | "id" : "cubeanim:root", 53 | "translation" : [-5.393930,0.0,0.0], 54 | "rotation" : [0.0,0.0,0.0,1.0], 55 | "scale" : [1.0,1.0,1.0], 56 | "children" : [ 57 | { 58 | "id" : "cubeanim:bone", 59 | "translation" : [0.0,0.0,0.0], 60 | "rotation" : [0.0,0.0,0.004592,0.999990], 61 | "scale" : [1.000000,1.000000,1.0], 62 | "children" : [ 63 | { 64 | "id" : "cubeanim:bone1", 65 | "translation" : [5.357296,0.000000,0.0], 66 | "rotation" : [0.0,0.0,-0.002285,0.999997], 67 | "scale" : [1.0,1.0,1.0], 68 | "children" : [ 69 | { 70 | "id" : "cubeanim:eff", 71 | "translation" : [5.332552,0.0,0.0], 72 | "rotation" : [0.0,0.0,0.0,1.0], 73 | "scale" : [1.0,1.0,1.0] 74 | } 75 | ] 76 | } 77 | ] 78 | } 79 | ] 80 | }, 81 | { 82 | "id" : "cubeanim:cube", 83 | "translation" : [0.0,0.0,0.0], 84 | "rotation" : [0.0,0.0,0.0,1.0], 85 | "scale" : [1.0,1.0,1.0], 86 | "mesh" : "cubeanim:cube_Mesh", 87 | "materials" : [ 88 | { 89 | "meshpartid" : "part0", 90 | "materialid" : "Material_1" 91 | } 92 | ] 93 | } 94 | ] 95 | } 96 | ], 97 | "animations" : [ 98 | { 99 | "id" : "Take 001", 100 | "bones" : [ 101 | { 102 | "boneId" : "cubeanim:bone1", 103 | "keyframes" : [ 104 | { 105 | "keytime" : 33.000000, 106 | "translation" : [5.357296,0.000000,0.0], 107 | "rotation" : [0.0,0.0,-0.002285,0.999997], 108 | "scale" : [1.0,1.0,1.0] 109 | }, 110 | { 111 | "keytime" : 66.333328, 112 | "translation" : [5.357296,0.000000,0.0], 113 | "rotation" : [0.0,0.0,0.054179,0.998531], 114 | "scale" : [1.000000,1.000000,1.0] 115 | }, 116 | { 117 | "keytime" : 99.666656, 118 | "translation" : [5.357296,0.000000,0.0], 119 | "rotation" : [0.0,0.0,0.179984,0.983670], 120 | "scale" : [1.000000,1.000000,1.0] 121 | }, 122 | { 123 | "keytime" : 132.999985, 124 | "translation" : [5.357296,0.000000,0.0], 125 | "rotation" : [0.0,0.0,0.304870,0.952394], 126 | "scale" : [1.0,1.0,1.0] 127 | } 128 | ] 129 | } 130 | ] 131 | } 132 | ] 133 | } -------------------------------------------------------------------------------- /samples/softimage/cube_anim_2clips.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/softimage/cube_anim_2clips.fbx -------------------------------------------------------------------------------- /samples/softimage/cube_single_uv.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/softimage/cube_single_uv.fbx -------------------------------------------------------------------------------- /samples/softimage/head.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/softimage/head.fbx -------------------------------------------------------------------------------- /samples/softimage/head2.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/softimage/head2.fbx -------------------------------------------------------------------------------- /samples/softimage/head_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/softimage/head_color.png -------------------------------------------------------------------------------- /samples/softimage/head_parented.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocos2d-x/fbx-conv/8104a81d298d4dafd94c10751e44aad7dea7a44a/samples/softimage/head_parented.fbx -------------------------------------------------------------------------------- /src/FbxConv.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif //_MSC_VER 20 | #ifndef FBXCONV_FBXCONV_H 21 | #define FBXCONV_FBXCONV_H 22 | 23 | #ifndef BUILD_NUMBER 24 | #define BUILD_NUMBER "0000" 25 | #endif 26 | 27 | #ifndef BUILD_ID 28 | #ifdef DEBUG 29 | #define BUILD_ID "debug version, cocos2d-x-3.4-beta0 or later version can use" 30 | #else 31 | #define BUILD_ID "release version, cocos2d-x-3.4-beta0 or later version can use" 32 | #endif 33 | #endif 34 | 35 | #define BIT_COUNT (sizeof(void*)*8) 36 | 37 | #include "log/messages.h" 38 | #include "modeldata/Model.h" 39 | #include "Settings.h" 40 | #include "readers/Reader.h" 41 | #include "FbxConvCommand.h" 42 | #include "json/JSONWriter.h" 43 | #include "json/UBJSONWriter.h" 44 | #include "readers/FbxConverter.h" 45 | #include "modeldata/C3BFile.h" 46 | namespace fbxconv { 47 | 48 | void simpleTextureCallback(std::map &textures) { 49 | for (std::map::iterator it = textures.begin(); it != textures.end(); ++it) { 50 | //printf("Texture name: %s\nbounds: %01.2f, %01.2f, %01.2f, %01.2f\ncount: %d\n", it->first.c_str(), it->second.bounds[0], it->second.bounds[1], it->second.bounds[2], it->second.bounds[3], it->second.nodeCount); 51 | it->second.path = it->first.substr(it->first.find_last_of("/\\")+1); 52 | } 53 | } 54 | 55 | class FbxConv { 56 | public: 57 | fbxconv::log::Log *log; 58 | 59 | FbxConv(fbxconv::log::Log *log) : log(log) { 60 | log->info(log::iNameAndVersion, modeldata::VERSION_HI, modeldata::VERSION_LO, /*BUILD_NUMBER,*/ BIT_COUNT, BUILD_ID); 61 | } 62 | 63 | const char *getVersionString() { 64 | return log->format(log::iVersion, modeldata::VERSION_HI, modeldata::VERSION_LO, BUILD_NUMBER, BIT_COUNT, BUILD_ID); 65 | } 66 | 67 | const char *getNameAndVersionString() { 68 | return log->format(log::iNameAndVersion, modeldata::VERSION_HI, modeldata::VERSION_LO, /*BUILD_NUMBER,*/ BIT_COUNT, BUILD_ID); 69 | } 70 | 71 | bool execute(int const &argc, const char** const &argv) { 72 | Settings settings; 73 | FbxConvCommand command(log, argc, argv, &settings); 74 | #ifdef DEBUG 75 | log->filter |= log::Log::LOG_DEBUG; 76 | #else 77 | log->filter &= ~log::Log::LOG_DEBUG; 78 | #endif 79 | if (settings.verbose) 80 | log->filter |= log::Log::LOG_VERBOSE; 81 | else 82 | log->filter &= ~log::Log::LOG_VERBOSE; 83 | 84 | 85 | if (command.error != log::iNoError) 86 | command.printCommand(); 87 | else if (!command.help) 88 | return execute(&settings); 89 | 90 | command.printHelp(); 91 | return false; 92 | } 93 | 94 | bool execute(Settings * const &settings) { 95 | bool result = false; 96 | modeldata::Model *model = new modeldata::Model(); 97 | if (load(settings, model)) { 98 | if (settings->verbose) 99 | info(model); 100 | if (save(settings, model)) 101 | result = true; 102 | } 103 | delete model; 104 | return result; 105 | } 106 | 107 | readers::Reader *createReader(const Settings * const &settings) { 108 | return createReader(settings->inType); 109 | } 110 | 111 | readers::Reader *createReader(const int &type) { 112 | switch(type) { 113 | case FILETYPE_FBX: 114 | return new readers::FbxConverter(log, simpleTextureCallback); 115 | case FILETYPE_G3DB: 116 | case FILETYPE_G3DJ: 117 | default: 118 | log->error(log::eSourceLoadFiletypeUnknown); 119 | return 0; 120 | } 121 | } 122 | 123 | bool load(Settings * const &settings, modeldata::Model *model) { 124 | log->status(log::sSourceLoad); 125 | 126 | readers::Reader *reader = createReader(settings); 127 | if (!reader) 128 | return false; 129 | 130 | bool result = reader->load(settings); 131 | if (!result) 132 | log->error(log::eSourceLoadGeneral, settings->inFile.c_str()); 133 | else { 134 | result = reader->convert(settings, model); 135 | log->status(log::sSourceConvert); 136 | } 137 | 138 | log->status(log::sSourceClose); 139 | 140 | delete reader; 141 | return result; 142 | } 143 | 144 | bool save(Settings * const &settings, modeldata::Model *model) { 145 | bool result = false; 146 | json::BaseJSONWriter *jsonWriter = 0; 147 | model->exportPart = settings->exportPart; 148 | if(settings->outType == FILETYPE_ALL || settings->outType == FILETYPE_C3T) 149 | { 150 | std::string out = settings->outFile; 151 | int o = out.find_last_of("."); 152 | out = out.substr(0, o+1) + "c3t"; 153 | 154 | std::ofstream myfile; 155 | myfile.open (out.c_str(), std::ios::binary); 156 | 157 | log->status(log::sExportToG3DJ, out.c_str()); 158 | jsonWriter = new json::JSONWriter(myfile); 159 | (*jsonWriter) << model; 160 | delete jsonWriter; 161 | result = true; 162 | myfile.close(); 163 | } 164 | if(settings->outType == FILETYPE_ALL || settings->outType == FILETYPE_C3B) 165 | { 166 | std::string out = settings->outFile; 167 | int o = out.find_last_of("."); 168 | out = out.substr(0, o+1) + "c3b"; 169 | C3BFile file; 170 | file.AddModel(model); 171 | file.saveBinary(out); 172 | log->status(log::sExportToG3DB, out.c_str()); 173 | } 174 | 175 | log->status(log::sExportClose); 176 | return result; 177 | } 178 | 179 | void info(modeldata::Model *model) { 180 | if (!model) 181 | log->verbose(log::iModelInfoNull); 182 | else { 183 | log->verbose(log::iModelInfoStart); 184 | log->verbose(log::iModelInfoID, model->id.c_str()); 185 | log->verbose(log::iModelInfoVersion, model->version[0], model->version[1]); 186 | log->verbose(log::iModelInfoMeshesSummary, model->meshes.size(), model->getTotalVertexCount(), model->getMeshpartCount(), model->getTotalIndexCount()); 187 | log->verbose(log::iModelInfoNodesSummary, model->nodes.size(), model->getTotalNodeCount(), model->getTotalNodePartCount()); 188 | log->verbose(log::iModelInfoMaterialsSummary, model->materials.size(), model->getTotalTextureCount()); 189 | } 190 | } 191 | }; 192 | } 193 | 194 | #endif //FBXCONV_FBXCONV_H -------------------------------------------------------------------------------- /src/FbxConvCommand.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifndef FBXCONVCOMMAND_H 18 | #define FBXCONVCOMMAND_H 19 | 20 | //#define ALLOW_INPUT_TYPE 21 | #include "Settings.h" 22 | #include 23 | #include "log/log.h" 24 | 25 | namespace fbxconv { 26 | 27 | struct FbxConvCommand { 28 | const int argc; 29 | const char **argv; 30 | int error; 31 | bool help; 32 | Settings *settings; 33 | log::Log *log; 34 | 35 | FbxConvCommand(log::Log *log, const int &argc, const char** argv, Settings *settings) 36 | : log(log), argc(argc), argv(argv), settings(settings), error(log::iNoError) { 37 | help = (argc <= 1); 38 | 39 | settings->flipV = false; 40 | settings->packColors = false; 41 | settings->verbose = false; 42 | settings->maxNodePartBonesCount = 40; 43 | settings->maxVertexBonesCount = 4; 44 | settings->forceMaxVertexBoneCount = true; 45 | settings->maxVertexCount = (1<<15)-1; 46 | settings->maxIndexCount = (1<<15)-1; 47 | settings->outType = FILETYPE_C3B; 48 | settings->inType = FILETYPE_AUTO; 49 | settings->needReusableMesh = true; 50 | settings->normalizeVertexNormal = false; 51 | settings->exportPart = EXPORT_PART_ALL; 52 | settings->normalMap = false; 53 | settings->compressLevel = COMPRESS_LEVEL_DEFAULT; 54 | 55 | for (int i = 1; i < argc; i++) { 56 | const char *arg = argv[i]; 57 | const int len = (int)strlen(arg); 58 | if (len > 1 && arg[0] == '-') { 59 | if (arg[1] == '?') 60 | help = true; 61 | else if (arg[1] == 'f') 62 | settings->flipV = true; 63 | else if (arg[1] == 'v') 64 | settings->verbose = true; 65 | //else if (arg[1] == 'p') 66 | // settings->packColors = true; 67 | else if (arg[1] == 'g') 68 | settings->needReusableMesh = false; 69 | else if (arg[1] == 'r') 70 | settings->normalizeVertexNormal = true; 71 | //else if ((arg[1] == 'i') && (i + 1 < argc)) 72 | // settings->inType = parseType(argv[++i]); 73 | //else if ((arg[1] == 'o') && (i + 1 < argc)) 74 | // settings->outType = parseType(argv[++i]); 75 | else if ((arg[1] == 'n') && (i + 1 < argc)) 76 | settings->maxNodePartBonesCount = atoi(argv[++i]); 77 | //else if ((arg[1] == 'w') && (i + 1 < argc)) 78 | // settings->maxVertexBonesCount = atoi(argv[++i]); 79 | else if ((arg[1] == 'm') && (i + 1 < argc)) 80 | settings->maxVertexCount = settings->maxIndexCount = atoi(argv[++i]); 81 | else if((arg[1] == 'c') && (i + 1 < argc)) 82 | settings->compressLevel = (COMPRESS_LEVEL)atoi(argv[++i]); 83 | else if(arg[1] == 'b') 84 | settings->outType = FILETYPE_C3B; 85 | else if(arg[1] == 't') 86 | settings->outType = FILETYPE_C3T; 87 | else if(arg[1] == 'a') 88 | settings->outType = FILETYPE_ALL; 89 | else if(arg[1] == 'l') 90 | settings->exportPart = EXPORT_PART_MODEL; 91 | else if(arg[1] == 'j') 92 | settings->exportPart = EXPORT_PART_ANIMATION; 93 | else if(arg[1] == 'p') 94 | settings->normalMap = true; 95 | else 96 | log->error(error = log::eCommandLineUnknownOption, arg); 97 | } 98 | else if (settings->inFile.length() < 1) 99 | settings->inFile = arg; 100 | else if (settings->outFile.length() < 1) 101 | settings->outFile = arg; 102 | else 103 | log->error(error = log::eCommandLineUnknownArgument, arg); 104 | if (error != log::iNoError) 105 | break; 106 | } 107 | if (!help && error == log::iNoError) 108 | validate(); 109 | } 110 | 111 | void printCommand() const { 112 | for (int i = 1; i < argc; i++) { 113 | if (i > 1) 114 | printf(" "); 115 | printf(argv[i]); 116 | } 117 | printf("\n"); 118 | } 119 | 120 | void printHelp() const { 121 | printf("\nUsage: fbx-conv [options] \n"); 122 | printf("\nExample: fbx-conv -a xx.fbx \n"); 123 | printf("\n"); 124 | printf("Options:\n"); 125 | printf("-? : Display this help information.\n"); 126 | //#ifdef ALLOW_INPUT_TYPE 127 | // printf("-i : Set the type of the input file to \n"); 128 | //#endif 129 | //printf("-o : Set the type of the output file to \n"); 130 | printf("-f : Flip the V texture coordinates.\n"); 131 | printf("-p : Export tagent binormal data.\n"); 132 | printf("-m : The maximum amount of vertices or indices a mesh may contain (default: 32k)\n"); 133 | printf("-n : The maximum amount of bones a nodepart can contain (default: 40)\n"); 134 | //printf("-w : The maximum amount of bone weights per vertex (default: 4)\n"); 135 | printf("-v : Verbose: print additional progress information\n"); 136 | printf("-g : Merge the mesh which have same vertex attribute\n"); 137 | printf("-a : Export c3b(binary) and c3t(text)\n"); 138 | printf("-b : Export c3b(binary)\n"); 139 | printf("-t : Export c3t(text)\n"); 140 | printf("-c : The compression level: 0 , 1 (default: 0)\n"); 141 | printf("-l : Export model data only.\n"); 142 | printf("-j : Export animation data only.\n"); 143 | printf("\n"); 144 | printf(" : The filename of the file to convert.\n"); 145 | //printf(" : The filename of the converted file.\n"); 146 | //printf(" : FBX, c3t (json) or c3b (binary).\n"); 147 | } 148 | private: 149 | void validate() { 150 | if (settings->inFile.empty()) { 151 | log->error(error = log::eCommandLineMissingInputFile); 152 | return; 153 | } 154 | #ifdef ALLOW_INPUT_TYPE 155 | if (inType == FILETYPE_AUTO) 156 | inType = guessType(inFile, FILETYPE_IN_DEFAULT); 157 | #else 158 | settings->inType = FILETYPE_IN_DEFAULT; 159 | #endif 160 | if (settings->outFile.empty()) 161 | setExtension( 162 | settings->outFile = settings->inFile, 163 | settings->outType = (settings->outType == FILETYPE_AUTO ? FILETYPE_OUT_DEFAULT : settings->outType)); 164 | else if (settings->outType == FILETYPE_AUTO) 165 | settings->outType = guessType(settings->outFile); 166 | if (settings->maxVertexBonesCount < 0 || settings->maxVertexBonesCount > 8) { 167 | log->error(error = log::eCommandLineInvalidVertexWeight); 168 | return; 169 | } 170 | if (settings->maxNodePartBonesCount < settings->maxVertexBonesCount) { 171 | log->error(error = log::eCommandLineInvalidBoneCount); 172 | return; 173 | } 174 | if (settings->maxVertexCount < 0 || settings->maxVertexCount > (1<<15)-1) { 175 | log->error(error = log::eCommandLineInvalidVertexCount); 176 | return; 177 | } 178 | if (settings->compressLevel < COMPRESS_LEVEL_DEFAULT || settings->compressLevel >= COMPRESS_LEVEL_NUM) { 179 | log->error(error = log::eCommandLineUnknownCompressLevel, (COMPRESS_LEVEL_NUM - 1)); 180 | return; 181 | } 182 | } 183 | 184 | int parseType(const char* arg, const int &def = -1) { 185 | if (stricmp(arg, "fbx")==0) 186 | return FILETYPE_FBX; 187 | else if (stricmp(arg, "g3db")==0) 188 | return FILETYPE_G3DB; 189 | else if (stricmp(arg, "g3dj")==0) 190 | return FILETYPE_G3DJ; 191 | else if (stricmp(arg, "c3b")==0) 192 | return FILETYPE_G3DB; 193 | else if (stricmp(arg, "c3t")==0) 194 | return FILETYPE_G3DJ; 195 | if (def < 0) 196 | log->error(error = log::eCommandLineUnknownFiletype, arg); 197 | return def; 198 | } 199 | 200 | int guessType(const std::string &fn, const int &def = -1) { 201 | int o = (int)fn.find_last_of('.'); 202 | if (o == std::string::npos) 203 | return def; 204 | std::string ext = fn.substr(++o, fn.length() - o); 205 | return parseType(ext.c_str(), def); 206 | } 207 | 208 | void setExtension(std::string &fn, const std::string &ext) const { 209 | int o = (int)fn.find_last_of('.'); 210 | if (o == std::string::npos) 211 | fn += "." + ext; 212 | else 213 | fn = fn.substr(0, ++o) + ext; 214 | } 215 | 216 | void setExtension(std::string &fn, const int &type) const { 217 | switch(type) { 218 | case FILETYPE_FBX: return setExtension(fn, "fbx"); 219 | case FILETYPE_G3DB: return setExtension(fn, "c3b"); 220 | case FILETYPE_G3DJ: return setExtension(fn, "c3t"); 221 | default: return setExtension(fn, ""); 222 | } 223 | } 224 | }; 225 | 226 | } 227 | 228 | #endif //FBXCONVCOMMAND_H -------------------------------------------------------------------------------- /src/Settings.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef SETTINGS_H 21 | #define SETTINGS_H 22 | 23 | #include 24 | 25 | namespace fbxconv { 26 | 27 | #define FILETYPE_AUTO 0x00 28 | #define FILETYPE_FBX 0x10 29 | #define FILETYPE_G3DB 0x20 30 | #define FILETYPE_G3DJ 0x21 31 | #define FILETYPE_OUT_DEFAULT FILETYPE_G3DB 32 | #define FILETYPE_IN_DEFAULT FILETYPE_FBX 33 | #define FILETYPE_C3B 0X30 34 | #define FILETYPE_C3T 0X31 35 | #define FILETYPE_ALL 0X32 36 | 37 | enum COMPRESS_LEVEL{ 38 | COMPRESS_LEVEL_DEFAULT, 39 | COMPRESS_LEVEL_1, 40 | COMPRESS_LEVEL_NUM 41 | }; 42 | 43 | enum EXPORT_PART{ 44 | EXPORT_PART_ALL, 45 | EXPORT_PART_MODEL, 46 | EXPORT_PART_ANIMATION 47 | }; 48 | 49 | struct Settings { 50 | std::string inFile; 51 | int inType; 52 | std::string outFile; 53 | int outType; 54 | /** Whether to flip the y-component of textures coordinates. */ 55 | bool flipV; 56 | /** Whether to pack colors into one float. */ 57 | bool packColors; 58 | bool verbose; 59 | /** The maximum allowed amount of bones in one nodepart, if a meshpart exceeds this amount it will be split up in parts. */ 60 | int maxNodePartBonesCount; 61 | /** The maximum allowed amount of bone weights in one vertex, if a vertex exceeds this amount it will clipped on importance. */ 62 | int maxVertexBonesCount; 63 | /** Always use maxVertexBoneCount for blendWeights, this might help merging meshes. */ 64 | bool forceMaxVertexBoneCount; 65 | /** The maximum allowed amount of vertices in one mesh, only used when deciding to merge meshes. */ 66 | int maxVertexCount; 67 | /** The maximum allowed amount of indices in one mesh, only used when deciding to merge meshes. */ 68 | int maxIndexCount; 69 | /** Whether to merge same attributes mesh. */ 70 | bool needReusableMesh; 71 | /** average the same position vertex's normal*/ 72 | bool normalizeVertexNormal; 73 | /** export normal map*/ 74 | bool normalMap; 75 | /** The level of compression, you may lose some animation detail when useing high compression level*/ 76 | COMPRESS_LEVEL compressLevel; 77 | /** export specific part*/ 78 | EXPORT_PART exportPart; 79 | }; 80 | 81 | } 82 | 83 | #endif //SETTINGS_H -------------------------------------------------------------------------------- /src/json/JSONWriter.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef JSON_JSONWRITER_H 21 | #define JSON_JSONWRITER_H 22 | 23 | #include "BaseJSONWriter.h" 24 | 25 | namespace json { 26 | 27 | class JSONWriter : public BaseJSONWriter { 28 | public: 29 | const char *newline; 30 | const char *indent; 31 | const char *openObject; 32 | const char *closeObject; 33 | const char *openArray; 34 | const char *closeArray; 35 | const char *keySeparator; 36 | const char *valueSeparator; 37 | public: 38 | std::ostream &stream; 39 | 40 | JSONWriter(std::ostream &stream) : BaseJSONWriter(), stream(stream), indentCount(0), 41 | newline("\r\n"), indent("\t"), openObject("{"), closeObject("}"), openArray("["), closeArray("]"), keySeparator(": "), valueSeparator(", ") 42 | {} 43 | protected: 44 | char tmp[256]; 45 | int indentCount; 46 | void nextline() { 47 | stream << newline; 48 | for (int i = 0; i < indentCount; i++) 49 | stream << indent; 50 | } 51 | virtual void writeOpenObject(const bool &varsize, const long long &size, const bool &inl) { 52 | stream << openObject; 53 | ++indentCount; 54 | if (!inl) 55 | nextline(); 56 | } 57 | virtual void writeCloseObject(const bool &varsize, const long long &size, const bool &inl) { 58 | if (--indentCount < 0) 59 | indentCount = 0; 60 | if (!inl) 61 | nextline(); 62 | stream << closeObject; 63 | } 64 | virtual void writeOpenArray(const bool &varsize, const long long &size, const bool &inl) { 65 | stream << openArray; 66 | ++indentCount; 67 | if (!inl) 68 | nextline(); 69 | } 70 | virtual void writeCloseArray(const bool &varsize, const long long &size, const bool &inl) { 71 | if (--indentCount < 0) 72 | indentCount = 0; 73 | if (!inl) 74 | nextline(); 75 | stream << closeArray; 76 | } 77 | virtual void writeNextValue(const bool &first, const bool &nl) { 78 | if (!first) { 79 | stream << valueSeparator; 80 | if (nl) 81 | nextline(); 82 | } 83 | } 84 | virtual void writeNull() { 85 | stream << "null"; 86 | } 87 | virtual void writeValue(const char * const &value, const bool &iskey = false) { 88 | stream << "\"" << value << "\""; 89 | if (iskey) 90 | stream << keySeparator; 91 | } 92 | 93 | virtual void writeValue(const bool &value, const bool &iskey = false) { 94 | stream << (value ? "true" : "false"); 95 | if (iskey) 96 | stream << keySeparator; 97 | } 98 | 99 | virtual void writeValue(const char &value, const bool &iskey = false) { 100 | writeValue((int)value, iskey); 101 | } 102 | 103 | virtual void writeValue(const short &value, const bool &iskey = false) { 104 | writeValue((int)value, iskey); 105 | } 106 | 107 | virtual void writeValue(const int &value, const bool &iskey = false) { 108 | sprintf(tmp, "% 3i", value); 109 | stream << tmp; 110 | if (iskey) 111 | stream << keySeparator; 112 | } 113 | 114 | virtual void writeValue(const long &value, const bool &iskey = false) { 115 | sprintf(tmp, "% 3i", value); 116 | stream << tmp; 117 | if (iskey) 118 | stream << keySeparator; 119 | } 120 | 121 | virtual void writeValue(const float &value, const bool &iskey = false) { 122 | if ((value * 0) != 0) { 123 | const unsigned int t = (*(unsigned int*)&value) & 0xfeffffff; 124 | sprintf(tmp, "% 8f", *(float*)&t); 125 | } else 126 | sprintf(tmp, "% 8f", value); 127 | stream << tmp; 128 | if (iskey) 129 | stream << keySeparator; 130 | } 131 | 132 | virtual void writeValue(const double &value, const bool &iskey = false) { 133 | sprintf(tmp, "% 8f", value); 134 | stream << tmp; 135 | if (iskey) 136 | stream << keySeparator; 137 | } 138 | 139 | virtual void writeValue(const unsigned char &value, const bool &iskey = false) { 140 | writeValue((int)value, iskey); 141 | } 142 | virtual void writeValue(const unsigned short &value, const bool &iskey = false) { 143 | writeValue((int)value, iskey); 144 | } 145 | virtual void writeValue(const unsigned int &value, const bool &iskey = false) { 146 | sprintf(tmp, "% 3i", value); 147 | stream << tmp; 148 | if (iskey) 149 | stream << keySeparator; 150 | } 151 | virtual void writeValue(const unsigned long &value, const bool &iskey = false) { 152 | sprintf(tmp, "% 3i", value); 153 | stream << tmp; 154 | if (iskey) 155 | stream << keySeparator; 156 | } 157 | }; 158 | 159 | } 160 | 161 | #endif //JSON_JSONWRITER_H -------------------------------------------------------------------------------- /src/json/UBJSON.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef JSON_UBJSON_H 21 | #define JSON_UBJSON_H 22 | 23 | namespace json { 24 | 25 | #define UBJSON_TYPE_NULL 'Z' 26 | #define UBJSON_TYPE_TRUE 'T' 27 | #define UBJSON_TYPE_FALSE 'F' 28 | #define UBJSON_TYPE_BYTE 'B' 29 | #define UBJSON_TYPE_SHORT 'i' 30 | #define UBJSON_TYPE_INT 'I' 31 | #define UBJSON_TYPE_LONG 'L' 32 | #define UBJSON_TYPE_FLOAT 'd' 33 | #define UBJSON_TYPE_DOUBLE 'D' 34 | #define UBJSON_TYPE_HUGE1 'h' 35 | #define UBJSON_TYPE_HUGE4 'H' 36 | #define UBJSON_TYPE_STRING1 's' 37 | #define UBJSON_TYPE_STRING4 'S' 38 | #define UBJSON_TYPE_NOOP 'N' 39 | #define UBJSON_TYPE_END 'E' 40 | 41 | #define UBJSON_TYPE_DATA1 'a' 42 | #define UBJSON_TYPE_DATA4 'A' 43 | 44 | #define SWAP(X,Y,T) {T=X; X=Y; Y=T;} 45 | 46 | const int one = 1; 47 | const bool is_bigendian = ( (*(char*)&one) == 0 ); 48 | 49 | template void swap(char * const &data) {assert(("This shouldnt happen", false));} 50 | template<> inline void swap<1>(char * const &data) {} 51 | template<> inline void swap<2>(char * const &data) { 52 | static char tmp; 53 | SWAP(data[0], data[1], tmp); 54 | } 55 | template<> inline void swap<4>(char * const &data) { 56 | static char tmp; 57 | SWAP(data[0], data[3], tmp); 58 | SWAP(data[1], data[2], tmp); 59 | } 60 | template<> inline void swap<8>(char * const &data) { 61 | static char tmp; 62 | SWAP(data[0], data[7], tmp); 63 | SWAP(data[1], data[6], tmp); 64 | SWAP(data[2], data[5], tmp); 65 | SWAP(data[3], data[4], tmp); 66 | } 67 | 68 | char swap_data[8]; 69 | template struct Swapper { 70 | static const char *swap(const T &v) { 71 | assert(("Data too big", n<=8)); 72 | memcpy(&swap_data[0], &v, n); 73 | json::swap(&swap_data[0]); 74 | return (const char*)(&swap_data[0]); 75 | } 76 | }; 77 | 78 | template struct Swapper { 79 | inline static const char *swap(const T &v) { 80 | return (const char*)&v; 81 | } 82 | }; 83 | 84 | template inline const char *swap(const T &v) { 85 | return Swapper::swap(v); 86 | } 87 | 88 | } 89 | 90 | #endif //JSON_UBJSON_H -------------------------------------------------------------------------------- /src/json/UBJSONWriter.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef JSON_UBJSONWRITER_H 21 | #define JSON_UBJSONWRITER_H 22 | 23 | #include 24 | #include "BaseJSONWriter.h" 25 | #include "UBJSON.h" 26 | 27 | namespace json { 28 | 29 | class UBJSONWriter : public BaseJSONWriter { 30 | public: 31 | std::ostream &stream; 32 | 33 | UBJSONWriter(std::ostream &stream) : BaseJSONWriter(), stream(stream) {} 34 | private: 35 | template inline void write(const T &v) { write(v); } 36 | template void write(const T &v) { 37 | stream.write(is_bigendian ? (const char*)&v : swap(v), n); 38 | /*assert(("Data too big", n<=8)); 39 | if (!is_bigendian && n > 1) { 40 | memcpy(&swapper.data[0], &v, n); 41 | swapper.swap(); 42 | stream.write((const char*)(&swapper.data[0]), n); 43 | } else 44 | stream.write((const char *)&v, n);*/ 45 | } 46 | protected: 47 | virtual void writeOpenObject(const bool &varsize, const long long &size, const bool &inl) { 48 | stream << "{"; 49 | } 50 | virtual void writeCloseObject(const bool &varsize, const long long &size, const bool &inl) { 51 | stream << "}"; 52 | } 53 | virtual void writeOpenArray(const bool &varsize, const long long &size, const bool &inl) { 54 | stream << "["; 55 | } 56 | virtual void writeCloseArray(const bool &varsize, const long long &size, const bool &inl) { 57 | stream << "]"; 58 | } 59 | virtual void writeNextValue(const bool &first, const bool &nl) { 60 | } 61 | virtual void writeNull() { 62 | stream << UBJSON_TYPE_NULL; 63 | } 64 | virtual void writeValue(const char * const &value, const bool &iskey = false) { 65 | size_t len = strlen(value); 66 | if (len < 256) { 67 | stream << UBJSON_TYPE_STRING1; 68 | write((unsigned char)len); 69 | stream.write(value, len); 70 | } else { 71 | stream << UBJSON_TYPE_STRING4; 72 | write((unsigned int)len); 73 | stream.write(value, len); 74 | } 75 | } 76 | virtual void writeValue(const bool &value, const bool &iskey = false) { 77 | stream << (value ? UBJSON_TYPE_TRUE : UBJSON_TYPE_FALSE); 78 | } 79 | virtual void writeValue(const char &value, const bool &iskey = false) { 80 | stream << UBJSON_TYPE_BYTE; 81 | write(value); 82 | } 83 | virtual void writeValue(const short &value, const bool &iskey = false) { 84 | stream << UBJSON_TYPE_SHORT; 85 | write(value); 86 | } 87 | virtual void writeValue(const int &value, const bool &iskey = false) { 88 | stream << UBJSON_TYPE_INT; 89 | write(value); 90 | } 91 | virtual void writeValue(const long &value, const bool &iskey = false) { 92 | stream << UBJSON_TYPE_LONG; 93 | write(value); 94 | } 95 | virtual void writeValue(const float &value, const bool &iskey = false) { 96 | stream << UBJSON_TYPE_FLOAT; 97 | write(value); 98 | } 99 | virtual void writeValue(const double &value, const bool &iskey = false) { 100 | stream << UBJSON_TYPE_DOUBLE; 101 | write(value); 102 | } 103 | virtual void writeValue(const unsigned char &value, const bool &iskey = false) { 104 | writeValue(*(char*)&value, iskey); 105 | } 106 | virtual void writeValue(const unsigned short &value, const bool &iskey = false) { 107 | writeValue(*(short*)&value, iskey); 108 | } 109 | virtual void writeValue(const unsigned int &value, const bool &iskey = false) { 110 | writeValue(*(int*)&value, iskey); 111 | } 112 | virtual void writeValue(const unsigned long &value, const bool &iskey = false) { 113 | writeValue(*(long*)&value, iskey); 114 | } 115 | bool writeOpenData(const char *type, const size_t &count) { 116 | // NOTE: This breaks the current ubjson specs because we use H as a strong typed container, 117 | // See: https://github.com/thebuzzmedia/universal-binary-json/issues/27 118 | if (count < 255) { 119 | stream << UBJSON_TYPE_DATA1 << type; 120 | const unsigned char len = (unsigned char)count; 121 | write(len); 122 | } else { 123 | stream << UBJSON_TYPE_DATA4 << type; 124 | const unsigned int len = (unsigned int)count; 125 | write(len); 126 | } 127 | return true; 128 | } 129 | template void writeData(const T * const &values, const size_t &count) { 130 | for (size_t i = 0; i < count; i++) 131 | write(values[i]); 132 | } 133 | 134 | inline virtual bool writeOpenFloatData(const size_t& count) { return writeOpenData("d", count); } 135 | inline virtual bool writeOpenDoubleData(const size_t& count) { return writeOpenData("D", count); } 136 | inline virtual bool writeOpenShortData(const size_t& count) { return writeOpenData("i", count); } 137 | inline virtual bool writeOpenUShortData(const size_t& count) { return writeOpenData("i", count); } 138 | inline virtual bool writeOpenIntData(const size_t& count) { return writeOpenData("I", count); } 139 | inline virtual bool writeOpenUIntData(const size_t& count) { return writeOpenData("I", count); } 140 | inline virtual bool writeOpenLongData(const size_t& count) { return writeOpenData("L", count); } 141 | inline virtual bool writeOpenULongData(const size_t& count) { return writeOpenData("L", count); } 142 | 143 | inline virtual void writeFloatData(const float * const &values, const size_t &count) { writeData(values, count); } 144 | inline virtual void writeDoubleData(const double * const &values, const size_t &count) {writeData(values, count); } 145 | inline virtual void writeShortData(const short * const &values, const size_t &count) {writeData(values, count); } 146 | inline virtual void writeUShortData(const unsigned short * const &values, const size_t &count) {writeData(values, count); } 147 | inline virtual void writeIntData(const int * const &values, const size_t &count) {writeData(values, count); } 148 | inline virtual void writeUIntData(const unsigned int * const &values, const size_t &count) {writeData(values, count); } 149 | inline virtual void writeLongData(const long * const &values, const size_t &count) {writeData(values, count); } 150 | inline virtual void writeULongData(const unsigned long * const &values, const size_t &count) {writeData(values, count); } 151 | 152 | virtual void writeCloseData() {} 153 | }; 154 | 155 | } 156 | 157 | #endif //JSON_UBJSONWRITER_H 158 | -------------------------------------------------------------------------------- /src/log/codes.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif //_MSC_VER 20 | #ifndef FBXCONV_LOG_CODES_H 21 | #define FBXCONV_LOG_CODES_H 22 | 23 | namespace fbxconv { 24 | namespace log { 25 | int num_codes = 0; 26 | 27 | #define LOG_ADD_CODE(code) const int code = num_codes++; 28 | 29 | LOG_ADD_CODE(iNoError) 30 | 31 | LOG_ADD_CODE(iVersion) 32 | LOG_ADD_CODE(iNameAndVersion) 33 | 34 | LOG_ADD_CODE(eCommandLineUnknownOption) 35 | LOG_ADD_CODE(eCommandLineUnknownArgument) 36 | LOG_ADD_CODE(eCommandLineMissingInputFile) 37 | LOG_ADD_CODE(eCommandLineInvalidVertexWeight) 38 | LOG_ADD_CODE(eCommandLineInvalidBoneCount) 39 | LOG_ADD_CODE(eCommandLineInvalidVertexCount) 40 | LOG_ADD_CODE(eCommandLineUnknownFiletype) 41 | LOG_ADD_CODE(eCommandLineUnknownCompressLevel) 42 | 43 | LOG_ADD_CODE(sSourceLoad) 44 | LOG_ADD_CODE(pSourceLoadFbxImport) 45 | LOG_ADD_CODE(wSourceLoadFbxNodeRrSs) 46 | LOG_ADD_CODE(eSourceLoadGeneral) 47 | LOG_ADD_CODE(eSourceLoadFiletypeUnknown) 48 | LOG_ADD_CODE(eSourceLoadFbxSdk) 49 | 50 | LOG_ADD_CODE(sSourceConvert) 51 | LOG_ADD_CODE(sSourceConvertFbxTriangulate) 52 | LOG_ADD_CODE(iSourceConvertFbxMeshInfo) 53 | LOG_ADD_CODE(wSourceConvertFbxDuplicateNodeId) 54 | LOG_ADD_CODE(wSourceConvertFbxInvalidBone) 55 | LOG_ADD_CODE(wSourceConvertFbxAdditiveBones) 56 | LOG_ADD_CODE(wSourceConvertFbxCantTriangulate) 57 | LOG_ADD_CODE(wSourceConvertFbxExceedsIndices) 58 | LOG_ADD_CODE(wSourceConvertFbxExceedsBones) 59 | LOG_ADD_CODE(wSourceConvertFbxZeroWeights) 60 | LOG_ADD_CODE(wSourceConvertFbxDuplicateMesh) 61 | LOG_ADD_CODE(wSourceConvertFbxEmptyMeshpart) 62 | LOG_ADD_CODE(wSourceConvertFbxNoMaterial) 63 | LOG_ADD_CODE(wSourceConvertFbxMaterialUnknown) 64 | LOG_ADD_CODE(wSourceConvertFbxMaterialHLSL) 65 | LOG_ADD_CODE(wSourceConvertFbxMaterialCgFX) 66 | LOG_ADD_CODE(wSourceConvertFbxPolyMaterialInvalid) 67 | LOG_ADD_CODE(eSourceConvert) 68 | 69 | LOG_ADD_CODE(sSourceClose) 70 | LOG_ADD_CODE(eSourceClose) 71 | 72 | LOG_ADD_CODE(sExportToG3DB) 73 | LOG_ADD_CODE(sExportToG3DJ) 74 | LOG_ADD_CODE(sExportClose) 75 | LOG_ADD_CODE(eExportFiletypeUnknown) 76 | 77 | LOG_ADD_CODE(iModelInfoNull) 78 | LOG_ADD_CODE(iModelInfoStart) 79 | LOG_ADD_CODE(iModelInfoID) 80 | LOG_ADD_CODE(iModelInfoVersion) 81 | LOG_ADD_CODE(iModelInfoMeshesSummary) 82 | LOG_ADD_CODE(iModelInfoNodesSummary) 83 | LOG_ADD_CODE(iModelInfoMaterialsSummary) 84 | 85 | } } 86 | 87 | #endif //FBXCONV_LOG_CODES_H -------------------------------------------------------------------------------- /src/log/log.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif //_MSC_VER 20 | #ifndef FBXCONV_LOG_LOG_H 21 | #define FBXCONV_LOG_LOG_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "codes.h" 30 | 31 | namespace fbxconv { 32 | namespace log { 33 | 34 | struct LogMessages : std::vector { 35 | LogMessages() { resize(num_codes); } 36 | virtual ~LogMessages() {} 37 | }; 38 | 39 | class Log { 40 | public: 41 | static const int LOG_STATUS = 0x1 << 0; 42 | static const int LOG_PROGRESS = 0x1 << 1; 43 | static const int LOG_DEBUG = 0x1 << 2; 44 | static const int LOG_INFO = 0x1 << 3; 45 | static const int LOG_VERBOSE = 0x1 << 4; 46 | static const int LOG_WARNING = 0x1 << 5; 47 | static const int LOG_ERROR = 0x1 << 6; 48 | 49 | int filter; 50 | LogMessages * messages; 51 | 52 | Log(LogMessages * const &messages, const int &filter = -1) : messages(messages), filter(filter) {} 53 | 54 | virtual ~Log() { 55 | delete messages; 56 | } 57 | 58 | const char *msg(int code) { 59 | return (*messages)[code]; 60 | } 61 | 62 | const char *vformat(int code, va_list vl) { 63 | static char buff[1024]; 64 | vsnprintf(buff, 1024, msg(code), vl); 65 | return buff; 66 | } 67 | 68 | const char *vformat(const char *m, va_list vl) { 69 | static char buff[1024]; 70 | vsnprintf(buff, 1024, m, vl); 71 | return buff; 72 | } 73 | 74 | const char *format(int code, ...) { 75 | va_list vl; 76 | va_start(vl, code); 77 | const char *result = vformat(code, vl); 78 | va_end(vl); 79 | return result; 80 | } 81 | 82 | const char *format(const char *m, ...) { 83 | va_list vl; 84 | va_start(vl, m); 85 | const char *result = vformat(m, vl); 86 | va_end(vl); 87 | return result; 88 | } 89 | 90 | virtual void log(const int &type, const char *s) { 91 | static bool inProgress = false; 92 | assert(!((type == 0) || (type & (type - 1)))); 93 | if (((filter & type) == 0)) 94 | return; 95 | if (type == LOG_PROGRESS) { 96 | inProgress = true; 97 | printf("PROGRESS: %-79s\r", s); 98 | } else { 99 | if (inProgress) { 100 | printf("\n"); 101 | inProgress = false; 102 | } 103 | switch(type) { 104 | case LOG_STATUS: printf("STATUS: %s\n", s); break; 105 | case LOG_DEBUG: printf("DEBUG: %s\n", s); break; 106 | case LOG_INFO: printf("INFO: %s\n", s); break; 107 | case LOG_VERBOSE: printf("VERBOSE: %s\n", s); break; 108 | case LOG_WARNING: printf("WARNING: %s\n", s); break; 109 | case LOG_ERROR: printf("ERROR: %s\n", s); break; 110 | default: break; 111 | } 112 | } 113 | } 114 | 115 | virtual void vlog(const int &type, const int &code, va_list vl) { 116 | log(type, vformat(code, vl)); 117 | } 118 | 119 | virtual void vlog(const int &type, const char *m, va_list vl) { 120 | log(type, vformat(m, vl)); 121 | } 122 | 123 | virtual void log(const int &type, const int &code, ...) { 124 | va_list vl; va_start(vl, code); vlog(type, code, vl); va_end(vl); 125 | } 126 | 127 | virtual void status(const char *s, ...) { 128 | va_list vl; va_start(vl, s); vlog(LOG_STATUS, s, vl); va_end(vl); 129 | } 130 | 131 | virtual void status(int code, ...) { 132 | va_list vl; va_start(vl, code); vlog(LOG_STATUS, code, vl); va_end(vl); 133 | } 134 | 135 | virtual void progress(const char *s, ...) { 136 | va_list vl; va_start(vl, s); vlog(LOG_PROGRESS, s, vl); va_end(vl); 137 | } 138 | 139 | virtual void progress(int code, ...) { 140 | va_list vl; va_start(vl, code); vlog(LOG_PROGRESS, code, vl); va_end(vl); 141 | } 142 | 143 | virtual void debug(const char *s, ...) { 144 | va_list vl; va_start(vl, s); vlog(LOG_DEBUG, s, vl); va_end(vl); 145 | } 146 | 147 | virtual void debug(int code, ...) { 148 | va_list vl; va_start(vl, code); vlog(LOG_DEBUG, code, vl); va_end(vl); 149 | } 150 | 151 | virtual void info(const char *s, ...) { 152 | va_list vl; va_start(vl, s); vlog(LOG_INFO, s, vl); va_end(vl); 153 | } 154 | 155 | virtual void info(int code, ...) { 156 | va_list vl; va_start(vl, code); vlog(LOG_INFO, code, vl); va_end(vl); 157 | } 158 | 159 | virtual void verbose(const char *s, ...) { 160 | va_list vl; va_start(vl, s); vlog(LOG_VERBOSE, s, vl); va_end(vl); 161 | } 162 | 163 | virtual void verbose(int code, ...) { 164 | va_list vl; va_start(vl, code); vlog(LOG_VERBOSE, code, vl); va_end(vl); 165 | } 166 | 167 | virtual void warning(const char *s, ...) { 168 | va_list vl; va_start(vl, s); vlog(LOG_WARNING, s, vl); va_end(vl); 169 | } 170 | 171 | virtual void warning(int code, ...) { 172 | va_list vl; va_start(vl, code); vlog(LOG_WARNING, code, vl); va_end(vl); 173 | } 174 | 175 | virtual void error(const char *s, ...) { 176 | va_list vl; va_start(vl, s); vlog(LOG_ERROR, s, vl); va_end(vl); 177 | } 178 | 179 | virtual void error(int code, ...) { 180 | va_list vl; va_start(vl, code); vlog(LOG_ERROR, code, vl); va_end(vl); 181 | } 182 | }; 183 | 184 | const int Log::LOG_STATUS; 185 | const int Log::LOG_PROGRESS; 186 | const int Log::LOG_DEBUG; 187 | const int Log::LOG_VERBOSE; 188 | const int Log::LOG_INFO; 189 | const int Log::LOG_WARNING; 190 | const int Log::LOG_ERROR; 191 | } } 192 | 193 | #define LOG_START_MESSAGES(clazz) \ 194 | struct clazz : LogMessages { \ 195 | clazz() { 196 | #define LOG_SET_MSG(code, msg) (*this)[code] = msg; 197 | #define LOG_END_MESSAGES() \ 198 | } \ 199 | }; 200 | 201 | #endif //FBXCONV_LOG_LOG_H -------------------------------------------------------------------------------- /src/log/messages.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif //_MSC_VER 20 | #ifndef FBXCONV_LOG_MESSAGES_H 21 | #define FBXCONV_LOG_MESSAGES_H 22 | 23 | #include "log.h" 24 | 25 | namespace fbxconv { 26 | namespace log { 27 | 28 | LOG_START_MESSAGES(DefaultMessages) 29 | 30 | LOG_SET_MSG(iNoError, "No error") 31 | 32 | LOG_SET_MSG(iVersion, "%d.%02d.%s x%d (%s)") 33 | LOG_SET_MSG(iNameAndVersion, "FBX to c3x converter, version %d.%d x%d (%s)") 34 | 35 | LOG_SET_MSG(eCommandLineUnknownOption, "Unknown command line option: %s") 36 | LOG_SET_MSG(eCommandLineUnknownArgument, "Unknown command line argument: %s") 37 | LOG_SET_MSG(eCommandLineMissingInputFile, "Missing input file") 38 | LOG_SET_MSG(eCommandLineInvalidVertexWeight, "Maximum vertex weights must be between 0 and 8") 39 | LOG_SET_MSG(eCommandLineInvalidBoneCount, "Maximum bones per nodepart must be greater or equal to the maximum vertex weights") 40 | LOG_SET_MSG(eCommandLineInvalidVertexCount, "Maximum vertex count must be between 0 and 32k") 41 | LOG_SET_MSG(eCommandLineUnknownFiletype, "Unknown filetype: %s") 42 | LOG_SET_MSG(eCommandLineUnknownCompressLevel, "Max compress level is: %d") 43 | 44 | LOG_SET_MSG(sSourceLoad, "Loading source file") 45 | LOG_SET_MSG(pSourceLoadFbxImport, "Import FBX %01.2f%% %s") 46 | LOG_SET_MSG(wSourceLoadFbxNodeRrSs, "[%s] Node uses RrSs mode, transformation might be incorrect") 47 | LOG_SET_MSG(eSourceLoadGeneral, "Error loading source file: %s") 48 | LOG_SET_MSG(eSourceLoadFiletypeUnknown, "Unknown source filetype") 49 | LOG_SET_MSG(eSourceLoadFbxSdk, "FBX SDK encountered an error: %s") 50 | 51 | LOG_SET_MSG(sSourceConvert, "Converting source file") 52 | LOG_SET_MSG(sSourceConvertFbxTriangulate, "[%s] Triangulating %s geometry") 53 | LOG_SET_MSG(iSourceConvertFbxMeshInfo, "[%s] polygons: %d (%d indices), control points: %d") 54 | LOG_SET_MSG(wSourceConvertFbxDuplicateNodeId, "[%s] Duplicate node id, skipping the node and all it's child nodes") 55 | LOG_SET_MSG(wSourceConvertFbxInvalidBone, "[%s] Skipping invalid bone: %s") 56 | LOG_SET_MSG(wSourceConvertFbxAdditiveBones, "[%s] Additive bones not supported (yet)") 57 | LOG_SET_MSG(wSourceConvertFbxCantTriangulate, "[%s] Skipping geometry, because it can't be triangulated") 58 | LOG_SET_MSG(wSourceConvertFbxExceedsIndices, "Mesh contains more indices (%d) than the specified maximum (%d)") 59 | LOG_SET_MSG(wSourceConvertFbxExceedsBones, "Mesh contains more blendweights per polygon than the specified maximum.") 60 | LOG_SET_MSG(wSourceConvertFbxZeroWeights, "Mesh contains vertices with zero bone weights.") 61 | LOG_SET_MSG(wSourceConvertFbxDuplicateMesh, "[%s] Skipping geometry with duplicate mesh") 62 | LOG_SET_MSG(wSourceConvertFbxNoMaterial, "[%s] Skipping geometry without material") 63 | LOG_SET_MSG(wSourceConvertFbxEmptyMeshpart, "[%s] Skipping empty node part, material: '%s'") 64 | LOG_SET_MSG(wSourceConvertFbxMaterialUnknown, "[%s] Material doesn\'t extend FbxSurfaceLambert, replaced with RED diffuse") 65 | LOG_SET_MSG(wSourceConvertFbxMaterialHLSL, "[%s] Material HLSL shading not supported, replaced with RED diffuse") 66 | LOG_SET_MSG(wSourceConvertFbxMaterialCgFX, "[%s] Material CgFX shading not supported, replaced with RED diffuse") 67 | LOG_SET_MSG(wSourceConvertFbxPolyMaterialInvalid,"[%s] Skipping vertices without material,please check the material ID") 68 | LOG_SET_MSG(eSourceConvert, "Error converting source file") 69 | 70 | LOG_SET_MSG(sSourceClose, "Closing source file") 71 | LOG_SET_MSG(eSourceClose, "Error closing source file") 72 | 73 | LOG_SET_MSG(sExportToG3DB, "Exporting to c3b file: %s") 74 | LOG_SET_MSG(sExportToG3DJ, "Exporting to c3t file: %s") 75 | LOG_SET_MSG(sExportClose, "Closing exported file") 76 | LOG_SET_MSG(eExportFiletypeUnknown, "Unknown target filetype") 77 | 78 | LOG_SET_MSG(iModelInfoNull, "Model is null") 79 | LOG_SET_MSG(iModelInfoStart, "Listing model information:") 80 | LOG_SET_MSG(iModelInfoID, "ID : %s") 81 | LOG_SET_MSG(iModelInfoVersion, "Version : Hi=%d, Lo=%d") 82 | LOG_SET_MSG(iModelInfoMeshesSummary, "Meshes : %d (%d vertices, %d parts, %d indices)") 83 | LOG_SET_MSG(iModelInfoNodesSummary, "Nodes : %d root, %d total, %d parts") 84 | LOG_SET_MSG(iModelInfoMaterialsSummary, "Materials : %d (%d textures)") 85 | 86 | LOG_END_MESSAGES() 87 | 88 | } } 89 | 90 | #endif //FBXCONV_LOG_MESSAGES_H -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #if defined(_MSC_VER) && defined(_DEBUG) 18 | #define _CRTDBG_MAP_ALLOC 19 | #include 20 | #include 21 | #endif 22 | 23 | #include "FbxConv.h" 24 | 25 | #include 26 | #include "Settings.h" 27 | #include "FbxConvCommand.h" 28 | #include "readers/FbxConverter.h" 29 | #include "json/JSONWriter.h" 30 | #include "json/UBJSONWriter.h" 31 | #include 32 | #include 33 | #include 34 | 35 | #include "log/messages.h" 36 | 37 | using namespace fbxconv; 38 | using namespace fbxconv::modeldata; 39 | using namespace fbxconv::readers; 40 | int process(int argc, const char** argv) { 41 | log::Log log(new log::DefaultMessages(), -1); 42 | FbxConv conv(&log); 43 | return conv.execute(argc, argv) ? 0 : 1; 44 | } 45 | 46 | int main(int argc, const char** argv) { 47 | 48 | #if defined(_MSC_VER) && defined(_DEBUG) 49 | _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); 50 | #endif 51 | 52 | int result = process(argc, argv); 53 | 54 | #ifdef _DEBUG 55 | std::cout << "Press ENTER to continue..."; 56 | std::cin.ignore(std::numeric_limits::max(), '\n'); 57 | #endif 58 | 59 | return result; 60 | } -------------------------------------------------------------------------------- /src/modeldata/Animation.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef MODELDATA_ANIMATION_H 21 | #define MODELDATA_ANIMATION_H 22 | 23 | #include 24 | #include "Node.h" 25 | #include "NodeAnimation.h" 26 | #include "../json/BaseJSONWriter.h" 27 | #include "Reference.h" 28 | namespace fbxconv { 29 | namespace modeldata { 30 | struct Node; 31 | 32 | struct Animation : public json::ConstSerializable { 33 | std::string id; 34 | float length; 35 | std::vector nodeAnimations; 36 | 37 | Animation(): 38 | length(0) 39 | { 40 | } 41 | 42 | Animation(const Animation ©From) { 43 | id = copyFrom.id; 44 | for (std::vector::const_iterator itr = copyFrom.nodeAnimations.begin(); itr != copyFrom.nodeAnimations.end(); ++itr) 45 | nodeAnimations.push_back(new NodeAnimation(*(*itr))); 46 | } 47 | 48 | ~Animation() { 49 | for (std::vector::iterator itr = nodeAnimations.begin(); itr != nodeAnimations.end(); ++itr) 50 | if ((*itr)!=0) 51 | delete *itr; 52 | } 53 | ObjRef object; 54 | ObjRef* GetObj() 55 | { 56 | object.tpyeid = ANIMATIONS_ID; 57 | object.fPosition = 0; 58 | object.id = id+"animation"; 59 | return &object; 60 | } 61 | virtual void serialize(json::BaseJSONWriter &writer) const; 62 | void writeBinary(FILE* file); 63 | }; 64 | } } 65 | 66 | #endif // MODELDATA_ANIMATION_H -------------------------------------------------------------------------------- /src/modeldata/C3BFile.cpp: -------------------------------------------------------------------------------- 1 | #include "C3BFile.h" 2 | #include "Animation.h" 3 | #include "Model.h" 4 | namespace fbxconv{ 5 | using namespace modeldata; 6 | unsigned char GPB_VERSION[2] = {VERSION_HI, VERSION_LO}; 7 | C3BFile::C3BFile(void) 8 | :_file(NULL) 9 | { 10 | 11 | } 12 | 13 | C3BFile::~C3BFile(void) 14 | { 15 | 16 | } 17 | 18 | bool C3BFile::saveBinary(const std::string& filepath) 19 | { 20 | _file = fopen(filepath.c_str(), "w+b"); 21 | 22 | // identifier 23 | char identifier[] = {'C','3','B','\0'}; 24 | 25 | fwrite(identifier, 1, sizeof(identifier), _file); 26 | 27 | //version 28 | fwrite(GPB_VERSION, 1, sizeof(GPB_VERSION), _file); 29 | 30 | _refTable.writeBinary(_file); 31 | 32 | if(_models) 33 | { 34 | _models->writeBinary(_file); 35 | } 36 | 37 | _refTable.updateOffset(_file); 38 | 39 | fclose(_file); 40 | return true; 41 | } 42 | 43 | void C3BFile::addToRefTable(ObjRef* obj) 44 | { 45 | if(obj) 46 | { 47 | std::string& id = obj->id; 48 | if(id.length() > 0) 49 | { 50 | if(_refTable.get(id) == NULL) 51 | { 52 | _refTable.add(id, obj); 53 | } 54 | } 55 | } 56 | } 57 | 58 | void C3BFile::AddModel(modeldata::Model* model) 59 | { 60 | _models = model; 61 | 62 | //Add Mesh 63 | if(model->meshes.size()>0) 64 | { 65 | Mesh* mesh = model->meshes[0]; 66 | addToRefTable(mesh->GetObj()); 67 | } 68 | //MeshPart* meshpart = mesh->parts[0]; 69 | //addToRefTable(meshpart->GetObj()); 70 | 71 | // Add Material 72 | if(model->materials.size()>0) 73 | { 74 | Material* mat = model->materials[0]; 75 | addToRefTable(mat->GetObj()); 76 | } 77 | // Add node 78 | if(model->nodes.size()>0) 79 | { 80 | Node* node = model->nodes[0]; 81 | addToRefTable(node->GetObj()); 82 | } 83 | 84 | // Add animations 85 | if(model->animations.size()>0) 86 | { 87 | for (int i = 0; i < model->animations.size(); i++) 88 | { 89 | Animation* anim = model->animations[i]; 90 | addToRefTable(anim->GetObj()); 91 | } 92 | } 93 | 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/modeldata/C3BFile.h: -------------------------------------------------------------------------------- 1 | #ifndef _GPBFILE_H_ 2 | #define _GPBFILE_H_ 3 | 4 | #include "FileIO.h" 5 | #include "Model.h" 6 | #include "ReferenceTable.h" 7 | 8 | namespace fbxconv { 9 | 10 | class C3BFile 11 | { 12 | public: 13 | // Construct. 14 | C3BFile(void); 15 | 16 | ~C3BFile(void); 17 | 18 | // Destruct. 19 | bool saveBinary(const std::string& filepath); 20 | 21 | void addToRefTable(ObjRef* obj); 22 | 23 | void AddModel(modeldata::Model* model); 24 | 25 | private: 26 | FILE* _file; 27 | modeldata::Model* _models; 28 | ReferenceTable _refTable; 29 | 30 | }; 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/modeldata/FileIO.cpp: -------------------------------------------------------------------------------- 1 | #include "FileIO.h" 2 | #include 3 | namespace fbxconv 4 | { 5 | 6 | 7 | // Writing out a binary file // 8 | //void write(size_t value, FILE* file) 9 | //{ 10 | // size_t r = fwrite(&value, sizeof(size_t), 1, file); 11 | //} 12 | 13 | 14 | void write(unsigned char value, FILE* file) 15 | { 16 | size_t r = fwrite(&value, sizeof(unsigned char), 1, file); 17 | assert(r == 1); 18 | } 19 | 20 | void write(char value, FILE* file) 21 | { 22 | size_t r = fwrite(&value, sizeof(char), 1, file); 23 | assert(r == 1); 24 | } 25 | 26 | void write(const char* str, FILE* file) 27 | { 28 | size_t length = strlen(str); 29 | size_t r = fwrite(str, 1, length, file); 30 | assert(r == length); 31 | } 32 | 33 | void write(unsigned int value, FILE* file) 34 | { 35 | size_t r = fwrite(&value, sizeof(unsigned int), 1, file); 36 | assert(r == 1); 37 | } 38 | 39 | void write(unsigned short value, FILE* file) 40 | { 41 | size_t r = fwrite(&value, sizeof(unsigned short), 1, file); 42 | assert(r == 1); 43 | } 44 | 45 | void write(bool value, FILE* file) 46 | { 47 | // write booleans as a unsigned char 48 | unsigned char b = value; 49 | write(b, file); 50 | } 51 | void write(float value, FILE* file) 52 | { 53 | fwrite(&value, sizeof(float), 1, file); 54 | } 55 | void write(const float* values, int length, FILE* file) 56 | { 57 | fwrite(values, sizeof(float), length, file); 58 | /*for (int i = 0; i < length; ++i) 59 | { 60 | write(values[i], file); 61 | }*/ 62 | } 63 | void write(const std::string& str, FILE* file) 64 | { 65 | // Write the length of the string 66 | write((unsigned int)str.size(), file); 67 | 68 | if (str.size() > 0) 69 | { 70 | // Write the array of characters of the string 71 | write(str.c_str(), file); 72 | } 73 | } 74 | 75 | void writeZero(FILE* file) 76 | { 77 | write((unsigned int)0, file); 78 | } 79 | 80 | void skipString(FILE* file) 81 | { 82 | // get the size of the char array 83 | unsigned int length = 0; 84 | fread(&length, sizeof(unsigned int), 1, file); 85 | // skip over the unsigned int length 86 | //fseek(file, sizeof(unsigned int), SEEK_CUR); 87 | if (length > 0) 88 | { 89 | // Skip over the array of chars 90 | long seek = (long)(length * sizeof(char)); 91 | fseek(file, seek, SEEK_CUR); 92 | } 93 | } 94 | 95 | void skipUint(FILE* file) 96 | { 97 | fseek(file, sizeof(unsigned int), SEEK_CUR); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/modeldata/FileIO.h: -------------------------------------------------------------------------------- 1 | #ifndef FILEIO_H_ 2 | #define FILEIO_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace fbxconv 11 | { 12 | 13 | /** 14 | * Writes binary data to the given file stream. 15 | * 16 | * @param value The value to be written 17 | * @param file The binary file stream. 18 | */ 19 | //void write(size_t value, FILE* file); 20 | void write(unsigned char value, FILE* file); 21 | void write(char value, FILE* file); 22 | void write(const char* str, FILE* file); 23 | void write(unsigned int value, FILE* file); 24 | void write(unsigned short value, FILE* file); 25 | void write(bool value, FILE* file); 26 | void write(float value, FILE* file); 27 | void write(const float* values, int length, FILE* file); 28 | 29 | /** 30 | * Writes the length of the string and the string bytes to the binary file stream. 31 | */ 32 | void write(const std::string& str, FILE* file); 33 | 34 | void writeZero(FILE* file); 35 | 36 | /** 37 | * Skips over the string at the current file stream offset by moving the file position. 38 | * Assumes the current position points to the unsigned int length of the string. 39 | * The string is assumed to be a char array. 40 | * 41 | * @param file The file stream. 42 | */ 43 | void skipString(FILE* file); 44 | 45 | void skipUint(FILE* file); 46 | 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/modeldata/Keyframe.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef MODELDATA_KEYFRAME_H 21 | #define MODELDATA_KEYFRAME_H 22 | 23 | #include "../json/BaseJSONWriter.h" 24 | 25 | namespace fbxconv { 26 | namespace modeldata { 27 | 28 | struct Keyframe : public json::ConstSerializable { 29 | float time; 30 | float translation[3]; 31 | float rotation[4]; 32 | float scale[3]; 33 | bool hasTranslation; 34 | bool hasRotation; 35 | bool hasScale; 36 | 37 | Keyframe() { 38 | time = 0.; 39 | translation[0] = translation[1] = translation[2] = 0.; 40 | rotation[0] = rotation[1] = rotation[2] = 0.; rotation[3] = 1.; 41 | scale[0] = scale[1] = scale[2] = 1.; 42 | hasTranslation = hasRotation = hasScale = false; 43 | } 44 | 45 | Keyframe(const Keyframe &rhs) { 46 | time = rhs.time; 47 | memcpy(translation, rhs.translation, sizeof(translation)); 48 | memcpy(rotation, rhs.rotation, sizeof(rotation)); 49 | memcpy(scale, rhs.scale, sizeof(scale)); 50 | hasTranslation = rhs.hasTranslation; 51 | hasRotation = rhs.hasRotation; 52 | hasScale = rhs.hasScale; 53 | } 54 | 55 | virtual void serialize(json::BaseJSONWriter &writer) const; 56 | }; 57 | } } 58 | 59 | #endif // MODELDATA_KEYFRAME_H -------------------------------------------------------------------------------- /src/modeldata/Material.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef MODELDATA_MATERIAL_H 21 | #define MODELDATA_MATERIAL_H 22 | 23 | #include 24 | #include 25 | #include "../readers/matrix3.h" 26 | #include "../json/BaseJSONWriter.h" 27 | #include "Reference.h" 28 | namespace fbxconv { 29 | namespace modeldata { 30 | template 31 | struct OptionalValue { 32 | bool valid; 33 | T value[n]; 34 | OptionalValue() : valid(false) { 35 | for (int i = 0; i < n; ++i) 36 | value[i] = (T)0; 37 | } 38 | inline void unset() { 39 | valid = false; 40 | } 41 | void set(T v0, ...) { 42 | va_list vl; 43 | value[0] = v0; 44 | va_start(vl, v0); 45 | for (int i = 1; i < n; i++) 46 | value[i] = va_arg(vl, T); 47 | va_end(vl); 48 | valid = true; 49 | } 50 | template void set(const S (&v)[m]) { 51 | const int c = m > n ? n : m; 52 | for (int i = 0; i < c; i++) 53 | value[i] = (T)v[i]; 54 | valid = true; 55 | } 56 | }; 57 | 58 | template 59 | struct OptionalValue { 60 | bool valid; 61 | T value; 62 | OptionalValue() : valid(false), value((T)0) {} 63 | inline void unset() { 64 | valid = false; 65 | } 66 | inline void set(T v) { 67 | valid = true; 68 | value = v; 69 | } 70 | }; 71 | 72 | struct Material : public json::ConstSerializable { 73 | struct Texture : public json::ConstSerializable { 74 | enum Usage { 75 | Unknown = 0, 76 | None = 1, 77 | Diffuse = 2, 78 | Emissive = 3, 79 | Ambient = 4, 80 | Specular = 5, 81 | Shininess = 6, 82 | Normal = 7, 83 | Bump = 8, 84 | Transparency = 9, 85 | Reflection = 10 86 | }; 87 | 88 | FbxFileTexture *source; 89 | std::string id; 90 | std::string path; 91 | float uvTranslation[2]; 92 | float uvScale[2]; 93 | // FIXME add Matrix3 uvTransform; 94 | Usage usage; 95 | FbxFileTexture::EWrapMode wrapModeU; 96 | FbxFileTexture::EWrapMode wrapModeV; 97 | 98 | Texture() : usage(Unknown), source(0) { 99 | uvTranslation[0] = uvTranslation[1] = 0.f; 100 | uvScale[0] = uvScale[1] = 1.f; 101 | } 102 | 103 | virtual void serialize(json::BaseJSONWriter &writer) const; 104 | }; 105 | 106 | FbxSurfaceMaterial *source; 107 | std::string id; 108 | OptionalValue diffuse; 109 | OptionalValue ambient; 110 | OptionalValue emissive; 111 | OptionalValue specular; 112 | OptionalValue shininess; 113 | OptionalValue opacity; 114 | std::vector textures; 115 | 116 | Material() : source(0), diffuse(), ambient(), emissive(), specular(), shininess(), opacity() { } 117 | 118 | Material(const Material &rhs) : source(rhs.source), id(rhs.id), diffuse(rhs.diffuse), 119 | ambient(rhs.ambient), emissive(rhs.emissive), specular(rhs.specular), shininess(rhs.shininess), opacity(rhs.opacity) { } 120 | 121 | ~Material() { 122 | for (std::vector::iterator itr = textures.begin(); itr != textures.end(); ++itr) 123 | delete (*itr); 124 | } 125 | 126 | Texture *getTexture(const char *id) const { 127 | for (std::vector::const_iterator itr = textures.begin(); itr != textures.end(); ++itr) 128 | if ((*itr)->id.compare(id)==0) 129 | return (*itr); 130 | return NULL; 131 | } 132 | 133 | int getTextureIndex(const Texture * const &texture) const { 134 | int n = (int)textures.size(); 135 | for (int i = 0; i < n; i++) 136 | if (textures[i] == texture) 137 | return i; 138 | return -1; 139 | } 140 | ObjRef object; 141 | ObjRef* GetObj() 142 | { 143 | object.tpyeid = MATERIAL_ID; 144 | object.fPosition = 0; 145 | object.id = id+"material"; 146 | return &object; 147 | } 148 | virtual void serialize(json::BaseJSONWriter &writer) const; 149 | void writeBinary(FILE* file); 150 | }; 151 | } 152 | } 153 | 154 | #endif //MODELDATA_MATERIAL_H -------------------------------------------------------------------------------- /src/modeldata/Mesh.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef MODELDATA_MESH_H 21 | #define MODELDATA_MESH_H 22 | 23 | #include 24 | #include "MeshPart.h" 25 | #include "Attributes.h" 26 | #include "../json/BaseJSONWriter.h" 27 | #include "Reference.h" 28 | 29 | namespace fbxconv { 30 | namespace modeldata { 31 | 32 | struct PN{ 33 | FbxVector4 position; 34 | FbxVector4 normal; 35 | }; 36 | 37 | /** A mesh is responsable for freeing all parts and vertices it contains. */ 38 | struct Mesh : public json::ConstSerializable { 39 | /** the attributes the vertices in this mesh describe */ 40 | Attributes attributes; 41 | /** the size (in number of floats) of each vertex */ 42 | unsigned int vertexSize; 43 | /** the vertices that this mesh contains */ 44 | std::vector vertices; 45 | /** hash lookup table for faster duplicate vertex checking */ 46 | std::vector hashes; 47 | /** the indexed parts of this mesh */ 48 | std::vector parts; 49 | std::string id; 50 | 51 | /** save position and normal */ 52 | std::list pnList; 53 | 54 | /** ctor */ 55 | Mesh() : attributes(0), vertexSize(0) { 56 | } 57 | 58 | /** copy constructor */ 59 | Mesh(const Mesh ©From) { 60 | attributes = copyFrom.attributes; 61 | vertexSize = copyFrom.vertexSize; 62 | vertices.insert(vertices.end(), copyFrom.vertices.begin(), copyFrom.vertices.end()); 63 | for (std::vector::const_iterator itr = copyFrom.parts.begin(); itr != copyFrom.parts.end(); ++itr) 64 | parts.push_back(new MeshPart(**itr)); 65 | } 66 | 67 | ~Mesh() { 68 | clear(); 69 | } 70 | 71 | void clear() { 72 | vertices.clear(); 73 | hashes.clear(); 74 | attributes = vertexSize = 0; 75 | for (std::vector::iterator itr = parts.begin(); itr != parts.end(); ++itr) 76 | delete (*itr); 77 | parts.clear(); 78 | pnList.clear(); 79 | } 80 | 81 | inline unsigned int indexCount() { 82 | unsigned int result = 0; 83 | for (std::vector::const_iterator itr = parts.begin(); itr != parts.end(); ++itr) 84 | result += (unsigned int)(*itr)->indices.size(); 85 | return result; 86 | } 87 | 88 | inline unsigned int add(const float *vertex) { 89 | const unsigned int hash = calcHash(vertex, vertexSize); 90 | const unsigned int n = (unsigned int)hashes.size(); 91 | for (unsigned int i = 0; i < n; i++) 92 | if ((hashes[i] == hash) && compare(&vertices[i*vertexSize], vertex, vertexSize)) 93 | return i; 94 | hashes.push_back(hash); 95 | vertices.insert(vertices.end(), &vertex[0], &vertex[vertexSize]); 96 | return (unsigned int)hashes.size() - 1; 97 | } 98 | 99 | inline unsigned int calcHash(const float *vertex, const unsigned int size) { 100 | unsigned int result = 0; 101 | for (unsigned int i = 0; i < size; i++) 102 | result += ((*((unsigned int *)&vertex[i])) & 0xffffff00) >> 8; 103 | return result; 104 | } 105 | 106 | inline bool compare(const float* lhs, const float* rhs, const unsigned int &n) { 107 | for (unsigned int i = 0; i < n; i++) 108 | if ((*(unsigned int*)&lhs[i] != *(unsigned int*)&rhs[i]) && lhs[i] != rhs[i]) 109 | return false; 110 | return true; 111 | } 112 | 113 | inline bool addN(const FbxVector4& position, const FbxVector4& normal){ 114 | std::list::iterator iter = pnList.begin(); 115 | for (; iter != pnList.end(); iter++) { 116 | if (iter->position == position) { 117 | iter->normal += normal; 118 | return true; 119 | } 120 | } 121 | 122 | PN pn; 123 | pn.position = position; 124 | pn.normal = normal; 125 | pnList.push_back(pn); 126 | return false; 127 | } 128 | 129 | inline bool getN(const FbxVector4& position, FbxVector4& normal){ 130 | std::list::iterator iter = pnList.begin(); 131 | for (; iter != pnList.end(); iter++) { 132 | if (iter->position == position) { 133 | normal = iter->normal; 134 | return true; 135 | } 136 | } 137 | return false; 138 | } 139 | 140 | inline void calcNormal(){ 141 | int stride = attributes.size(); 142 | unsigned int num = vertices.size(); 143 | for (int i = 0; i < num; i += stride) { 144 | // get position 145 | float *position = &vertices[i]; 146 | FbxVector4 pos(position[0], position[1], position[2]); 147 | 148 | // get normal 149 | float *normal = &vertices[i + 3]; 150 | FbxVector4 tnormal(normal[0], normal[1], normal[2]); 151 | 152 | // sum the target position's normal 153 | addN(pos, tnormal); 154 | } 155 | 156 | // normalize the normal in pnList 157 | std::list::iterator iter = pnList.begin(); 158 | for (; iter != pnList.end(); iter++) { 159 | iter->normal.Normalize(); 160 | } 161 | 162 | // modify the vertex buffer data 163 | for (int i = 0; i < num; i += stride) { 164 | // get position 165 | float *position = &vertices[i]; 166 | FbxVector4 pos(position[0], position[1], position[2]); 167 | 168 | float *normal = &vertices[i + 3]; 169 | FbxVector4 tnormal; 170 | getN(pos, tnormal); 171 | normal[0] = tnormal[0]; 172 | normal[1] = tnormal[1]; 173 | normal[2] = tnormal[2]; 174 | } 175 | } 176 | 177 | inline void calcAABB(){ 178 | int stride = attributes.size(); 179 | unsigned int num = vertices.size(); 180 | 181 | for (unsigned int i = 0; i < parts.size(); ++i){ 182 | auto meshPart = parts[i]; 183 | for (auto iter : meshPart->indices){ 184 | float *position = &vertices[iter * stride]; 185 | //update aabb min 186 | meshPart->aabb[0] = position[0] < meshPart->aabb[0]? position[0]: meshPart->aabb[0]; 187 | meshPart->aabb[1] = position[1] < meshPart->aabb[1]? position[1]: meshPart->aabb[1]; 188 | meshPart->aabb[2] = position[2] < meshPart->aabb[2]? position[2]: meshPart->aabb[2]; 189 | //update aabb max 190 | meshPart->aabb[3] = position[0] > meshPart->aabb[3]? position[0]: meshPart->aabb[3]; 191 | meshPart->aabb[4] = position[1] > meshPart->aabb[4]? position[1]: meshPart->aabb[4]; 192 | meshPart->aabb[5] = position[2] > meshPart->aabb[5]? position[2]: meshPart->aabb[5]; 193 | } 194 | } 195 | } 196 | 197 | ObjRef object; 198 | ObjRef* GetObj() 199 | { 200 | object.tpyeid = MESH_ID; 201 | object.fPosition = 0; 202 | object.id = id+"mesh"; 203 | return &object; 204 | } 205 | virtual void serialize(json::BaseJSONWriter &writer) const; 206 | void writeBinary(FILE* file); 207 | }; 208 | } 209 | } 210 | 211 | #endif //MODELDATA_MESH_H 212 | -------------------------------------------------------------------------------- /src/modeldata/MeshPart.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef MODELDATA_MESHPART_H 21 | #define MODELDATA_MESHPART_H 22 | 23 | #define PRIMITIVETYPE_POINTS 0 24 | #define PRIMITIVETYPE_LINES 1 25 | #define PRIMITIVETYPE_LINESTRIP 3 26 | #define PRIMITIVETYPE_TRIANGLES 4 27 | #define PRIMITIVETYPE_TRIANGLESTRIP 5 28 | 29 | #include 30 | #include 31 | #include "../json/BaseJSONWriter.h" 32 | 33 | namespace fbxconv { 34 | namespace modeldata { 35 | struct MeshPart : public json::ConstSerializable { 36 | std::string id; 37 | std::vector indices; 38 | unsigned int primitiveType; 39 | std::vector sourceBones; 40 | float aabb[6]; 41 | 42 | MeshPart() : primitiveType(0) { 43 | aabb[0] = aabb[1] = aabb[2] = 99999.0f; 44 | aabb[3] = aabb[4] = aabb[5] = -99999.0f; 45 | } 46 | 47 | MeshPart(const MeshPart ©From) { 48 | set(copyFrom.id.c_str(), copyFrom.primitiveType, copyFrom.indices); 49 | memcpy(aabb, copyFrom.aabb, sizeof(aabb)); 50 | } 51 | 52 | ~MeshPart() { 53 | clear(); 54 | } 55 | 56 | void clear() { 57 | indices.clear(); 58 | id.clear(); 59 | primitiveType = 0; 60 | aabb[0] = aabb[1] = aabb[2] = 99999.0f; 61 | aabb[3] = aabb[4] = aabb[5] = -99999.0f; 62 | } 63 | 64 | void set(const char *id, const unsigned int &primitiveType, const std::vector &indices) { 65 | this->id = id; 66 | this->primitiveType = primitiveType; 67 | this->indices.clear(); 68 | this->indices.insert(this->indices.end(), indices.begin(), indices.end()); 69 | } 70 | virtual void serialize(json::BaseJSONWriter &writer) const; 71 | void writeBinary(FILE* file); 72 | }; 73 | } 74 | } 75 | 76 | #endif //MODELDATA_MESHPART_H -------------------------------------------------------------------------------- /src/modeldata/Model.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef MODELDATA_MODEL_H 21 | #define MODELDATA_MODEL_H 22 | 23 | #include 24 | #include 25 | #include "Animation.h" 26 | #include "Material.h" 27 | #include "Mesh.h" 28 | #include "Node.h" 29 | #include "../json/BaseJSONWriter.h" 30 | #include "../Settings.h" 31 | 32 | namespace fbxconv { 33 | namespace modeldata { 34 | const short VERSION_HI = 0; 35 | const short VERSION_LO = 7; 36 | 37 | /** A model is responsable for freeing all animations, materials, meshes and nodes it contains */ 38 | struct Model : public json::ConstSerializable { 39 | short version[2]; 40 | std::string id; 41 | std::vector animations; 42 | std::vector materials; 43 | std::vector meshes; 44 | std::vector nodes; 45 | EXPORT_PART exportPart; 46 | 47 | Model() { version[0] = VERSION_HI; version[1] = VERSION_LO; exportPart = EXPORT_PART_ALL;} 48 | 49 | Model(const Model ©From) { 50 | version[0] = copyFrom.version[0]; 51 | version[1] = copyFrom.version[1]; 52 | id = copyFrom.id; 53 | for (std::vector::const_iterator itr = copyFrom.animations.begin(); itr != copyFrom.animations.end(); ++itr) 54 | animations.push_back(new Animation(**itr)); 55 | for (std::vector::const_iterator itr = copyFrom.materials.begin(); itr != copyFrom.materials.end(); ++itr) 56 | materials.push_back(new Material(**itr)); 57 | for (std::vector::const_iterator itr = copyFrom.meshes.begin(); itr != copyFrom.meshes.end(); ++itr) 58 | meshes.push_back(new Mesh(**itr)); 59 | for (std::vector::const_iterator itr = copyFrom.nodes.begin(); itr != copyFrom.nodes.end(); ++itr) 60 | nodes.push_back(new Node(**itr)); 61 | exportPart = copyFrom.exportPart; 62 | } 63 | 64 | ~Model() { 65 | clear(); 66 | } 67 | 68 | void clear() { 69 | for (std::vector::iterator itr = animations.begin(); itr != animations.end(); ++itr) 70 | delete *itr; 71 | animations.clear(); 72 | for (std::vector::iterator itr = materials.begin(); itr != materials.end(); ++itr) 73 | delete *itr; 74 | materials.clear(); 75 | for (std::vector::iterator itr = meshes.begin(); itr != meshes.end(); ++itr) 76 | delete *itr; 77 | meshes.clear(); 78 | for (std::vector::iterator itr = nodes.begin(); itr != nodes.end(); ++itr) 79 | delete *itr; 80 | nodes.clear(); 81 | } 82 | 83 | Node *getNode(const char *id) const { 84 | for (std::vector::const_iterator itr = nodes.begin(); itr != nodes.end(); ++itr) { 85 | if ((*itr)->id.compare(id)==0) 86 | return *itr; 87 | Node *cnode = (*itr)->getChild(id); 88 | if (cnode != NULL) 89 | return cnode; 90 | } 91 | return NULL; 92 | } 93 | 94 | Material *getMaterial(const char *id) const { 95 | for (std::vector::const_iterator itr = materials.begin(); itr != materials.end(); ++itr) 96 | if ((*itr)->id.compare(id)==0) 97 | return *itr; 98 | return NULL; 99 | } 100 | 101 | size_t getTotalNodeCount() const { 102 | size_t result = nodes.size(); 103 | for (std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) 104 | result += (*it)->getTotalNodeCount(); 105 | return result; 106 | } 107 | 108 | size_t getTotalNodePartCount() const { 109 | size_t result = 0; 110 | for (std::vector::const_iterator it = nodes.begin(); it != nodes.end(); ++it) 111 | result += (*it)->getTotalNodePartCount(); 112 | return result; 113 | } 114 | 115 | size_t getMeshpartCount() const { 116 | size_t result = 0; 117 | for (std::vector::const_iterator it = meshes.begin(); it != meshes.end(); ++it) 118 | result += (*it)->parts.size(); 119 | return result; 120 | } 121 | 122 | size_t getTotalVertexCount() const { 123 | size_t result = 0; 124 | for (std::vector::const_iterator it = meshes.begin(); it != meshes.end(); ++it) 125 | result += (*it)->vertices.size(); 126 | return result; 127 | } 128 | 129 | size_t getTotalIndexCount() const { 130 | size_t result = 0; 131 | for (std::vector::const_iterator it = meshes.begin(); it != meshes.end(); ++it) 132 | result += (*it)->indexCount(); 133 | return result; 134 | } 135 | 136 | size_t getTotalTextureCount() const { 137 | size_t result = 0; 138 | for (std::vector::const_iterator it = materials.begin(); it != materials.end(); ++it) 139 | result += (*it)->textures.size(); 140 | return result; 141 | } 142 | 143 | virtual void serialize(json::BaseJSONWriter &writer) const; 144 | void writeBinary(FILE* file); 145 | }; 146 | } 147 | } 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /src/modeldata/Node.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef MODELDATA_NODE_H 21 | #define MODELDATA_NODE_H 22 | 23 | #include 24 | #include 25 | #include "NodePart.h" 26 | #include "../json/BaseJSONWriter.h" 27 | #include 28 | namespace fbxconv { 29 | namespace modeldata { 30 | /** A node is responsable for destroying its parts and children */ 31 | struct Node : public json::ConstSerializable { 32 | struct { 33 | float translation[3]; 34 | float rotation[4]; 35 | float scale[3]; 36 | } transform; 37 | float transforms[16]; 38 | std::string id; 39 | std::vector parts; 40 | std::vector children; 41 | FbxNode *source; 42 | bool _skeleton; 43 | Node(const char *id = NULL) : source(0) { 44 | memset(&transform, 0, sizeof(transform)); 45 | transform.scale[0] = transform.scale[1] = transform.scale[2] = 1.f; 46 | if (id != NULL) 47 | this->id = id; 48 | _skeleton=false; 49 | } 50 | 51 | Node(const Node ©From) { 52 | id = copyFrom.id; 53 | source = copyFrom.source; 54 | memcpy(&transform, &(copyFrom.transform), sizeof(transform)); 55 | for (std::vector::const_iterator itr = copyFrom.parts.begin(); itr != copyFrom.parts.end(); ++itr) 56 | parts.push_back(new NodePart(**itr)); 57 | for (std::vector::const_iterator itr = copyFrom.children.begin(); itr != copyFrom.children.end(); ++itr) 58 | children.push_back(new Node(**itr)); 59 | _skeleton=copyFrom._skeleton; 60 | } 61 | 62 | ~Node() { 63 | for (std::vector::iterator itr = parts.begin(); itr != parts.end(); ++itr) 64 | delete (*itr); 65 | for (std::vector::iterator itr = children.begin(); itr != children.end(); ++itr) 66 | delete (*itr); 67 | } 68 | 69 | Node * getChild(const char *id) const { 70 | for (std::vector::const_iterator itr = children.begin(); itr != children.end(); ++itr) { 71 | if ((*itr)->id.compare(id)==0) 72 | return *itr; 73 | Node *cnode = (*itr)->getChild(id); 74 | if (cnode != NULL) 75 | return cnode; 76 | } 77 | return NULL; 78 | } 79 | 80 | bool hasPartsRecursive() const { 81 | if (!parts.empty()) 82 | return true; 83 | for (std::vector::const_iterator itr = children.begin(); itr != children.end(); ++itr) 84 | if ((*itr)->hasPartsRecursive()) 85 | return true; 86 | return false; 87 | } 88 | 89 | size_t getTotalNodeCount() const { 90 | size_t result = children.size(); 91 | for (std::vector::const_iterator it = children.begin(); it != children.end(); ++it) 92 | result += (*it)->getTotalNodeCount(); 93 | return result; 94 | } 95 | 96 | size_t getTotalNodePartCount() const { 97 | size_t result = parts.size(); 98 | for (std::vector::const_iterator it = children.begin(); it != children.end(); ++it) 99 | result += (*it)->getTotalNodePartCount(); 100 | return result; 101 | } 102 | ObjRef object; 103 | ObjRef* GetObj() 104 | { 105 | object.tpyeid = NODE_ID; 106 | object.fPosition = 0; 107 | object.id = id+"node"; 108 | return &object; 109 | } 110 | virtual void serialize(json::BaseJSONWriter &writer) const; 111 | void writeBinary(FILE* file); 112 | void loadBoneNames(std::list& bonenames) 113 | { 114 | for ( int i = 0; i < parts.size() ; i++) 115 | { 116 | 117 | for ( int j = 0; j < parts[i]->bones.size() ; j++) 118 | { 119 | std::string bonename = parts[i]->bones[j].first->id; 120 | if (!checkIsBone(bonename,bonenames)) 121 | { 122 | bonenames.push_back(bonename); 123 | } 124 | } 125 | } 126 | for (int i = 0; i < children.size() ; i++) 127 | { 128 | children[i]->loadBoneNames(bonenames); 129 | } 130 | } 131 | bool checkIsBone(const std::string& name,std::list& bonenames) 132 | { 133 | std::list::iterator iter = std::find(bonenames.begin(), bonenames.end(), name); 134 | bool ret = (iter != bonenames.end()) ? true : false; 135 | return ret; 136 | } 137 | void checkIsSkeleton(bool& skeleton,std::list& bonenames) 138 | { 139 | if (checkIsBone(id,bonenames)) 140 | skeleton = true; 141 | for (int i = 0; i < children.size() ; i++) 142 | { 143 | children[i]->checkIsSkeleton(skeleton,bonenames); 144 | } 145 | } 146 | void setSkeleton(bool skeleton) 147 | { 148 | _skeleton= skeleton; 149 | } 150 | }; 151 | } 152 | } 153 | 154 | #endif // MODELDATA_NODE_H -------------------------------------------------------------------------------- /src/modeldata/NodeAnimation.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef MODELDATA_NODEANIMATION_H 21 | #define MODELDATA_NODEANIMATION_H 22 | 23 | #include 24 | #include "Keyframe.h" 25 | #include "../json/BaseJSONWriter.h" 26 | 27 | namespace fbxconv { 28 | namespace modeldata { 29 | struct Node; 30 | 31 | struct NodeAnimation : public json::ConstSerializable { 32 | const Node *node; 33 | std::vector keyframes; 34 | bool translate, rotate, scale; 35 | 36 | NodeAnimation() : node(0), translate(false), rotate(false), scale(false) {} 37 | 38 | NodeAnimation(const NodeAnimation ©From) { 39 | node = copyFrom.node; 40 | translate = copyFrom.translate; 41 | rotate = copyFrom.rotate; 42 | scale = copyFrom.scale; 43 | for (std::vector::const_iterator itr = copyFrom.keyframes.begin(); itr != copyFrom.keyframes.end(); ++itr) 44 | keyframes.push_back(new Keyframe(*(*itr))); 45 | } 46 | 47 | ~NodeAnimation() { 48 | for (std::vector::iterator itr = keyframes.begin(); itr != keyframes.end(); ++itr) 49 | if ((*itr)!=0) 50 | delete *itr; 51 | } 52 | ObjRef object; 53 | ObjRef* GetObj() 54 | { 55 | object.tpyeid = ANIMATIONS_ID; 56 | object.fPosition = 0; 57 | return &object; 58 | } 59 | virtual void serialize(json::BaseJSONWriter &writer) const; 60 | }; 61 | } } 62 | 63 | #endif //MODELDATA_NODEANIMATION_H -------------------------------------------------------------------------------- /src/modeldata/NodePart.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif 20 | #ifndef MODELDATA_NODEPART_H 21 | #define MODELDATA_NODEPART_H 22 | 23 | #include 24 | #include "MeshPart.h" 25 | #include "Material.h" 26 | #include "../json/BaseJSONWriter.h" 27 | 28 | namespace fbxconv { 29 | namespace modeldata { 30 | struct Node; 31 | /** A nodepart references (but not owns) a meshpart and a material */ 32 | struct NodePart : public json::ConstSerializable { 33 | const MeshPart *meshPart; 34 | const Material *material; 35 | std::vector > bones; 36 | std::vector > uvMapping; 37 | 38 | NodePart() : meshPart(0), material(0) {} 39 | 40 | NodePart(const NodePart ©From) : meshPart(copyFrom.meshPart), material(copyFrom.material) { 41 | bones.insert(bones.end(), copyFrom.bones.begin(), copyFrom.bones.end()); 42 | uvMapping.resize(copyFrom.uvMapping.size()); 43 | for (unsigned int i = 0; i < uvMapping.size(); i++) 44 | uvMapping[i].insert(uvMapping[i].begin(), copyFrom.uvMapping[i].begin(), copyFrom.uvMapping[i].end()); 45 | } 46 | 47 | virtual void serialize(json::BaseJSONWriter &writer) const; 48 | }; 49 | } 50 | } 51 | 52 | #endif // MODELDATA_NODEPART_H -------------------------------------------------------------------------------- /src/modeldata/Reference.cpp: -------------------------------------------------------------------------------- 1 | #include "Reference.h" 2 | #include "FileIO.h" 3 | //#include 4 | 5 | namespace fbxconv { 6 | 7 | Reference::Reference(): 8 | _ref(nullptr), 9 | _xref(""), 10 | _type(0), 11 | _offset(0), 12 | _fPosition(0.f) 13 | { 14 | 15 | } 16 | 17 | Reference::Reference(std::string xref, ObjRef* ref): 18 | _ref(ref), 19 | _xref(xref), 20 | _type(ref->tpyeid), 21 | _offset(0), 22 | _fPosition(0.f) 23 | { 24 | 25 | } 26 | 27 | void Reference::writeBinary(FILE* file) 28 | { 29 | saveFilePosition(file); 30 | write(_xref, file); 31 | write(_type,file); 32 | write(_offset, file); 33 | } 34 | 35 | bool Reference::updateOffset(FILE* file) 36 | { 37 | long newOffset = _ref->fPosition; 38 | return updateOffset(file,newOffset); 39 | } 40 | 41 | bool Reference::updateOffset(FILE* file, long newOffset) 42 | { 43 | if(getFilePosition() > 0) 44 | { 45 | // save the current offset 46 | long saveOffset = ftell(file); 47 | 48 | // update the offset data for us 49 | _offset = newOffset; 50 | // seek this Reference object in the file. 51 | fseek(file, getFilePosition(), SEEK_SET); 52 | 53 | //Skip over the id string 54 | skipString(file); 55 | 56 | // Skip TypeID unsigned int 57 | skipUint(file); 58 | 59 | // write over the old offset. 60 | write(_offset, file); 61 | 62 | // restore the offset. 63 | fseek(file, saveOffset, SEEK_SET); 64 | return true; 65 | } 66 | 67 | return false; 68 | } 69 | 70 | ObjRef* Reference::getRef() 71 | { 72 | return _ref; 73 | } 74 | 75 | unsigned int Reference::getFilePosition() 76 | { 77 | return (unsigned int)_fPosition; 78 | } 79 | 80 | void Reference::saveFilePosition(FILE* file) 81 | { 82 | _fPosition = ftell(file); 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /src/modeldata/Reference.h: -------------------------------------------------------------------------------- 1 | #ifndef _REFERENCE_H_ 2 | #define _REFERENCE_H_ 3 | 4 | #include 5 | 6 | namespace fbxconv { 7 | 8 | // TypeID's 9 | enum TypeID 10 | { 11 | SCENE_ID = 1, 12 | NODE_ID = 2, 13 | ANIMATIONS_ID = 3, 14 | ANIMATION_ID = 4, 15 | ANIMATIONCHANNEL_ID = 5, 16 | NODEINSTANCE_ID = 8, 17 | MODEL_ID = 11, 18 | MATERIAL_ID = 16, 19 | EFFECT_ID = 17, 20 | CAMERA_ID = 32, 21 | LIGHT_ID = 33, 22 | MESH_ID = 34, 23 | MESHPART_ID = 35, 24 | MESHSKIN_ID = 36, 25 | BONEPART_ID = 37, 26 | FONT_ID = 128, 27 | }; 28 | 29 | struct ObjRef 30 | { 31 | unsigned int tpyeid; 32 | long fPosition; 33 | std::string id; 34 | }; 35 | 36 | 37 | class Reference 38 | { 39 | public: 40 | // Construct 41 | Reference(); 42 | Reference(std::string xref, ObjRef* ref); 43 | 44 | // Destruct 45 | ~Reference() {;} 46 | void writeBinary(FILE* file); 47 | void saveFilePosition(FILE* file); 48 | unsigned int getFilePosition(); 49 | 50 | // Updates the offset of the reference object if it has already need written to files. 51 | bool updateOffset(FILE* file); 52 | bool updateOffset(FILE* file, long newOffset); 53 | 54 | ObjRef* getRef(); 55 | ObjRef* _ref; 56 | private: 57 | std::string _xref; 58 | unsigned int _type; 59 | unsigned int _offset; 60 | long _fPosition; 61 | 62 | }; 63 | 64 | 65 | } 66 | 67 | #endif -------------------------------------------------------------------------------- /src/modeldata/ReferenceTable.cpp: -------------------------------------------------------------------------------- 1 | #include "ReferenceTable.h" 2 | #include "FileIO.h" 3 | 4 | namespace fbxconv { 5 | 6 | 7 | void ReferenceTable::add(std::string &xref, ObjRef* obj) 8 | { 9 | _tables[xref] = Reference(xref, obj); 10 | _tables[xref]._ref = obj; 11 | 12 | } 13 | 14 | ObjRef* ReferenceTable::get(const std::string& xref) 15 | { 16 | auto itr = _tables.find(xref); 17 | if(itr != _tables.end()) 18 | { 19 | Reference ref = itr->second; 20 | return ref.getRef(); 21 | } 22 | 23 | return NULL; 24 | } 25 | 26 | void ReferenceTable::writeBinary(FILE* file) 27 | { 28 | unsigned int size = _tables.size(); 29 | write(size,file); 30 | for(auto itr = _tables.begin(); itr != _tables.end(); itr++) 31 | { 32 | itr->second.writeBinary(file); 33 | } 34 | } 35 | 36 | void ReferenceTable::updateOffset(FILE* file) 37 | { 38 | for(auto itr = _tables.begin(); itr != _tables.end(); ++itr) 39 | { 40 | Reference& ref = itr->second; 41 | ref.updateOffset(file); 42 | } 43 | } 44 | 45 | std::map::iterator ReferenceTable::begin() 46 | { 47 | return _tables.begin(); 48 | } 49 | 50 | std::map::iterator ReferenceTable::end() 51 | { 52 | return _tables.end(); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /src/modeldata/ReferenceTable.h: -------------------------------------------------------------------------------- 1 | #ifndef _REFTABLE_H_ 2 | #define _REFTABLE_H_ 3 | 4 | #include 5 | #include 6 | #include "Reference.h" 7 | 8 | namespace fbxconv { 9 | 10 | class ReferenceTable 11 | { 12 | public: 13 | // Construct 14 | ReferenceTable(){}; 15 | 16 | // Destruct 17 | virtual ~ReferenceTable(){}; 18 | 19 | 20 | void add(std::string &xref, ObjRef* obj); 21 | 22 | ObjRef* get(const std::string& xref); 23 | 24 | void writeBinary(FILE* file); 25 | 26 | void updateOffset(FILE* file); 27 | 28 | std::map::iterator begin(); 29 | std::map::iterator end(); 30 | 31 | private: 32 | std::map _tables; 33 | }; 34 | 35 | } 36 | #endif -------------------------------------------------------------------------------- /src/modeldata/Serialization.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #include "Node.h" 18 | #include "NodePart.h" 19 | #include "Animation.h" 20 | #include "NodeAnimation.h" 21 | #include "Keyframe.h" 22 | #include "Material.h" 23 | #include "Attributes.h" 24 | #include "MeshPart.h" 25 | #include "Mesh.h" 26 | #include "Model.h" 27 | 28 | namespace fbxconv { 29 | namespace modeldata { 30 | 31 | //std::string versions = "0.4"; 32 | 33 | static const char* getPrimitiveTypeString(const int &primitiveTypeId) { 34 | switch(primitiveTypeId){ 35 | case 0: 36 | return "POINTS"; 37 | case 1: 38 | return "LINES"; 39 | case 3: 40 | return "LINE_STRIP"; 41 | case 4: 42 | return "TRIANGLES"; 43 | case 5: 44 | return "TRIANGLE_STRIP"; 45 | default: 46 | return "UNKNOWN"; 47 | } 48 | } 49 | static const char* getWrapModeUseString(const FbxFileTexture::EWrapMode &textureUse) 50 | { 51 | switch(textureUse){ 52 | case FbxFileTexture::eRepeat: 53 | return "REPEAT"; 54 | case FbxFileTexture::eClamp: 55 | return "CLAMP"; 56 | default: 57 | return "UNKNOWN"; 58 | } 59 | } 60 | static const char* getTextureUseString(const Material::Texture::Usage &textureUse) { 61 | switch(textureUse){ 62 | case Material::Texture::Ambient: 63 | return "AMBIENT"; 64 | case Material::Texture::Bump: 65 | return "BUMP"; 66 | case Material::Texture::Diffuse: 67 | return "DIFFUSE"; 68 | case Material::Texture::Emissive: 69 | return "EMISSIVE"; 70 | case Material::Texture::None: 71 | return "NONE"; 72 | case Material::Texture::Normal: 73 | return "NORMAL"; 74 | case Material::Texture::Reflection: 75 | return "REFLECTION"; 76 | case Material::Texture::Shininess: 77 | return "SHININESS"; 78 | case Material::Texture::Specular: 79 | return "SPECULAR"; 80 | case Material::Texture::Transparency: 81 | return "TRANSPARENCY"; 82 | default: 83 | return "UNKNOWN"; 84 | } 85 | } 86 | 87 | void Model::serialize(json::BaseJSONWriter &writer) const { 88 | 89 | std::list _bonenames; 90 | for (std::vector::const_iterator itr = nodes.begin(); itr != nodes.end(); ++itr) 91 | { 92 | (*itr)->loadBoneNames(_bonenames); 93 | } 94 | for (std::vector::const_iterator itr = nodes.begin(); itr != nodes.end(); ++itr) 95 | { 96 | bool skeleton=false; 97 | (*itr)->checkIsSkeleton(skeleton,_bonenames); 98 | (*itr)->setSkeleton(skeleton); 99 | } 100 | writer.obj(6); 101 | char szVersion[64] = {0}; 102 | sprintf(szVersion, "%d.%d", VERSION_HI, VERSION_LO); 103 | writer << "version" = szVersion; 104 | if(exportPart == EXPORT_PART_ALL || exportPart == EXPORT_PART_MODEL) 105 | { 106 | writer << "id" = id; 107 | writer << "meshes" = meshes; 108 | writer << "materials" = materials; 109 | writer << "nodes" = nodes; 110 | } 111 | 112 | if(exportPart == EXPORT_PART_ALL || exportPart == EXPORT_PART_ANIMATION) 113 | { 114 | writer << "animations" = animations; 115 | } 116 | writer.end(); 117 | } 118 | 119 | void Mesh::serialize(json::BaseJSONWriter &writer) const { 120 | writer.obj(3); 121 | writer << "attributes" = attributes; 122 | writer.val("vertices").is().data(vertices, vertexSize); 123 | writer << "parts" = parts; 124 | writer.end(); 125 | } 126 | 127 | void Attributes::serialize(json::BaseJSONWriter &writer) const { 128 | const unsigned int len = length(); 129 | writer.arr(len, 8); 130 | for (unsigned int i = 0; i < len; i++) 131 | { 132 | writer << json::obj; 133 | //const char *test = name(i); 134 | //writer.val(name(i)); 135 | 136 | //int size; 137 | //std::string type; 138 | //std::string name; 139 | 140 | MeshVertexAttrib v; 141 | std::string key = name(i); 142 | v = attributemap.find(key)->second; 143 | 144 | writer << "size" << v.size; 145 | writer << "type" << v.type; 146 | writer << "attribute" << v.name; 147 | writer << json::end; 148 | if(key == "VERTEX_ATTRIB_BLEND_INDEX") 149 | { 150 | break; 151 | } 152 | } 153 | writer.end(); 154 | } 155 | void MeshPart::serialize(json::BaseJSONWriter &writer) const { 156 | writer.obj(4); 157 | writer << "id" = id; 158 | writer << "type" = getPrimitiveTypeString(primitiveType); 159 | writer.val("indices").is().data(indices, 12); 160 | writer << "aabb" = aabb; 161 | writer << json::end; 162 | } 163 | 164 | void Material::serialize(json::BaseJSONWriter &writer) const { 165 | writer << json::obj; 166 | writer << "id" = id; 167 | if (ambient.valid) 168 | writer << "ambient" = ambient.value; 169 | if (diffuse.valid) 170 | writer << "diffuse" = diffuse.value; 171 | if (emissive.valid) 172 | writer << "emissive" = emissive.value; 173 | if (opacity.valid) 174 | writer << "opacity" = opacity.value; 175 | if (specular.valid) 176 | writer << "specular" = specular.value; 177 | if (shininess.valid) 178 | writer << "shininess" = shininess.value; 179 | if (!textures.empty()) 180 | writer << "textures" = textures; 181 | writer << json::end; 182 | } 183 | 184 | void Material::Texture::serialize(json::BaseJSONWriter &writer) const { 185 | writer << json::obj; 186 | writer << "id" = id; 187 | writer << "filename" = path; 188 | if (uvTranslation[0] != 0.f || uvTranslation[1] != 0.f) 189 | writer << "uvtranslation" = uvTranslation; 190 | if (uvScale[0] != 1.f || uvScale[1] != 1.f) 191 | writer << "uvscaling" = uvScale; 192 | writer << "type" = getTextureUseString(usage); 193 | writer << "wrapModeU" = getWrapModeUseString(wrapModeU); 194 | writer << "wrapModeV" =getWrapModeUseString(wrapModeV); 195 | writer << json::end; 196 | } 197 | 198 | void Node::serialize(json::BaseJSONWriter &writer) const { 199 | writer << json::obj; 200 | writer << "id" = id; 201 | writer << "skeleton" = _skeleton; 202 | writer << "transform" << transforms; 203 | //if (transform.rotation[0] != 0. || transform.rotation[1] != 0. || transform.rotation[2] != 0. || transform.rotation[3] != 1.) 204 | // writer << "rotation" = transform.rotation; 205 | //if (transform.scale[0] != 1. || transform.scale[1] != 1. || transform.scale[2] != 1.) 206 | // writer << "scale" = transform.scale; 207 | //if (transform.translation[0] != 0. || transform.translation[1] != 0. || transform.translation[2] != 0.) 208 | // writer << "translation" = transform.translation; 209 | if (!parts.empty()) 210 | writer << "parts" = parts; 211 | if (!children.empty()) 212 | writer << "children" = children; 213 | writer << json::end; 214 | } 215 | 216 | template void writeAsFloat(json::BaseJSONWriter &writer, const char *k, const T(&v)[n]) { 217 | static float tmp[n]; 218 | for (int i = 0; i < n; ++i) 219 | tmp[i] = (float)v[i]; 220 | writer << k << tmp; 221 | } 222 | 223 | void NodePart::serialize(json::BaseJSONWriter &writer) const { 224 | writer << json::obj; 225 | writer << "meshpartid" = meshPart->id; 226 | writer << "materialid" = material->id; 227 | if (!bones.empty()) { 228 | writer.val("bones").is().arr(); 229 | for (std::vector >::const_iterator it = bones.begin(); it != bones.end(); ++it) { 230 | writer << json::obj; 231 | writer << "node" = it->first->id; 232 | float tmp[16]; 233 | for(int i = 0; i < 4; i++) 234 | { 235 | for(int j = 0; j < 4; j++) 236 | { 237 | tmp[i*4 + j] = it->second.Double44()[i][j]; 238 | } 239 | } 240 | writer << "transform" << tmp; 241 | //writeAsFloat(writer, "translation", it->second.GetT().mData); 242 | //writeAsFloat(writer, "rotation", it->second.GetQ().mData); 243 | //writeAsFloat(writer, "scale", it->second.GetS().mData); 244 | writer << json::end; 245 | } 246 | writer.end(); 247 | } 248 | if (!uvMapping.empty()) { 249 | writer.val("uvMapping").is().arr(uvMapping.size(), 16); 250 | for (std::vector >::const_iterator it = uvMapping.begin(); it != uvMapping.end(); ++it) { 251 | writer.arr((*it).size(), 16); 252 | for (std::vector::const_iterator tt = (*it).begin(); tt != (*it).end(); ++tt) 253 | writer << material->getTextureIndex(*tt); 254 | writer.end(); 255 | } 256 | writer.end(); 257 | } 258 | writer << json::end; 259 | } 260 | 261 | void Animation::serialize(json::BaseJSONWriter &writer) const { 262 | writer.obj(2); 263 | writer << "id" = id; 264 | writer << "length" = length; 265 | writer << "bones" = nodeAnimations; 266 | writer.end(); 267 | } 268 | 269 | void NodeAnimation::serialize(json::BaseJSONWriter &writer) const { 270 | writer.obj(2); 271 | writer << "boneId" = node->id; 272 | writer << "keyframes" = keyframes; 273 | writer.end(); 274 | } 275 | 276 | void Keyframe::serialize(json::BaseJSONWriter &writer) const { 277 | writer << json::obj; 278 | writer << "keytime" = time; 279 | if (hasRotation) 280 | writer << "rotation" = rotation; 281 | if (hasScale) 282 | writer << "scale" = scale; 283 | if (hasTranslation) 284 | writer << "translation" = translation; 285 | writer << json::end; 286 | } 287 | 288 | } } -------------------------------------------------------------------------------- /src/readers/Reader.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif //_MSC_VER 20 | #ifndef FBXCONV_READERS_READER_H 21 | #define FBXCONV_READERS_READER_H 22 | 23 | #include "../modeldata/Model.h" 24 | 25 | using namespace fbxconv::modeldata; 26 | 27 | namespace fbxconv { 28 | namespace readers { 29 | 30 | class Reader { 31 | public: 32 | virtual ~Reader() {} 33 | virtual bool load(Settings *settings) = 0; 34 | virtual bool convert(Settings *settings, Model * const &model) = 0; 35 | }; 36 | 37 | } // readers 38 | } // fbxconv 39 | 40 | #endif //FBXCONV_READERS_READER_H -------------------------------------------------------------------------------- /src/readers/matrix3.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif //_MSC_VER 20 | #ifndef FBXCONV_READERS_MATRIX3_H 21 | #define FBXCONV_READERS_MATRIX3_H 22 | 23 | namespace fbxconv { 24 | namespace readers { 25 | // Quick and dirty matrix implementation, might not work as expected... 26 | template struct Matrix3 { 27 | T m[9]; 28 | T &x1; 29 | T &x2; 30 | T &x3; 31 | T &y1; 32 | T &y2; 33 | T &y3; 34 | T &z1; 35 | T &z2; 36 | T &z3; 37 | 38 | Matrix3() : x1(m[0]), x2(m[1]), x3(m[2]), y1(m[3]), y2(m[4]), y3(m[5]), z1(m[6]), z2(m[7]), z3(m[8]) { 39 | idt(); 40 | } 41 | 42 | Matrix3(const Matrix3 ©From) : x1(m[0]), x2(m[1]), x3(m[2]), y1(m[3]), y2(m[4]), y3(m[5]), z1(m[6]), z2(m[7]), z3(m[8]) { 43 | set(copyFrom); 44 | } 45 | 46 | inline Matrix3 &operator=(const Matrix3 &rhs) { 47 | return set(rhs); 48 | } 49 | 50 | inline Matrix3 &operator*=(const Matrix3 &rhs) { 51 | return mul(rhs); 52 | } 53 | 54 | inline Matrix3 &operator+=(const Matrix3 &rhs) { 55 | return add(rhs); 56 | } 57 | 58 | Matrix3 &idt() { 59 | return set(1.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 1.f); 60 | } 61 | 62 | Matrix3 &set(const Matrix3 &rhs) { 63 | return set(rhs.x1, rhs.x2, rhs.x3, rhs.y1, rhs.y2, rhs.y3, rhs.z1, rhs.z2, rhs.z3); 64 | } 65 | 66 | Matrix3 &set(const T &_x1, const T &_x2, const T &_x3, const T &_y1, const T &_y2, const T &_y3, const T &_z1, const T &_z2, const T &_z3) { 67 | x1 = _x1; x2 = _x2; x3 = _x3; 68 | y1 = _y1; y2 = _y2; y3 = _y3; 69 | z1 = _z1; z2 = _z2; z3 = _z3; 70 | return *this; 71 | } 72 | 73 | inline Matrix3 &scale(const T &x = (T)1., const T &y = (T)1., const T &z = (T)1.) { 74 | return mulr(x, y, z); 75 | } 76 | 77 | Matrix3 &rotate(const T &radians) { 78 | const T c = cos(radians); 79 | const T s = sin(radians); 80 | return mul(c, -s, s, c); 81 | } 82 | 83 | Matrix3 &translate(const T &x = (T)0., const T &y = (T)0.) { 84 | return set( x1, x2, x1 * x + x2 * y + x3, 85 | y1, y2, y1 * x + y2 * y + y3, 86 | z1, z2, z1 * x + z2 * y + z3); 87 | } 88 | 89 | Matrix3 &trn(const T &x = (T)0., const T &y = (T)0.) { 90 | x3 += x; 91 | y3 += y; 92 | return *this; 93 | } 94 | 95 | Matrix3 &mul(const Matrix3 &rhs) { 96 | return mul(rhs.x1, rhs.x2, rhs.x3, rhs.y1, rhs.y2, rhs.y3, rhs.z1, rhs.z2, rhs.z3); 97 | } 98 | 99 | Matrix3 &mul(const T &_x1, const T &_x2, const T &_x3, const T &_y1, const T &_y2, const T &_y3, const T &_z1, const T &_z2, const T &_z3) { 100 | return set( x1 * _x1 + x2 * _y1 + x3 * _z1, x1 * _x2 + x2 * _y2 + x3 * _z2, x1 * _x3 + x2 * _y3 + x3 * _z3, 101 | y1 * _x1 + y2 * _y1 + y3 * _z1, x2 * _x2 + y2 * _y2 + y3 * _z2, y1 * _x3 + y2 * _y3 + y3 * _z3, 102 | z1 * _x1 + z2 * _y1 + z3 * _z1, x3 * _x2 + z2 * _y2 + z3 * _z2, z1 * _x3 + z2 * _y3 + z3 * _z3); 103 | } 104 | 105 | Matrix3 &mulr(const T &x = (T)1., const T &y = (T)1., const T &z = (T)1.) { 106 | return set( x1 * x, z2 * y, x3 * z, 107 | y1 * x, y2 * y, y3 * z, 108 | z1 * x, z2 * y, z3 * z); 109 | } 110 | 111 | Matrix3 &mulc(const T &x = (T)1., const T &y = (T)1., const T &z = (T)1.) { 112 | return set( x1 * x, x2 * x, z3 * x, 113 | y1 * y, y2 * y, y3 * y, 114 | z1 * z, z2 * z, z3 * z); 115 | } 116 | 117 | Matrix3 &mul(const T &_x1, const T &_x2, const T &_y1, const T &_y2) { 118 | return set( x1 * _x1 + x2 * _y1, x1 * _x2 + x2 * _y2, x3, 119 | y1 * _x1 + y2 * _y1, y1 * _x2 + y2 * _y2, y3, 120 | z1 * _x1 + z2 * _y1, z1 * _x2 + z2 * _y2, z3); 121 | } 122 | 123 | Matrix3 &add(const Matrix3 &rhs) { 124 | return add(rhs.x1, rhs.x2, rhs.x3, rhs.y1, rhs.y2, rhs.y3, rhs.z1, rhs.z2, rhs.z3); 125 | } 126 | 127 | Matrix3 &add(const T &_x1, const T &_x2, const T &_x3, const T &_y1, const T &_y2, const T &_y3, const T &_z1, const T &_z2, const T &_z3) { 128 | return set(x1 + _x1, x2 + _x2, x3 + _x3, y1 + _y1, y2 + _y2, y3 + _y3, z1 + _z1, z2 + _z2, z3 * _z3); 129 | } 130 | 131 | void transform(float &x, float &y) const { 132 | const float _x = x, _y = y; 133 | x = x1 * _x + x2 * _y + x3; 134 | y = y1 * _x + y2 * _y + y3; 135 | } 136 | 137 | void transform(float &x, float &y, float &z) const { 138 | const float _x = x, _y = y, _z = z; 139 | x = x1 * _x + x2 * _y + x3 * _z; 140 | y = y1 * _x + y2 * _y + y3 * _z; 141 | z = z1 * _x + z2 * _y + z3 * _z; 142 | } 143 | }; 144 | } } 145 | 146 | #endif //FBXCONV_READERS_MATRIX3_H -------------------------------------------------------------------------------- /src/readers/util.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2011 See AUTHORS file. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | ******************************************************************************/ 16 | /** @author Xoppa */ 17 | #ifdef _MSC_VER 18 | #pragma once 19 | #endif //_MSC_VER 20 | #ifndef FBXCONV_READERS_UTIL_H 21 | #define FBXCONV_READERS_UTIL_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace fbxconv { 28 | namespace readers { 29 | 30 | // Index + weight pair for vertex blending 31 | struct BlendWeight { 32 | float weight; 33 | int index; 34 | BlendWeight() : weight(0.f), index(-1) {} 35 | BlendWeight(float w, int i) : weight(w), index(i) {} 36 | inline bool operator<(const BlendWeight& rhs) const { 37 | return weight < rhs.weight; 38 | } 39 | inline bool operator>(const BlendWeight& rhs) const { 40 | return weight > rhs.weight; 41 | } 42 | inline bool operator==(const BlendWeight& rhs) const { 43 | return weight == rhs.weight; 44 | } 45 | }; 46 | 47 | // Group of indices for vertex blending 48 | struct BlendBones { 49 | int *bones; 50 | unsigned int capacity; 51 | BlendBones(const unsigned int &capacity = 2) : capacity(capacity) { 52 | bones = new int[capacity]; 53 | memset(bones, -1, capacity * sizeof(int)); 54 | } 55 | BlendBones(const BlendBones &rhs) : capacity(rhs.capacity) { 56 | bones = new int[capacity]; 57 | memcpy(bones, rhs.bones, capacity * sizeof(int)); 58 | } 59 | ~BlendBones() { 60 | delete bones; 61 | } 62 | inline bool has(const int &bone) const { 63 | for (unsigned int i = 0; i < capacity; i++) 64 | if (bones[i] == bone) 65 | return true; 66 | return false; 67 | } 68 | inline unsigned int size() const { 69 | for (unsigned int i = 0; i < capacity; i++) 70 | if (bones[i] < 0) 71 | return i; 72 | return capacity; 73 | } 74 | inline unsigned int available() const { 75 | return capacity - size(); 76 | } 77 | inline int cost(const std::vector*> &rhs) const { 78 | int result = 0; 79 | for (std::vector*>::const_iterator itr = rhs.begin(); itr != rhs.end(); ++itr) 80 | for (std::vector::const_iterator jtr = (*itr)->begin(); jtr != (*itr)->end(); ++jtr) 81 | if (!has((*jtr).index)) 82 | result++; 83 | return (result > (int)available()) ? -1 : result; 84 | } 85 | inline void sort() { 86 | std::sort(bones, bones + size()); 87 | } 88 | inline int idx(const int &bone) const { 89 | for (unsigned int i = 0; i < capacity; i++) 90 | if (bones[i] == bone) 91 | return i; 92 | return -1; 93 | } 94 | inline int add(const int &v) { 95 | for (unsigned int i = 0; i < capacity; i++) { 96 | if (bones[i] == v) 97 | return i; 98 | else if (bones[i] < 0) { 99 | bones[i] = v; 100 | return i; 101 | } 102 | } 103 | return -1; 104 | } 105 | inline bool add(const std::vector*> &rhs) { 106 | for (std::vector*>::const_iterator itr = rhs.begin(); itr != rhs.end(); ++itr) 107 | for (std::vector::const_iterator jtr = (*itr)->begin(); jtr != (*itr)->end(); ++jtr) 108 | if (add((*jtr).index)<0) 109 | return false; 110 | return true; 111 | } 112 | inline int operator[](const unsigned int idx) const { 113 | return idx < capacity ? bones[idx] : -1; 114 | } 115 | inline BlendBones &operator=(const BlendBones &rhs) { 116 | if (&rhs == this) 117 | return *this; 118 | if (capacity != rhs.capacity) { 119 | delete[] bones; 120 | bones = new int[capacity = rhs.capacity]; 121 | } 122 | memcpy(bones, rhs.bones, capacity * sizeof(int)); 123 | return *this; 124 | } 125 | }; 126 | 127 | // Collection of group of indices for vertex blending 128 | struct BlendBonesCollection { 129 | std::vector bones; 130 | unsigned int bonesCapacity; 131 | BlendBonesCollection(const unsigned int &bonesCapacity) : bonesCapacity(bonesCapacity) { } 132 | BlendBonesCollection(const BlendBonesCollection &rhs) : bonesCapacity(rhs.bonesCapacity) { 133 | bones.insert(bones.begin(), rhs.bones.begin(), rhs.bones.end()); 134 | } 135 | inline BlendBonesCollection &operator=(const BlendBonesCollection &rhs) { 136 | if (&rhs == this) 137 | return (*this); 138 | bones = rhs.bones; 139 | bonesCapacity = rhs.bonesCapacity; 140 | return (*this); 141 | } 142 | inline unsigned int size() const { 143 | return (unsigned int)bones.size(); 144 | } 145 | inline BlendBones &operator[](const unsigned int &idx) { 146 | return bones[idx]; 147 | } 148 | inline unsigned int add(const std::vector*> &rhs) { 149 | int cost = (int)bonesCapacity, idx = -1, n = bones.size(); 150 | for (int i = 0; i < n; i++) { 151 | const int c = bones[i].cost(rhs); 152 | if (c >= 0 && c < cost) { 153 | cost = c; 154 | idx = i; 155 | } 156 | } 157 | if (idx < 0) { 158 | bones.push_back(BlendBones(bonesCapacity)); 159 | idx = n; 160 | } 161 | return bones[idx].add(rhs) ? idx : -1; 162 | } 163 | inline void sortBones() { 164 | for (std::vector::iterator itr = bones.begin(); itr != bones.end(); ++itr) 165 | (*itr).sort(); 166 | } 167 | }; 168 | 169 | // Provides information about an animation 170 | struct AnimInfo { 171 | float start; 172 | float stop; 173 | float framerate; 174 | bool translate; 175 | bool rotate; 176 | bool scale; 177 | 178 | AnimInfo() : start(FLT_MAX), stop(-1.f), framerate(0.f), translate(false), rotate(false), scale(false) {} 179 | 180 | inline AnimInfo& operator+=(const AnimInfo& rhs) { 181 | start = std::min(rhs.start, start); 182 | stop = std::max(rhs.stop, stop); 183 | framerate = std::max(rhs.framerate, framerate); 184 | translate = translate || rhs.translate; 185 | rotate = rotate || rhs.rotate; 186 | scale = scale || rhs.scale; 187 | return *this; 188 | } 189 | }; 190 | } } 191 | #endif //FBXCONV_READERS_UTIL_H --------------------------------------------------------------------------------