domCOLLADA* root = dae.add(file); CheckResult(root); CheckTestResult(addAsset(root)); CheckTestResult(addGeometry(root)); CheckTestResult(addImage(root)); CheckTestResult(addEffect(root)); CheckTestResult(addMaterial(root)); CheckTestResult(addVisualScene(root)); dae.writeAll(); // As a very simple check for possible errors, make sure the document loads // back in successfully. dae.clear(); CheckResult(dae.open(file)); return testResult(true); } testResult addAsset(daeElement* root) { SafeAdd(root, "asset", asset); asset->add("created")->setCharData("2008-02-23T13:30:00Z"); asset->add("modified")->setCharData("2008-02-23T13:30:00Z"); return testResult(true); } template<typename T> daeTArray<T> rawArrayToDaeArray(T rawArray[], size_t count) { daeTArray<T> result; for (size_t i = 0; i < count; i++)
int main(int argc, char **argv ) { // describe command-line options std::string scene_file; // input collada scene filename std::string hdf5_file; // input hdf5 filename std::string hdf5_group; std::string file_out; // output collada animation filename po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("hdf5-file", po::value<std::string>(&hdf5_file), "HDF5 input data file") ("hdf5-group", po::value<std::string>(&hdf5_group)->default_value("/"), "subgroup within the HDF5 file") ("scene-file", po::value<std::string>(&scene_file), "collada input scene file") ("output-file,o", po::value<std::string>(&file_out)->default_value("out.dae"), "output file") ; po::positional_options_description p; p.add("hdf5-file", 1); p.add("scene-file", 1); p.add("output-file", 1); po::variables_map vm; po::store(po::command_line_parser(argc, argv). options(desc).positional(p).run(), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << "\n"; return 1; } std::vector<std::string> elements; DAE *dae = new DAE; //daeElement *root = (daeElement*)dae->open(scene_file); domCOLLADA *root = (domCOLLADA*)dae->open(scene_file); H5RandomReader myReader(hdf5_file, hdf5_group); FrameData fd = myReader.getFrame(0); std::map <std::string, Matrix >::iterator it; for (it = fd.matrices.begin(); it != fd.matrices.end(); ++it){ elements.push_back(std::string(it->first)); } //printf("Found %i elements... \n", elements.size() ); domLibrary_animations *lib_anim; if (elements.size()!=0) { lib_anim = (domLibrary_animations*)root->add("library_animations"); } //printf("Found %i steps...\n", (int)myReader.getNbSteps()); for (int j=0; j<elements.size(); j++){ AnimationExporter *matrix = new AnimationExporter(lib_anim, 16, elements[j].c_str(), "matrix"); for (int i=0; i<myReader.getNbSteps(); i++){ //printf("Step %i\n", i); fd = myReader.getFrame(i); std::map <std::string, Matrix >::iterator it; for (it = fd.matrices.begin(); it != fd.matrices.end(); ++it){ if (elements[j] == (it->first).c_str()) { //std::cout << "Key : " << it->first << std::endl; //td::cout << ax << "\t" << ay << "\t" << az << std::endl; matrix->add(myReader.getTime(i), it->second[0 + 0*4], it->second[1 + 0*4], it->second[2 + 0*4], it->second[3 + 0*4], it->second[0 + 1*4], it->second[1 + 1*4], it->second[2 + 1*4], it->second[3 + 1*4], it->second[0 + 2*4], it->second[1 + 2*4], it->second[2 + 2*4], it->second[3 + 2*4], it->second[0 + 3*4], it->second[1 + 3*4], it->second[2 + 3*4], it->second[3 + 3*4]); } } } } dae->add(file_out); dae->setRoot(file_out, (domCOLLADA*)root); dae->write(file_out); return 0; }
int main(int argc, const char *argv[]) { if (argc != 6) { if (fprintf(stderr, "Usage: %s [dimension] [bgR] [bgG] [bgB] [texture]\n", argv[0]) < 0) perror("fprintf"); return 0; } buf = new FrameBuffer(atoi(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4])); #ifdef WIN32 const char *fn = _tempnam("C:\tmp", "transform"); if (!fn) { perror("_tempnam"); return 0; } #else const char *fn = tmpnam(NULL); if (!fn) { perror("tmpnam"); return 0; } #endif FILE *tmpfile = fopen(fn, "w"); if (!tmpfile) { perror("fopen"); return 0; } int c; while ((c = getchar()) != EOF) if (fputc(c, tmpfile) == EOF) { perror("fputc"); return 0; } if (ferror(tmpfile)) { perror("getchar"); return 0; } if (fclose(tmpfile) == EOF) { perror("fclose"); return 0; } DAE dae; daeElement *root = dae.open(fn); if (!root) { if (fprintf(stderr, "Problem opening temporary file.\n") < 0) perror("fprintf"); return 0; } const daeTArray<daeElementRef> visualSceneChildren = daeSafeCast<domInstanceWithExtra>(root->getChild("scene")->getChild("instance_visual_scene")) ->getUrl().getElement()->getChildren(); for (size_t i = 0; i < visualSceneChildren.getCount(); i++) { const daeElementRef node = visualSceneChildren[i]; if (!strcmp(node->getElementName(), "node")) processNode(daeSafeCast<domNode>(node), dae, argv[5]); } dae.clear(); buf->write(dae, fn); tmpfile = fopen(fn, "r"); if (!tmpfile) { perror("fopen"); return 0; } while ((c = fgetc(tmpfile)) != EOF) if (putchar(c) == EOF) { perror("putchar"); return 0; } if (ferror(tmpfile)) { perror("fgetc"); return 0; } if (fclose(tmpfile) == EOF) { perror("fclose"); return 0; } if (remove(fn)) { perror("remove"); return 0; } }
int main(int argc, char* argv[]) { if (argc < NUM_COMMAND_LINE_PARAMETERS) { printf("Usage : HierarchyPreservationChecking.exe file1.dae file2.dae\n"); exit(0); } DAE *dae; dae = new DAE; daeDocument *pDocuments[NUM_COMMAND_LINE_PARAMETERS - 1]; domCOLLADA *root[NUM_COMMAND_LINE_PARAMETERS - 1]; domCOLLADA::domScene *scene[NUM_COMMAND_LINE_PARAMETERS - 1]; domVisual_scene *visualScene[NUM_COMMAND_LINE_PARAMETERS - 1]; // loading files to DAE containers for (int i = 0;i < NUM_COMMAND_LINE_PARAMETERS - 1;i++) { root[i] = dae->open(argv[i + PARAMETER_OFFSET]); if (root[i] == NULL) { printf("DOM Load error at = %d\n", i); printf("Filename = %s\n", argv[i]); // clear memory if needed: delete dae; // report error code: return -1; } // visual scene library for each scene[i] = root[i]->getScene(); // Get visual scene visualScene[i] = daeSafeCast <domVisual_scene> ( scene[i]->getInstance_visual_scene()->getUrl().getElement() ); // Check visual scene if (visualScene[i] == NULL) { printf("Error: Visual Scene loading error at = %d\n", i); printf("Filename = %s\n", argv[i]); // clear memory if needed: delete dae; // report error code: return -1; } // check documents pDocuments[i] = dae->getDoc(argv[i + PARAMETER_OFFSET]); if (pDocuments[i] == NULL) { printf("Documents Load error at = %d\n", i); printf("Filename = %s\n", argv[i]); // clear memory if needed: delete dae; // report error code: return -1; } } NodeHPChecker * pNChecker = new NodeHPChecker(pDocuments[0], pDocuments[1], visualScene[0], visualScene[1]); if (pNChecker->IsPreserved()) { #ifdef TESTING printf("They are the same.\n"); #endif return 1; } else { #ifdef TESTING printf("They are not the same.\n"); #endif return 0; } }
void TSRModelExporterDOM::ProcessModel( const char* _pSrcFileName, const char* _pDestFileName, eTSRExportPlatform _Platform ) { DAE dae; daeString DomVersion = dae.getDomVersion(); domCOLLADA* root = dae.open( _pSrcFileName ); #ifndef COLLADA14 if ( root == NULL ) { ConvertToCollada15( file ); root = dae.open( file ); } #endif if ( root ) { printf( "\nCollada Asset is OK..\n" ); } else { throw "Asset cooking failed"; return; } domCOLLADA& _colladaRoot = *root; m_Platform = _Platform; m_SrcFileName = _pSrcFileName; m_DestFileName = _pDestFileName; string fullPath = _pDestFileName; int slashPosition = ( int ) fullPath.find_last_of( "/" ); string dstFileNameHeader = ""; if( slashPosition > -1 ) { dstFileNameHeader = fullPath.substr( 0, slashPosition ); } TSRFileSystem::CreateFolder( dstFileNameHeader.c_str() ); m_ShadersNames.clear(); m_ShadersNames.push_back( "supershader.fx" ); /// up axis is Z or Y..? CalculateFixupMatrixDOM( _colladaRoot ); /// process all images... ProcessImagesLibraryDOM( _colladaRoot ); /// process all materials... ProcessMaterialsLibraryDOM( _colladaRoot ); /// process all animations ProcessAnimationsLibraryDOM( _colladaRoot ); domVisual_scene* visualScene = daeSafeCast< domVisual_scene >( _colladaRoot.getDescendant( "visual_scene" ) ); /// Now covert all the <node>s in the <visual_scene>. This is a recursive process, // so any child nodes will also be converted. domNode_Array& nodes = visualScene->getNode_array(); m_MatrixStack.Push(); m_MatrixStack.LoadMatrix( m_FixupMatrix.d ); /// generate the skeleton bones for ( size_t i = 0; i < nodes.getCount(); i++ ) { GenerateSkeletonRecDOM( nodes[ i ] ); } /// generate the nodes and the render nodes.. for ( size_t i = 0; i < nodes.getCount(); i++ ) { GenerateTwisterNodesRecDOM( nodes[ i ], m_FixupMatrix ); } m_MatrixStack.Pop(); /// compute the whole aabb... TSRBBox aabb; for( unsigned int i = 0; i < nodes.getCount(); i++ ) { domNode* pNode=nodes[ i ]; ComputeAABBDOM( pNode, aabb ); } m_AABB.m_vMin = aabb.m_vMin * m_FixupMatrix; m_AABB.m_vMax = aabb.m_vMax * m_FixupMatrix; m_pDomRootNodes = &nodes; /// ready to write WriteProcessedModel( _pDestFileName ); }