コード例 #1
0
ファイル: modelinterface.cpp プロジェクト: glararan/QEditor
ModelInterface::ModelInterface(TextureManager* manager, const QString filename)
: has_animations(false)
, meshes(0)
, animations(0)
, bones(0)
, textureManager(manager)
{
    if(filename.contains("/"))
    {
        int index = filename.lastIndexOf("/") + 1;

        filePath = filename.left(index);
        fileName = filename.right(filename.size() - index);
    }
    else
        fileName = filename;

    Assimp::Importer importer;
    importer.SetPropertyInteger(AI_CONFIG_PP_LBW_MAX_WEIGHTS, 4);

    const aiScene* scene = importer.ReadFile(filename.toStdString(), aiProcess_GenSmoothNormals | aiProcess_Triangulate | aiProcess_CalcTangentSpace/* | aiProcess_FlipUVs*/);

    if(!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
    {
        throw QString("The file wasn't successfuly opened");

        return;
    }

    if(scene->HasAnimations())
    {
        has_animations = true;
        bones          = loadBones(scene);

        buildSkeleton(scene->mRootNode, NULL);

        animations = new Animations();
        animations->setBones(bones);

        for(uint i = 0; i < scene->mNumAnimations; ++i)
            animations->add(loadAnimation(scene->mAnimations[i], i));
    }

    meshes = new Meshes();

    for(uint i = 0; i < scene->mNumMeshes; ++i)
        meshes->add(loadMesh(scene->mMeshes[i], scene->mMaterials[scene->mMeshes[i]->mMaterialIndex], i));

    initialize(scene);
    // try delete scene probably crash
}
コード例 #2
0
ファイル: modelinterface.cpp プロジェクト: glararan/QEditor
void ModelInterface::buildSkeleton(aiNode* current, Bone* parent)
{
    Bone* bone;

    if(!bones->hasBone(QString(current->mName.data)))
        bone = bones->createEmptyBone(QString(current->mName.data));
    else
        bone = bones->getBone(QString(current->mName.data));

    bone->setNodeTransformation(getMatrix(&current->mTransformation));

    if(parent != NULL)
        parent->addChild(bone);

    for(uint child_index = 0; child_index < current->mNumChildren; ++child_index)
        buildSkeleton(current->mChildren[child_index], bone);
}
コード例 #3
0
void fbxLoader2::loadFbx(char* filename)
{
	//create memory manager
	loaderManager = FbxManager::Create();
	//create settings for input/output
	ios = FbxIOSettings::Create(loaderManager, IOSROOT);
	loaderManager->SetIOSettings(ios);

	lImporter = FbxImporter::Create(loaderManager, "");
	lImportStatus = lImporter->Initialize(filename, -1, loaderManager->GetIOSettings());

	scene = FbxScene::Create(loaderManager, "newscene");

	FbxAxisSystem SceneAxisSystem = scene->GetGlobalSettings().GetAxisSystem();
	FbxAxisSystem OurAxisSystem(FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eLeftHanded);

	lImporter->Import(scene);
	lImporter->Destroy();

	lRootNode = scene->GetRootNode();

	//int numberOfChildren = lRootNode->GetChildCount();
	skeleton = new SkeletalData();
	animationStructure = new AnimationData();
	buildSkeleton(findSkeletonRootBone(lRootNode));
	readAnimationTakeData(findSkeletonRootBone(lRootNode)->GetChild(0));
	readVertexData(lRootNode);
	
	indices = new indexesStructure[indicesMaxCount];
	vertexArray = new vertexWeights[vertexMaxCount];

	processNode(lRootNode);

	//processMesh(lRootNode);


	/*for (int i = 0; i< numberOfChildren; i++)
	{
		lNode = lRootNode->GetChild(i);
		printf("Child name: %s\n", lNode->GetName());
		lMesh = lNode->GetMesh();
		if(lMesh == NULL)
		{
			printf("No mesh here\n");
		}
		else
		{
			if(lMesh->IsTriangleMesh())
			{
				int numVerts = lMesh->GetControlPointsCount();

				for (int j = 0; j < numVerts; j++)
				{
					FbxVector4 vert = lMesh->GetControlPointAt(j);
					Vertices[numberVertices].x = (float)vert.mData[0];
					Vertices[numberVertices].y = (float)vert.mData[1];
					Vertices[numberVertices].z = (float)vert.mData[2];
					numberVertices++;
				}
				int *indices = lMesh->GetPolygonVertices();
				numIndices+= lMesh->GetPolygonVertexCount();
			}
			else 
			{
				printf("Mesh not triangulated\n");
			}
			
		}
	}*/
}