/* * load() */ bool CPrimChecker::load(const string &outputDirectory) { string outputfname = CPath::standardizePath(outputDirectory)+"pacs.packed_prims"; CIFile f; if (f.open(outputfname)) { f.serial(_Grid); f.serialCont(_WaterHeight); } else { nlwarning("Couldn't load pacs.packed_prims file '%s'", outputfname.c_str()); return false; } return true; }
//----------------------------------------------- // loadDump : // Create a file with the current state of the client (good to report a bug). //----------------------------------------------- void loadDump(const std::string &name) { CVectorD currentPos; // Load information to start as the version CIFile fStart; if(fStart.open(name + "_start.rec", false)) { fStart.serialVersion(RecordVersion); fStart.serial(currentPos); // Close the File. fStart.close(); } else nlwarning("loadDump: cannot open the file '%s_start.rec'.", name.c_str()); // Update the position for the vision. NetMngr.setReferencePosition(currentPos); // Select the closest continent from the new position. class CDummyProgress : public IProgressCallback { void progress (float /* value */) {} }; CDummyProgress dummy; ContinentMngr.select(currentPos, dummy); // Load the DB IngameDbMngr.read(name + "_db.rec"); // Open the file. CIFile f; if(f.open(name + ".rec", false)) { // Dump entities. EntitiesMngr.dump(f); // Close the File. f.close(); } else nlwarning("loadDump: cannot open '%s.rec'.", name.c_str()); }// loadDump //
void NLPACS::CZoneTessellation::loadTessellation(CIFile &input) { input.serialCont(_Vertices); uint i; uint32 numTessel; input.serial(numTessel); _Tessellation.resize(numTessel); for (i=0; i<_Tessellation.size(); ++i) { _Tessellation[i].serial(input, _Tessellation); } Elements.resize(_Tessellation.size()); for (i=0; i<_Tessellation.size(); ++i) { Elements[i] = &_Tessellation[i]; } }
int main(int argc, char *argv[]) { uint i; // Avoid warnings. NLMISC::createDebug(); DebugLog->addNegativeFilter("Exception will be launched"); WarningLog->addNegativeFilter("Exception will be launched"); InfoLog->addNegativeFilter("FEHTIMER>"); InfoLog->addNegativeFilter("adding the path"); // Init serial registerSerial3d(); if(argc<4) { puts("Usage: build_clod_bank path_file.cfg config_file.cfg destfile.clodbank [bakeFrameRate=20] "); return 0; } try { // The bank to fill CLodCharacterShapeBank lodShapeBank; // Read the frameRate to process bake of anims float bakeFrameRate= 20; if(argc>=5) { bakeFrameRate= (float)atof(argv[4]); if(bakeFrameRate<=1) { nlwarning("bad bakeFrameRate value, use a default of 20"); bakeFrameRate= 20; } } // parse the path file. //================== // try to load the config file. CConfigFile pathConfig; pathConfig.load (argv[1]); // Get the search pathes CConfigFile::CVar &search_pathes = pathConfig.getVar ("search_pathes"); for (i = 0; i < (uint)search_pathes.size(); i++) { // Add to search path CPath::addSearchPath (search_pathes.asString(i)); } // parse the config file. //================== // try to load the config file. CConfigFile config; config.load (argv[2]); // For all .clod to process //================== CConfigFile::CVar &clod_list = config.getVar ("clod_list"); uint lodId; for (lodId = 0; lodId < (uint)clod_list.size(); lodId++) { string lodName= clod_list.asString(lodId); printf("Process LOD: %s\n", lodName.c_str()); // Search the variable with this name. try { CIFile iFile; // get the anim list. CConfigFile::CVar &clod_anim_list = config.getVar (lodName); // Correct format? if(clod_anim_list.size()<3) { nlwarning("%s skipped. Must have at least the skeleton file name, the lod file name, and one animation", lodName.c_str()); // go to next. continue; } // Init lod shape process //=========================== // The first variable is the name of the skeleton. string skeletonName= clod_anim_list.asString(0); CSmartPtr<CSkeletonShape> skeletonShape; // Load it. iFile.open(CPath::lookup(skeletonName)); CShapeStream strShape; strShape.serial(iFile); iFile.close(); // Get the pointer, check it's a skeleton if(dynamic_cast<CSkeletonShape*>(strShape.getShapePointer()) == NULL) throw Exception("%s is not a Skeleton", skeletonName.c_str()); skeletonShape= (CSkeletonShape*)strShape.getShapePointer(); // The second var is the filename of the lod. string lodFileName= clod_anim_list.asString(1); // Load the shape. CLodCharacterShapeBuild lodShapeBuild; iFile.open( CPath::lookup(lodFileName) ); iFile.serial(lodShapeBuild); iFile.close(); // Prepare to build the lod. CLodCharacterBuilder lodBuilder; lodBuilder.setShape(lodName, skeletonShape, &lodShapeBuild); // Traverse all anim in the list. //=========================== uint animId; for (animId = 2; animId < (uint)clod_anim_list.size(); animId++) { string animFileName= clod_anim_list.asString(animId); // display. printf("Process Anim: %d/%d\r", animId-1, clod_anim_list.size()-2); // Try to load the animation CAnimation *anim= new CAnimation; // NB: continue, to list all ANIM if anim not found try { iFile.open( CPath::lookup(animFileName) ); iFile.serial(*anim); iFile.close(); // Add to the builder. NB: animation will be delete in this method. // NB: the key name here is the entire file, with the .anim, for easier georges editing. lodBuilder.addAnim(animFileName.c_str(), anim, bakeFrameRate); } catch(EPathNotFound &) { printf("ERROR anim not found %s\n", animFileName.c_str()); delete anim; } } printf("\n"); // Add to the bank. //=========================== uint32 shapeId= lodShapeBank.addShape(); *lodShapeBank.getShapeFullAcces(shapeId)= lodBuilder.getLodShape(); } catch(EUnknownVar &evar) { nlwarning(evar.what()); // Any other exception will make the program quit. } } // Save bank. //=========================== // compile lodShapeBank.compile(); // Save COFile oFile(argv[3]); oFile.serial(lodShapeBank); oFile.close(); } catch (Exception& except) { // Error message printf ("ERROR %s.\n Aborting.\n", except.what()); } 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<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; }
///========================================================= int main (int argc, char* argv[]) { // Filter addSearchPath NLMISC::createDebug(); InfoLog->addNegativeFilter ("adding the path"); TShapeMap shapeMap; // Check number of args if (argc<5) { // Help message printf ("zone_dependencies [properties.cfg] [firstZone.zone] [lastzone.zone] [output_dependencies.cfg]\n"); } else { NL3D::registerSerial3d(); // Light direction CVector lightDirection; // Config file handler try { // Read the properties file CConfigFile properties; // Load and parse the properties file properties.load (argv[1]); // Get the light direction CConfigFile::CVar &sun_direction = properties.getVar ("sun_direction"); lightDirection.set (sun_direction.asFloat(0), sun_direction.asFloat(1), sun_direction.asFloat(2)); lightDirection.normalize(); // Get the search pathes CConfigFile::CVar &search_pathes = properties.getVar ("search_pathes"); uint path; for (path = 0; path < (uint)search_pathes.size(); path++) { // Add to search path CPath::addSearchPath (search_pathes.asString(path)); } /* CConfigFile::CVar &ig_path = properties.getVar ("ig_path"); NLMISC::CPath::addSearchPath(ig_path.asString(), true, true); CConfigFile::CVar &shapes_path = properties.getVar ("shapes_path"); NLMISC::CPath::addSearchPath(shapes_path.asString(), true, true); */ CConfigFile::CVar &compute_dependencies_with_igs = properties.getVar ("compute_dependencies_with_igs"); bool computeDependenciesWithIgs = compute_dependencies_with_igs.asInt() != 0; // Get the file extension string ext=getExt (argv[2]); // Get the file directory string dir=getDir (argv[2]); // Get output extension string outExt=getExt (argv[4]); // Get output directory string outDir=getDir (argv[4]); // Get the first and last name string firstName=getName (argv[2]); string lastName=getName (argv[3]); // Get the coordinates uint16 firstX, firstY; uint16 lastX, lastY; if (getZoneCoordByName (firstName.c_str(), firstX, firstY)) { // Last zone if (getZoneCoordByName (lastName.c_str(), lastX, lastY)) { // Take care if (lastX<firstX) { uint16 tmp=firstX; firstX=lastX; lastX=firstX; } if (lastY<firstY) { uint16 tmp=firstY; firstY=lastY; lastY=firstY; } // Min z float minZ=FLT_MAX; // Make a quad grid CQuadGrid<CZoneDescriptorBB> quadGrid; quadGrid.create (256, 100); // The dependencies list vector< CZoneDependencies > dependencies; dependencies.resize ((lastX-firstX+1)*(lastY-firstY+1)); // Ryzom specific: build bbox for villages TString2LightingBBox villagesBBox; computeIGBBoxFromContinent(properties, shapeMap, villagesBBox); // Insert each zone in the quad tree sint y, x; for (y=firstY; y<=lastY; y++) for (x=firstX; x<=lastX; x++) { // Progress progress ("Build bounding boxes", (float)(x+y*lastX)/(float)(lastX*lastY)); // Make a zone file name string zoneName; getZoneNameByCoord (x, y, zoneName); // Open the file CIFile file; if (file.open (dir+zoneName+ext)) { // The zone CZone zone; try { // Serial the zone file.serial (zone); /// get bbox from the ig of this zone CLightingBBox igBBox; if (computeDependenciesWithIgs) { computeZoneIGBBox(zoneName.c_str(), igBBox, shapeMap, villagesBBox); } // Create a zone descriptor NLMISC::CAABBox zoneBox; zoneBox.setCenter(zone.getZoneBB().getCenter()); zoneBox.setHalfSize(zone.getZoneBB().getHalfSize()); CLightingBBox zoneLBox; zoneLBox.OccludingBox = zoneLBox.ReceivingBox = zoneBox; // can't be void zoneLBox.makeUnion(igBBox); nlassert(!zoneLBox.ReceivingBox.IsVoid); // CZoneDescriptorBB zoneDesc; zoneDesc.X=x; zoneDesc.Y=y; zoneDesc.BBox=zoneLBox.ReceivingBox.Box; // if (!zoneLBox.OccludingBox.IsVoid) { quadGrid.insert (zoneLBox.ReceivingBox.Box.getMin(), zoneLBox.ReceivingBox.Box.getMax(), zoneDesc); } // Insert in the dependencies // Index uint index=(x-firstX)+(y-firstY)*(lastX-firstX+1); // Loaded dependencies[index].Loaded=true; dependencies[index].X=x; dependencies[index].Y=y; dependencies[index].BBox=zoneLBox.OccludingBox.Box; // ZMin float newZ=zoneLBox.ReceivingBox.Box.getMin().z; if (newZ<minZ) minZ=newZ; } catch (Exception& e) { // Error handling nlwarning ("ERROR in file %s, %s", (dir+zoneName+ext).c_str(), e.what ()); } } } // Now select each zone in others and make a depencies list for (y=firstY; y<=lastY; y++) for (x=firstX; x<=lastX; x++) { // Progress progress ("Compute dependencies", (float)(x+y*lastX)/(float)(lastX*lastY)); // Index uint index=(x-firstX)+(y-firstY)*(lastX-firstX+1); // Loaded ? if (dependencies[index].Loaded) { // Min max vectors CVector vMin (dependencies[index].BBox.getMin()); CVector vMax (dependencies[index].BBox.getMax()); // Make a corner array CVector corners[4] = { CVector (vMin.x, vMin.y, vMax.z), CVector (vMax.x, vMin.y, vMax.z), CVector (vMax.x, vMax.y, vMax.z), CVector (vMin.x, vMax.y, vMax.z) }; // Extended bbox CAABBox bBox=dependencies[index].BBox.getAABBox(); // For each corner uint corner; for (corner=0; corner<4; corner++) { // Target position CVector target; if (lightDirection.z!=0) { // Not horizontal target target=corners[corner]+(lightDirection*((minZ-corners[corner].z)/lightDirection.z)); } else { // Horizontal target, select 500 meters around. target=(500*lightDirection)+corners[corner]; } // Extend the bbox bBox.extend (target); } // Clear quad tree selection quadGrid.clearSelection (); // Select quadGrid.select (bBox.getMin(), bBox.getMax()); // Check selection CQuadGrid<CZoneDescriptorBB>::CIterator it=quadGrid.begin(); while (it!=quadGrid.end()) { // Index uint targetIndex=((*it).X-firstX)+((*it).Y-firstY)*(lastX-firstX+1); // Not the same if (targetIndex!=index) { // Target min z float targetMinZ=dependencies[targetIndex].BBox.getMin().z; if (targetMinZ<vMax.z) { // Min z inf to max z ? // Target optimized bbox CAABBox bBoxOptimized=dependencies[index].BBox.getAABBox(); // For each corner for (corner=0; corner<4; corner++) { // Target position CVector target; if (lightDirection.z!=0) { // Not horizontal target target=corners[corner]+(lightDirection*((targetMinZ-corners[corner].z) /lightDirection.z)); } else { // Horizontal target, select 500 meters around. target=(500*lightDirection)+corners[corner]; } // Extend the bbox bBoxOptimized.extend (target); } // Check it more presisly //if ((*it).BBox.intersect (bBoxOptimized)) if ((*it).BBox.intersect (bBox)) { // Insert in the set dependencies[targetIndex].Dependences.insert (CZoneDependenciesValue (x, y)); } } } // Next selected it++; } } } // For each zone for (y=firstY; y<=lastY; y++) for (x=firstX; x<=lastX; x++) { // Progress progress ("Save depend files", (float)(x+y*lastX)/(float)(lastX*lastY)); // Index uint index=(x-firstX)+(y-firstY)*(lastX-firstX+1); // Loaded ? if (dependencies[index].Loaded) { // Make a file name string outputFileName; getZoneNameByCoord(x, y, outputFileName); outputFileName=outDir+outputFileName+outExt; // Write the dependencies file FILE *outputFile; if ((outputFile=fopen (toLower (outputFileName).c_str(), "w"))) { // Add a dependency entry fprintf (outputFile, "dependencies =\n{\n"); // Add dependent zones set<CZoneDependenciesValue>::iterator ite=dependencies[index].Dependences.begin(); while (ite!=dependencies[index].Dependences.end()) { // Name of the dependent zone std::string zoneName; getZoneNameByCoord(ite->first, ite->second, zoneName); // Write it string message="\t\""+zoneName+"\""; fprintf (outputFile, "%s", toLower (message).c_str()); // Next ite; ite++; if (ite!=dependencies[index].Dependences.end()) fprintf (outputFile, ",\n"); } // Close the variable fprintf (outputFile, "\n};\n\n"); } else { nlwarning ("ERROR can't open %s for writing.\n", outputFileName.c_str()); } // Close the file fclose (outputFile); } } } else { // Not valid nlwarning ("ERROR %s is not a valid zone name.\n", lastName.c_str()); } } else { // Not valid nlwarning ("ERROR %s is not a valid zone name.\n", firstName.c_str()); } } catch (Exception &ee) { nlwarning ("ERROR %s\n", ee.what()); } } return 0; }
BOOL CTexGenThumbnailDoc::OnOpenDocument(LPCTSTR lpszPathName) { CIFile file; if (file.open (lpszPathName)) { try { NLTEXGEN::CTexGenDocument doc; file.serial(doc); CFloatBitmap bitmap; CRenderParameter renderParameters (false, false, false); doc.Operators[0]->eval (bitmap, renderParameters); if ((bitmap.getWidth() != 0) && (bitmap.getHeight() != 0)) { bitmap.resample (m_sizeDoc.cx, m_sizeDoc.cy); _DibBitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFO); _DibBitmapInfo.bmiHeader.biWidth = m_sizeDoc.cx; _DibBitmapInfo.bmiHeader.biHeight = m_sizeDoc.cy; _DibBitmapInfo.bmiHeader.biPlanes = 1; _DibBitmapInfo.bmiHeader.biBitCount = 32; _DibBitmapInfo.bmiHeader.biCompression = BI_RGB; _DibBitmapInfo.bmiHeader.biSizeImage = 0; _DibBitmapInfo.bmiHeader.biXPelsPerMeter = 0; _DibBitmapInfo.bmiHeader.biYPelsPerMeter = 0; _DibBitmapInfo.bmiHeader.biClrUsed = 0; _DibBitmapInfo.bmiHeader.biClrImportant = 0; HWND desktop = ::GetDesktopWindow(); HDC dc = ::GetDC (desktop); nlverify(_Dib = CreateDIBSection(dc, &_DibBitmapInfo, DIB_RGB_COLORS, (void**)&_DibBits, NULL, 0)); const float *pixels = bitmap.getPixels(); if (pixels) { uint8 *dst = _DibBits; const uint height = m_sizeDoc.cy; uint y; for (y=0; y<height; y++) { const uint width = m_sizeDoc.cx*4 + y*m_sizeDoc.cx*4; uint i = y*m_sizeDoc.cx*4; uint j = (height-y-1)*m_sizeDoc.cx*4; for (;i<width; i+=4, j+=4) { /*if (alpha) { int r = (int)(pixels[i+0] * 255.f); clamp (r, 0, 255); dst[j+0] = r; dst[j+1] = r; dst[j+2] = r; } else*/ { int r = (int)(pixels[i+0] * 255.f); int g = (int)(pixels[i+1] * 255.f); int b = (int)(pixels[i+2] * 255.f); clamp (r, 0, 255); clamp (g, 0, 255); clamp (b, 0, 255); dst[j+0] = b; dst[j+1] = g; dst[j+2] = r; } } } } ::ReleaseDC (desktop, dc); return TRUE; } } catch (Exception &) { } } return FALSE; }
// *************************************************************************** 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; }