Simplified FBX import pipeline. Resources are now immediately stored in their associated manager classes. You can access the imported resources through KRContext::getResources
This commit is contained in:
@@ -160,7 +160,7 @@ std::vector<KRResource *> KRContext::getResources()
|
|||||||
|
|
||||||
unordered_map<std::string, unordered_map<std::string, KRUnknown *> > unknowns = m_pUnknownManager->getUnknowns();
|
unordered_map<std::string, unordered_map<std::string, KRUnknown *> > unknowns = m_pUnknownManager->getUnknowns();
|
||||||
for(unordered_map<std::string, unordered_map<std::string, KRUnknown *> >::iterator itr = unknowns.begin(); itr != unknowns.end(); itr++) {
|
for(unordered_map<std::string, unordered_map<std::string, KRUnknown *> >::iterator itr = unknowns.begin(); itr != unknowns.end(); itr++) {
|
||||||
for(unordered_map<std::string, KRUnknown *>::iterator itr2 = (*itr).second.begin(); itr2 != (*itr).second.end(); itr++) {
|
for(unordered_map<std::string, KRUnknown *>::iterator itr2 = (*itr).second.begin(); itr2 != (*itr).second.end(); itr2++) {
|
||||||
resources.push_back((*itr2).second);
|
resources.push_back((*itr2).second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -202,6 +202,14 @@ void KRContext::loadResource(const std::string &file_name, KRDataBlock *data) {
|
|||||||
m_pSoundManager->load(name.c_str(), extension, data);
|
m_pSoundManager->load(name.c_str(), extension, data);
|
||||||
} else if(extension.compare("aac") == 0) {
|
} else if(extension.compare("aac") == 0) {
|
||||||
m_pSoundManager->load(name.c_str(), extension, data);
|
m_pSoundManager->load(name.c_str(), extension, data);
|
||||||
|
} else if(extension.compare("obj") == 0) {
|
||||||
|
KRResource::LoadObj(*this, file_name);
|
||||||
|
#if TARGET_OS_MAC
|
||||||
|
} else if(extension.compare("fbx") == 0) {
|
||||||
|
KRResource::LoadFbx(*this, file_name);
|
||||||
|
} else if(extension.compare("blend") == 0) {
|
||||||
|
KRResource::LoadBlenderScene(*this, file_name);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
m_pUnknownManager->load(name, extension, data);
|
m_pUnknownManager->load(name, extension, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,15 +39,14 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF
|
|||||||
KRAnimation *LoadAnimation(KRContext &context, FbxAnimStack* pAnimStack);
|
KRAnimation *LoadAnimation(KRContext &context, FbxAnimStack* pAnimStack);
|
||||||
KRAnimationCurve *LoadAnimationCurve(KRContext &context, FbxAnimCurve* pAnimCurve);
|
KRAnimationCurve *LoadAnimationCurve(KRContext &context, FbxAnimCurve* pAnimCurve);
|
||||||
KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLayer);
|
KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLayer);
|
||||||
void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
||||||
//void BakeNode(KFbxNode* pNode);
|
//void BakeNode(KFbxNode* pNode);
|
||||||
void LoadMaterial(KRContext &context, std::vector<KRResource *> &resources, FbxSurfaceMaterial *pMaterial);
|
void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial);
|
||||||
void LoadMesh(KRContext &context, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh);
|
void LoadMesh(KRContext &context, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh);
|
||||||
KRNode *LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
KRNode *LoadMesh(KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
||||||
KRNode *LoadLight(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode);
|
KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode);
|
||||||
KRNode *LoadSkeleton(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode);
|
KRNode *LoadSkeleton(KRNode *parent_node, KFbxNode* pNode);
|
||||||
KRNode *LoadCamera(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode);
|
KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode);
|
||||||
void LoadLOD(KRContext &context, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, FbxLODGroup* pSourceLodGroup);
|
|
||||||
std::string GetFbxObjectName(FbxObject *obj);
|
std::string GetFbxObjectName(FbxObject *obj);
|
||||||
|
|
||||||
const float KRAKEN_FBX_ANIMATION_FRAMERATE = 30.0f; // FINDME - This should be configurable
|
const float KRAKEN_FBX_ANIMATION_FRAMERATE = 30.0f; // FINDME - This should be configurable
|
||||||
@@ -67,12 +66,10 @@ std::string GetFbxObjectName(FbxObject *obj)
|
|||||||
return st.str();
|
return st.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::string& path)
|
void KRResource::LoadFbx(KRContext &context, const std::string& path)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::vector<KRResource *> resources;
|
|
||||||
KRScene *pScene = new KRScene(context, KRResource::GetFileBase(path));
|
KRScene *pScene = new KRScene(context, KRResource::GetFileBase(path));
|
||||||
resources.push_back(pScene);
|
context.getSceneManager()->add(pScene);
|
||||||
|
|
||||||
KFbxSdkManager* lSdkManager = NULL;
|
KFbxSdkManager* lSdkManager = NULL;
|
||||||
KFbxScene* pFbxScene = NULL;
|
KFbxScene* pFbxScene = NULL;
|
||||||
@@ -105,7 +102,6 @@ std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::str
|
|||||||
KRAnimation *new_animation = LoadAnimation(context, animation);
|
KRAnimation *new_animation = LoadAnimation(context, animation);
|
||||||
if(new_animation) {
|
if(new_animation) {
|
||||||
context.getAnimationManager()->addAnimation(new_animation);
|
context.getAnimationManager()->addAnimation(new_animation);
|
||||||
resources.push_back(new_animation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +114,6 @@ std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::str
|
|||||||
KRAnimationCurve *new_curve = LoadAnimationCurve(context, curve);
|
KRAnimationCurve *new_curve = LoadAnimationCurve(context, curve);
|
||||||
if(new_curve) {
|
if(new_curve) {
|
||||||
context.getAnimationCurveManager()->addAnimationCurve(new_curve);
|
context.getAnimationCurveManager()->addAnimationCurve(new_curve);
|
||||||
resources.push_back(new_curve);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +123,7 @@ std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::str
|
|||||||
for(int i=0; i < material_count; i++) {
|
for(int i=0; i < material_count; i++) {
|
||||||
FbxSurfaceMaterial *material = pFbxScene->GetSrcObject<FbxSurfaceMaterial>(i);
|
FbxSurfaceMaterial *material = pFbxScene->GetSrcObject<FbxSurfaceMaterial>(i);
|
||||||
printf(" Material %i of %i: %s\n", i+1, material_count, material->GetName());
|
printf(" Material %i of %i: %s\n", i+1, material_count, material->GetName());
|
||||||
LoadMaterial(context, resources, material);
|
LoadMaterial(context, material);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----====---- Import Meshes ----====----
|
// ----====---- Import Meshes ----====----
|
||||||
@@ -138,7 +133,7 @@ std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::str
|
|||||||
FbxMesh *mesh = pFbxScene->GetSrcObject<FbxMesh>(i);
|
FbxMesh *mesh = pFbxScene->GetSrcObject<FbxMesh>(i);
|
||||||
|
|
||||||
printf(" Mesh %i of %i: %s\n", i+1, mesh_count, mesh->GetNode()->GetName());
|
printf(" Mesh %i of %i: %s\n", i+1, mesh_count, mesh->GetNode()->GetName());
|
||||||
LoadMesh(context, resources, pGeometryConverter, mesh);
|
LoadMesh(context, pGeometryConverter, mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----====---- Import Textures ----====----
|
// ----====---- Import Textures ----====----
|
||||||
@@ -158,60 +153,15 @@ std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::str
|
|||||||
{
|
{
|
||||||
for(int i = 0; i < pNode->GetChildCount(); i++)
|
for(int i = 0; i < pNode->GetChildCount(); i++)
|
||||||
{
|
{
|
||||||
LoadNode(pFbxScene, pScene->getRootNode(), resources, pGeometryConverter, pNode->GetChild(i));
|
LoadNode(pFbxScene, pScene->getRootNode(), pGeometryConverter, pNode->GetChild(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<KRResource *> resources2 = context.getResources();
|
|
||||||
resources.insert(resources.begin(), resources2.begin(), resources2.end());
|
|
||||||
|
|
||||||
DestroySdkObjects(lSdkManager);
|
DestroySdkObjects(lSdkManager);
|
||||||
|
|
||||||
// Compress textures to PVR format
|
|
||||||
context.getTextureManager()->compress(); // TODO, HACK, FINDME - This should be configurable and exposed through the World Builder GUI
|
|
||||||
|
|
||||||
std::string base_name = KRResource::GetFileBase(path);
|
|
||||||
std::vector<KRResource *> output_resources;
|
|
||||||
|
|
||||||
// KRBundle *main_bundle = new KRBundle(context, base_name);
|
|
||||||
KRBundle *texture_bundle = new KRBundle(context, base_name + "_textures");
|
|
||||||
KRBundle *animation_bundle = new KRBundle(context, base_name + "_animations");
|
|
||||||
KRBundle *material_bundle = new KRBundle(context, base_name + "_materials");
|
|
||||||
KRBundle *meshes_bundle = new KRBundle(context, base_name + "_meshes");
|
|
||||||
|
|
||||||
for(std::vector<KRResource *>::iterator resource_itr=resources.begin(); resource_itr != resources.end(); resource_itr++) {
|
|
||||||
KRResource *resource = *resource_itr;
|
|
||||||
if(dynamic_cast<KRTexture *>(resource) != NULL) {
|
|
||||||
texture_bundle->append(*resource);
|
|
||||||
} else if(dynamic_cast<KRAnimation *>(resource) != NULL) {
|
|
||||||
animation_bundle->append(*resource);
|
|
||||||
} else if(dynamic_cast<KRAnimationCurve *>(resource) != NULL) {
|
|
||||||
animation_bundle->append(*resource);
|
|
||||||
} else if(dynamic_cast<KRMaterial *>(resource) != NULL) {
|
|
||||||
material_bundle->append(*resource);
|
|
||||||
} else if(dynamic_cast<KRMesh *>(resource) != NULL) {
|
|
||||||
meshes_bundle->append(*resource);
|
|
||||||
} else {
|
|
||||||
output_resources.push_back(resource);
|
|
||||||
// main_bundle->append(*resource);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
output_resources.push_back(texture_bundle);
|
|
||||||
output_resources.push_back(animation_bundle);
|
|
||||||
output_resources.push_back(material_bundle);
|
|
||||||
output_resources.push_back(meshes_bundle);
|
|
||||||
|
|
||||||
// main_bundle->append(texture_bundle);
|
|
||||||
// main_bundle->append(animation_bundle);
|
|
||||||
// main_bundle->append(material_bundle);
|
|
||||||
// main_bundle->append(meshes_bundle);
|
|
||||||
// output_resources.push_back(main_bundle);
|
|
||||||
|
|
||||||
return output_resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene)
|
void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene)
|
||||||
{
|
{
|
||||||
@@ -585,7 +535,7 @@ KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLaye
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
||||||
KFbxVector4 lTmpVector;
|
KFbxVector4 lTmpVector;
|
||||||
pNode->UpdatePropertiesFromPivotsAndLimits();
|
pNode->UpdatePropertiesFromPivotsAndLimits();
|
||||||
|
|
||||||
@@ -793,7 +743,7 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource
|
|||||||
new_node->setUseWorldUnits(use_world_space_units);
|
new_node->setUseWorldUnits(use_world_space_units);
|
||||||
parent_node->addChild(new_node);
|
parent_node->addChild(new_node);
|
||||||
|
|
||||||
LoadNode(pFbxScene, new_node, resources, pGeometryConverter, pNode->GetChild(i));
|
LoadNode(pFbxScene, new_node, pGeometryConverter, pNode->GetChild(i));
|
||||||
|
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
// Calculate reference point using the bounding box center from the highest quality LOD level
|
// Calculate reference point using the bounding box center from the highest quality LOD level
|
||||||
@@ -806,16 +756,16 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource
|
|||||||
KRNode *new_node = NULL;
|
KRNode *new_node = NULL;
|
||||||
switch(attribute_type) {
|
switch(attribute_type) {
|
||||||
case KFbxNodeAttribute::eMesh:
|
case KFbxNodeAttribute::eMesh:
|
||||||
new_node = LoadMesh(parent_node, resources, pGeometryConverter, pNode);
|
new_node = LoadMesh(parent_node, pGeometryConverter, pNode);
|
||||||
break;
|
break;
|
||||||
case KFbxNodeAttribute::eLight:
|
case KFbxNodeAttribute::eLight:
|
||||||
new_node = LoadLight(parent_node, resources, pNode);
|
new_node = LoadLight(parent_node, pNode);
|
||||||
break;
|
break;
|
||||||
case KFbxNodeAttribute::eSkeleton:
|
case KFbxNodeAttribute::eSkeleton:
|
||||||
new_node = LoadSkeleton(parent_node, resources, pNode);
|
new_node = LoadSkeleton(parent_node, pNode);
|
||||||
break;
|
break;
|
||||||
case KFbxNodeAttribute::eCamera:
|
case KFbxNodeAttribute::eCamera:
|
||||||
new_node = LoadCamera(parent_node, resources, pNode);
|
new_node = LoadCamera(parent_node, pNode);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@@ -877,17 +827,13 @@ void LoadNode(KFbxScene* pFbxScene, KRNode *parent_node, std::vector<KRResource
|
|||||||
// Load child nodes
|
// Load child nodes
|
||||||
for(int i = 0; i < pNode->GetChildCount(); i++)
|
for(int i = 0; i < pNode->GetChildCount(); i++)
|
||||||
{
|
{
|
||||||
LoadNode(pFbxScene, new_node, resources, pGeometryConverter, pNode->GetChild(i));
|
LoadNode(pFbxScene, new_node, pGeometryConverter, pNode->GetChild(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadLOD(KRContext &context, std::vector<KRResource *> &resources, FbxLODGroup* pSourceLodGroup) {
|
void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoadMaterial(KRContext &context, std::vector<KRResource *> &resources, FbxSurfaceMaterial *pMaterial) {
|
|
||||||
//printf(" %s: %i - %i\n", pMaterial->GetName(), mat_vertex_start, mat_vertex_count + mat_vertex_start - 1);
|
//printf(" %s: %i - %i\n", pMaterial->GetName(), mat_vertex_start, mat_vertex_count + mat_vertex_start - 1);
|
||||||
|
|
||||||
// ----====---- Output Material File ----====----
|
// ----====---- Output Material File ----====----
|
||||||
@@ -1039,22 +985,6 @@ void LoadMaterial(KRContext &context, std::vector<KRResource *> &resources, FbxS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
bool bFound = false;
|
|
||||||
for(vector<KRResource *>::iterator resource_itr = resources.begin(); resource_itr != resources.end(); resource_itr++) {
|
|
||||||
KRResource *pResource = (*resource_itr);
|
|
||||||
if(pResource->getName() == new_material->getName() && pResource->getExtension() == new_material->getExtension()) {
|
|
||||||
bFound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(bFound) {
|
|
||||||
delete new_material;
|
|
||||||
} else {
|
|
||||||
resources.push_back(new_material);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// Only save unique materials
|
// Only save unique materials
|
||||||
KRMaterial *found_material = context.getMaterialManager()->getMaterial(new_material->getName());
|
KRMaterial *found_material = context.getMaterialManager()->getMaterial(new_material->getName());
|
||||||
if(found_material == NULL) {
|
if(found_material == NULL) {
|
||||||
@@ -1064,7 +994,7 @@ void LoadMaterial(KRContext &context, std::vector<KRResource *> &resources, FbxS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadMesh(KRContext &context, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh) {
|
void LoadMesh(KRContext &context, FbxGeometryConverter *pGeometryConverter, KFbxMesh* pSourceMesh) {
|
||||||
KFbxMesh* pMesh = pGeometryConverter->TriangulateMesh(pSourceMesh);
|
KFbxMesh* pMesh = pGeometryConverter->TriangulateMesh(pSourceMesh);
|
||||||
|
|
||||||
int control_point_count = pMesh->GetControlPointsCount();
|
int control_point_count = pMesh->GetControlPointsCount();
|
||||||
@@ -1314,7 +1244,7 @@ void LoadMesh(KRContext &context, std::vector<KRResource *> &resources, FbxGeome
|
|||||||
context.getModelManager()->addModel(new_mesh);
|
context.getModelManager()->addModel(new_mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRNode *LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
KRNode *LoadMesh(KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
||||||
std::string name = GetFbxObjectName(pNode);
|
std::string name = GetFbxObjectName(pNode);
|
||||||
|
|
||||||
KFbxMesh* pSourceMesh = (KFbxMesh*) pNode->GetNodeAttribute();
|
KFbxMesh* pSourceMesh = (KFbxMesh*) pNode->GetNodeAttribute();
|
||||||
@@ -1342,13 +1272,13 @@ KRNode *LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, FbxG
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRNode *LoadSkeleton(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode) {
|
KRNode *LoadSkeleton(KRNode *parent_node, KFbxNode* pNode) {
|
||||||
std::string name = GetFbxObjectName(pNode);
|
std::string name = GetFbxObjectName(pNode);
|
||||||
KRBone *new_bone = new KRBone(parent_node->getScene(), name.c_str());
|
KRBone *new_bone = new KRBone(parent_node->getScene(), name.c_str());
|
||||||
return new_bone;
|
return new_bone;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRNode *LoadCamera(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode) {
|
KRNode *LoadCamera(KRNode *parent_node, KFbxNode* pNode) {
|
||||||
FbxCamera *camera = (FbxCamera *)pNode->GetNodeAttribute();
|
FbxCamera *camera = (FbxCamera *)pNode->GetNodeAttribute();
|
||||||
const char *szName = pNode->GetName();
|
const char *szName = pNode->GetName();
|
||||||
|
|
||||||
@@ -1356,7 +1286,7 @@ KRNode *LoadCamera(KRNode *parent_node, std::vector<KRResource *> &resources, KF
|
|||||||
return new_camera;
|
return new_camera;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRNode *LoadLight(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode) {
|
KRNode *LoadLight(KRNode *parent_node, KFbxNode* pNode) {
|
||||||
const GLfloat PI = 3.14159265;
|
const GLfloat PI = 3.14159265;
|
||||||
const GLfloat d2r = PI * 2 / 360;
|
const GLfloat d2r = PI * 2 / 360;
|
||||||
|
|
||||||
|
|||||||
@@ -55,23 +55,6 @@ std::string KRResource::GetFilePath(const std::string& name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<KRResource *> KRResource::Load(KRContext &context, const std::string& path)
|
|
||||||
{
|
|
||||||
std::vector<KRResource *> resources;
|
|
||||||
std::string extension = GetFileExtension(path);
|
|
||||||
if(extension.compare("obj") == 0) {
|
|
||||||
return LoadObj(context, path);
|
|
||||||
#if TARGET_OS_MAC
|
|
||||||
} else if(extension.compare("fbx") == 0) {
|
|
||||||
return LoadFbx(context, path);
|
|
||||||
} else if(extension.compare("blend") == 0) {
|
|
||||||
return LoadBlenderScene(context, path);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KRResource::save(const std::string& path)
|
bool KRResource::save(const std::string& path)
|
||||||
{
|
{
|
||||||
KRDataBlock data;
|
KRDataBlock data;
|
||||||
|
|||||||
@@ -25,10 +25,15 @@ public:
|
|||||||
static std::string GetFileBase(const std::string& name);
|
static std::string GetFileBase(const std::string& name);
|
||||||
static std::string GetFilePath(const std::string& name);
|
static std::string GetFilePath(const std::string& name);
|
||||||
|
|
||||||
static std::vector<KRResource *> Load(KRContext &context, const std::string& path);
|
|
||||||
|
|
||||||
virtual ~KRResource();
|
virtual ~KRResource();
|
||||||
|
|
||||||
|
|
||||||
|
static std::vector<KRResource *> LoadObj(KRContext &context, const std::string& path);
|
||||||
|
#if TARGET_OS_MAC
|
||||||
|
static void LoadFbx(KRContext &context, const std::string& path);
|
||||||
|
static std::vector<KRResource *> LoadBlenderScene(KRContext &context, const std::string& path);
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
KRResource(KRContext &context, std::string name);
|
KRResource(KRContext &context, std::string name);
|
||||||
|
|
||||||
@@ -36,11 +41,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
static std::vector<KRResource *> LoadObj(KRContext &context, const std::string& path);
|
|
||||||
#if TARGET_OS_MAC
|
|
||||||
static std::vector<KRResource *> LoadFbx(KRContext &context, const std::string& path);
|
|
||||||
static std::vector<KRResource *> LoadBlenderScene(KRContext &context, const std::string& path);
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -42,14 +42,30 @@ KRSceneManager::~KRSceneManager() {
|
|||||||
m_scenes.empty();
|
m_scenes.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
KRScene *KRSceneManager::loadScene(const char *szName, KRDataBlock *data) {
|
KRScene *KRSceneManager::loadScene(const std::string &name, KRDataBlock *data) {
|
||||||
KRScene *pScene = KRScene::Load(*m_pContext, szName, data);
|
std::string lowerName = name;
|
||||||
m_scenes[szName] = pScene;
|
std::transform(lowerName.begin(), lowerName.end(),
|
||||||
|
lowerName.begin(), ::tolower);
|
||||||
|
|
||||||
|
KRScene *pScene = KRScene::Load(*m_pContext, name, data);
|
||||||
|
m_scenes[lowerName] = pScene;
|
||||||
return pScene;
|
return pScene;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRScene *KRSceneManager::getScene(const char *szName) {
|
void KRSceneManager::add(KRScene *scene)
|
||||||
return m_scenes[szName];
|
{
|
||||||
|
std::string lowerName = scene->getName();
|
||||||
|
std::transform(lowerName.begin(), lowerName.end(),
|
||||||
|
lowerName.begin(), ::tolower);
|
||||||
|
m_scenes[lowerName] = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
KRScene *KRSceneManager::getScene(const std::string &name) {
|
||||||
|
std::string lowerName = name;
|
||||||
|
std::transform(lowerName.begin(), lowerName.end(),
|
||||||
|
lowerName.begin(), ::tolower);
|
||||||
|
|
||||||
|
return m_scenes[lowerName];
|
||||||
}
|
}
|
||||||
|
|
||||||
KRScene *KRSceneManager::getFirstScene() {
|
KRScene *KRSceneManager::getFirstScene() {
|
||||||
@@ -61,7 +77,7 @@ KRScene *KRSceneManager::getFirstScene() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unordered_map<std::string, KRScene *> KRSceneManager::getScenes() {
|
unordered_map<std::string, KRScene *> &KRSceneManager::getScenes() {
|
||||||
return m_scenes;
|
return m_scenes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,13 +44,14 @@ public:
|
|||||||
KRSceneManager(KRContext &context);
|
KRSceneManager(KRContext &context);
|
||||||
virtual ~KRSceneManager();
|
virtual ~KRSceneManager();
|
||||||
|
|
||||||
KRScene *loadScene(const char *szName, KRDataBlock *data);
|
void add(KRScene *scene);
|
||||||
|
KRScene *loadScene(const std::string &name, KRDataBlock *data);
|
||||||
|
|
||||||
KRScene *getScene(const char *szName);
|
KRScene *getScene(const std::string &name);
|
||||||
KRScene *getFirstScene();
|
KRScene *getFirstScene();
|
||||||
|
|
||||||
std::vector<std::string> getSceneNames();
|
std::vector<std::string> getSceneNames();
|
||||||
unordered_map<std::string, KRScene *> getScenes();
|
unordered_map<std::string, KRScene *> &getScenes();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user