From cc5c698b1389c80db09bb639de562ee59351a414 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 23 Nov 2013 12:16:31 -0800 Subject: [PATCH] Updated to FBX SDK 2014.2 Nodes in the FBX file starting with so_ will no longer be decorated with fbx_##_ prefixes. Updated import pipeline for compatibility with C++11 --HG-- branch : nfb --- KREngine/Kraken.xcodeproj/project.pbxproj | 34 ++- KREngine/kraken/KRContext.cpp | 2 +- KREngine/kraken/KRDataBlock.cpp | 4 + KREngine/kraken/KREngine-common.h | 21 +- KREngine/kraken/KRMeshStreamer.mm | 35 ++- KREngine/kraken/KRResource+fbx.cpp | 248 ++++++++++++---------- KREngine/kraken/KRTextureStreamer.mm | 40 ++++ 7 files changed, 227 insertions(+), 157 deletions(-) diff --git a/KREngine/Kraken.xcodeproj/project.pbxproj b/KREngine/Kraken.xcodeproj/project.pbxproj index b3554fb..e9aabca 100644 --- a/KREngine/Kraken.xcodeproj/project.pbxproj +++ b/KREngine/Kraken.xcodeproj/project.pbxproj @@ -76,15 +76,15 @@ E43F70DC181B20E400136169 /* KRLODSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43F70DA181B20E300136169 /* KRLODSet.cpp */; }; E43F70DD181B20E400136169 /* KRLODSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43F70DA181B20E300136169 /* KRLODSet.cpp */; }; E43F70DE181B20E400136169 /* KRLODSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70DB181B20E400136169 /* KRLODSet.h */; }; - E43F70DF181B20E400136169 /* KRLODSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70DB181B20E400136169 /* KRLODSet.h */; }; + E43F70DF181B20E400136169 /* KRLODSet.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70DB181B20E400136169 /* KRLODSet.h */; settings = {ATTRIBUTES = (Public, ); }; }; E43F70E51824D9AB00136169 /* KRTextureStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70E31824D9AB00136169 /* KRTextureStreamer.mm */; }; E43F70E61824D9AB00136169 /* KRTextureStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70E31824D9AB00136169 /* KRTextureStreamer.mm */; }; E43F70E71824D9AB00136169 /* KRTextureStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70E41824D9AB00136169 /* KRTextureStreamer.h */; }; - E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70E41824D9AB00136169 /* KRTextureStreamer.h */; }; + E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70E41824D9AB00136169 /* KRTextureStreamer.h */; settings = {ATTRIBUTES = (Public, ); }; }; E43F70FF1824E73100136169 /* KRMeshStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70FD1824E73100136169 /* KRMeshStreamer.mm */; }; E43F71001824E73100136169 /* KRMeshStreamer.mm in Sources */ = {isa = PBXBuildFile; fileRef = E43F70FD1824E73100136169 /* KRMeshStreamer.mm */; }; E43F71011824E73100136169 /* KRMeshStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70FE1824E73100136169 /* KRMeshStreamer.h */; }; - E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70FE1824E73100136169 /* KRMeshStreamer.h */; }; + E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */ = {isa = PBXBuildFile; fileRef = E43F70FE1824E73100136169 /* KRMeshStreamer.h */; settings = {ATTRIBUTES = (Public, ); }; }; E4409D2916FA748700310F76 /* font.tga in Resources */ = {isa = PBXBuildFile; fileRef = E41AE1DD16B124CA00980428 /* font.tga */; }; E44F38241683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; settings = {ATTRIBUTES = (); }; }; E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = E44F38231683B22C00399B5D /* KRRenderSettings.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -102,7 +102,7 @@ E459040616C30CD9002B00A0 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E459040516C30CD9002B00A0 /* AudioUnit.framework */; }; E460292616681CFF00261BB9 /* KRTextureAnimated.h in Headers */ = {isa = PBXBuildFile; fileRef = E460292516681CFE00261BB9 /* KRTextureAnimated.h */; settings = {ATTRIBUTES = (); }; }; E460292816681D1000261BB9 /* KRTextureAnimated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E460292716681D1000261BB9 /* KRTextureAnimated.cpp */; }; - E460292B16682BF700261BB9 /* libfbxsdk-2013.3-static.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */; }; + E460292B16682BF700261BB9 /* libfbxsdk.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E460292916682BD900261BB9 /* libfbxsdk.a */; }; E460292C166834AB00261BB9 /* KRTextureAnimated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E460292716681D1000261BB9 /* KRTextureAnimated.cpp */; }; E461A152152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; settings = {ATTRIBUTES = (); }; }; E461A153152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -124,7 +124,7 @@ E468447F17FFDF51001F1FA1 /* KRLocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E468447D17FFDF51001F1FA1 /* KRLocator.cpp */; }; E468448017FFDF51001F1FA1 /* KRLocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E468447D17FFDF51001F1FA1 /* KRLocator.cpp */; }; E468448117FFDF51001F1FA1 /* KRLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = E468447E17FFDF51001F1FA1 /* KRLocator.h */; }; - E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = E468447E17FFDF51001F1FA1 /* KRLocator.h */; }; + E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */ = {isa = PBXBuildFile; fileRef = E468447E17FFDF51001F1FA1 /* KRLocator.h */; settings = {ATTRIBUTES = (Public, ); }; }; E46A6B6D1559E97D000DBD37 /* KRResource+blend.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46A6B6C1559E97D000DBD37 /* KRResource+blend.cpp */; }; E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */ = {isa = PBXBuildFile; fileRef = E46A6B6F1559EF0A000DBD37 /* KRResource+blend.h */; settings = {ATTRIBUTES = (Public, ); }; }; E46C214515364BC8009CABF3 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C214215364BC8009CABF3 /* tinyxml2.cpp */; }; @@ -451,7 +451,7 @@ E459040516C30CD9002B00A0 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; }; E460292516681CFE00261BB9 /* KRTextureAnimated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRTextureAnimated.h; sourceTree = ""; }; E460292716681D1000261BB9 /* KRTextureAnimated.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRTextureAnimated.cpp; sourceTree = ""; }; - E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libfbxsdk-2013.3-static.a"; path = "lib/gcc4/ub/libfbxsdk-2013.3-static.a"; sourceTree = FBXSDK; }; + E460292916682BD900261BB9 /* libfbxsdk.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfbxsdk.a; path = "../../FBX SDK/2014.2/lib/ios-i386/release/libfbxsdk.a"; sourceTree = FBXSDK; }; E461A151152E54B500F2044A /* KRLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRLight.h; sourceTree = ""; }; E461A155152E54F700F2044A /* KRLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = KRLight.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E461A157152E555400F2044A /* KRPointLight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRPointLight.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -671,7 +671,7 @@ E4BBBB9F1512A4B100F43B5B /* Cocoa.framework in Frameworks */, E497B95D151BF05F00D3DC67 /* CoreServices.framework in Frameworks */, E497B95F151BF09600D3DC67 /* SystemConfiguration.framework in Frameworks */, - E460292B16682BF700261BB9 /* libfbxsdk-2013.3-static.a in Frameworks */, + E460292B16682BF700261BB9 /* libfbxsdk.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1091,7 +1091,7 @@ E459040316C30CC5002B00A0 /* AudioUnit.framework */, E41B6BA916BE437800B510EB /* CoreAudio.framework */, 10CC33A3168530A300BB9846 /* libPVRTexLib.a */, - E460292916682BD900261BB9 /* libfbxsdk-2013.3-static.a */, + E460292916682BD900261BB9 /* libfbxsdk.a */, E4BBBB9A1512A48200F43B5B /* Foundation.framework */, E46DBE7D1512AD4900D59F86 /* OpenGL.framework */, E4F027D41697A02D00D4427D /* OpenAL.framework */, @@ -1293,7 +1293,6 @@ E497B948151BB89D00D3DC67 /* KRVector2.h in Headers */, E4D0683F1512A790005FFBEB /* KRVector3.h in Headers */, E461A177152E5C6600F2044A /* KRMat4.h in Headers */, - E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */, E4F975461536327C00FD60B2 /* KRMeshManager.h in Headers */, E497B94B151BCEE900D3DC67 /* KRResource.h in Headers */, E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */, @@ -1309,9 +1308,7 @@ E4F9754C153632F000FD60B2 /* KRCamera.h in Headers */, E4F975501536333500FD60B2 /* KRMesh.h in Headers */, E488399F15F92BE000BD66D5 /* KRBundleManager.h in Headers */, - E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */, E4AFC6BC15F7C95D00DDB4C8 /* KRSceneManager.h in Headers */, - E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */, E428C2F31669610500A16EDF /* KRAnimationManager.h in Headers */, E4D133661537685A0070068C /* KRShader.h in Headers */, E461A153152E54B500F2044A /* KRLight.h in Headers */, @@ -1328,7 +1325,6 @@ E428C312166971FF00A16EDF /* KRAnimationLayer.h in Headers */, E4AFC6B615F7C46800DDB4C8 /* KRAABB.cpp in Headers */, E428C3171669A24B00A16EDF /* KRAnimationAttribute.h in Headers */, - E43F70DF181B20E400136169 /* KRLODSet.h in Headers */, E4AFC6BE15F7C9E600DDB4C8 /* KROctreeNode.h in Headers */, E4AFC6BD15F7C9DA00DDB4C8 /* KROctree.h in Headers */, E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */, @@ -1361,8 +1357,12 @@ E44F38251683B23000399B5D /* KRRenderSettings.h in Headers */, E499BF1D16AE74FF007FCDBE /* KRTextureAnimated.h in Headers */, E4EC73C41720B1FF0065299F /* KRVector4.h in Headers */, + E468448217FFDF51001F1FA1 /* KRLocator.h in Headers */, + E43F70DF181B20E400136169 /* KRLODSet.h in Headers */, E4AE63601704FB0A00B460CD /* KRLODGroup.h in Headers */, E45134B91746A4A300443C21 /* KRBehavior.h in Headers */, + E43F71021824E73100136169 /* KRMeshStreamer.h in Headers */, + E43F70E81824D9AB00136169 /* KRTextureStreamer.h in Headers */, E48CF945173453990005EBBB /* KRFloat.h in Headers */, E499BF1F16AE753E007FCDBE /* KRCollider.h in Headers */, E499BF2316AE7636007FCDBE /* kraken-prefix.pch in Headers */, @@ -1847,7 +1847,6 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LIBRARY = "libstdc++"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1866,14 +1865,14 @@ GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; HEADER_SEARCH_PATHS = ( - "\"/Applications/Autodesk/FBX SDK/2013.3/include\"", + "\"/Applications/Autodesk/FBX SDK/2014.2/include\"", /usr/local/include, ); INFOPLIST_FILE = "kraken_osx/Kraken-Info.plist"; LD_DYLIB_INSTALL_NAME = "@rpath/${EXECUTABLE_PATH}"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", - "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2013.3/lib/gcc4/ub\"", + "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2014.2/lib/ios-i386/release\"", "\"$(SYSTEM_APPS_DIR)/Imagination/PowerVR/GraphicsSDK/PVRTexTool/Library/OSX_x86/Static\"", ); MACOSX_DEPLOYMENT_TARGET = 10.7; @@ -1891,7 +1890,6 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = YES; ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - CLANG_CXX_LIBRARY = "libstdc++"; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; @@ -1910,14 +1908,14 @@ GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; HEADER_SEARCH_PATHS = ( - "\"/Applications/Autodesk/FBX SDK/2013.3/include\"", + "\"/Applications/Autodesk/FBX SDK/2014.2/include\"", /usr/local/include, ); INFOPLIST_FILE = "kraken_osx/Kraken-Info.plist"; LD_DYLIB_INSTALL_NAME = "@rpath/${EXECUTABLE_PATH}"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", - "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2013.3/lib/gcc4/ub\"", + "\"$(SYSTEM_APPS_DIR)/Autodesk/FBX SDK/2014.2/lib/ios-i386/release\"", "\"$(SYSTEM_APPS_DIR)/Imagination/PowerVR/GraphicsSDK/PVRTexTool/Library/OSX_x86/Static\"", ); MACOSX_DEPLOYMENT_TARGET = 10.7; diff --git a/KREngine/kraken/KRContext.cpp b/KREngine/kraken/KRContext.cpp index fa4d2b9..a26e398 100644 --- a/KREngine/kraken/KRContext.cpp +++ b/KREngine/kraken/KRContext.cpp @@ -284,7 +284,7 @@ void KRContext::setStreamingEnabled(bool enable) void KRContext::getMemoryStats(long &free_memory) { free_memory = 0; -#if TARGET_OS_IPHONE +#if TARGET_OS_IPHONE || TARGET_OS_MAC mach_port_t host_port = mach_host_self(); mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t); vm_size_t pagesize = 0; diff --git a/KREngine/kraken/KRDataBlock.cpp b/KREngine/kraken/KRDataBlock.cpp index 28578f8..cfc2421 100644 --- a/KREngine/kraken/KRDataBlock.cpp +++ b/KREngine/kraken/KRDataBlock.cpp @@ -35,6 +35,10 @@ #include +int KRAKEN_MEM_PAGE_SIZE = getpagesize(); +#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) +#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) + KRAKEN_MEM_PAGE_SIZE) + int m_mapCount = 0; size_t m_mapSize = 0; size_t m_mapOverhead = 0; diff --git a/KREngine/kraken/KREngine-common.h b/KREngine/kraken/KREngine-common.h index 1edc1af..1b60047 100644 --- a/KREngine/kraken/KREngine-common.h +++ b/KREngine/kraken/KREngine-common.h @@ -71,10 +71,6 @@ using std::queue; #define KRAKEN_HAVE_BLAS 1 #endif -int KRAKEN_MEM_PAGE_SIZE = getpagesize(); - -#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) -#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRAKEN_MEM_PAGE_SIZE - 1)) + KRAKEN_MEM_PAGE_SIZE) #define KRENGINE_MAX_TEXTURE_UNITS 8 @@ -83,23 +79,11 @@ int KRAKEN_MEM_PAGE_SIZE = getpagesize(); #endif -#if TARGET_OS_IPHONE - #include using std::unordered_map; using std::unordered_multimap; using std::hash; -#else - -#include -using std::tr1::unordered_map; -using std::tr1::unordered_multimap; -using std::tr1::hash; - -#endif - - #if TARGET_OS_IPHONE #include @@ -137,9 +121,6 @@ using std::tr1::hash; #include #endif -#endif - - #if DEBUG #define GLDEBUG(x) \ @@ -205,3 +186,5 @@ fprintf(stderr, "Error at line number %d, in file %s. Returned %d for call %s\n" #include "KRVector3.h" #include "KRVector2.h" #include "KRBehavior.h" + +#endif diff --git a/KREngine/kraken/KRMeshStreamer.mm b/KREngine/kraken/KRMeshStreamer.mm index 1940386..3067fe3 100644 --- a/KREngine/kraken/KRMeshStreamer.mm +++ b/KREngine/kraken/KRMeshStreamer.mm @@ -13,11 +13,36 @@ #include -EAGLContext *gMeshStreamerContext; +#if TARGET_OS_IPHONE + +EAGLContext *gMeshStreamerContext = nil; + +#elif TARGET_OS_MAC + +NSOpenGLContext *gMeshStreamerContext = nil; + +#else + +#error Unsupported Platform +#endif KRMeshStreamer::KRMeshStreamer(KRContext &context) : m_context(context) { + +#if TARGET_OS_IPHONE gMeshStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup]; +#elif TARGET_OS_MAC + NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = + { + NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, + 0 + }; + NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease]; + gMeshStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease]; +#else + #error Unsupported Platform +#endif + m_stop = false; m_thread = std::thread(&KRMeshStreamer::run, this); } @@ -35,7 +60,15 @@ void KRMeshStreamer::run() pthread_setname_np("Kraken - Mesh Streamer"); std::chrono::microseconds sleep_duration( 100 ); + +#if TARGET_OS_IPHONE [EAGLContext setCurrentContext: gMeshStreamerContext]; +#elif TARGET_OS_MAC + [gMeshStreamerContext makeCurrentContext]; +#else + #error Unsupported Platform +#endif + while(!m_stop) { diff --git a/KREngine/kraken/KRResource+fbx.cpp b/KREngine/kraken/KRResource+fbx.cpp index c5ee30d..bb82a8f 100644 --- a/KREngine/kraken/KRResource+fbx.cpp +++ b/KREngine/kraken/KRResource+fbx.cpp @@ -34,21 +34,21 @@ #define IOS_REF (*(pSdkManager->GetIOSettings())) #endif -void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene); -void DestroySdkObjects(KFbxSdkManager* pSdkManager); -bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename); +void InitializeSdkObjects(FbxManager*& pSdkManager, FbxScene*& pScene); +void DestroySdkObjects(FbxManager* pSdkManager); +bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename); KRAnimation *LoadAnimation(KRContext &context, FbxAnimStack* pAnimStack); KRAnimationCurve *LoadAnimationCurve(KRContext &context, FbxAnimCurve* pAnimCurve); KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLayer); -void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode); +void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode); //void BakeNode(KFbxNode* pNode); void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial); -void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh); -KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode); -KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode); -KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pScene, KFbxNode* pNode); -KRNode *LoadLocator(KRNode *parent_node, FbxScene* pScene, KFbxNode* pNode); -KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode); +void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxMesh* pSourceMesh); +KRNode *LoadMesh(KRNode *parent_node, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode); +KRNode *LoadLight(KRNode *parent_node, FbxNode* pNode); +KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pScene, FbxNode* pNode); +KRNode *LoadLocator(KRNode *parent_node, FbxScene* pScene, FbxNode* pNode); +KRNode *LoadCamera(KRNode *parent_node, FbxNode* pNode); std::string GetFbxObjectName(FbxObject *obj); const float KRAKEN_FBX_ANIMATION_FRAMERATE = 30.0f; // FINDME - This should be configurable @@ -57,12 +57,12 @@ const float KRAKEN_FBX_ANIMATION_FRAMERATE = 30.0f; // FINDME - This should be c std::string GetFbxObjectName(FbxObject *obj) { bool is_locator = false; - KFbxNode *node = FbxCast(obj); + FbxNode *node = FbxCast(obj); if(node) { - KFbxNodeAttribute::EType attribute_type = (node->GetNodeAttribute()->GetAttributeType()); - if(attribute_type == KFbxNodeAttribute::eNull) { - KFbxNull* pSourceNull = (KFbxNull*) node->GetNodeAttribute(); - if(pSourceNull->Look.Get() == KFbxNull::eCross ) { + FbxNodeAttribute::EType attribute_type = (node->GetNodeAttribute()->GetAttributeType()); + if(attribute_type == FbxNodeAttribute::eNull) { + FbxNull* pSourceNull = (FbxNull*) node->GetNodeAttribute(); + if(pSourceNull->Look.Get() == FbxNull::eCross ) { is_locator = true; } } @@ -74,6 +74,9 @@ std::string GetFbxObjectName(FbxObject *obj) if(is_locator) { // We do not rename locators return std::string(obj->GetName()); + } else if(strncmp(obj->GetName(), "so_", 3) == 0) { + // An so_ prefix indicates that this is a "Scriptable Object" that should not have the name decorated; + return obj->GetName(); } else if(strcmp(obj->GetName(), "default_camera") == 0) { // There is currently support for rendering from only one camera, "default_camera". We don't translate this node's name, so that animations can drive the camera return "default_camera"; @@ -94,8 +97,8 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) KRScene *pScene = new KRScene(context, KRResource::GetFileBase(path)); context.getSceneManager()->add(pScene); - KFbxSdkManager* lSdkManager = NULL; - KFbxScene* pFbxScene = NULL; + FbxManager* lSdkManager = NULL; + FbxScene* pFbxScene = NULL; bool lResult; FbxGeometryConverter *pGeometryConverter = NULL; @@ -108,7 +111,7 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) // Load the scene. lResult = LoadScene(lSdkManager, pFbxScene, path.c_str()); - KFbxNode* pNode = pFbxScene->GetRootNode(); + FbxNode* pNode = pFbxScene->GetRootNode(); // ----====---- Bake pivots into transforms, as Kraken doesn't support them directly ----====---- /* @@ -189,11 +192,11 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path) DestroySdkObjects(lSdkManager); } -void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene) +void InitializeSdkObjects(FbxManager*& pSdkManager, FbxScene*& pScene) { // The first thing to do is to create the FBX SDK manager which is the // object allocator for almost all the classes in the SDK. - pSdkManager = KFbxSdkManager::Create(); + pSdkManager = FbxManager::Create(); if (!pSdkManager) { @@ -202,25 +205,27 @@ void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene) } // create an IOSettings object - KFbxIOSettings * ios = KFbxIOSettings::Create(pSdkManager, IOSROOT ); + FbxIOSettings * ios = FbxIOSettings::Create(pSdkManager, IOSROOT ); pSdkManager->SetIOSettings(ios); // Load plugins from the executable directory - KString lPath = FbxGetApplicationDirectory(); -#if defined(KARCH_ENV_WIN) - KString lExtension = "dll"; -#elif defined(KARCH_ENV_MACOSX) - KString lExtension = "dylib"; -#elif defined(KARCH_ENV_LINUX) - KString lExtension = "so"; + FbxString lPath = FbxGetApplicationDirectory(); +#if TARGET_OS_WIN32 + FbxString lExtension = "dll"; +#elif TARGET_OS_MAC + FbxString lExtension = "dylib"; +#elif TARGET_OS_UNIX + FbxString lExtension = "so"; +#elif + #error Unsupported Platform #endif pSdkManager->LoadPluginsDirectory(lPath.Buffer(), lExtension.Buffer()); // Create the entity that will hold the scene. - pScene = KFbxScene::Create(pSdkManager,""); + pScene = FbxScene::Create(pSdkManager,""); } -void DestroySdkObjects(KFbxSdkManager* pSdkManager) +void DestroySdkObjects(FbxManager* pSdkManager) { // Delete the FBX SDK manager. All the objects that have been allocated // using the FBX SDK manager and that haven't been explicitly destroyed @@ -230,7 +235,7 @@ void DestroySdkObjects(KFbxSdkManager* pSdkManager) } -bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename) +bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilename) { int lFileMajor, lFileMinor, lFileRevision; int lSDKMajor, lSDKMinor, lSDKRevision; @@ -240,10 +245,10 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF char lPassword[1024]; // Get the file version number generate by the FBX SDK. - KFbxSdkManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision); + FbxManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision); // Create an importer. - KFbxImporter* lImporter = KFbxImporter::Create(pSdkManager,""); + FbxImporter* lImporter = FbxImporter::Create(pSdkManager,""); // Initialize the importer by providing a filename. const bool lImportStatus = lImporter->Initialize(pFilename, -1, pSdkManager->GetIOSettings()); @@ -251,11 +256,14 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF if( !lImportStatus ) { - printf("Call to KFbxImporter::Initialize() failed.\n"); - printf("Error returned: %s\n\n", lImporter->GetLastErrorString()); + FbxStatus &status = lImporter->GetStatus(); - if (lImporter->GetLastErrorID() == FbxIOBase::eFileVersionNotSupportedYet || - lImporter->GetLastErrorID() == FbxIOBase::eFileVersionNotSupportedAnymore) + printf("Call to KFbxImporter::Initialize() failed.\n"); + printf("Error returned: %s\n\n", status.GetErrorString()); + + + + if (status.GetCode() == FbxStatus::EStatusCode::eInvalidFileVersion) { printf("FBX version number for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision); printf("FBX version number for file %s is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision); @@ -299,21 +307,21 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF // Import the scene. lStatus = lImporter->Import(pScene); - if(lStatus == false && lImporter->GetLastErrorID() == FbxIOBase::ePasswordError) + if(lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) { printf("Please enter password: "); lPassword[0] = '\0'; scanf("%s", lPassword); - KString lString(lPassword); + FbxString lString(lPassword); IOS_REF.SetStringProp(IMP_FBX_PASSWORD, lString); IOS_REF.SetBoolProp(IMP_FBX_PASSWORD_ENABLE, true); lStatus = lImporter->Import(pScene); - if(lStatus == false && lImporter->GetLastErrorID() == FbxIOBase::ePasswordError) + if(lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) { printf("\nPassword is wrong, import aborted.\n"); } @@ -561,8 +569,8 @@ KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLaye // } //} -void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) { - KFbxVector4 lTmpVector; +void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode) { + FbxVector4 lTmpVector; pNode->UpdatePropertiesFromPivotsAndLimits(); @@ -832,26 +840,26 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p } } - fbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSourcePivot); - fbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSourcePivot); - fbxDouble3 local_scale = pNode->LclScaling.Get(); // pNode->GetGeometricScaling(KFbxNode::eSourcePivot); + FbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSourcePivot); + FbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSourcePivot); + FbxDouble3 local_scale = pNode->LclScaling.Get(); // pNode->GetGeometricScaling(KFbxNode::eSourcePivot); bool rotation_active = pNode->RotationActive.Get(); - fbxDouble3 post_rotation = pNode->PostRotation.Get(); - fbxDouble3 pre_rotation = pNode->PreRotation.Get(); - fbxDouble3 rotation_offset = pNode->RotationOffset.Get(); - fbxDouble3 scaling_offset = pNode->ScalingOffset.Get(); - fbxDouble3 rotation_pivot = pNode->RotationPivot.Get(); - fbxDouble3 scaling_pivot = pNode->ScalingPivot.Get(); - fbxDouble3 geometric_rotation = pNode->GeometricRotation.Get(); - fbxDouble3 geometric_translation = pNode->GeometricTranslation.Get(); - fbxDouble3 geometric_scaling = pNode->GeometricScaling.Get(); - ERotationOrder rotation_order = pNode->RotationOrder.Get(); + FbxDouble3 post_rotation = pNode->PostRotation.Get(); + FbxDouble3 pre_rotation = pNode->PreRotation.Get(); + FbxDouble3 rotation_offset = pNode->RotationOffset.Get(); + FbxDouble3 scaling_offset = pNode->ScalingOffset.Get(); + FbxDouble3 rotation_pivot = pNode->RotationPivot.Get(); + FbxDouble3 scaling_pivot = pNode->ScalingPivot.Get(); + FbxDouble3 geometric_rotation = pNode->GeometricRotation.Get(); + FbxDouble3 geometric_translation = pNode->GeometricTranslation.Get(); + FbxDouble3 geometric_scaling = pNode->GeometricScaling.Get(); + EFbxRotationOrder rotation_order = pNode->RotationOrder.Get(); - KFbxVector4 lZero(0.0, 0.0, 0.0); - KFbxVector4 lOne(1.0, 1.0, 1.0); + FbxVector4 lZero(0.0, 0.0, 0.0); + FbxVector4 lOne(1.0, 1.0, 1.0); assert(geometric_rotation == lZero); assert(geometric_translation == lZero); @@ -879,8 +887,8 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p // printf(" Local Rotation: %f %f %f\n", local_rotation[0], local_rotation[1], local_rotation[2]); // printf(" Local Scaling: %f %f %f\n", local_scale[0], local_scale[1], local_scale[2]); - KFbxNodeAttribute::EType attribute_type = (pNode->GetNodeAttribute()->GetAttributeType()); - if(attribute_type == KFbxNodeAttribute::eLODGroup) { + FbxNodeAttribute::EType attribute_type = (pNode->GetNodeAttribute()->GetAttributeType()); + if(attribute_type == FbxNodeAttribute::eLODGroup) { std::string name = GetFbxObjectName(pNode); FbxLODGroup *fbx_lod_group = (FbxLODGroup*) pNode->GetNodeAttribute(); // FbxCast(pNode); bool use_world_space_units = fbx_lod_group->WorldSpace.Get(); @@ -964,25 +972,25 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *p } else { KRNode *new_node = NULL; switch(attribute_type) { - case KFbxNodeAttribute::eMesh: + case FbxNodeAttribute::eMesh: new_node = LoadMesh(parent_node, pFbxScene, pGeometryConverter, pNode); break; - case KFbxNodeAttribute::eLight: + case FbxNodeAttribute::eLight: new_node = LoadLight(parent_node, pNode); break; - case KFbxNodeAttribute::eSkeleton: + case FbxNodeAttribute::eSkeleton: new_node = LoadSkeleton(parent_node, pFbxScene, pNode); break; - case KFbxNodeAttribute::eCamera: + case FbxNodeAttribute::eCamera: new_node = LoadCamera(parent_node, pNode); break; default: { bool is_locator = false; - if(attribute_type == KFbxNodeAttribute::eNull) { - KFbxNull* pSourceNull = (KFbxNull*) pNode->GetNodeAttribute(); - if(pSourceNull->Look.Get() == KFbxNull::eCross ) { + if(attribute_type == FbxNodeAttribute::eNull) { + FbxNull* pSourceNull = (FbxNull*) pNode->GetNodeAttribute(); + if(pSourceNull->Look.Get() == FbxNull::eCross ) { is_locator = true; } } @@ -1059,7 +1067,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { FbxPropertyT lKFbxDouble3; FbxPropertyT lKFbxDouble1; - if (pMaterial->GetClassId().Is(KFbxSurfacePhong::ClassId)) { + if (pMaterial->GetClassId().Is(FbxSurfacePhong::ClassId)) { // We found a Phong material. // Ambient Color @@ -1067,11 +1075,11 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Diffuse Color - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Diffuse; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Diffuse; new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Specular Color (unique to Phong materials) - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Specular; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Specular; new_material->setSpecular(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Emissive Color @@ -1084,7 +1092,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { */ // Shininess - lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->Shininess; + lKFbxDouble1 =((FbxSurfacePhong *) pMaterial)->Shininess; new_material->setShininess(lKFbxDouble1.Get()); /* @@ -1094,27 +1102,27 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { */ // Transparency Color - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->TransparentColor; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->TransparentColor; new_material->setTransparency( 1.0f - (lKFbxDouble3.Get()[0] + lKFbxDouble3.Get()[1] + lKFbxDouble3.Get()[2]) / 3.0f); // Reflection factor - lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->ReflectionFactor; + lKFbxDouble1 =((FbxSurfacePhong *) pMaterial)->ReflectionFactor; // Reflection color - lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Reflection; + lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Reflection; // We modulate Relection color by reflection factor, as we only have one "reflection color" variable in Kraken new_material->setReflection(KRVector3(lKFbxDouble3.Get()[0] * lKFbxDouble1.Get(), lKFbxDouble3.Get()[1] * lKFbxDouble1.Get(), lKFbxDouble3.Get()[2] * lKFbxDouble1.Get())); - } else if(pMaterial->GetClassId().Is(KFbxSurfaceLambert::ClassId) ) { + } else if(pMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId) ) { // We found a Lambert material. // Ambient Color - lKFbxDouble3=((KFbxSurfaceLambert *)pMaterial)->Ambient; + lKFbxDouble3=((FbxSurfaceLambert *)pMaterial)->Ambient; new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Diffuse Color - lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Diffuse; + lKFbxDouble3 =((FbxSurfaceLambert *)pMaterial)->Diffuse; new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); // Emissive @@ -1126,7 +1134,7 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { */ // Transparency Color - lKFbxDouble3 =((KFbxSurfaceLambert *) pMaterial)->TransparentColor; + lKFbxDouble3 =((FbxSurfaceLambert *) pMaterial)->TransparentColor; new_material->setTransparency(1.0f - (lKFbxDouble3.Get()[0] + lKFbxDouble3.Get()[1] + lKFbxDouble3.Get()[2]) / 3.0f); } else { @@ -1135,31 +1143,31 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { - KFbxProperty pProperty; + FbxProperty pProperty; // Diffuse Map Texture - pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sDiffuse); - if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) { + pProperty = pMaterial->FindProperty(FbxSurfaceMaterial::sDiffuse); + if(pProperty.GetSrcObjectCount(FbxLayeredTexture::ClassId) > 0) { printf("Warning! Layered textures not supported.\n"); } - int texture_count = pProperty.GetSrcObjectCount(KFbxTexture::ClassId); + int texture_count = pProperty.GetSrcObjectCount(FbxTexture::ClassId); if(texture_count > 1) { printf("Error! Multiple diffuse textures not supported.\n"); } else if(texture_count == 1) { - KFbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(KFbxTexture::ClassId,0)); + FbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(FbxTexture::ClassId,0)); assert(!pTexture->GetSwapUV()); assert(pTexture->GetCroppingTop() == 0); assert(pTexture->GetCroppingLeft() == 0); assert(pTexture->GetCroppingRight() == 0); assert(pTexture->GetCroppingBottom() == 0); - assert(pTexture->GetWrapModeU() == KFbxTexture::eRepeat); - assert(pTexture->GetWrapModeV() == KFbxTexture::eRepeat); + assert(pTexture->GetWrapModeU() == FbxTexture::eRepeat); + assert(pTexture->GetWrapModeV() == FbxTexture::eRepeat); assert(pTexture->GetRotationU() == 0.0f); assert(pTexture->GetRotationV() == 0.0f); assert(pTexture->GetRotationW() == 0.0f); - KFbxFileTexture *pFileTexture = FbxCast(pTexture); + FbxFileTexture *pFileTexture = FbxCast(pTexture); if(pFileTexture) { new_material->setDiffuseMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV())); } @@ -1167,24 +1175,24 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { // Specular Map Texture - pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sSpecular); - if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) { + pProperty = pMaterial->FindProperty(FbxSurfaceMaterial::sSpecular); + if(pProperty.GetSrcObjectCount(FbxLayeredTexture::ClassId) > 0) { printf("Warning! Layered textures not supported.\n"); } - texture_count = pProperty.GetSrcObjectCount(KFbxTexture::ClassId); + texture_count = pProperty.GetSrcObjectCount(FbxTexture::ClassId); if(texture_count > 1) { printf("Error! Multiple specular textures not supported.\n"); } else if(texture_count == 1) { - KFbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(KFbxTexture::ClassId,0)); - KFbxFileTexture *pFileTexture = FbxCast(pTexture); + FbxTexture* pTexture = FbxCast (pProperty.GetSrcObject(FbxTexture::ClassId,0)); + FbxFileTexture *pFileTexture = FbxCast(pTexture); if(pFileTexture) { new_material->setSpecularMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV())); } } // Normal Map Texture - pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sNormalMap); - if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) { + pProperty = pMaterial->FindProperty(FbxSurfaceMaterial::sNormalMap); + if(pProperty.GetSrcObjectCount(FbxLayeredTexture::ClassId) > 0) { printf("Warning! Layered textures not supported.\n"); } @@ -1193,8 +1201,8 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { if(texture_count > 1) { printf("Error! Multiple normal map textures not supported.\n"); } else if(texture_count == 1) { - KFbxTexture* pTexture = pProperty.GetSrcObject(0); - KFbxFileTexture *pFileTexture = FbxCast(pTexture); + FbxTexture* pTexture = pProperty.GetSrcObject(0); + FbxFileTexture *pFileTexture = FbxCast(pTexture); if(pFileTexture) { new_material->setNormalMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV())); } @@ -1211,8 +1219,8 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { -void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh) { - KFbxMesh* pMesh = pGeometryConverter->TriangulateMesh(pSourceMesh); +void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxMesh* pSourceMesh) { + FbxMesh* pMesh = pGeometryConverter->TriangulateMesh(pSourceMesh); KRMesh::mesh_info mi; mi.format = KRMesh::KRENGINE_MODEL_FORMAT_TRIANGLES; @@ -1223,7 +1231,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG } control_point_weight_info_t; int control_point_count = pMesh->GetControlPointsCount(); - KFbxVector4* control_points = pMesh->GetControlPoints(); + FbxVector4* control_points = pMesh->GetControlPoints(); control_point_weight_info_t *control_point_weights = new control_point_weight_info_t[control_point_count]; for(int control_point=0; control_point < control_point_count; control_point++) { @@ -1346,7 +1354,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG bool need_tangents = false; for(int iMaterial=0; iMaterial < material_count; iMaterial++) { - KFbxSurfaceMaterial *pMaterial = pSourceMesh->GetNode()->GetMaterial(iMaterial); + FbxSurfaceMaterial *pMaterial = pSourceMesh->GetNode()->GetMaterial(iMaterial); KRMaterial *material = context.getMaterialManager()->getMaterial(pMaterial->GetName()); if(material) { @@ -1384,7 +1392,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG for(int iVertex=0; iVertex<3; iVertex++) { // ----====---- Read Vertex Position ----====---- int lControlPointIndex = pMesh->GetPolygonVertex(iPolygon, iVertex); - KFbxVector4 v = control_points[lControlPointIndex]; + FbxVector4 v = control_points[lControlPointIndex]; mi.vertices.push_back(KRVector3(v[0], v[1], v[2])); if(mi.bone_names.size() > 0) { @@ -1405,12 +1413,14 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG // ----====---- Read UVs ----====---- - KStringList uvNames; + FbxStringList uvNames; pMesh->GetUVSetNames(uvNames); if(uv_count >= 1) { const char *setName = uvNames[0].Buffer(); - KFbxVector2 uv; - if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv)) { + FbxVector2 uv; + bool unmapped = false; + if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv, unmapped)) { + assert(!unmapped); new_uva = KRVector2(uv[0], uv[1]); } mi.uva.push_back(new_uva); @@ -1418,8 +1428,10 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG if(uv_count >= 2) { const char *setName = uvNames[1].Buffer(); - KFbxVector2 uv; - if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv)) { + FbxVector2 uv; + bool unmapped = false; + if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv, unmapped)) { + assert(!unmapped); new_uvb = KRVector2(uv[0], uv[1]); } mi.uvb.push_back(new_uvb); @@ -1427,7 +1439,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG // ----====---- Read Normals ----====---- - KFbxVector4 new_normal; + FbxVector4 new_normal; if(pMesh->GetPolygonVertexNormal(iPolygon, iVertex, new_normal)) { mi.normals.push_back(KRVector3(new_normal[0], new_normal[1], new_normal[2])); } @@ -1436,7 +1448,7 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG // ----====---- Read Tangents ----====---- for(int l = 0; l < tangent_count; ++l) { - KFbxVector4 new_tangent; + FbxVector4 new_tangent; FbxGeometryElementTangent* leTangent = pMesh->GetElementTangent(l); if(leTangent->GetMappingMode() == FbxGeometryElement::eByPolygonVertex) { @@ -1488,10 +1500,10 @@ void LoadMesh(KRContext &context, KFbxScene* pFbxScene, FbxGeometryConverter *pG context.getModelManager()->addModel(new_mesh); } -KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) { +KRNode *LoadMesh(KRNode *parent_node, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode) { std::string name = GetFbxObjectName(pNode); - KFbxMesh* pSourceMesh = (KFbxMesh*) pNode->GetNodeAttribute(); + FbxMesh* pSourceMesh = (FbxMesh*) pNode->GetNodeAttribute(); if(KRMesh::GetLODCoverage(pNode->GetName()) == 100) { // If this is the full detail model, add an instance of it to the scene file @@ -1516,7 +1528,7 @@ KRNode *LoadMesh(KRNode *parent_node, KFbxScene* pFbxScene, FbxGeometryConverter } -KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) { +KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) { std::string name = GetFbxObjectName(pNode); KRBone *new_bone = new KRBone(parent_node->getScene(), name.c_str()); @@ -1530,7 +1542,7 @@ KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) return new_bone; } -KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) { +KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) { std::string name = GetFbxObjectName(pNode); KRLocator *new_locator = new KRLocator(parent_node->getScene(), name.c_str()); @@ -1545,7 +1557,7 @@ KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, KFbxNode* pNode) { return new_locator; } -KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode) { +KRNode *LoadCamera(KRNode *parent_node, FbxNode* pNode) { FbxCamera *camera = (FbxCamera *)pNode->GetNodeAttribute(); const char *szName = pNode->GetName(); @@ -1553,7 +1565,7 @@ KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode) { return new_camera; } -KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { +KRNode *LoadLight(KRNode *parent_node, FbxNode* pNode) { const GLfloat PI = 3.14159265; const GLfloat d2r = PI * 2 / 360; @@ -1564,7 +1576,7 @@ KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { FbxDouble light_intensity = pLight->Intensity.Get(); FbxDouble light_hotspot = pLight->InnerAngle.Get(); // light inner cone angle (in degrees). Also know as the HotSpot FbxDouble light_coneangle = pLight->OuterAngle.Get(); // light outer cone angle (in degrees). Also known as the Falloff - KFbxLight::EDecayType light_decaytype = pLight->DecayType.Get(); // decay type + FbxLight::EDecayType light_decaytype = pLight->DecayType.Get(); // decay type FbxDouble light_decaystart = pLight->DecayStart.Get(); // decay start distance @@ -1576,20 +1588,20 @@ KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { KRLight *new_light = NULL; switch(pLight->LightType.Get()) { - case KFbxLight::ePoint: + case FbxLight::ePoint: { KRPointLight *l = new KRPointLight(parent_node->getScene(), szName); new_light = l; } break; - case KFbxLight::eDirectional: + case FbxLight::eDirectional: { KRDirectionalLight *l = new KRDirectionalLight(parent_node->getScene(), szName); new_light = l; } break; - case KFbxLight::eSpot: + case FbxLight::eSpot: { KRSpotLight *l = new KRSpotLight(parent_node->getScene(), szName); l->setInnerAngle(light_hotspot * d2r); @@ -1597,8 +1609,8 @@ KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) { new_light = l; } break; - case KFbxLight::eVolume: - case KFbxLight::eArea: + case FbxLight::eVolume: + case FbxLight::eArea: // Not supported yet break; } diff --git a/KREngine/kraken/KRTextureStreamer.mm b/KREngine/kraken/KRTextureStreamer.mm index 5dc8682..46043cc 100644 --- a/KREngine/kraken/KRTextureStreamer.mm +++ b/KREngine/kraken/KRTextureStreamer.mm @@ -13,8 +13,21 @@ #include + +#if TARGET_OS_IPHONE + EAGLContext *gTextureStreamerContext = nil; +#elif TARGET_OS_MAC + +NSOpenGLContext *gTextureStreamerContext = nil; + +#else + +#error Unsupported Platform +#endif + + KRTextureStreamer::KRTextureStreamer(KRContext &context) : m_context(context) { m_running = false; @@ -25,7 +38,27 @@ void KRTextureStreamer::startStreamer() { if(!m_running) { m_running = true; + +#if TARGET_OS_IPHONE + gTextureStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup]; + + +#elif TARGET_OS_MAC + + NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = + { + NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, + 0 + }; + NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease]; + gTextureStreamerContext = [[[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ] autorelease]; + +#else + + #error Unsupported Platform +#endif + m_thread = std::thread(&KRTextureStreamer::run, this); } } @@ -43,7 +76,14 @@ void KRTextureStreamer::run() pthread_setname_np("Kraken - Texture Streamer"); std::chrono::microseconds sleep_duration( 100 ); + +#if TARGET_OS_IPHONE [EAGLContext setCurrentContext: gTextureStreamerContext]; +#elif TARGET_OS_MAC + [gTextureStreamerContext makeCurrentContext]; +#else +#error Unsupported Platform +#endif while(!m_stop) {