コード例 #1
0
ファイル: polyimport.cpp プロジェクト: RobLach/Polycode
int exportToFile(const char *fileName, bool swapZY) {
	String fileNameMesh = String(fileName)+".mesh";
	OSFILE *outFile = OSBasics::open(fileNameMesh.c_str(), "wb");
	Polycode::Mesh *mesh = new Polycode::Mesh(Mesh::TRI_MESH);
	addToMesh(mesh, scene, scene->mRootNode, swapZY);
	mesh->saveToFile(outFile);
	OSBasics::close(outFile);

	if(hasWeights) {
		printf("Mesh has weights, exporting skeleton...\n");
		String fileNameSkel = String(fileName)+".skeleton";
		ISkeleton *skeleton = new ISkeleton();
	
		for (int n = 0; n < scene->mRootNode->mNumChildren; ++n) {
			if(scene->mRootNode->mChildren[n]->mNumChildren > 0) {
				addToISkeleton(skeleton, NULL, scene, scene->mRootNode->mChildren[n]);
			}
		}

		if(scene->HasAnimations()) {
			printf("Importing animations...\n");
			for(int i=0; i < scene->mNumAnimations;i++) {
				aiAnimation *a = scene->mAnimations[i];
				printf("Importing '%s' (%d tracks)\n", a->mName.data, a->mNumChannels);
			
				IAnimation *anim = new IAnimation();
				anim->tps = a->mTicksPerSecond;
				anim->name = a->mName.data;
				anim->numTracks = a->mNumChannels;
				anim->length = a->mDuration/a->mTicksPerSecond;
	
				for(int c=0; c < a->mNumChannels; c++) {
					aiNodeAnim *nodeAnim = a->mChannels[c];

					ITrack *track = new ITrack();
					track->nodeAnim = nodeAnim;
					anim->tracks.push_back(track);
				}


				skeleton->addAnimation(anim);
				
			}
		} else {
			printf("No animations in file...\n");
		}

		skeleton->saveToFile(fileName, swapZY);
	} else {
		printf("No weight data, skipping skeleton export...\n");
	}


	delete mesh;
	return 1;
}
コード例 #2
0
ファイル: polyimport.cpp プロジェクト: Gwill/Polycode
int exportToFile(String prefix, bool swapZY, bool addSubmeshes, bool listOnly, bool exportEntity) {

    Object sceneObject;
    sceneObject.root.name = "entity";
    ObjectEntry *parentEntry = sceneObject.root.addChild("root");
    
    parentEntry->addChild("id", "");
    parentEntry->addChild("tags", "");
    parentEntry->addChild("type", "Entity");
    parentEntry->addChild("cR", "1");
    parentEntry->addChild("cG", "1");
    parentEntry->addChild("cB", "1");
    parentEntry->addChild("cA", "1");
    parentEntry->addChild("blendMode", "0");
    parentEntry->addChild("sX", 1.0);
    parentEntry->addChild("sY", 1.0);
    parentEntry->addChild("sZ", 1.0);
    
    parentEntry->addChild("rX", 0.0);
    parentEntry->addChild("rY", 0.0);
    parentEntry->addChild("rZ", 0.0);
    parentEntry->addChild("rW", 1.0);
    
    parentEntry->addChild("pX", 0.0);
    parentEntry->addChild("pY", 0.0);
    parentEntry->addChild("pZ", 0.0);
    
    parentEntry->addChild("bbX", 0.0);
    parentEntry->addChild("bbY", 0.0);
    parentEntry->addChild("bbZ", 0.0);
    
    ObjectEntry *children = parentEntry->addChild("children");

		
	Polycode::Mesh *mesh = new Polycode::Mesh(Mesh::TRI_MESH);
    mesh->indexedMesh = true;
	addToMesh(prefix, mesh, scene, scene->mRootNode, swapZY, addSubmeshes, listOnly, children);
    
	
	if(addSubmeshes) {
		String fileNameMesh;
		if(prefix != "") {
			fileNameMesh = prefix+".mesh";			
		} else {
			fileNameMesh = "out.mesh";
		}		

		if(listOnly) {
			printf("%s\n", fileNameMesh.c_str());
		} else {
			OSFILE *outFile = OSBasics::open(fileNameMesh.c_str(), "wb");	
			mesh->saveToFile(outFile, writeNormals, writeTangents, writeColors, writeBoneWeights, writeUVs, writeSecondaryUVs);
			OSBasics::close(outFile);
		}
	}
		
	if(hasWeights) {		
		if(listOnly) {
			printf("%s.skeleton\n", prefix.c_str());
		} else {
			printf("Mesh has weights, exporting skeleton...\n");
		}	
		
		String fileNameSkel;
        if(prefix != "") {
            fileNameSkel = prefix+".skeleton";
        } else {
            fileNameSkel = "out.skeleton";
        }
		ISkeleton *skeleton = new ISkeleton();
	
		for (int n = 0; n < scene->mRootNode->mNumChildren; ++n) {
			if(scene->mRootNode->mChildren[n]->mNumChildren > 0) {
				addToISkeleton(skeleton, NULL, scene, scene->mRootNode->mChildren[n]);
			}
		}

		if(scene->HasAnimations()) {
			printf("Importing animations...\n");
			for(int i=0; i < scene->mNumAnimations;i++) {
				aiAnimation *a = scene->mAnimations[i];
				
				if(listOnly) {
					printf("%s%s.anim\n", prefix.c_str(), a->mName.data);
				} else {
					printf("Importing '%s' (%d tracks)\n", a->mName.data, a->mNumChannels);					
				}	
				
			
				IAnimation *anim = new IAnimation();
				anim->tps = a->mTicksPerSecond;
				anim->name = a->mName.data;
				anim->numTracks = a->mNumChannels;
				anim->length = a->mDuration/a->mTicksPerSecond;
	
				for(int c=0; c < a->mNumChannels; c++) {
					aiNodeAnim *nodeAnim = a->mChannels[c];

					ITrack *track = new ITrack();
					track->nodeAnim = nodeAnim;
					anim->tracks.push_back(track);
				}


				skeleton->addAnimation(anim);
				
			}
		} else {
			printf("No animations in file...\n");
		}

		if(!listOnly) {
			skeleton->saveToFile(fileNameSkel.c_str(), swapZY);
		}
	} else {
		if(!listOnly) {
			printf("No weight data, skipping skeleton export...\n");
		}
	}
    
    if(!listOnly && exportEntity) {
		String entityFileName;
		if(prefix != "") {
			entityFileName = prefix+".entity";
		} else {
			entityFileName = "out.entity";
		}        sceneObject.saveToXML(entityFileName);
    }

	if(mesh) {
		delete mesh;
	}
	return 1;
}