void NLPACS::CZoneTessellation::saveTessellation(COFile &output) { output.serialCont(_Vertices); uint i; for (i=0; i<_Tessellation.size(); ++i) _Tessellation[i].ElemId = i; uint32 numTessel = (uint32)_Tessellation.size(); output.serial(numTessel); for (i=0; i<_Tessellation.size(); ++i) { _Tessellation[i].serial(output, _Tessellation); } }
// *************************************************************************** int main(int argc, char* argv[]) { // Filter addSearchPath NLMISC::createDebug(); InfoLog->addNegativeFilter ("adding the path"); // Register 3d registerSerial3d (); // Good number of args ? if (argc<4) { // Help message printf ("ig_lighter [directoryIn] [pathOut] [parameter_file] \n"); } else { try { string directoryIn= argv[1]; string pathOut= argv[2]; string paramFile= argv[3]; CInstanceLighter::CLightDesc lighterDesc; string grFile, rbankFile; // Verify directoryIn. directoryIn= CPath::standardizePath(directoryIn); if( !CFile::isDirectory(directoryIn) ) { printf("DirectoryIn %s is not a directory", directoryIn.c_str()); return -1; } // Verify pathOut. pathOut= CPath::standardizePath(pathOut); if( !CFile::isDirectory(pathOut) ) { printf("PathOut %s is not a directory", pathOut.c_str()); return -1; } // Load and setup configFile. //================= CConfigFile parameter; // Load and parse the param file parameter.load (paramFile); // Get the search pathes CConfigFile::CVar &search_pathes = parameter.getVar ("search_pathes"); uint path; for (path = 0; path < (uint)search_pathes.size(); path++) { // Add to search path CPath::addSearchPath (search_pathes.asString(path)); } // Light direction CConfigFile::CVar &sun_direction = parameter.getVar ("sun_direction"); lighterDesc.LightDirection.x=sun_direction.asFloat(0); lighterDesc.LightDirection.y=sun_direction.asFloat(1); lighterDesc.LightDirection.z=sun_direction.asFloat(2); lighterDesc.LightDirection.normalize (); // Grid size CConfigFile::CVar &quad_grid_size = parameter.getVar ("quad_grid_size"); lighterDesc.GridSize=quad_grid_size.asInt(); // Grid size CConfigFile::CVar &quad_grid_cell_size = parameter.getVar ("quad_grid_cell_size"); lighterDesc.GridCellSize=quad_grid_cell_size.asFloat(); // Shadows enabled ? CConfigFile::CVar &shadow = parameter.getVar ("shadow"); lighterDesc.Shadow=shadow.asInt ()!=0; // OverSampling CConfigFile::CVar &ig_oversampling = parameter.getVar ("ig_oversampling"); lighterDesc.OverSampling= ig_oversampling.asInt (); // validate value: 0, 2, 4, 8, 16 lighterDesc.OverSampling= raiseToNextPowerOf2(lighterDesc.OverSampling); clamp(lighterDesc.OverSampling, 0U, 16U); if(lighterDesc.OverSampling<2) lighterDesc.OverSampling= 0; // gr CConfigFile::CVar &grbank = parameter.getVar ("grbank"); grFile= grbank.asString (); // rbank CConfigFile::CVar &rbank = parameter.getVar ("rbank"); rbankFile= rbank.asString (); // CellSurfaceLightSize; CConfigFile::CVar &cell_surface_light_size = parameter.getVar ("cell_surface_light_size"); float cellSurfaceLightSize= cell_surface_light_size.asFloat (); if(cellSurfaceLightSize<=0) throw Exception("cell_surface_light_size must be > 0"); // CellRaytraceDeltaZ CConfigFile::CVar &cell_raytrace_delta_z = parameter.getVar ("cell_raytrace_delta_z"); float cellRaytraceDeltaZ= cell_raytrace_delta_z.asFloat (); // colIdentifierPrefix CConfigFile::CVar &col_identifier_prefix = parameter.getVar ("col_identifier_prefix"); string colIdentifierPrefix= col_identifier_prefix.asString (); // colIdentifierSuffix CConfigFile::CVar &col_identifier_suffix = parameter.getVar ("col_identifier_suffix"); string colIdentifierSuffix= col_identifier_suffix.asString (); // colIdentifierSuffix CConfigFile::CVar &build_debug_surface_shape = parameter.getVar ("build_debug_surface_shape"); bool buildDebugSurfaceShape= build_debug_surface_shape.asInt()!=0; // try to open gr and rbank CRetrieverBank *retrieverBank= NULL; CGlobalRetriever *globalRetriever= NULL; uint32 grFileDate= 0; uint32 rbankFileDate= 0; if( grFile!="" && rbankFile!="" ) { CIFile fin; // serial the retrieverBank. Exception if not found. fin.open(CPath::lookup(rbankFile)); retrieverBank= new CRetrieverBank; retrieverBank->setNamePrefix(CFile::getFilenameWithoutExtension(rbankFile).c_str ()); // Add the search path for LR files CPath::addSearchPath (CFile::getPath(rbankFile)); fin.serial(*retrieverBank); fin.close(); // serial the globalRetriever. Exception if not found. fin.open(CPath::lookup(grFile)); globalRetriever= new CGlobalRetriever; // set the RetrieverBank before loading globalRetriever->setRetrieverBank(retrieverBank); fin.serial(*globalRetriever); fin.close(); // Get File Dates rbankFileDate= CFile::getFileModificationDate(CPath::lookup(rbankFile)); grFileDate= CFile::getFileModificationDate(CPath::lookup(grFile)); // And init them. globalRetriever->initAll(); } // Scan and load all files .ig in directories //================= vector<string> listFile; vector<CInstanceGroup*> listIg; vector<string> listIgFileName; vector<string> listIgPathName; CPath::getPathContent(directoryIn, false, false, true, listFile); for(uint iFile=0; iFile<listFile.size(); iFile++) { string &igFile= listFile[iFile]; // verify it is a .ig. if( CFile::getExtension(igFile) == "ig" ) { // Read the InstanceGroup. CInstanceGroup *ig= new CInstanceGroup; CIFile fin; fin.open(CPath::lookup(igFile)); fin.serial(*ig); // add to list. listIg.push_back(ig); listIgPathName.push_back(igFile); listIgFileName.push_back(CFile::getFilename(igFile)); } } // For all ig, light them, and save. //================= for(uint iIg= 0; iIg<listIg.size(); iIg++) { string fileNameIn= listIgFileName[iIg]; string fileNameOut= pathOut + fileNameIn; // If File Out exist if(CFile::fileExists(fileNameOut)) { // If newer than file In (and also newer than retrieverInfos), skip uint32 fileOutDate= CFile::getFileModificationDate(fileNameOut); if( fileOutDate > CFile::getFileModificationDate(listIgPathName[iIg]) && fileOutDate > rbankFileDate && fileOutDate > grFileDate ) { printf("Skiping %s\n", fileNameIn.c_str()); continue; } } // progress printf("Processing %s\n", fileNameIn.c_str()); CInstanceGroup igOut; // Export a debugSun Name. string debugSunName; debugSunName= pathOut + "/" + CFile::getFilenameWithoutExtension(fileNameIn) + "_debug_sun_.shape"; string debugPLName; debugPLName= pathOut + "/" + CFile::getFilenameWithoutExtension(fileNameIn) + "_debug_pl_.shape"; // light the ig. CIgLighterLib::CSurfaceLightingInfo slInfo; slInfo.CellSurfaceLightSize= cellSurfaceLightSize; slInfo.CellRaytraceDeltaZ= cellRaytraceDeltaZ; slInfo.RetrieverBank= retrieverBank; slInfo.GlobalRetriever= globalRetriever; slInfo.IgFileName= CFile::getFilenameWithoutExtension(fileNameIn); slInfo.ColIdentifierPrefix= colIdentifierPrefix; slInfo.ColIdentifierSuffix= colIdentifierSuffix; slInfo.BuildDebugSurfaceShape= buildDebugSurfaceShape; slInfo.DebugSunName= debugSunName; slInfo.DebugPLName= debugPLName; lightIg(*listIg[iIg], igOut, lighterDesc, slInfo, fileNameIn.c_str ()); // Save this ig. COFile fout; fout.open(fileNameOut); fout.serial(igOut); fout.close(); // skip a line printf("\n"); } } catch (Exception& except) { // Error message nlwarning ("ERROR %s\n", except.what()); } } // Landscape is not deleted, nor the instanceGroups, for faster quit. // Must disalbe BlockMemory checks (for pointLights). NL3D_BlockMemoryAssertOnPurge= false; // exit. return 0; }
//----------------------------------------------- // dump : // Create a file with information to debug. //----------------------------------------------- void dump(const std::string &name) { // Write information to start as the version COFile fStart; if(fStart.open(name + "_start.rec", false, false)) { CVectorD currentPos = UserEntity->pos(); fStart.serialVersion(RecordVersion); fStart.serial(currentPos); // Close the File. fStart.close(); } else nlwarning("dump: cannot open/create the file '%s_start.rec'.", name.c_str()); // Write the DB IngameDbMngr.write(name + "_db.rec"); // Open the file. COFile f; if(f.open(name + ".rec", false, false)) { // Dump entities. EntitiesMngr.dump(f); // Dump Client CFG. ClientCfg.serial(f); // Close the File. f.close(); } else nlwarning("dump: cannot open/create the file '%s.rec'.", name.c_str()); // Open the file. if(f.open(name + ".xml", false, true)) { // Create the XML stream COXml output; // Init if(output.init (&f, "1.0")) { // Open the XML Dump. output.xmlPush("XML"); // Dump Client CFG. ClientCfg.serial(output); // Dump entities. EntitiesMngr.dumpXML(output); // Close the XML Dump. output.xmlPop(); // Flush the stream, write all the output file output.flush(); } else nlwarning("dump: cannot initialize '%s.xml'.", name.c_str()); // Close the File. f.close(); } else nlwarning("dump: cannot open/create the file '%s.xml'.", name.c_str()); }// dump //
// *************************************************************************** int main(int argc, char *argv[]) { // Filter addSearchPath NLMISC::createDebug(); NLMISC::InfoLog->addNegativeFilter ("adding the path"); if (argc != 3) { nlwarning("usage : %s hlsinfo_dir output_name ", argv[0]); exit(-1); } // get all .hlsinfo file in directory. vector<string> files; vector<string> hlsInfofiles; NLMISC::CPath::getPathContent(argv[1], false, false, true, files); hlsInfofiles.reserve(files.size()); uint k; for (k = 0; k < files.size(); ++k) { std::string fileExt = NLMISC::strupr(NLMISC::CFile::getExtension(files[k])); if(fileExt=="HLSINFO") hlsInfofiles.push_back(files[k]); } // If none, quit. if(hlsInfofiles.empty()) exit(-1); // Concat all hlsinfo in a Bank CHLSTextureBank textBank; for (k = 0; k < hlsInfofiles.size(); ++k) { printf("HLSBank Process [%2d]\r", (uint)(100*k/hlsInfofiles.size())); try { CIFile f(hlsInfofiles[k]); CHLSBankTextureInfo textInfo; f.serial(textInfo); addTextToBank(textInfo, textBank); } catch(Exception &e) { nlwarning("ERROR: Unable to process %s. Reason: %s. Processing next", hlsInfofiles[k].c_str(), e.what()); } } // compile it textBank.compile(); // save the bank. COFile fOut; try { if(!fOut.open(argv[2])) throw int(0); fOut.serial(textBank); fOut.close(); } catch(Exception &e) { nlwarning("ERROR: Unable to write HLS Bank %s: %s", argv[2], e.what()); exit(-1); } catch(...) { nlwarning("ERROR: Unable to write HLS Bank %s.", argv[2]); exit(-1); } return 0; }
int main(int argc, char* argv[]) { // Filter addSearchPath NLMISC::createDebug(); InfoLog->addNegativeFilter ("adding the path"); // Register 3d registerSerial3d (); // Good number of args ? if (argc<5) { // Help message printf ("%s [zonein.zonel] [igout.ig] [parameter_file] [dependancy_file]\n", argv[0]); } else { // Ok, read the zone CIFile inputFile; // Get extension string ext=getExt (argv[1]); string dir=getDir (argv[1]); // Open it for reading if (inputFile.open (argv[1])) { // Zone name string zoneName=toLower (string ("zone_"+getName (argv[1]))); // Load the zone try { // Read the config file CConfigFile parameter; // Load and parse the parameter file parameter.load (argv[3]); // ********** // *** Build the lighter descriptor // ********** CInstanceLighter::CLightDesc lighterDesc; // Light direction CConfigFile::CVar &sun_direction = parameter.getVar ("sun_direction"); lighterDesc.LightDirection.x=sun_direction.asFloat(0); lighterDesc.LightDirection.y=sun_direction.asFloat(1); lighterDesc.LightDirection.z=sun_direction.asFloat(2); lighterDesc.LightDirection.normalize (); // Grid size CConfigFile::CVar &quad_grid_size = parameter.getVar ("quad_grid_size"); lighterDesc.GridSize=quad_grid_size.asInt(); // Grid size CConfigFile::CVar &quad_grid_cell_size = parameter.getVar ("quad_grid_cell_size"); lighterDesc.GridCellSize=quad_grid_cell_size.asFloat(); // Shadows enabled ? CConfigFile::CVar &shadow = parameter.getVar ("shadow"); lighterDesc.Shadow=shadow.asInt ()!=0; // OverSampling CConfigFile::CVar &ig_oversampling = parameter.getVar ("ig_oversampling"); lighterDesc.OverSampling= ig_oversampling.asInt (); // validate value: 0, 2, 4, 8, 16 lighterDesc.OverSampling= raiseToNextPowerOf2(lighterDesc.OverSampling); clamp(lighterDesc.OverSampling, 0U, 16U); if(lighterDesc.OverSampling<2) lighterDesc.OverSampling= 0; // For ig of Zones, never disable Sun contrib !!! lighterDesc.DisableSunContribution= false; // Get the search pathes CConfigFile::CVar &search_pathes = parameter.getVar ("search_pathes"); uint path; for (path = 0; path < (uint)search_pathes.size(); path++) { // Add to search path CPath::addSearchPath (search_pathes.asString(path)); } // A landscape allocated with new: it is not delete because destruction take 3 secondes more! CLandscape *landscape=new CLandscape; landscape->init(); // A zone lighter CMyIgZoneLighter lighter; lighter.init (); // A vector of zone id vector<uint> listZoneId; // The zone CZone zone; // List of ig std::list<CInstanceGroup*> instanceGroup; // Load zone.serial (inputFile); inputFile.close(); // Load ig of the zone string igName = getName (argv[1])+".ig"; string igNameLookup = CPath::lookup (igName, false, false); if (!igNameLookup.empty()) igName = igNameLookup; bool zoneIgLoaded; // Try to open the file CInstanceGroup *centerInstanceGroup= NULL; if (inputFile.open (igName)) { // load the center ig centerInstanceGroup=new CInstanceGroup; // Serial it centerInstanceGroup->serial (inputFile); inputFile.close(); // Add to the list instanceGroup.push_back (centerInstanceGroup); zoneIgLoaded = true; } else { // Warning fprintf (stderr, "Warning: can't load instance group %s\n", igName.c_str()); zoneIgLoaded = false; } // If can't load the center instanceGroup, skip it. if(!zoneIgLoaded) return 0; // Get bank path CConfigFile::CVar &bank_name_var = parameter.getVar ("bank_name"); string bank_name = bank_name_var.asString (); string bank_name_lookup = CPath::lookup (bank_name); if (!bank_name_lookup.empty()) bank_name = bank_name_lookup; // Load the bank if (inputFile.open (bank_name)) { try { // Load landscape->TileBank.serial (inputFile); landscape->initTileBanks(); } catch (const Exception &e) { // Error nlwarning ("ERROR error loading tile bank %s\n%s\n", bank_name.c_str(), e.what()); } } else { // Error nlwarning ("ERROR can't load tile bank %s\n", bank_name.c_str()); } // Add the zone landscape->addZone (zone); listZoneId.push_back (zone.getZoneId()); // Load instance group ? CConfigFile::CVar &load_ig= parameter.getVar ("load_ig"); bool loadInstanceGroup = load_ig.asInt ()!=0; // Continue to build ? bool continu=true; // Try to load additionnal instance group. if (loadInstanceGroup) { // Additionnal instance group try { CConfigFile::CVar &additionnal_ig = parameter.getVar ("additionnal_ig"); for (uint add=0; add<(uint)additionnal_ig.size(); add++) { // Input file CIFile inputFile; // Name of the instance group string name = additionnal_ig.asString(add); string nameLookup = CPath::lookup (name, false, false); if (!nameLookup.empty()) name = nameLookup; // Try to open the file if (inputFile.open (name)) { // New ig CInstanceGroup *group=new CInstanceGroup; // Serial it group->serial (inputFile); inputFile.close(); // Add to the list instanceGroup.push_back (group); } else { // Error nlwarning ("ERROR can't load instance group %s\n", name.c_str()); // Stop before build continu=false; } } } catch (const NLMISC::EUnknownVar &) { nlinfo("No additionnal ig's to load"); } } // Shadow ? if (lighterDesc.Shadow) { // Load and parse the dependency file CConfigFile dependency; dependency.load (argv[4]); // *** Scan dependency file CConfigFile::CVar &dependant_zones = dependency.getVar ("dependencies"); for (uint i=0; i<(uint)dependant_zones.size(); i++) { // Get zone name string zoneName=dependant_zones.asString(i); // Load the zone CZone zoneBis; // Open it for reading if (inputFile.open (dir+zoneName+ext)) { // Read it zoneBis.serial (inputFile); inputFile.close(); // Add the zone landscape->addZone (zoneBis); listZoneId.push_back (zoneBis.getZoneId()); } else { // Error message and continue nlwarning ("ERROR can't load zone %s\n", (dir+zoneName+ext).c_str()); } // Try to load an instance group. if (loadInstanceGroup) { string name = zoneName+".ig"; string nameLookup = CPath::lookup (name, false, false); if (!nameLookup.empty()) name = nameLookup; // Name of the instance group if (inputFile.open (name)) { // New ig CInstanceGroup *group=new CInstanceGroup; // Serial it group->serial (inputFile); inputFile.close(); // Add to the list instanceGroup.push_back (group); } else { // Error message and continue nlwarning ("WARNING can't load instance group %s\n", name.c_str()); } } } } // A vector of CInstanceLighter::CTriangle vector<CInstanceLighter::CTriangle> vectorTriangle; // ********** // *** Build triangle array // ********** landscape->checkBinds (); // Add triangles from landscape, for pointLight lighting. landscape->enableAutomaticLighting (false); lighter.addTriangles (*landscape, listZoneId, 0, vectorTriangle); // Load and add shapes // Map of shape std::map<string, IShape*> shapeMap; // For each instance group std::list<CInstanceGroup*>::iterator ite=instanceGroup.begin(); while (ite!=instanceGroup.end()) { // Instance group CInstanceGroup *group=*ite; // For each instance for (uint instance=0; instance<group->getNumInstance(); instance++) { // Get the instance shape name string name=group->getShapeName (instance); // Skip it?? use the DontCastShadowForExterior flag. See doc of this flag if(group->getInstance(instance).DontCastShadow || group->getInstance(instance).DontCastShadowForExterior) continue; // Add a .shape at the end ? if (!name.empty()) { if (name.find('.') == std::string::npos) name += ".shape"; // Find the file string nameLookup = CPath::lookup (name, false, false); if (!nameLookup.empty()) name = nameLookup; // Find the shape in the bank std::map<string, IShape*>::iterator iteMap=shapeMap.find (name); if (iteMap==shapeMap.end()) { // Input file CIFile inputFile; if (inputFile.open (name)) { // Load it CShapeStream stream; stream.serial (inputFile); // Get the pointer iteMap=shapeMap.insert (std::map<string, IShape*>::value_type (name, stream.getShapePointer ())).first; } else { // Error nlwarning ("WARNING can't load shape %s\n", name.c_str()); } } // Loaded ? if (iteMap!=shapeMap.end()) { // Build the matrix CMatrix scale; scale.identity (); scale.scale (group->getInstanceScale (instance)); CMatrix rot; rot.identity (); rot.setRot (group->getInstanceRot (instance)); CMatrix pos; pos.identity (); pos.setPos (group->getInstancePos (instance)); CMatrix mt=pos*rot*scale; // If centerInstanceGroup, take good instanceId, to avoid selfShadowing sint instanceId; if(group == centerInstanceGroup) instanceId= instance; else instanceId= -1; // Add triangles lighter.addTriangles (*iteMap->second, mt, vectorTriangle, instanceId); } } } // For each point light of the ig const std::vector<CPointLightNamed> &pointLightList= group->getPointLightList(); for (uint plId=0; plId<pointLightList.size(); plId++) { // Add it to the Ig. lighter.addStaticPointLight(pointLightList[plId], igName.c_str ()); } // Next instance group ite++; } // Continue ? if (continu) { // ********** // *** Light! // ********** // Start time TTime time=CTime::getLocalTime (); // Output ig CInstanceGroup output; // Light the zone lighter.light (*centerInstanceGroup, output, lighterDesc, vectorTriangle, landscape); // Compute time printf ("\rCompute time: %d ms \r", (uint)(CTime::getLocalTime ()-time)); // Save the zone COFile outputFile; // Open it if (outputFile.open (argv[2])) { try { // Save the new ig outputFile.serial(output); } catch (const Exception& except) { // Error message nlwarning ("ERROR writing %s: %s\n", argv[2], except.what()); } } else { // Error can't open the file nlwarning ("ERROR Can't open %s for writing\n", argv[2]); } } else { // Error nlwarning ("ERROR Abort: files are missing.\n"); } } catch (const Exception& except) { // Error message nlwarning ("ERROR %s\n", except.what()); } } else { // Error can't open the file nlwarning ("ERROR Can't open %s for reading\n", argv[1]); } } // Landscape is not deleted, nor the instanceGroups, for faster quit. // Must disalbe BlockMemory checks (for pointLights). NL3D_BlockMemoryAssertOnPurge= false; // exit. return 0; }
// *************************************************************************** int main(int argc, char* argv[]) { // Register 3d registerSerial3d (); // Avoid some stupids warnings. NLMISC::createDebug(); skipLog("variable \"RootConfigFilename\""); skipLog("variable \"anim_low_precision_tracks\""); skipLog("variable \"anim_sample_rate\""); InfoLog->addNegativeFilter("FEHTIMER>"); InfoLog->addNegativeFilter("adding the path"); // Good number of args ? if (argc<4) { // Help message printf ("anim_builder [directoryIn] [pathOut] [parameter_file] \n"); } else { try { string directoryIn= argv[1]; string pathOut= argv[2]; string paramFile= argv[3]; // Verify directoryIn. directoryIn= CPath::standardizePath(directoryIn); if( !CFile::isDirectory(directoryIn) ) { printf("DirectoryIn %s is not a directory", directoryIn.c_str()); return -1; } // Verify pathOut. pathOut= CPath::standardizePath(pathOut); if( !CFile::isDirectory(pathOut) ) { printf("PathOut %s is not a directory", pathOut.c_str()); return -1; } // Our Animation optimizer. //================= CAnimationOptimizer animationOptimizer; // Leave thresholds as default. animationOptimizer.clearLowPrecisionTracks(); // Load and setup configFile. //================= CConfigFile parameter; // Load and parse the param file parameter.load (paramFile); // Get the Low Precision Track Key Names try { CConfigFile::CVar &anim_low_precision_tracks = parameter.getVar ("anim_low_precision_tracks"); uint lpt; for (lpt = 0; lpt < (uint)anim_low_precision_tracks.size(); lpt++) { animationOptimizer.addLowPrecisionTrack(anim_low_precision_tracks.asString(lpt)); } } catch(EUnknownVar &) { nlwarning("\"anim_low_precision_tracks\" not found in the parameter file. Add \"Finger\" and \"Ponytail\" by default"); animationOptimizer.addLowPrecisionTrack("Finger"); animationOptimizer.addLowPrecisionTrack("Ponytail"); } // Sample Rate. try { CConfigFile::CVar &anim_sample_rate = parameter.getVar ("anim_sample_rate"); float sr= anim_sample_rate.asFloat(0); // Consider values > 1000 as error values. if(sr<=0 || sr>1000) { nlwarning("Bad \"anim_sample_rate\" value. Use Default of 30 fps."); animationOptimizer.setSampleFrameRate(30); } else { animationOptimizer.setSampleFrameRate(sr); } } catch(EUnknownVar &) { nlwarning("\"anim_sample_rate\" not found in the parameter file. Use Default of 30 fps."); animationOptimizer.setSampleFrameRate(30); } // Scan and load all files .ig in directories //================= uint numSkipped= 0; uint numBuilded= 0; vector<string> listFile; CPath::getPathContent(directoryIn, false, false, true, listFile); for(uint iFile=0; iFile<listFile.size(); iFile++) { string &igFile= listFile[iFile]; // verify it is a .anim. if( CFile::getExtension(igFile) == "anim" ) { string fileNameIn= CFile::getFilename(igFile); string fileNameOut= pathOut + fileNameIn; // skip the file? bool mustSkip= false; // If File Out exist if(CFile::fileExists(fileNameOut)) { // If newer than file In, skip uint32 fileOutDate= CFile::getFileModificationDate(fileNameOut); if( fileOutDate > CFile::getFileModificationDate(igFile) ) { mustSkip= true; } } // If must process the file. if(!mustSkip) { // Read the animation. CAnimation animIn; CIFile fin; fin.open(CPath::lookup(igFile)); fin.serial(animIn); // process. CAnimation animOut; animationOptimizer.optimize(animIn, animOut); // Save this animation. COFile fout; fout.open(fileNameOut); fout.serial(animOut); fout.close(); numBuilded++; } else { numSkipped++; } // progress printf("Anim builded: %4d. Anim Skipped: %4d\r", numBuilded, numSkipped); } } // Add some info in the log. nlinfo("Anim builded: %4d", numBuilded); nlinfo("Anim skipped: %4d", numSkipped); } catch (Exception& except) { // Error message nlwarning ("ERROR %s\n", except.what()); } } // exit. return 0; }
/* * init() */ bool CPrimChecker::build(const string &primitivesPath, const string &igLandPath, const string &igVillagePath, const string &outputDirectory, bool forceRebuild) { if (Verbose) nlinfo("Checking pacs.packed_prims consistency"); NLLIGO::Register(); // Init ligo if (!LigoConfig.readPrimitiveClass ("world_editor_classes.xml", false)) { // Should be in l:\leveldesign\world_edit_files nlwarning ("Can't load ligo primitive config file world_editor_classes.xml"); return false; } uint i, j; string outputfname = CPath::standardizePath(outputDirectory)+"pacs.packed_prims"; _Grid.clear(); vector<string> files; CPath::getPathContent(primitivesPath, true, false, true, files); for (i=0; i<files.size(); ++i) { if (CFile::getExtension(files[i]) == "primitive") { readFile(files[i]); } } files.clear(); CPath::getPathContent(igLandPath, true, false, true, files); CPath::getPathContent(igVillagePath, true, false, true, files); set<string> noWaterShapes; for (i=0; i<files.size(); ++i) { try { // load ig associated to the zone string igname = files[i]; string ignamelookup = CPath::lookup(igname); //nlinfo("Reading ig '%s'", ignamelookup.c_str()); CIFile igStream(ignamelookup); CInstanceGroup ig; igStream.serial(ig); // search in group for water instance for (j=0; j<ig._InstancesInfos.size(); ++j) { string shapeName = ig._InstancesInfos[j].Name; if (CFile::getExtension (shapeName) == "") shapeName += ".shape"; if (noWaterShapes.find(shapeName) != noWaterShapes.end()) continue; string shapeNameLookup = CPath::lookup (shapeName, false, false); if (!shapeNameLookup.empty()) { CIFile f; if (f.open (shapeNameLookup)) { CShapeStream shape; shape.serial(f); CWaterShape *wshape = dynamic_cast<CWaterShape*>(shape.getShapePointer()); if (wshape == NULL) { noWaterShapes.insert(shapeName); continue; } //nlinfo("Render water shape '%s'", shapeNameLookup.c_str()); CMatrix matrix; ig.getInstanceMatrix(j, matrix); CPolygon wpoly; //wshape->getShapeInWorldSpace(wpoly); CPolygon2D wpoly2d = wshape->getShape(); uint k; for (k=0; k<wpoly2d.Vertices.size(); ++k) { wpoly.Vertices.push_back(matrix * wpoly2d.Vertices[k]); } float zwater = wpoly.Vertices[0].z - WaterThreshold; uint16 idx = (uint16)_WaterHeight.size(); _WaterHeight.push_back(zwater); render(wpoly, idx); if (Verbose) nlinfo("Rendered water shape '%s' in instance '%s'", CFile::getFilenameWithoutExtension(shapeName).c_str(), CFile::getFilenameWithoutExtension(igname).c_str()); } else if (Verbose) { noWaterShapes.insert(shapeName); nlwarning ("Can't load shape %s", shapeNameLookup.c_str()); } } else if (Verbose) { noWaterShapes.insert(shapeName); nlwarning ("Can't find shape %s", shapeName.c_str()); } } } catch (const Exception &e) { nlwarning("%s", e.what()); } } COFile f; if (f.open(outputfname)) { f.serial(_Grid); f.serialCont(_WaterHeight); } else { nlwarning("Couldn't save pacs.packed_prims file '%s'", outputfname.c_str()); } return true; }