2012-03-23 02:28:46 +00:00
|
|
|
//
|
|
|
|
|
// KRResource+fbx.cpp
|
|
|
|
|
// KREngine
|
|
|
|
|
//
|
|
|
|
|
// Created by Kearwood Gilbert on 12-03-22.
|
|
|
|
|
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <vector.h>
|
|
|
|
|
|
|
|
|
|
#include <fbxsdk.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "KRResource.h"
|
|
|
|
|
#include "KRMesh.h"
|
2012-03-28 21:58:55 +00:00
|
|
|
#include "KRMaterial.h"
|
2012-03-23 02:28:46 +00:00
|
|
|
|
|
|
|
|
#ifdef IOS_REF
|
|
|
|
|
#undef IOS_REF
|
|
|
|
|
#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 LoadNode(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
|
|
|
|
void LoadMesh(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeometryConverter, KFbxNode* pNode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<KRResource *> KRResource::LoadFbx(const std::string& path)
|
|
|
|
|
{
|
|
|
|
|
std::vector<KRResource *> resources;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KFbxSdkManager* lSdkManager = NULL;
|
|
|
|
|
KFbxScene* pScene = NULL;
|
|
|
|
|
bool lResult;
|
|
|
|
|
KFbxGeometryConverter *pGeometryConverter = NULL;
|
|
|
|
|
|
|
|
|
|
// Prepare the FBX SDK.
|
|
|
|
|
InitializeSdkObjects(lSdkManager, pScene);
|
|
|
|
|
|
|
|
|
|
// Initialize Geometry Converter
|
|
|
|
|
pGeometryConverter = new KFbxGeometryConverter(lSdkManager);
|
|
|
|
|
|
|
|
|
|
// Load the scene.
|
|
|
|
|
lResult = LoadScene(lSdkManager, pScene, path.c_str());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----====---- Walk Through Scene ----====----
|
|
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
KFbxNode* pNode = pScene->GetRootNode();
|
|
|
|
|
|
|
|
|
|
if(pNode)
|
|
|
|
|
{
|
|
|
|
|
for(i = 0; i < pNode->GetChildCount(); i++)
|
|
|
|
|
{
|
|
|
|
|
LoadNode(resources, pGeometryConverter, pNode->GetChild(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DestroySdkObjects(lSdkManager);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
KRMesh *new_mesh = new KRMesh(KRResource::GetFileBase(path));
|
|
|
|
|
|
|
|
|
|
std::vector<KRVector3> vertices;
|
|
|
|
|
std::vector<KRVector2> uva;
|
|
|
|
|
std::vector<KRVector3> normals;
|
|
|
|
|
std::vector<KRVector3> tangents;
|
|
|
|
|
std::vector<int> submesh_lengths;
|
|
|
|
|
std::vector<int> submesh_starts;
|
|
|
|
|
std::vector<std::string> material_names;
|
|
|
|
|
|
|
|
|
|
new_mesh->LoadData(vertices, uva, normals, tangents, submesh_starts, submesh_lengths, material_names);
|
|
|
|
|
resources.push_back(new_mesh);
|
|
|
|
|
*/
|
|
|
|
|
return resources;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& 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();
|
|
|
|
|
|
|
|
|
|
if (!pSdkManager)
|
|
|
|
|
{
|
|
|
|
|
printf("Unable to create the FBX SDK manager\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create an IOSettings object
|
|
|
|
|
KFbxIOSettings * ios = KFbxIOSettings::Create(pSdkManager, IOSROOT );
|
|
|
|
|
pSdkManager->SetIOSettings(ios);
|
|
|
|
|
|
|
|
|
|
// Load plugins from the executable directory
|
|
|
|
|
KString lPath = KFbxGetApplicationDirectory();
|
|
|
|
|
#if defined(KARCH_ENV_WIN)
|
|
|
|
|
KString lExtension = "dll";
|
|
|
|
|
#elif defined(KARCH_ENV_MACOSX)
|
|
|
|
|
KString lExtension = "dylib";
|
|
|
|
|
#elif defined(KARCH_ENV_LINUX)
|
|
|
|
|
KString lExtension = "so";
|
|
|
|
|
#endif
|
|
|
|
|
pSdkManager->LoadPluginsDirectory(lPath.Buffer(), lExtension.Buffer());
|
|
|
|
|
|
|
|
|
|
// Create the entity that will hold the scene.
|
|
|
|
|
pScene = KFbxScene::Create(pSdkManager,"");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DestroySdkObjects(KFbxSdkManager* 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
|
|
|
|
|
// are automatically destroyed at the same time.
|
|
|
|
|
if (pSdkManager) pSdkManager->Destroy();
|
|
|
|
|
pSdkManager = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename)
|
|
|
|
|
{
|
|
|
|
|
int lFileMajor, lFileMinor, lFileRevision;
|
|
|
|
|
int lSDKMajor, lSDKMinor, lSDKRevision;
|
|
|
|
|
//int lFileFormat = -1;
|
|
|
|
|
int i, lAnimStackCount;
|
|
|
|
|
bool lStatus;
|
|
|
|
|
char lPassword[1024];
|
|
|
|
|
|
|
|
|
|
// Get the file version number generate by the FBX SDK.
|
|
|
|
|
KFbxSdkManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision);
|
|
|
|
|
|
|
|
|
|
// Create an importer.
|
|
|
|
|
KFbxImporter* lImporter = KFbxImporter::Create(pSdkManager,"");
|
|
|
|
|
|
|
|
|
|
// Initialize the importer by providing a filename.
|
|
|
|
|
const bool lImportStatus = lImporter->Initialize(pFilename, -1, pSdkManager->GetIOSettings());
|
|
|
|
|
lImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision);
|
|
|
|
|
|
|
|
|
|
if( !lImportStatus )
|
|
|
|
|
{
|
|
|
|
|
printf("Call to KFbxImporter::Initialize() failed.\n");
|
|
|
|
|
printf("Error returned: %s\n\n", lImporter->GetLastErrorString());
|
|
|
|
|
|
|
|
|
|
if (lImporter->GetLastErrorID() == KFbxIO::eFILE_VERSION_NOT_SUPPORTED_YET ||
|
|
|
|
|
lImporter->GetLastErrorID() == KFbxIO::eFILE_VERSION_NOT_SUPPORTED_ANYMORE)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("FBX version number for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision);
|
|
|
|
|
|
|
|
|
|
if (lImporter->IsFBX())
|
|
|
|
|
{
|
|
|
|
|
printf("FBX version number for file %s is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision);
|
|
|
|
|
|
|
|
|
|
// From this point, it is possible to access animation stack information without
|
|
|
|
|
// the expense of loading the entire file.
|
|
|
|
|
|
|
|
|
|
printf("Animation Stack Information\n");
|
|
|
|
|
|
|
|
|
|
lAnimStackCount = lImporter->GetAnimStackCount();
|
|
|
|
|
|
|
|
|
|
printf(" Number of Animation Stacks: %d\n", lAnimStackCount);
|
|
|
|
|
printf(" Current Animation Stack: \"%s\"\n", lImporter->GetActiveAnimStackName().Buffer());
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < lAnimStackCount; i++)
|
|
|
|
|
{
|
|
|
|
|
KFbxTakeInfo* lTakeInfo = lImporter->GetTakeInfo(i);
|
|
|
|
|
|
|
|
|
|
printf(" Animation Stack %d\n", i);
|
|
|
|
|
printf(" Name: \"%s\"\n", lTakeInfo->mName.Buffer());
|
|
|
|
|
printf(" Description: \"%s\"\n", lTakeInfo->mDescription.Buffer());
|
|
|
|
|
|
|
|
|
|
// Change the value of the import name if the animation stack should be imported
|
|
|
|
|
// under a different name.
|
|
|
|
|
printf(" Import Name: \"%s\"\n", lTakeInfo->mImportName.Buffer());
|
|
|
|
|
|
|
|
|
|
// Set the value of the import state to false if the animation stack should be not
|
|
|
|
|
// be imported.
|
|
|
|
|
printf(" Import State: %s\n", lTakeInfo->mSelect ? "true" : "false");
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the import states. By default, the import states are always set to
|
|
|
|
|
// true. The code below shows how to change these states.
|
|
|
|
|
IOS_REF.SetBoolProp(IMP_FBX_MATERIAL, true);
|
|
|
|
|
IOS_REF.SetBoolProp(IMP_FBX_TEXTURE, true);
|
|
|
|
|
IOS_REF.SetBoolProp(IMP_FBX_LINK, true);
|
|
|
|
|
IOS_REF.SetBoolProp(IMP_FBX_SHAPE, true);
|
|
|
|
|
IOS_REF.SetBoolProp(IMP_FBX_GOBO, true);
|
|
|
|
|
IOS_REF.SetBoolProp(IMP_FBX_ANIMATION, true);
|
|
|
|
|
IOS_REF.SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Import the scene.
|
|
|
|
|
lStatus = lImporter->Import(pScene);
|
|
|
|
|
|
|
|
|
|
if(lStatus == false && lImporter->GetLastErrorID() == KFbxIO::ePASSWORD_ERROR)
|
|
|
|
|
{
|
|
|
|
|
printf("Please enter password: ");
|
|
|
|
|
|
|
|
|
|
lPassword[0] = '\0';
|
|
|
|
|
|
|
|
|
|
scanf("%s", lPassword);
|
|
|
|
|
KString 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() == KFbxIO::ePASSWORD_ERROR)
|
|
|
|
|
{
|
|
|
|
|
printf("\nPassword is wrong, import aborted.\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Destroy the importer.
|
|
|
|
|
lImporter->Destroy();
|
|
|
|
|
|
|
|
|
|
return lStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LoadNode(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
|
|
|
|
KFbxVector4 lTmpVector;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
lTmpVector = pNode->GetGeometricTranslation(KFbxNode::eSOURCE_SET);
|
|
|
|
|
printf(" Translation: %f %f %f\n", lTmpVector[0], lTmpVector[1], lTmpVector[2]);
|
|
|
|
|
lTmpVector = pNode->GetGeometricRotation(KFbxNode::eSOURCE_SET);
|
|
|
|
|
printf(" Rotation: %f %f %f\n", lTmpVector[0], lTmpVector[1], lTmpVector[2]);
|
|
|
|
|
lTmpVector = pNode->GetGeometricScaling(KFbxNode::eSOURCE_SET);
|
|
|
|
|
printf(" Scaling: %f %f %f\n", lTmpVector[0], lTmpVector[1], lTmpVector[2]);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
KFbxNodeAttribute::EAttributeType attribute_type = (pNode->GetNodeAttribute()->GetAttributeType());
|
|
|
|
|
switch(attribute_type) {
|
|
|
|
|
case KFbxNodeAttribute::eMESH:
|
|
|
|
|
LoadMesh(resources, pGeometryConverter, pNode);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load child nodes
|
|
|
|
|
for(int i = 0; i < pNode->GetChildCount(); i++)
|
|
|
|
|
{
|
|
|
|
|
LoadNode(resources, pGeometryConverter, pNode->GetChild(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LoadMesh(std::vector<KRResource *> &resources, KFbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) {
|
|
|
|
|
printf("Mesh: %s\n", pNode->GetName());
|
|
|
|
|
KFbxMesh* pSourceMesh = (KFbxMesh*) pNode->GetNodeAttribute();
|
|
|
|
|
KFbxMesh* pMesh = pGeometryConverter->TriangulateMesh(pSourceMesh);
|
|
|
|
|
|
|
|
|
|
KFbxVector4* control_points = pMesh->GetControlPoints();
|
|
|
|
|
|
|
|
|
|
int polygon_count = pMesh->GetPolygonCount();
|
2012-03-28 19:06:23 +00:00
|
|
|
int uv_count = pMesh->GetElementUVCount();
|
|
|
|
|
int normal_count = pMesh->GetElementNormalCount();
|
|
|
|
|
int tangent_count = pMesh->GetElementTangentCount();
|
2012-03-28 19:34:52 +00:00
|
|
|
int elementmaterial_count = pMesh->GetElementMaterialCount();
|
|
|
|
|
int material_count = pNode->GetMaterialCount();
|
2012-03-23 02:28:46 +00:00
|
|
|
|
2012-03-28 19:06:23 +00:00
|
|
|
|
2012-03-23 02:28:46 +00:00
|
|
|
printf(" Polygon Count: %i (before triangulation: %i)\n", polygon_count, pSourceMesh->GetPolygonCount());
|
|
|
|
|
|
|
|
|
|
std::vector<KRVector3> vertices;
|
|
|
|
|
std::vector<KRVector2> uva;
|
2012-03-28 19:06:23 +00:00
|
|
|
std::vector<KRVector2> uvb;
|
2012-03-23 02:28:46 +00:00
|
|
|
std::vector<KRVector3> normals;
|
|
|
|
|
std::vector<KRVector3> tangents;
|
|
|
|
|
std::vector<int> submesh_lengths;
|
|
|
|
|
std::vector<int> submesh_starts;
|
|
|
|
|
std::vector<std::string> material_names;
|
|
|
|
|
|
2012-03-28 19:06:23 +00:00
|
|
|
int dest_vertex_id = 0;
|
|
|
|
|
|
2012-03-28 19:34:52 +00:00
|
|
|
for(int iMaterial=0; iMaterial < material_count; iMaterial++) {
|
2012-03-28 21:58:55 +00:00
|
|
|
KFbxSurfaceMaterial *pMaterial = pNode->GetMaterial(iMaterial);
|
2012-03-28 19:34:52 +00:00
|
|
|
int source_vertex_id = 0;
|
|
|
|
|
int mat_vertex_count = 0;
|
|
|
|
|
int mat_vertex_start = dest_vertex_id;
|
|
|
|
|
for(int iPolygon = 0; iPolygon < polygon_count; iPolygon++) {
|
|
|
|
|
int lPolygonSize = pMesh->GetPolygonSize(iPolygon);
|
|
|
|
|
if(lPolygonSize != 3) {
|
|
|
|
|
source_vertex_id += lPolygonSize;
|
|
|
|
|
printf(" Warning - Poly with %i vertices found. Expecting only triangles.", lPolygonSize);
|
|
|
|
|
} else {
|
|
|
|
|
// ----====---- Read SubMesh / Material Mapping ----====----
|
|
|
|
|
int iNewMaterial = -1;
|
|
|
|
|
for (int l = 0; l < elementmaterial_count; l++)
|
|
|
|
|
{
|
|
|
|
|
KFbxGeometryElementMaterial* leMat = pMesh->GetElementMaterial(l);
|
|
|
|
|
if(leMat) {
|
|
|
|
|
if (leMat->GetReferenceMode() == KFbxGeometryElement::eINDEX || leMat->GetReferenceMode() == KFbxGeometryElement::eINDEX_TO_DIRECT) {
|
|
|
|
|
int new_id = leMat->GetIndexArray().GetAt(iPolygon);
|
|
|
|
|
if(new_id >= 0) {
|
|
|
|
|
iNewMaterial = new_id;
|
|
|
|
|
}
|
2012-03-28 19:06:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-28 19:34:52 +00:00
|
|
|
if(iMaterial == iNewMaterial) {
|
|
|
|
|
// ----====---- Read Vertex-level Attributes ----====----
|
|
|
|
|
for(int iVertex=0; iVertex<3; iVertex++) {
|
|
|
|
|
// ----====---- Read Vertex Position ----====----
|
|
|
|
|
int lControlPointIndex = pMesh->GetPolygonVertex(iPolygon, iVertex);
|
|
|
|
|
KFbxVector4 v = control_points[lControlPointIndex];
|
|
|
|
|
vertices.push_back(KRVector3(v[0], v[1], v[2]));
|
|
|
|
|
|
2012-04-05 20:12:39 +00:00
|
|
|
KRVector2 new_uva = KRVector2(0.0, 0.0);
|
|
|
|
|
KRVector2 new_uvb = KRVector2(0.0, 0.0);
|
|
|
|
|
|
2012-03-28 19:34:52 +00:00
|
|
|
|
|
|
|
|
// ----====---- Read UVs ----====----
|
2012-04-05 20:12:39 +00:00
|
|
|
// for (int l = 0; l < uv_count; ++l)
|
|
|
|
|
// {
|
|
|
|
|
// KFbxVector2 uv;
|
|
|
|
|
// KFbxGeometryElementUV* leUV = pMesh->GetElementUV(l);
|
|
|
|
|
//
|
|
|
|
|
// switch (leUV->GetMappingMode()) {
|
|
|
|
|
// case KFbxGeometryElement::eBY_CONTROL_POINT:
|
|
|
|
|
// switch (leUV->GetReferenceMode()) {
|
|
|
|
|
// case KFbxGeometryElement::eDIRECT:
|
|
|
|
|
// uv = leUV->GetDirectArray().GetAt(lControlPointIndex);
|
|
|
|
|
// break;
|
|
|
|
|
// case KFbxGeometryElement::eINDEX_TO_DIRECT:
|
|
|
|
|
// {
|
|
|
|
|
// int id = leUV->GetIndexArray().GetAt(lControlPointIndex);
|
|
|
|
|
// uv = leUV->GetDirectArray().GetAt(id);
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
// default:
|
|
|
|
|
// break; // other reference modes not shown here!
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
//
|
|
|
|
|
// case KFbxGeometryElement::eBY_POLYGON_VERTEX:
|
|
|
|
|
// switch (leUV->GetReferenceMode()) {
|
|
|
|
|
// case KFbxGeometryElement::eDIRECT:
|
|
|
|
|
// uv = leUV->GetDirectArray().GetAt(source_vertex_id);
|
|
|
|
|
// break;
|
|
|
|
|
// case KFbxGeometryElement::eINDEX_TO_DIRECT:
|
|
|
|
|
// {
|
|
|
|
|
// int id = leUV->GetIndexArray().GetAt(source_vertex_id);
|
|
|
|
|
// uv = leUV->GetDirectArray().GetAt(id);
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
// default:
|
|
|
|
|
// break; // other reference modes not shown here!
|
|
|
|
|
// }
|
|
|
|
|
// break;
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//// case KFbxGeometryElement::eBY_POLYGON_VERTEX:
|
|
|
|
|
//// {
|
|
|
|
|
//// int lTextureUVIndex = pMesh->GetTextureUVIndex(iPolygon, iVertex);
|
|
|
|
|
//// switch (leUV->GetReferenceMode())
|
|
|
|
|
//// {
|
|
|
|
|
//// case KFbxGeometryElement::eDIRECT:
|
|
|
|
|
//// case KFbxGeometryElement::eINDEX_TO_DIRECT:
|
|
|
|
|
//// {
|
|
|
|
|
//// uv = leUV->GetDirectArray().GetAt(lTextureUVIndex);
|
|
|
|
|
//// }
|
|
|
|
|
//// break;
|
|
|
|
|
//// default:
|
|
|
|
|
//// break; // other reference modes not shown here!
|
|
|
|
|
//// }
|
|
|
|
|
//// }
|
|
|
|
|
//// break;
|
|
|
|
|
////
|
|
|
|
|
//
|
|
|
|
|
// case KFbxGeometryElement::eBY_POLYGON: // doesn't make much sense for UVs
|
|
|
|
|
// case KFbxGeometryElement::eALL_SAME: // doesn't make much sense for UVs
|
|
|
|
|
// case KFbxGeometryElement::eNONE: // doesn't make much sense for UVs
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// if(l == 0) {
|
|
|
|
|
// new_uva = KRVector2(uv[0], uv[1]);
|
|
|
|
|
// // uva.push_back(KRVector2(uv[0], uv[1]));
|
|
|
|
|
// } else if(l == 1) {
|
|
|
|
|
// new_uvb = KRVector2(uv[0], uv[1]);
|
|
|
|
|
// // uvb.push_back(KRVector2(uv[0], uv[1]));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if(uv_count > 0) {
|
|
|
|
|
// uva.push_back(new_uva);
|
|
|
|
|
// }
|
|
|
|
|
// if(uv_count > 1) {
|
|
|
|
|
// uvb.push_back(new_uvb);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// KFbxLayerElementArrayTemplate<KFbxVector2>* lUVArray = NULL;
|
|
|
|
|
// pMesh->GetTextureUV(&lUVArray, KFbxLayerElement::eDIFFUSE_TEXTURES);
|
|
|
|
|
//
|
|
|
|
|
// int lCurrentUVIndex = pMesh->GetTextureUVIndex(iPolygon, iVertex, KFbxLayerElement::eDIFFUSE_TEXTURES);
|
|
|
|
|
//
|
|
|
|
|
// KFbxVector2 uv = lUVArray->GetAt(lCurrentUVIndex);
|
|
|
|
|
// new_uva = KRVector2(uv[0], uv[1]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(pMesh->GetLayerCount() >= 1) {
|
|
|
|
|
// KFbxLayerElementUV* uvs = pMesh->GetLayer(0)->GetUVs();
|
|
|
|
|
// KFbxVector2 uv;
|
|
|
|
|
// int index = 0;
|
|
|
|
|
// switch (uvs->GetMappingMode())
|
|
|
|
|
// {
|
|
|
|
|
// case KFbxLayerElement::eBY_CONTROL_POINT:
|
|
|
|
|
// index = pMesh->GetPolygonVertex(iPolygon, iVertex);
|
|
|
|
|
// break;
|
|
|
|
|
// case KFbxLayerElement::eBY_POLYGON_VERTEX:
|
|
|
|
|
// index = source_vertex_id;
|
|
|
|
|
// break;
|
|
|
|
|
// case KFbxLayerElement::eBY_POLYGON:
|
|
|
|
|
// index = iPolygon;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (uvs->GetReferenceMode() != KFbxLayerElement::eDIRECT)
|
|
|
|
|
// {
|
|
|
|
|
// index = uvs->GetIndexArray().GetAt(index);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// uv = uvs->GetDirectArray().GetAt(index);
|
|
|
|
|
//
|
|
|
|
|
// new_uva = KRVector2(uv[0], uv[1]);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if(pMesh->GetLayerCount() >= 2) {
|
|
|
|
|
// KFbxLayerElementUV* uvs = pMesh->GetLayer(1)->GetUVs();
|
|
|
|
|
// KFbxVector2 uv;
|
|
|
|
|
// int index = 0;
|
|
|
|
|
// switch (uvs->GetMappingMode())
|
|
|
|
|
// {
|
|
|
|
|
// case KFbxLayerElement::eBY_CONTROL_POINT:
|
|
|
|
|
// index = pMesh->GetPolygonVertex(iPolygon, iVertex);
|
|
|
|
|
// break;
|
|
|
|
|
// case KFbxLayerElement::eBY_POLYGON_VERTEX:
|
|
|
|
|
// index = source_vertex_id;
|
|
|
|
|
// break;
|
|
|
|
|
// case KFbxLayerElement::eBY_POLYGON:
|
|
|
|
|
// index = iPolygon;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (uvs->GetReferenceMode() != KFbxLayerElement::eDIRECT)
|
|
|
|
|
// {
|
|
|
|
|
// index = uvs->GetIndexArray().GetAt(index);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// uv = uvs->GetDirectArray().GetAt(index);
|
|
|
|
|
//
|
|
|
|
|
// new_uva = KRVector2(uv[0], uv[1]);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KStringList uvNames;
|
|
|
|
|
pMesh->GetUVSetNames(uvNames);
|
|
|
|
|
if(uv_count >= 1) {
|
|
|
|
|
const char *setName = uvNames[0].Buffer();
|
|
|
|
|
KFbxVector2 uv;
|
|
|
|
|
if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv)) {
|
|
|
|
|
new_uva = KRVector2(uv[0], uv[1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(uv_count >= 2) {
|
|
|
|
|
const char *setName = uvNames[1].Buffer();
|
|
|
|
|
KFbxVector2 uv;
|
|
|
|
|
if(pMesh->GetPolygonVertexUV(iPolygon, iVertex, setName, uv)) {
|
|
|
|
|
new_uvb = KRVector2(uv[0], uv[1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
for (int iLayer = 0; iLayer < pMesh->GetLayerCount(); iLayer++)
|
2012-03-28 19:06:23 +00:00
|
|
|
{
|
2012-04-05 20:12:39 +00:00
|
|
|
KFbxLayerElementUV* uvs = pMesh->GetLayer(iLayer)->GetUVs();
|
2012-03-28 19:34:52 +00:00
|
|
|
KFbxVector2 uv;
|
2012-04-05 20:12:39 +00:00
|
|
|
if (uvs == NULL) continue;
|
2012-03-28 19:34:52 +00:00
|
|
|
|
2012-04-05 20:12:39 +00:00
|
|
|
|
|
|
|
|
switch (uvs->GetMappingMode())
|
|
|
|
|
{
|
|
|
|
|
case KFbxLayerElement::eBY_CONTROL_POINT:
|
|
|
|
|
//uvs_index_vector[iLayer] = cpIndex; break;
|
|
|
|
|
switch (uvs->GetReferenceMode())
|
|
|
|
|
{
|
|
|
|
|
case KFbxLayerElement::eDIRECT:
|
|
|
|
|
uv = uvs->GetDirectArray().GetAt(cpIndex));
|
2012-03-28 19:34:52 +00:00
|
|
|
break;
|
2012-04-05 20:12:39 +00:00
|
|
|
case KFbxLayerElement::eINDEX_TO_DIRECT:
|
2012-03-28 19:34:52 +00:00
|
|
|
{
|
2012-04-05 20:12:39 +00:00
|
|
|
int id = uvs->GetIndexArray().GetAt(cpIndex);
|
|
|
|
|
uv = uvs->GetDirectArray().GetAt(id));
|
2012-03-28 19:34:52 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break; // other reference modes not shown here!
|
|
|
|
|
}
|
|
|
|
|
break;
|
2012-04-05 20:12:39 +00:00
|
|
|
case KFbxLayerElement::eBY_POLYGON_VERTEX: //BUG: This wont work in some FBXs, so we will skip the uvs
|
2012-03-28 19:06:23 +00:00
|
|
|
{
|
2012-04-05 20:12:39 +00:00
|
|
|
//int id = fbxmesh->GetTextureUVIndex(lPolygonIndex, iVertex);
|
|
|
|
|
int id = lCurrentPolygonIndex + iVertex;
|
|
|
|
|
|
|
|
|
|
switch (uvs->GetReferenceMode() )
|
2012-03-28 19:34:52 +00:00
|
|
|
{
|
2012-04-05 20:12:39 +00:00
|
|
|
case KFbxLayerElement::eDIRECT:
|
|
|
|
|
break;
|
|
|
|
|
case KFbxLayerElement::eINDEX_TO_DIRECT:
|
|
|
|
|
//uvs_index_vector[iLayer] = id;
|
|
|
|
|
id = uvs->GetIndexArray().GetAt(id);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2012-03-28 19:34:52 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-05 20:12:39 +00:00
|
|
|
Display2DVector(header, uvs->GetDirectArray().GetAt(id));
|
|
|
|
|
int numuvs = uvs->GetDirectArray().GetCount();
|
|
|
|
|
assert( id < numuvs );
|
|
|
|
|
}
|
2012-03-28 19:34:52 +00:00
|
|
|
break;
|
2012-03-28 19:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-05 20:12:39 +00:00
|
|
|
if(iLayer == 0) {
|
|
|
|
|
new_uva = KRVector2(uv[0], uv[1]);
|
|
|
|
|
// uva.push_back(KRVector2(uv[0], uv[1]));
|
|
|
|
|
} else if(iLayer == 1) {
|
|
|
|
|
new_uvb = KRVector2(uv[0], uv[1]);
|
|
|
|
|
// uvb.push_back(KRVector2(uv[0], uv[1]));
|
2012-03-28 19:34:52 +00:00
|
|
|
}
|
2012-04-05 20:12:39 +00:00
|
|
|
|
2012-03-28 19:34:52 +00:00
|
|
|
}
|
2012-04-05 20:12:39 +00:00
|
|
|
*/
|
2012-03-28 19:34:52 +00:00
|
|
|
|
2012-04-05 20:12:39 +00:00
|
|
|
if(uv_count > 0) {
|
|
|
|
|
uva.push_back(new_uva);
|
|
|
|
|
}
|
|
|
|
|
if(uv_count > 1) {
|
|
|
|
|
uvb.push_back(new_uvb);
|
|
|
|
|
}
|
2012-03-28 23:34:39 +00:00
|
|
|
|
2012-03-28 19:34:52 +00:00
|
|
|
// ----====---- Read Normals ----====----
|
2012-03-28 23:34:39 +00:00
|
|
|
|
|
|
|
|
KFbxVector4 new_normal;
|
|
|
|
|
if(pMesh->GetPolygonVertexNormal(iPolygon, iVertex, new_normal)) {
|
|
|
|
|
normals.push_back(KRVector3(new_normal[0], new_normal[1], new_normal[2]));
|
2012-03-28 19:06:23 +00:00
|
|
|
}
|
2012-03-28 19:34:52 +00:00
|
|
|
|
2012-03-28 23:34:39 +00:00
|
|
|
|
2012-03-28 19:34:52 +00:00
|
|
|
// ----====---- Read Tangents ----====----
|
|
|
|
|
for(int l = 0; l < tangent_count; ++l)
|
|
|
|
|
{
|
|
|
|
|
KFbxVector4 new_tangent;
|
|
|
|
|
KFbxGeometryElementTangent* leTangent = pMesh->GetElementTangent(l);
|
|
|
|
|
|
|
|
|
|
if(leTangent->GetMappingMode() == KFbxGeometryElement::eBY_POLYGON_VERTEX) {
|
|
|
|
|
switch (leTangent->GetReferenceMode()) {
|
|
|
|
|
case KFbxGeometryElement::eDIRECT:
|
2012-03-28 23:34:39 +00:00
|
|
|
new_tangent = leTangent->GetDirectArray().GetAt(lControlPointIndex);
|
2012-03-28 19:34:52 +00:00
|
|
|
break;
|
|
|
|
|
case KFbxGeometryElement::eINDEX_TO_DIRECT:
|
|
|
|
|
{
|
2012-03-28 23:34:39 +00:00
|
|
|
int id = leTangent->GetIndexArray().GetAt(lControlPointIndex);
|
2012-03-28 19:34:52 +00:00
|
|
|
new_tangent = leTangent->GetDirectArray().GetAt(id);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break; // other reference modes not shown here!
|
|
|
|
|
}
|
2012-03-28 19:06:23 +00:00
|
|
|
}
|
2012-03-28 19:34:52 +00:00
|
|
|
if(l == 0) {
|
|
|
|
|
tangents.push_back(KRVector3(new_tangent[0], new_tangent[1], new_tangent[2]));
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-28 19:06:23 +00:00
|
|
|
}
|
2012-03-28 23:34:39 +00:00
|
|
|
|
2012-03-28 19:34:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
source_vertex_id++;
|
|
|
|
|
dest_vertex_id++;
|
|
|
|
|
mat_vertex_count++;
|
2012-03-28 19:06:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-23 02:28:46 +00:00
|
|
|
}
|
2012-03-28 19:34:52 +00:00
|
|
|
|
2012-03-28 21:58:55 +00:00
|
|
|
|
2012-03-28 19:34:52 +00:00
|
|
|
if(mat_vertex_count) {
|
2012-03-28 21:58:55 +00:00
|
|
|
// ----====---- Output last material / submesh details ----====----
|
2012-03-28 19:34:52 +00:00
|
|
|
submesh_starts.push_back(mat_vertex_start);
|
|
|
|
|
submesh_lengths.push_back(mat_vertex_count);
|
2012-03-28 21:58:55 +00:00
|
|
|
material_names.push_back(pMaterial->GetName());
|
|
|
|
|
printf(" %s: %i - %i\n", pMaterial->GetName(), mat_vertex_start, mat_vertex_count + mat_vertex_start - 1);
|
|
|
|
|
|
|
|
|
|
// ----====---- Output Material File ----====----
|
|
|
|
|
KRMaterial *new_material = new KRMaterial(pMaterial->GetName());
|
|
|
|
|
|
|
|
|
|
KFbxPropertyDouble3 lKFbxDouble3;
|
|
|
|
|
KFbxPropertyDouble1 lKFbxDouble1;
|
|
|
|
|
|
|
|
|
|
if (pMaterial->GetClassId().Is(KFbxSurfacePhong::ClassId)) {
|
|
|
|
|
// We found a Phong material.
|
|
|
|
|
|
|
|
|
|
// Ambient Color
|
|
|
|
|
lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Ambient;
|
|
|
|
|
new_material->setAmbient(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
|
|
|
|
|
|
|
|
|
// Diffuse Color
|
|
|
|
|
lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Diffuse;
|
|
|
|
|
new_material->setDiffuse(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
|
|
|
|
|
|
|
|
|
// Specular Color (unique to Phong materials)
|
|
|
|
|
lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Specular;
|
|
|
|
|
new_material->setSpecular(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
|
|
|
|
|
|
|
|
|
// Emissive Color
|
|
|
|
|
//lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Emissive;
|
|
|
|
|
|
|
|
|
|
// Transparency
|
|
|
|
|
lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->TransparencyFactor;
|
|
|
|
|
new_material->setTransparency(1.0-lKFbxDouble1.Get());
|
|
|
|
|
|
|
|
|
|
// Shininess
|
|
|
|
|
lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->Shininess;
|
|
|
|
|
new_material->setShininess(lKFbxDouble1.Get());
|
|
|
|
|
|
|
|
|
|
// Display the Reflectivity
|
|
|
|
|
//lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->ReflectionFactor;
|
|
|
|
|
} else if(pMaterial->GetClassId().Is(KFbxSurfaceLambert::ClassId) ) {
|
|
|
|
|
// We found a Lambert material.
|
|
|
|
|
|
|
|
|
|
// Ambient Color
|
|
|
|
|
lKFbxDouble3=((KFbxSurfaceLambert *)pMaterial)->Ambient;
|
|
|
|
|
new_material->setAmbient(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
|
|
|
|
|
|
|
|
|
// Diffuse Color
|
|
|
|
|
lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Diffuse;
|
|
|
|
|
new_material->setDiffuse(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);
|
|
|
|
|
|
|
|
|
|
// Emissive
|
|
|
|
|
//lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Emissive;
|
|
|
|
|
|
|
|
|
|
// Opacity
|
|
|
|
|
lKFbxDouble1 =((KFbxSurfaceLambert *)pMaterial)->TransparencyFactor;
|
|
|
|
|
new_material->setTransparency(1.0-lKFbxDouble1.Get());
|
|
|
|
|
} else {
|
|
|
|
|
printf("Error! Unable to convert material: %s", pMaterial->GetName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KFbxProperty pProperty;
|
|
|
|
|
|
|
|
|
|
// Diffuse Map Texture
|
|
|
|
|
pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sDiffuse);
|
|
|
|
|
if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) {
|
|
|
|
|
printf("Error! Layered textures not supported.\n");
|
|
|
|
|
} else {
|
|
|
|
|
int texture_count = pProperty.GetSrcObjectCount(KFbxTexture::ClassId);
|
|
|
|
|
if(texture_count > 1) {
|
|
|
|
|
printf("Error! Multiple diffuse textures not supported.\n");
|
|
|
|
|
} else if(texture_count == 1) {
|
|
|
|
|
KFbxTexture* pTexture = KFbxCast <KFbxTexture> (pProperty.GetSrcObject(KFbxTexture::ClassId,0));
|
2012-03-30 00:54:44 +00:00
|
|
|
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->GetRotationU() == 0.0f);
|
|
|
|
|
assert(pTexture->GetRotationV() == 0.0f);
|
|
|
|
|
assert(pTexture->GetRotationW() == 0.0f);
|
|
|
|
|
|
2012-03-28 21:58:55 +00:00
|
|
|
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
|
|
|
|
|
if(pFileTexture) {
|
2012-03-30 00:54:44 +00:00
|
|
|
new_material->setDiffuseMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV()));
|
2012-03-28 21:58:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Specular Map Texture
|
|
|
|
|
pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sSpecular);
|
|
|
|
|
if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) {
|
|
|
|
|
printf("Error! Layered textures not supported.\n");
|
|
|
|
|
} else {
|
|
|
|
|
int texture_count = pProperty.GetSrcObjectCount(KFbxTexture::ClassId);
|
|
|
|
|
if(texture_count > 1) {
|
|
|
|
|
printf("Error! Multiple specular textures not supported.\n");
|
|
|
|
|
} else if(texture_count == 1) {
|
|
|
|
|
KFbxTexture* pTexture = KFbxCast <KFbxTexture> (pProperty.GetSrcObject(KFbxTexture::ClassId,0));
|
|
|
|
|
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
|
|
|
|
|
if(pFileTexture) {
|
2012-03-30 00:54:44 +00:00
|
|
|
new_material->setSpecularMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV()));
|
2012-03-28 21:58:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Normal Map Texture
|
|
|
|
|
pProperty = pMaterial->FindProperty(KFbxSurfaceMaterial::sNormalMap);
|
|
|
|
|
if(pProperty.GetSrcObjectCount(KFbxLayeredTexture::ClassId) > 0) {
|
|
|
|
|
printf("Error! Layered textures not supported.\n");
|
|
|
|
|
} else {
|
|
|
|
|
int texture_count = pProperty.GetSrcObjectCount(KFbxTexture::ClassId);
|
|
|
|
|
if(texture_count > 1) {
|
|
|
|
|
printf("Error! Multiple normal map textures not supported.\n");
|
|
|
|
|
} else if(texture_count == 1) {
|
|
|
|
|
KFbxTexture* pTexture = KFbxCast <KFbxTexture> (pProperty.GetSrcObject(KFbxTexture::ClassId,0));
|
|
|
|
|
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
|
|
|
|
|
if(pFileTexture) {
|
2012-03-30 00:54:44 +00:00
|
|
|
new_material->setNormalMap(KRResource::GetFileBase(pFileTexture->GetFileName()), KRVector2(pTexture->GetScaleU(), pTexture->GetScaleV()), KRVector2(pTexture->GetTranslationU(), pTexture->GetTranslationV()));
|
2012-03-28 21:58:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool bFound = false;
|
|
|
|
|
vector<KRResource *>::iterator resource_itr = resources.begin();
|
|
|
|
|
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);
|
|
|
|
|
}
|
2012-03-28 19:34:52 +00:00
|
|
|
}
|
2012-03-23 02:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-28 19:34:52 +00:00
|
|
|
|
2012-03-28 19:06:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----====---- Generate Output Mesh Object ----====----
|
2012-03-23 02:28:46 +00:00
|
|
|
|
|
|
|
|
KRMesh *new_mesh = new KRMesh(pNode->GetName());
|
2012-03-29 19:39:28 +00:00
|
|
|
new_mesh->LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names);
|
2012-03-23 02:28:46 +00:00
|
|
|
resources.push_back(new_mesh);
|
2012-03-28 21:58:55 +00:00
|
|
|
|
2012-03-23 02:28:46 +00:00
|
|
|
}
|
|
|
|
|
|