UObject* UFbxFactory::ImportANode(void* VoidFbxImporter, void* VoidNode, UObject* InParent, FName InName, EObjectFlags Flags, int32& NodeIndex, int32 Total, UObject* InMesh, int LODIndex)
{
	UnFbx::FFbxImporter* FFbxImporter = (UnFbx::FFbxImporter*)VoidFbxImporter;
	FbxNode* Node = (FbxNode*)VoidNode;

	UObject* NewObject = NULL;
	FName OutputName = FFbxImporter->MakeNameForMesh(InName.ToString(), Node);
	
	{
		// skip collision models
		FbxString NodeName(Node->GetName());
		if ( NodeName.Find("UCX") != -1 || NodeName.Find("MCDCX") != -1 ||
			 NodeName.Find("UBX") != -1 || NodeName.Find("USP") != -1 )
		{
			return NULL;
		}

		NewObject = FFbxImporter->ImportStaticMesh( InParent, Node, OutputName, Flags, ImportUI->StaticMeshImportData, Cast<UStaticMesh>(InMesh), LODIndex );
	}

	if (NewObject)
	{
		NodeIndex++;
		FFormatNamedArguments Args;
		Args.Add( TEXT("NodeIndex"), NodeIndex );
		Args.Add( TEXT("ArrayLength"), Total );
		GWarn->StatusUpdate( NodeIndex, Total, FText::Format( NSLOCTEXT("UnrealEd", "Importingf", "Importing ({NodeIndex} of {ArrayLength})"), Args ) );
	}

	return NewObject;
}
Esempio n. 2
0
void fbxLoader2::buildSkeletonCycle(FbxNode* boneNode, int parentBoneIndex)
{
	BoneData* bone1 = new BoneData();
	FbxNodeAttribute * attrib = boneNode->GetNodeAttribute();
	if(((FbxSkeleton*) attrib)->GetSkeletonType() == FbxSkeleton::eLimbNode)
	{
		bone1->SetName(boneNode->GetName());
		bone1->SetID(skeleton->GetBonesCount());
		bone1->SetParent(parentBoneIndex);

		skeleton->SetBones(bone1);
	}

	int childCount = boneNode->GetChildCount();

	for( int childIndex = 0; childIndex < childCount; ++childIndex )
	{
		FbxNode* childNode = boneNode->GetChild( childIndex );
		std::string s2("Nub");
		std::string s3 ("Footsteps");
		std::string s1(childNode->GetName());
		int found = s1.find(s2);
		int found2 = s1.find(s3);
		if (found == std::string::npos && found2 == std::string::npos)
		{
			buildSkeletonCycle(childNode, bone1->GetID());
		}
	}
}
void FBXSceneEncoder::loadBindShapes(FbxScene* fbxScene)
{
    float m[16];
    const int poseCount = fbxScene->GetPoseCount();
    for (int i = 0; i < poseCount; ++i)
    {
        FbxPose* pose = fbxScene->GetPose(i);
        assert(pose);
        if (pose->IsBindPose() && pose->GetCount() > 0)
        {
            FbxNode* fbxNode = pose->GetNode(0);
            if (fbxNode->GetMesh() != NULL)
            {
                Node* node = _gamePlayFile.getNode(fbxNode->GetName());
                assert(node && node->getModel());

                Model* model = node->getModel();
                if (model && model->getSkin())
                {
                    MeshSkin* skin = model->getSkin();
                    copyMatrix(pose->GetMatrix(0), m);
                    skin->setBindShape(m);
                }
            }
        }
    }
}
Esempio n. 4
0
void fbxLoader2::setBindPoseCluster(FbxNode *node)
{
	if( node->GetNodeAttribute())
	{
		switch(node->GetNodeAttribute()->GetAttributeType())
		{
		case FbxNodeAttribute::eMesh: 
			FbxMesh *mesh = node->GetMesh();

			for (int j = 0; j<mesh->GetDeformerCount(); j++)
			{
				FbxSkin *skin = (FbxSkin*) mesh->GetDeformer(j,FbxDeformer::eSkin);
				int clusters = skin->GetClusterCount();
				for(int k = 0; k<clusters; k++)
				{
					FbxCluster* cluster = skin->GetCluster(k);
					FbxNode* boneLink = cluster->GetLink();

					if(boneLink)
					{
						std::string nameLink = boneLink->GetName();
						FbxAMatrix translationM;
						FbxAMatrix invert;
						cluster->GetTransformLinkMatrix(translationM);
						cluster->GetTransformMatrix(invert);

						translationM = translationM * invert.Inverse();

						D3DXMATRIX mat = D3DXMATRIX((float)translationM.mData[0].mData[0], (float)translationM.mData[0].mData[1], (float)translationM.mData[0].mData[2], (float)translationM.mData[3].mData[0],
													(float)translationM.mData[1].mData[0], (float)translationM.mData[1].mData[1], (float)translationM.mData[1].mData[2], (float)translationM.mData[3].mData[1],
													(float)translationM.mData[2].mData[0], (float)translationM.mData[2].mData[1], (float)translationM.mData[2].mData[2], (float)translationM.mData[3].mData[2],
													0,0,0,1);

						skeleton->GetBone(skeleton->GetBoneByName(nameLink))->SetTransformation(mat);
					}
				}
			}
			break;
		}
	}
	for (int i = 0; i<node->GetChildCount(); i++)
	{
		FbxNode* child = node->GetChild(i);
		setBindPoseCluster(child);
	}
}
void FBXSceneEncoder::loadSkin(FbxMesh* fbxMesh, Model* model)
{
    const int deformerCount = fbxMesh->GetDeformerCount();
    for (int i = 0; i < deformerCount; ++i)
    {
        FbxDeformer* deformer = fbxMesh->GetDeformer(i);
        if (deformer->GetDeformerType() == FbxDeformer::eSkin)
        {
            FbxSkin* fbxSkin = FbxCast<FbxSkin>(deformer);

            MeshSkin* skin = new MeshSkin();

            vector<string> jointNames;
            vector<Node*> joints;
            vector<Matrix> bindPoses;

            const int clusterCount = fbxSkin->GetClusterCount();
            for (int j = 0; j < clusterCount; ++j)
            {
                FbxCluster* cluster = fbxSkin->GetCluster(j);
                assert(cluster);
                FbxNode* linkedNode = cluster->GetLink();
                if (linkedNode && linkedNode->GetSkeleton())
                {
                    const char* jointName = linkedNode->GetName();
                    assert(jointName);
                    jointNames.push_back(jointName);
                    Node* joint = loadNode(linkedNode);
                    assert(joint);
                    joints.push_back(joint);

                    FbxAMatrix matrix;
                    cluster->GetTransformLinkMatrix(matrix);
                    Matrix m;
                    copyMatrix(matrix.Inverse(), m);
                    bindPoses.push_back(m);
                }
            }
            skin->setJointNames(jointNames);
            skin->setJoints(joints);
            skin->setBindPoses(bindPoses);
            model->setSkin(skin);
            break;
        }
    }
}
Esempio n. 6
0
Model::Model(char* name)
{
	FbxManager* lSdkManager = FbxManager::Create();
	FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT);
	this->modelName = name;		
	lSdkManager->SetIOSettings(ios);
	FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "");
	std::string path = MODELS_SUBDIR + std::string(name);
	if (!lImporter->Initialize(path.c_str(), -1, lSdkManager->GetIOSettings()))
		TriggerCrash("Nie mo¿na znaleœæ modelu!");
	FbxScene* lScene = FbxScene::Create(lSdkManager, "myScene");	//pobranie calego fbx'a
	lImporter->Import(lScene);
	for (int i = 0; i < lScene->GetRootNode()->GetChildCount(); i++){	//leci po wszystkich modelach w fbx
		FbxNode* node = lScene->GetRootNode()->GetChild(i);
		char* texBaseName = (char*) node->GetName();
		this->objects.push_back(new ModelObject(node));
	}
	Models.push_back(this);
}
Esempio n. 7
0
Model::Model(const std::string &filename) {
  key = filename;

  if (ResourceManager::access<Data *>(key))
    return;

  int level = 0;
  // Initialize the SDK manager. This object handles memory management.
  FbxManager* lSdkManager = FbxManager::Create();

  // Create the IO settings object.
  FbxIOSettings *ios = FbxIOSettings::Create(lSdkManager, IOSROOT);
  lSdkManager->SetIOSettings(ios);

  // Create an importer using the SDK manager.
  FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "");

  Data *model = new Data();

  // Create a new scene so that it can be populated by the imported file.
  if (!lImporter->Initialize(filename.c_str(), -1, lSdkManager->GetIOSettings())) {
    LOG(FATAL) << "Failed to load model " << filename;
  }

  // Create a new scene so that it can be populated by the imported file.
  FbxScene* lScene = FbxScene::Create(lSdkManager, "myScene");
  // Import the contents of the file into the scene.
  lImporter->Import(lScene);

  // Print the nodes of the scene and their attributes recursively.
  // Note that we are not printing the root node because it should
  // not contain any attributes.
  FbxNode* lRootNode = lScene->GetRootNode();
  if (lRootNode) {
    LOG(INFO) << "Root Node " << lRootNode->GetName();
    for (int i = 0; i < lRootNode->GetChildCount(); i++) {
      level = processNode(lRootNode->GetChild(i), level, *model);
    }
  }

  ResourceManager::store(filename, Resource::Type::Model, model);
}
GameObject * loadFBXFromFile(const std::string& filename)
{
	GameObject *rootGo = NULL;
	level = 0;
	// Initialize the SDK manager. This object handles memory management.
	FbxManager* lSdkManager = FbxManager::Create();

	// Create the IO settings object.
	FbxIOSettings *ios = FbxIOSettings::Create(lSdkManager, IOSROOT);
	lSdkManager->SetIOSettings(ios);

	// Create an importer using the SDK manager.
	FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "");

	// Create a new scene so that it can be populated by the imported file.
	if (!lImporter->Initialize(filename.c_str(), -1, lSdkManager->GetIOSettings())) 
	{
		return rootGo;
	}

	// Create a new scene so that it can be populated by the imported file.
	FbxScene* lScene = FbxScene::Create(lSdkManager, "myScene");
	// Import the contents of the file into the scene.
	lImporter->Import(lScene);

	// Print the nodes of the scene and their attributes recursively.
	// Note that we are not printing the root node because it should
	// not contain any attributes.
	FbxNode* lRootNode = lScene->GetRootNode();
	if (lRootNode) {
		rootGo = new GameObject();
		rootGo->setTransform(new Transform());

		std::cout << "Root Node " << lRootNode->GetName() << std::endl;
		for (int i = 0; i < lRootNode->GetChildCount(); i++)
		{
			processNode(lRootNode->GetChild(i), rootGo);
		}
	}

	return rootGo;
}
Esempio n. 9
0
Bone::Bone(FbxNode& node)
  : index ( -1 )
  , name ( node.GetName() )
  , parentName ( node.GetParent() != nullptr ? node.GetParent()->GetName() : "none" )
  , numChildren ( unsigned(node.GetChildCount()) )
  , transformation ( to_gua::mat4f(node.EvaluateLocalTransform()) )
  , offsetMatrix ( scm::math::mat4f::identity() )
{
  for (int i = 0; i < node.GetChildCount(); ++i) {
    FbxSkeleton const* skelnode { node.GetChild(i)->GetSkeleton() };
    if (skelnode && skelnode->GetSkeletonType() == FbxSkeleton::eEffector &&
        node.GetChild(i)->GetChildCount() == 0) {
      Logger::LOG_DEBUG << node.GetChild(i)->GetName()
                        << " is effector, ignoring it" << std::endl;
    } else {
      auto child = std::make_shared<Bone>(*(node.GetChild(i)));
      children.push_back(child);
    }
  }
}
Esempio n. 10
0
	FBX::FBX(FbxScene* lScene) {
		material_library = new MaterialLibrary("");

		// This function show how to cycle through scene elements in a linear way.
		const int lNodeCount = lScene->GetSrcObjectCount<FbxNode>();
		FbxStatus lStatus;

		for (int lIndex=0; lIndex<lNodeCount; lIndex++) {
			FbxNode *lNode = lScene->GetSrcObject<FbxNode>(lIndex);
			printf("Node found: %s\n", lNode->GetName());

			FbxMesh *lMesh=lNode->GetMesh();
			if (lMesh) {
				TerrainInstance *terrain_instance=buildTerrainInstanceFromFBX(lNode);
				instances.push_back(terrain_instance);
				models.push_back(terrain_instance->getModel());
			}
		}

		scene = lScene;
	}
Esempio n. 11
0
void FBXSceneInstance::ProcessSkeleton(FbxNode* pNode)
{
	FbxSkeleton* pFBXSkeleton = pNode->GetSkeleton();
	if( !pFBXSkeleton )
		return;
	
	if( !m_pSkeleton )
	{
		m_pSkeleton = new Skeleton();
	}

	int nParentBoneIndex = -1;
	FbxNode* pParentNode = pNode->GetParent();

	if( pParentNode )
		nParentBoneIndex = m_pSkeleton->FindBoneIndex(pParentNode->GetName());

	SkeletonBone* pSkeletonBone = new SkeletonBone( pNode->GetName(), nParentBoneIndex, m_pSkeleton );
	m_pSkeleton->AddSkeletonBone(pSkeletonBone);
	
	int boneIndex = m_pSkeleton->FindBoneIndex(pNode->GetName());
	pSkeletonBone->SetBoneIndex(boneIndex);
}
Esempio n. 12
0
Node::Node( FbxNode& _Node, Node* _pParent ) : m_Node( _Node ), m_pParent( _pParent )
{
	FBXSDK_printf( "Node Name: %s\n", _Node.GetName() );

// 	DisplayUserProperties(&_Node);
// 	DisplayTarget(&_Node);
// 	DisplayPivotsAndLimits(&_Node);
// 	DisplayTransformPropagation(&_Node);
// 	DisplayGeometricTransform(&_Node);

	FbxVector4	T = _Node.GetGeometricTranslation( FbxNode::eSourcePivot );
	FbxVector4	R = _Node.GetGeometricRotation( FbxNode::eSourcePivot );
	FbxVector4	S = _Node.GetGeometricScaling( FbxNode::eSourcePivot );

	m_Local2Parent.SetTRS( T, R, S );

	if ( m_pParent != NULL )
	{
		m_Local2World = m_Local2Parent * m_pParent->m_Local2World;
	}
	else
		m_Local2World = m_Local2Parent;
}
Esempio n. 13
0
//--------------------------------------------------------------------------------------
void FBXScene::ProcessBoneWeights(FbxSkin* pFBXSkin, std::vector<BoneWeights>& meshBoneWeights)
{
	FbxCluster::ELinkMode linkMode = FbxCluster::eNormalize; //Default link mode

	std::vector<BoneWeights> skinBoneWeights(meshBoneWeights.size(), BoneWeights());
	unsigned int nClusterCount = pFBXSkin->GetClusterCount();

	for( unsigned int i = 0; i < nClusterCount; ++i )
	{
		FbxCluster* pFBXCluster = pFBXSkin->GetCluster(i);

		if( !pFBXCluster )
			continue;

		linkMode = pFBXCluster->GetLinkMode();
		FbxNode* pLinkNode = pFBXCluster->GetLink();

		if( !pLinkNode )
			continue;
		
		int nBoneIndex = m_pSkeleton->FindBoneIndex(pLinkNode->GetName());
		if( nBoneIndex < 0 )
			continue;

		SkeletonBone* pSkeletonBone = m_pSkeleton->GetSkeletonBone(nBoneIndex);

		FbxAMatrix matClusterTransformMatrix;
		FbxAMatrix matClusterLinkTransformMatrix;
		pFBXCluster->GetTransformMatrix(matClusterTransformMatrix);
		pFBXCluster->GetTransformLinkMatrix(matClusterLinkTransformMatrix);

		pSkeletonBone->SetBindPoseTransform2(matClusterLinkTransformMatrix);
		pSkeletonBone->SetBoneReferenceTransform2(matClusterTransformMatrix);

		int* indices = pFBXCluster->GetControlPointIndices();
		double* weights = pFBXCluster->GetControlPointWeights();

		for( int j = 0; j < pFBXCluster->GetControlPointIndicesCount(); ++j )
		{
			skinBoneWeights[indices[j]].AddBoneWeight(nBoneIndex, (float)weights[j]);
		}
	}

	switch(linkMode)
	{
	case FbxCluster::eNormalize: //Normalize so weight sum is 1.0.
		for( unsigned int i = 0; i < skinBoneWeights.size(); ++i )
		{
			skinBoneWeights[i].Normalize();
		}
	break;

	case FbxCluster::eAdditive:	//Not supported yet. Do nothing
	break;

	case FbxCluster::eTotalOne:
		//The weight sum should already be 1.0. Do nothing.
	break;
	}

	for( unsigned int i = 0; i < meshBoneWeights.size(); ++i )
	{
		meshBoneWeights[i].AddBoneWeights(skinBoneWeights[i]);
	}	
}
Esempio n. 14
0
Bone::Bone(FbxScene& scene) {
  //construct hierarchy
  *this = Bone { *(scene.GetRootNode()) };

  std::map<std::string, std::pair<unsigned int, scm::math::mat4f> > bone_info{}
  ;
  unsigned num_bones = 0;
  for (unsigned int i = 0; i < scene.GetGeometryCount(); i++) {
    FbxGeometry* geo = scene.GetGeometry(i);
    if (geo->GetAttributeType() == FbxNodeAttribute::eMesh) {

      //check for skinning, use first skin deformer
      FbxSkin* skin;
      for (unsigned i = 0; i < geo->GetDeformerCount(); ++i) {
        FbxDeformer* defPtr = { geo->GetDeformer(i) };
        if (defPtr->GetDeformerType() == FbxDeformer::eSkin) {
          skin = static_cast<FbxSkin*>(defPtr);
          break;
        }
      }

      if (!skin) {
        Logger::LOG_ERROR << "Mesh does not contain skin deformer" << std::endl;
        assert(false);
      }

      //one cluster corresponds to one bone
      for (unsigned i = 0; i < skin->GetClusterCount(); ++i) {
        FbxCluster* cluster = skin->GetCluster(i);
        FbxNode* node = cluster->GetLink();

        if (!node) {
          Logger::LOG_ERROR << "associated node does not exist!" << std::endl;
          assert(false);
        }

        std::string bone_name(node->GetName());
        //helper to check for matrix magnitude
        auto magnitude = [](scm::math::mat4f const & mat)->float {
          float mag = 0.0f;
          for (unsigned i = 0; i < 16; ++i) {
            mag += mat[i] * mat[i];
          }
          return mag;
        }
        ;

        //reference pose of bone
        FbxAMatrix bind_transform;
        cluster->GetTransformLinkMatrix(bind_transform);
        //check if the clusters have an extra transformation
        FbxAMatrix cluster_transform;
        cluster->GetTransformMatrix(cluster_transform);
        if (magnitude(to_gua::mat4f(cluster_transform) -
                      scm::math::mat4f::identity()) > 0.000000001f) {
          Logger::LOG_WARNING
              << "weight cluster of bone '" << bone_name
              << "' has transformation, animation will be skewed" << std::endl;
        }
        //add bone to list if it is not already included
        if (bone_info.find(bone_name) == bone_info.end()) {
          bone_info[bone_name] = std::make_pair(
              num_bones,
              to_gua::mat4f(bind_transform.Inverse() * cluster_transform));
          ++num_bones;
        }
      }

      // traverse hierarchy and set accumulated values in the bone
      this->set_properties(bone_info);
    }
  }
}
Esempio n. 15
0
int main(int argc, char **argv)
{
#ifndef _DEBUG
	if (argc != 2)
	{
		printf("invalid arg");
		return 0;
	}
	const char* filename = argv[1];
#else
	const char* filename = "*****@*****.**";
#endif
	
	output.open("output.txt", ios::out | ios::trunc);
	output2.open("output2.txt", ios::out | ios::trunc);
	output3.open("output3.txt", ios::out | ios::trunc);
	if (!output.is_open())
	{
		exit(1);
	}
	FbxManager* fm = FbxManager::Create();
	FbxIOSettings *ios = FbxIOSettings::Create(fm, IOSROOT);
	//ios->SetBoolProp(EXP_FBX_ANIMATION, false);
	ios->SetIntProp(EXP_FBX_COMPRESS_LEVEL, 9);
	
	ios->SetAllObjectFlags(true);
	fm->SetIOSettings(ios);

	FbxImporter* importer = FbxImporter::Create(fm, "");
	if (!importer->Initialize(filename, -1, fm->GetIOSettings()))
	{
		printf("error returned : %s\n", importer->GetStatus().GetErrorString());
		exit(-1);
	}

	FbxScene* scene = FbxScene::Create(fm, "myscene");

	importer->Import(scene);
	importer->Destroy();
	output << "some\n";
	output << "charcnt : " << scene->GetCharacterCount() << endl << "node cnt : " << scene->GetNodeCount() << endl;
	int animstackcnt = scene->GetSrcObjectCount<FbxAnimStack>();
	output << "animstackcnt : " << animstackcnt << endl;

	output << "------------" << endl;
	vector<FbxNode*> removableNodes;

	for (int i = 0; i < scene->GetNodeCount(); i++)
	{
		FbxNode* node = scene->GetNode(i);
		output << "scene's node " << i << " : " << node->GetName() << ", childcnt : " << node->GetChildCount();
		if (node->GetNodeAttribute())
		{
			output <<", att type : " << node->GetNodeAttribute()->GetAttributeType();
			if (node->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::EType::eMesh)
			{
				FbxMesh* mesh = node->GetMesh();

				output << ", mem usage : " << mesh->MemoryUsage() << ", deformer cnt : " << mesh->GetDeformerCount(FbxDeformer::EDeformerType::eSkin) << endl;
				collapseMesh(mesh);
				FbxSkin* skin = (FbxSkin*) (mesh->GetDeformer(0, FbxDeformer::EDeformerType::eSkin));
				if (skin)
				{
					
					for (int cli = 0; cli < skin->GetClusterCount(); cli++)
					{
						FbxCluster* cluster = skin->GetCluster(cli);
						output << "\tcluster no." << cli << " has " << cluster->GetControlPointIndicesCount() << " connected verts" << endl;
						if (cluster->GetControlPointIndicesCount() == 0)
							removableNodes.push_back( cluster->GetLink() );
						
						//cluster->
						//skin->RemoveCluster(cluster);효과없음
					}

					
					
				}
				if (mesh->IsTriangleMesh())
				{
					output << "\tit's triangle mesh" << endl;
					
				}
				//mesh->RemoveDeformer(0);효과없음
			}
			else
				output << endl;
		}
		else
		{
			output << ", att type : none" << endl;
		}
	}

	for (int rni = 0; rni < removableNodes.size(); rni++)
	{
		FbxNode* rnd = removableNodes[rni];
		if (rnd && rnd->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::EType::eSkeleton)
		{
			output3 << rnd->GetName() << " node with no vert attached's curve : " << rnd->GetSrcObjectCount<FbxAnimCurve>() << "," << rnd->GetSrcObjectCount<FbxAnimCurveNode>() << endl;
		}
	}

	output << "-----------animinfo" << endl;
	int cubic = 0, linear = 0, cons = 0;
	for (int si = 0; si < animstackcnt; si++)
	{
		FbxAnimStack* stack = scene->GetSrcObject<FbxAnimStack>(si);
		for (int i = 0; i < stack->GetMemberCount<FbxAnimLayer>(); i++)
		{
			FbxAnimLayer* layer = stack->GetMember<FbxAnimLayer>(i);
			int curvenodecnt = layer->GetMemberCount<FbxAnimCurveNode>();
			int compositcnt = 0;
			for (int j = 0; j < curvenodecnt; j++)
			{
				FbxAnimCurveNode* cnode = layer->GetMember<FbxAnimCurveNode>(j);
				compositcnt += (cnode->IsComposite() ? 1 : 0);
			}
			output << "\tanimstack's layer " << i << " : " << layer->GetName() << ", curve node cnt : " << curvenodecnt << ", composit node cnt : " << compositcnt << endl;
			vector<FbxAnimCurveNode*> nodes2del;
			
			for (int j = 0; j < curvenodecnt; j++)
			{
				FbxAnimCurveNode* cnode = layer->GetMember<FbxAnimCurveNode>(j);
				output << "\t\tcurvenode " << j << " channel cnt : " << cnode->GetChannelsCount() << ", dst obj cnt " << cnode->GetDstObjectCount() << "(";
				for (int dsti = 0; dsti < cnode->GetDstObjectCount(); dsti++)
				{
					output << "," << cnode->GetDstObject(dsti)->GetName();
					if (cnode->GetDstObject(dsti)->GetSrcObjectCount() > 0)
						output << "<" << cnode->GetDstObject(dsti)->GetSrcObjectCount<FbxSkeleton>() << ">";
				}
				output << ")";
				FbxTimeSpan interval;
				if (cnode->GetAnimationInterval(interval))
				{
					output << ", start : " << interval.GetStart().GetTimeString() << ", end : " << interval.GetStop().GetTimeString() << endl;
				}
				else
				{
					nodes2del.push_back(cnode);
					output << ", no interval" << endl;
				}

				for (int chi = 0; chi < cnode->GetChannelsCount(); chi++)
				{
					
					int curvecnt = cnode->GetCurveCount(chi);
					output << "\t\t\tchannel." << chi << " curvecnt : " << curvecnt << endl;
					for (int ci = 0; ci < curvecnt; ci++)
					{
						FbxAnimCurve* curve = cnode->GetCurve(chi, ci);
						int keycnt = curve->KeyGetCount();
						output << "\t\t\t\tcurve no." << ci << " : key count : " << keycnt;
						output2 << "curve  " << ci << endl;
						
						vector<int> keys2Remove;
						for (int cki = 0; cki < keycnt; cki++)
						{
							FbxAnimCurveKey prevkey, currkey, nextkey;

							if (cki == 0 || cki == keycnt - 1)
								continue;
							
							currkey = curve->KeyGet(cki);
							prevkey = curve->KeyGet(cki-1);
							nextkey = curve->KeyGet(cki + 1);
							
							bool keepit = true;

							output2 << ci << "-" << cki;

//							keepit = keepTestHorizon(curve, prevkey, currkey, nextkey);
	//						if (keepit)
	//							keepit = slopkeepTest(curve, prevkey, currkey, nextkey);

							if (!keepit)
							{
								if (!(currkey.GetInterpolation() == FbxAnimCurveDef::EInterpolationType::eInterpolationConstant && nextkey.GetInterpolation() != FbxAnimCurveDef::EInterpolationType::eInterpolationConstant))
									keys2Remove.push_back(cki);
							}
						}
						for (int kri = keys2Remove.size() - 1; kri >= 0; kri--)
						{
							
							//curve->KeyRemove(keys2Remove[kri]);
						}
						output2 << endl;
						//output << ", cubic:linear:const : " << cubic << ":" << linear << ":" << cons << endl;
						if (keys2Remove.size() > 0)
							output << ", " << keys2Remove.size() << " keys removed";

						keycnt = curve->KeyGetCount();
						
					}

				}
			}
			//이부분은 별로 효과없음
			/*
			for (int di = 0; di < nodes2del.size(); di++)
			{
				layer->RemoveMember(nodes2del[di]);
			}
			*/
			
		}
	}
	output << "cubic:linear:const  " << cubic << ":" << linear << ":" << cons << endl;
	FbxExporter* exporter = FbxExporter::Create(fm, "");
	const char* outFBXName = "after.fbx";

	bool exportstatus = exporter->Initialize(outFBXName, -1, fm->GetIOSettings());
	if (exportstatus == false)
	{
		puts("err export fail");
	}
	exporter->Export(scene);
	exporter->Destroy();
	scene->Destroy();
	
	ios->Destroy();
	fm->Destroy();
	output.close();
	output2.close();
	output3.close();
	return 0;
}
Esempio n. 16
0
CC_FILE_ERROR FBXFilter::loadFile(const char* filename, ccHObject& container, bool alwaysDisplayLoadDialog/*=true*/, bool* coordinatesShiftEnabled/*=0*/, CCVector3d* coordinatesShift/*=0*/)
{
	// Initialize the SDK manager. This object handles memory management.
	FbxManager* lSdkManager = FbxManager::Create();

	// Create the IO settings object.
	FbxIOSettings *ios = FbxIOSettings::Create(lSdkManager, IOSROOT);
	lSdkManager->SetIOSettings(ios);
	
	// Import options determine what kind of data is to be imported.
	// True is the default, but here we’ll set some to true explicitly, and others to false.
	//(*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_MATERIAL,        true);
	//(*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_TEXTURE,         true);
	
	// Create an importer using the SDK manager.
	FbxImporter* lImporter = FbxImporter::Create(lSdkManager,"");

	CC_FILE_ERROR result = CC_FERR_NO_ERROR;
	
	// Use the first argument as the filename for the importer.
	if (!lImporter->Initialize(filename, -1, lSdkManager->GetIOSettings()))
	{ 
		ccLog::Warning(QString("[FBX] Error: %1").arg(lImporter->GetStatus().GetErrorString()));
		result = CC_FERR_READING;
	}
	else
	{
		// Create a new scene so that it can be populated by the imported file.
		FbxScene* lScene = FbxScene::Create(lSdkManager,"myScene");

		// Import the contents of the file into the scene.
		if (lImporter->Import(lScene))
		{
			// Print the nodes of the scene and their attributes recursively.
			// Note that we are not printing the root node because it should
			// not contain any attributes.
			FbxNode* lRootNode = lScene->GetRootNode();
			std::vector<FbxNode*> nodes;
			nodes.push_back(lRootNode);

			while (!nodes.empty())
			{
				FbxNode* lNode = nodes.back();
				nodes.pop_back();

				const char* nodeName = lNode->GetName();
#ifdef _DEBUG
				ccLog::Print(QString("Node: %1 - %2 properties").arg(nodeName).arg(lNode->GetNodeAttributeCount()));
#endif
				// scan the node's attributes.
				for(int i=0; i<lNode->GetNodeAttributeCount(); i++)
				{
					FbxNodeAttribute* pAttribute = lNode->GetNodeAttributeByIndex(i);
					FbxNodeAttribute::EType type = pAttribute->GetAttributeType();
#ifdef _DEBUG
					ccLog::Print(QString("\tProp. #%1").arg(GetAttributeTypeName(type)));
#endif

					switch(type)
					{ 
					case FbxNodeAttribute::eMesh:
						{
							ccMesh* mesh = FromFbxMesh(static_cast<FbxMesh*>(pAttribute),alwaysDisplayLoadDialog,coordinatesShiftEnabled,coordinatesShift);
							if (mesh)
							{
								//apply transformation
								FbxAMatrix& transform = lNode->EvaluateGlobalTransform();
								ccGLMatrix mat;
								float* data = mat.data();
								for (int c=0; c<4; ++c)
								{
									FbxVector4 C = transform.GetColumn(c);
									*data++ = static_cast<float>(C[0]);
									*data++ = static_cast<float>(C[1]);
									*data++ = static_cast<float>(C[2]);
									*data++ = static_cast<float>(C[3]);
								}
								mesh->applyGLTransformation_recursive(&mat);

								if (mesh->getName().isEmpty())
									mesh->setName(nodeName);

								container.addChild(mesh);
							}
						}
						break;

					case FbxNodeAttribute::eUnknown: 
					case FbxNodeAttribute::eNull:
					case FbxNodeAttribute::eMarker:
					case FbxNodeAttribute::eSkeleton:
					case FbxNodeAttribute::eNurbs:
					case FbxNodeAttribute::ePatch:
					case FbxNodeAttribute::eCamera:
					case FbxNodeAttribute::eCameraStereo:
					case FbxNodeAttribute::eCameraSwitcher:
					case FbxNodeAttribute::eLight:
					case FbxNodeAttribute::eOpticalReference:
					case FbxNodeAttribute::eOpticalMarker:
					case FbxNodeAttribute::eNurbsCurve:
					case FbxNodeAttribute::eTrimNurbsSurface:
					case FbxNodeAttribute::eBoundary:
					case FbxNodeAttribute::eNurbsSurface:
					case FbxNodeAttribute::eShape:
					case FbxNodeAttribute::eLODGroup:
					case FbxNodeAttribute::eSubDiv:
					default:
						//not handled yet
						break;
					}
				}

				// Recursively add the children.
				for(int j=0; j<lNode->GetChildCount(); j++)
				{
					nodes.push_back(lNode->GetChild(j));
				}
			}
		}
	}

	// The file is imported, so get rid of the importer.
	lImporter->Destroy();
	// Destroy the SDK manager and all the other objects it was handling.
	lSdkManager->Destroy();

	return container.getChildrenNumber() == 0 ? CC_FERR_NO_LOAD : CC_FERR_NO_ERROR;
}
Esempio n. 17
0
// This method is templated on the implementation of hctMayaSceneExporter::createHkxNodes()
void FbxToHkxConverter::addNodesRecursive(hkxScene *scene, FbxNode* fbxNode, hkxNode* node, int animStackIndex)
{
	for (int childIndex = 0; childIndex < fbxNode->GetChildCount(); childIndex++)
	{
		FbxNode* fbxChildNode = fbxNode->GetChild(childIndex);
		FbxNodeAttribute* fbxNodeAtttrib = fbxChildNode->GetNodeAttribute();
		bool selected = fbxChildNode->GetSelected();

		// Ignore nodes(and their descendants) if they're invisible and we ignore invisible objects
		if ( !(!m_options.m_visibleOnly || fbxNode->GetVisibility()) )
			continue;

		// Ignore nodes(and their descendants) if they're not selected and we ignore deselected objects
		if ( !(!m_options.m_selectedOnly || selected) )
			continue;

		hkxNode* newChildNode = new hkxNode();
		{
			newChildNode->m_name = fbxChildNode->GetName();			
			node->m_children.pushBack(newChildNode);
		}

		newChildNode->m_selected = selected;

		// Extract the following types of data from this node (taken from hkxScene.h):
		if (fbxNodeAtttrib != NULL)
		{
			switch (fbxNodeAtttrib->GetAttributeType())
			{
			case FbxNodeAttribute::eMesh:
				{
					// Generate hkxMesh and all its dependent data (ie: hkxSkinBinding, hkxMeshSection, hkxMaterial)
					if (m_options.m_exportMeshes)
					{
						addMesh(scene, fbxChildNode, newChildNode);
					}
					break;
				}
			case FbxNodeAttribute::eNurbsCurve:
				{
					if (m_options.m_exportSplines)
					{
						addSpline(scene, fbxChildNode, newChildNode);
					}
					break;
				}
			case FbxNodeAttribute::eCamera:
				{
					// Generate hkxCamera
					if (m_options.m_exportCameras)
					{
						addCamera(scene, fbxChildNode, newChildNode);
					}
					break;
				}
			case FbxNodeAttribute::eLight:
				{
					// Generate hkxLight
					if (m_options.m_exportLights)
					{
						addLight(scene, fbxChildNode, newChildNode);
					}
					break;
				}
			case FbxNodeAttribute::eSkeleton:
				{
					// Flag this node as a bone if it's associated with a skeleton attribute
					newChildNode->m_bone = true;
					break;
				}
			default:
				break;
			}		
		}

		// Extract this node's animation data and bind transform
		extractKeyFramesAndAnnotations(scene, fbxChildNode, newChildNode, animStackIndex);

		if (m_options.m_exportAttributes)
		{
			addSampledNodeAttributeGroups(scene, animStackIndex, fbxChildNode, newChildNode);
		}

		GetCustomVisionData(fbxChildNode, newChildNode->m_userProperties);

		addNodesRecursive(scene, fbxChildNode, newChildNode, animStackIndex);
		newChildNode->removeReference();
	}
}
Esempio n. 18
0
void fbxLoader2::readAnimationWeigths(FbxMesh* mesh)
{
	if(!animationStructure)
	{
		animationStructure = new AnimationData();
	}

	int numSkins = mesh->GetDeformerCount(FbxDeformer::eSkin);

	weightsNumber = 0;

	for (int l = 0; l<this->vertexMaxCount; l++)
	{
		for(int p = 0; p<4; p++)
		{
			this->vertexArray[l].weights[p].boneID = 0;
			this->vertexArray[l].weights[p].weight = 0.0f;
		}
	}

	int next = 0;
	int numindicestest = 0;

	for(int i = 0; i < numSkins; i++)
	{
		FbxSkin* skin = (FbxSkin*) mesh->GetDeformer(i, FbxDeformer::eSkin);

		int clusterCount = skin->GetClusterCount();
		if( clusterCount == 0 ) continue;

		for (int j = 0; j < clusterCount; j++)
		{
			FbxCluster* cluster = skin->GetCluster(j);///trzeba jakoś zrobić wszystkie linki... edit, have no idea what i meant xD
			FbxNode* bone = cluster->GetLink();

			if( !bone )
			{
				continue;
			}

			int numInfluencedVertices = cluster->GetControlPointIndicesCount();

			int* pIndexArray = cluster->GetControlPointIndices();
			numindicestest += cluster->GetControlPointIndicesCount();
			
			double *pWeightArray = cluster->GetControlPointWeights();


			for(int iControlPoint = 0; iControlPoint < numInfluencedVertices; iControlPoint++)
			{
				/*int iControlPointIndex = pIndexArray[iControlPoint];
				////////////muszę poprawić indeksy wierzchołków. teraz odwoluje sie do vertow afaik
				int boneIndex = skeleton->GetBoneByName(bone->GetName());
				int boneI = skeleton->GetBoneIndex(boneIndex);
				//boneIndices[iControlPointIndex] = iCluster;
				double weightAdd = pWeightArray[iControlPoint];

				weightsStructure* added = new weightsStructure(boneI, iControlPointIndex, weightAdd);

				this->weights[next] = added;
				next++;*/

				int iControlPointIndex = pIndexArray[iControlPoint];

				int boneIndex = skeleton->GetBoneByName(bone->GetName());
				int k = 0;

				if(vertexArray[iControlPointIndex].weights[0].weight == 0.0f)
				{
					vertexArray[iControlPointIndex].weights[0].boneID = skeleton->GetBoneIndex(boneIndex);
					vertexArray[iControlPointIndex].weights[0].weight = pWeightArray[iControlPoint];
					vertexArray[iControlPointIndex].weightsNum = 1;
				}
				else
				{
					while (k < 3 && vertexArray[iControlPointIndex].weights[k].weight != 0.0f)
					{
						k++;
					}
					vertexArray[iControlPointIndex].weights[k].boneID = skeleton->GetBoneIndex(boneIndex);
					vertexArray[iControlPointIndex].weights[k].weight = pWeightArray[iControlPoint];
					vertexArray[iControlPointIndex].weightsNum++;
				}
			}
		}
	}
}