void FileTransferRequestHandler::mvFileRequested() { WinFilePath oldFileName; WinFilePath newFileName; { m_input->readUTF8(&oldFileName); m_input->readUTF8(&newFileName); } // end of reading block. m_log->message(_T("move \"%s\" \"%s\" command requested"), oldFileName.getString(), newFileName.getString()); checkAccess(); File srcFile(oldFileName.getString()); File dstFile(newFileName.getString()); if (!srcFile.renameTo(&dstFile)) { throw SystemException(); } { AutoLock l(m_output); m_output->writeUInt32(FTMessage::RENAME_REPLY); m_output->flush(); } }
int _tmain(int argc, _TCHAR* argv[]) { if (argc != 3) { return 1; } string srcFile(argv[1]); string dstFile(argv[2]); srcImg = imread(srcFile); dstImg = imread(dstFile); if (srcImg.size() != dstImg.size()) { resize(srcImg, dstImg, dstImg.size()); } flip(dstImg, dstImg, 1); namedWindow("Comparison", CV_WINDOW_AUTOSIZE); int trackbarInitPos = TRACKBAR_MAX_POSITION / 2; createTrackbar("SplitImg", "Comparison", &trackbarInitPos, TRACKBAR_MAX_POSITION, onTrackbarChange); onTrackbarChange(trackbarInitPos, NULL); waitKey(); return 0; }
void KisAslLayerStyleSerializerTest::testWriting() { QVector<KisPSDLayerStyleSP> styles; QByteArray refXMLDoc; { KisAslLayerStyleSerializer s; QString srcFileName(TestUtil::fetchDataFileLazy("asl/test_all_and_pattern.asl")); QFile aslFile(srcFileName); aslFile.open(QIODevice::ReadOnly); s.readFromDevice(&aslFile); styles = s.styles(); { aslFile.seek(0); KisAslReader reader; QDomDocument doc = reader.readFile(&aslFile); refXMLDoc = doc.toByteArray(); } } // now we have an initialized KisPSDLayerStyle object { KisAslLayerStyleSerializer s; s.setStyles(styles); QFile dstFile("test_written.asl"); dstFile.open(QIODevice::WriteOnly); s.saveToDevice(&dstFile); dstFile.close(); } QByteArray resultXMLDoc; { QFile resultFile("test_written.asl"); resultFile.open(QIODevice::ReadOnly); KisAslReader reader; QDomDocument doc = reader.readFile(&resultFile); resultXMLDoc = doc.toByteArray(); } QFile refXMLFile("save_round_trip_src.xml"); refXMLFile.open(QIODevice::WriteOnly); refXMLFile.write(refXMLDoc); refXMLFile.close(); QFile resultXMLFile("save_round_trip_dst.xml"); resultXMLFile.open(QIODevice::WriteOnly); resultXMLFile.write(resultXMLDoc); resultXMLFile.close(); QCOMPARE(resultXMLDoc, refXMLDoc); }
void MainWindow::copyFile() { QFile srcFile(m_srcFileDir+m_fileName); QFile dstFile(m_dstFileDir+m_fileName); if (srcFile.exists() && dstFile.exists()) { dstFile.remove(); srcFile.copy(m_srcFileDir+m_fileName,m_dstFileDir+m_fileName); m_status->setText("Copied file successfully."); }else { // TODO m_status->setText("Failed to copy file."); } }
bool decompressDir(const QString& inFile, const QString& targetDir, bool isUtf8) { QString path = targetDir; if (!path.endsWith("/") && !path.endsWith("\\")) path += "/"; QDir dir(path); if (!dir.exists()) dir.mkpath(targetDir); //set gbk default if (!isUtf8) QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK")); QuaZip archive(inFile); //archive.setFileNameCodec("GBK"); if (!archive.open(QuaZip::mdUnzip)) { QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); return false; } for (bool f = archive.goToFirstFile(); f; f = archive.goToNextFile()) { QString filePath = archive.getCurrentFileName(); QuaZipFile zFile(archive.getZipName(), filePath); zFile.open(QIODevice::ReadOnly); QByteArray ba = zFile.readAll(); zFile.close(); if (filePath.endsWith("/")) { dir.mkpath(filePath); } else { QString utf8FileName = path + filePath; QFile dstFile(utf8FileName); if (!dstFile.open(QIODevice::WriteOnly)) { QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); return false; } dstFile.write(ba); dstFile.close(); } } //restore QTextCodec QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); return true; }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QuaZip archive("Desktop.zip"); if (!archive.open(QuaZip::mdUnzip)) return false; QString out_dir = "./zip"; QString path = out_dir; if (!path.endsWith("/") && !out_dir.endsWith("\\")) path += "/"; QDir dir(out_dir); if (!dir.exists()) dir.mkpath("."); for( bool f = archive.goToFirstFile(); f; f = archive.goToNextFile() ) { QString filePath = archive.getCurrentFileName(); QuaZipFile zFile(archive.getZipName(), filePath); zFile.open(QIODevice::ReadOnly ); QByteArray ba = zFile.readAll(); qDebug() << ba.size()/1024 <<"Byte\t" << "--------\t" << filePath; zFile.close(); if (filePath.endsWith("/")) { dir.mkpath(filePath); } else { QFile dstFile(path + filePath); if (!dstFile.open(QIODevice::WriteOnly)) return false; dstFile.write(ba); dstFile.close(); } } if(archive.getZipError()==UNZ_OK) { // ok, there was no error qDebug() << "ok"; } return a.exec(); }
void VMacResFile::DebugTest() { // look for a "test.rsrc" file in same folder as the app // and duplicate it VFilePath sourcePath = VProcess::Get()->GetExecutableFolderPath(); sourcePath.SetFileName(VStr63("test.rsrc")); DebugMsg("Looking for file = %V\n", &sourcePath); VMacResFile srcFile(sourcePath, FA_READ, false); sourcePath.SetFileName(VStr63("test copy.rsrc")); VMacResFile dstFile(sourcePath, FA_READ_WRITE, true); VError error = srcFile.CopyResourcesInto(dstFile); dstFile.Close(); srcFile.Close(); }
void KisAslLayerStyleSerializerTest::testWritingGlobalPatterns() { KisPSDLayerStyleSP style(new KisPSDLayerStyle()); KoResourceServer<KoPattern> *server = KoResourceServerProvider::instance()->patternServer(); QList<KoPattern*> sortedResources = server->sortedResources(); KoPattern *pattern = sortedResources.first(); Q_ASSERT(pattern); dbgKrita << ppVar(pattern->name()); dbgKrita << ppVar(pattern->filename()); style->patternOverlay()->setEffectEnabled(true); style->patternOverlay()->setPattern(pattern); { KisAslLayerStyleSerializer s; s.setStyles(QVector<KisPSDLayerStyleSP>() << style); QFile dstFile("test_written_pattern_only.asl"); dstFile.open(QIODevice::WriteOnly); s.saveToDevice(&dstFile); dstFile.close(); } /* QByteArray resultXMLDoc; { QFile resultFile("test_written.asl"); resultFile.open(QIODevice::ReadOnly); KisAslReader reader; QDomDocument doc = reader.readFile(&resultFile); resultXMLDoc = doc.toByteArray(); } */ }
// Format of aFileNames is [srcFile]|[dstFile] GLDEF_C TInt E32Main() { CTrapCleanup* cleanup = CTrapCleanup::New(); TBuf<KMaxFileName*2> names; User::CommandLine(names); TInt pos = names.Find(KSeparator); TFileName srcFile(names.Mid(0, pos)); TFileName dstFile(names.Mid(pos + 1, names.Length() - (pos + 1))); TInt err = KErrNone; TRAP(err, CopyFileL(srcFile, dstFile)); if (err == KErrNone) { RDebug::Print(_L("CFileMan Copy file '%S' to '%S' succeeded.\n"), &srcFile, &dstFile); } else { RDebug::Print(_L("CFileMan Copy file '%S' to '%S' failed with error = %d.\n"), &srcFile, &dstFile, err); } delete cleanup; return err; }
int main(int argc, char *argv[]) { qInstallMsgHandler(myMessageHandler); QCoreApplication app(argc, argv); if (argc != 3) { qCritical("Usage: autotranslate <destination-dir> <source-dir>."); return -1; } QDir dstDir(app.arguments().value(1)); if (!dstDir.exists()) { qCritical("Destination directory '%s' not found.",dstDir.dirName().toLocal8Bit().constData()); return -1; } QDir srcDir(app.arguments().value(2),"*.ts",QDir::Name,QDir::Files); if (!srcDir.exists()) { qCritical("Source directory '%s' not found.",srcDir.dirName().toLocal8Bit().constData()); return -1; } QDirIterator srcIt(srcDir); while (srcIt.hasNext()) { QFile srcFile(srcIt.next()); if (srcFile.open(QFile::ReadOnly)) { QDomDocument doc; if (doc.setContent(&srcFile,true)) { qDebug("Generation auto translation from '%s'.",srcFile.fileName().toLocal8Bit().constData()); QDomElement rootElem = doc.firstChildElement("TS"); rootElem.setAttribute("language",rootElem.attribute("sourcelanguage","en")); QDomElement contextElem = rootElem.firstChildElement("context"); while(!contextElem.isNull()) { QDomElement messageElem = contextElem.firstChildElement("message"); while(!messageElem.isNull()) { QDomElement sourceElem = messageElem.firstChildElement("source"); QDomElement translationElem = messageElem.firstChildElement("translation"); if (!sourceElem.isNull() && !translationElem.isNull()) { QString sourceText = sourceElem.text(); if (messageElem.attribute("numerus") == "yes") { QDomElement numerusEelem = translationElem.firstChildElement("numerusform"); while(!numerusEelem.isNull()) { numerusEelem.removeChild(numerusEelem.firstChild()); numerusEelem.appendChild(doc.createTextNode(sourceText)); numerusEelem = numerusEelem.nextSiblingElement("numerusform"); } } else { translationElem.removeChild(translationElem.firstChild()); translationElem.appendChild(doc.createTextNode(sourceText)); } translationElem.removeAttribute("type"); } messageElem = messageElem.nextSiblingElement("message"); } contextElem = contextElem.nextSiblingElement("context"); } srcFile.close(); QFileInfo srcFileInfo(srcDir.absoluteFilePath(srcFile.fileName())); QFile dstFile(dstDir.absoluteFilePath(srcFileInfo.fileName())); if (dstFile.open(QFile::WriteOnly|QFile::Truncate)) { dstFile.write(doc.toByteArray()); dstFile.close(); } else { qWarning("Failed to open destination file '%s' for write.",dstFile.fileName().toLocal8Bit().constData()); } } else { qWarning("Invalid translation source file '%s'.",srcFile.fileName().toLocal8Bit().constData()); } srcFile.close(); } else { qWarning("Could not open translation source file '%s'.",srcFile.fileName().toLocal8Bit().constData()); } } return 0; }
bool ModelImport::ImportObj(const std::string& srcFilename, std::string& dstFilename) { const AssetLib::AssetDef& rAssetDef = AssetLib::Model::GetAssetDef(); std::ifstream srcFile(srcFilename); assert(srcFile.is_open()); std::ofstream dstFile(dstFilename, std::ios::binary); assert(dstFile.is_open()); // Write header AssetLib::BinFileHeader header; header.binUID = AssetLib::BinFileHeader::kUID; header.assetUID = rAssetDef.GetAssetUID(); header.version = rAssetDef.GetBinVersion(); header.srcHash = Hashing::SHA1(); dstFile.write((char*)&header, sizeof(header)); // Build and write the main geo data GeoData geo; ObjData obj; char line[1024]; int lineNum = 0; // for debugging while (srcFile.getline(line, 1024)) { ++lineNum; char* context = nullptr; char* tok = strtok_s(line, " ", &context); if (strcmp(tok, "v") == 0) { // Position Vec3 pos; pos.x = (float)atof(strtok_s(nullptr, " ", &context)); pos.y = (float)atof(strtok_s(nullptr, " ", &context)); pos.z = (float)atof(strtok_s(nullptr, " ", &context)); obj.positions.push_back(pos); } else if (strcmp(tok, "vn") == 0) { // Normal Vec3 norm; norm.x = (float)atof(strtok_s(nullptr, " ", &context)); norm.y = (float)atof(strtok_s(nullptr, " ", &context)); norm.z = (float)atof(strtok_s(nullptr, " ", &context)); obj.normals.push_back(norm); } else if (strcmp(tok, "vt") == 0) { // Tex coord Vec2 uv; uv.x = (float)atof(strtok_s(nullptr, " ", &context)); uv.y = (float)atof(strtok_s(nullptr, " ", &context)); obj.texcoords.push_back(uv); } else if (strcmp(tok, "f") == 0) { // Face for (int i = 0; i < 3; ++i) { ObjVertex objVert; objVert.iPos = atoi(strtok_s(nullptr, "/ ", &context)) - 1; objVert.iUv = atoi(strtok_s(nullptr, "/ ", &context)) - 1; objVert.iNorm = atoi(strtok_s(nullptr, "/ ", &context)) - 1; // Find matching vert to re-use. int reuseIndex = -1; for (int v = (int)obj.verts.size() - 1; v >= 0; --v) { const ObjVertex& otherVert = obj.verts[v]; if (otherVert.iPos == objVert.iPos && otherVert.iUv == objVert.iUv && otherVert.iNorm == objVert.iNorm) { reuseIndex = v; break; } } if (reuseIndex >= 0) { geo.indices.push_back((uint16)reuseIndex); } else { geo.indices.push_back((uint16)geo.positions.size()); Color color = { 1.f, 1.f, 1.f, 1.f }; geo.positions.push_back(obj.positions[objVert.iPos]); geo.texcoords.push_back(obj.texcoords[objVert.iUv]); geo.normals.push_back(obj.normals[objVert.iNorm]); geo.colors.push_back(color); obj.verts.push_back(objVert); } } } else if (strcmp(tok, "usemtl") == 0) { std::string material = strtok_s(nullptr, " ", &context); obj.materials.push_back(material); obj.subobjectStartIndices.push_back((uint)geo.indices.size()); } } obj.subobjectStartIndices.push_back((uint)geo.indices.size()); geo.tangents.resize(geo.positions.size()); geo.bitangents.resize(geo.positions.size()); // TODO: Tangents/bitangents for shared verts for (uint i = 0; i < geo.indices.size(); i += 3) { uint v0 = geo.indices[i + 0]; uint v1 = geo.indices[i + 1]; uint v2 = geo.indices[i + 2]; const Vec3& pos0 = geo.positions[v0]; const Vec3& pos1 = geo.positions[v1]; const Vec3& pos2 = geo.positions[v2]; const Vec2& uv0 = geo.texcoords[v0]; const Vec2& uv1 = geo.texcoords[v1]; const Vec2& uv2 = geo.texcoords[v2]; Vec3 edge1 = pos1 - pos0; Vec3 edge2 = pos2 - pos0; Vec2 uvEdge1 = uv1 - uv0; Vec2 uvEdge2 = uv2 - uv0; float r = 1.f / (uvEdge1.y * uvEdge2.x - uvEdge1.x * uvEdge2.y); Vec3 tangent = (edge1 * -uvEdge2.y + edge2 * uvEdge1.y) * r; Vec3 bitangent = (edge1 * -uvEdge2.x + edge2 * uvEdge1.x) * r; tangent = Vec3Normalize(tangent); bitangent = Vec3Normalize(bitangent); geo.tangents[v0] = geo.tangents[v1] = geo.tangents[v2] = tangent; geo.bitangents[v0] = geo.bitangents[v1] = geo.bitangents[v2] = bitangent; } // Calc radius Vec3 vMin(FLT_MAX, FLT_MAX, FLT_MAX); Vec3 vMax(-FLT_MIN, -FLT_MIN, -FLT_MIN); for (int i = (int)geo.positions.size() - 1; i >= 0; --i) { vMin.x = std::min(geo.positions[i].x, vMin.x); vMax.x = std::max(geo.positions[i].x, vMax.x); vMin.y = std::min(geo.positions[i].y, vMin.y); vMax.y = std::max(geo.positions[i].y, vMax.y); vMin.z = std::min(geo.positions[i].z, vMin.z); vMax.z = std::max(geo.positions[i].z, vMax.z); } Vec3 modelBoundsMin(FLT_MAX, FLT_MAX, FLT_MAX); Vec3 modelBoundsMax(-FLT_MIN, -FLT_MIN, -FLT_MIN); uint totalVertCount = 0; for (int i = 0; i < obj.subobjectStartIndices.size() - 1; ++i) { AssetLib::Model::SubObject subobj; strcpy_s(subobj.materialName, obj.materials[i].c_str()); subobj.indexCount = obj.subobjectStartIndices[i + 1] - obj.subobjectStartIndices[i]; uint16 vertMin = -1; uint16 vertMax = 0; subobj.boundsMin = Vec3(FLT_MAX, FLT_MAX, FLT_MAX); subobj.boundsMax = Vec3(-FLT_MIN, -FLT_MIN, -FLT_MIN); for (uint tri = obj.subobjectStartIndices[i]; tri < obj.subobjectStartIndices[i + 1]; ++tri) { uint16 iVert = geo.indices[tri]; vertMin = std::min(iVert, vertMin); vertMax = std::max(iVert, vertMax); subobj.boundsMin.x = std::min(geo.positions[iVert].x, subobj.boundsMin.x); subobj.boundsMax.x = std::max(geo.positions[iVert].x, subobj.boundsMax.x); subobj.boundsMin.y = std::min(geo.positions[iVert].y, subobj.boundsMin.y); subobj.boundsMax.y = std::max(geo.positions[iVert].y, subobj.boundsMax.y); subobj.boundsMin.z = std::min(geo.positions[iVert].z, subobj.boundsMin.z); subobj.boundsMax.z = std::max(geo.positions[iVert].z, subobj.boundsMax.z); } subobj.vertCount = (vertMax - vertMin) + 1; totalVertCount += subobj.vertCount; modelBoundsMin = Vec3Min(modelBoundsMin, subobj.boundsMin); modelBoundsMax = Vec3Max(modelBoundsMax, subobj.boundsMax); geo.subobjects.push_back(subobj); } assert(totalVertCount == (uint)geo.positions.size()); AssetLib::Model modelBin; modelBin.totalVertCount = totalVertCount; modelBin.totalIndexCount = (uint)geo.indices.size(); modelBin.boundsMin = modelBoundsMin; modelBin.boundsMax = modelBoundsMax; modelBin.subObjectCount = (uint)geo.subobjects.size(); modelBin.subobjects.offset = 0; modelBin.positions.offset = modelBin.subobjects.offset + modelBin.subobjects.CalcSize(modelBin.subObjectCount); modelBin.texcoords.offset = modelBin.positions.offset + modelBin.positions.CalcSize(totalVertCount); modelBin.normals.offset = modelBin.texcoords.offset + modelBin.texcoords.CalcSize(totalVertCount); modelBin.colors.offset = modelBin.normals.offset + modelBin.normals.CalcSize(totalVertCount); modelBin.tangents.offset = modelBin.colors.offset + modelBin.colors.CalcSize(totalVertCount); modelBin.bitangents.offset = modelBin.tangents.offset + modelBin.tangents.CalcSize(totalVertCount); modelBin.indices.offset = modelBin.bitangents.offset + modelBin.bitangents.CalcSize(totalVertCount); dstFile.write((char*)&modelBin, sizeof(AssetLib::Model)); dstFile.write((char*)geo.subobjects.data(), sizeof(geo.subobjects[0]) * geo.subobjects.size()); dstFile.write((char*)geo.positions.data(), sizeof(geo.positions[0]) * geo.positions.size()); dstFile.write((char*)geo.texcoords.data(), sizeof(geo.texcoords[0]) * geo.texcoords.size()); dstFile.write((char*)geo.normals.data(), sizeof(geo.normals[0]) * geo.normals.size()); dstFile.write((char*)geo.colors.data(), sizeof(geo.colors[0]) * geo.colors.size()); dstFile.write((char*)geo.tangents.data(), sizeof(geo.tangents[0]) * geo.tangents.size()); dstFile.write((char*)geo.bitangents.data(), sizeof(geo.bitangents[0]) * geo.bitangents.size()); dstFile.write((char*)geo.indices.data(), sizeof(geo.indices[0]) * geo.indices.size()); return true; }
void KisAslLayerStyleSerializerTest::testWritingGradients() { KoStopGradient stopGradient(""); { const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); QList<KoGradientStop> stops; stops << KoGradientStop(0.0, KoColor(Qt::black, cs)); stops << KoGradientStop(0.3, KoColor(Qt::red, cs)); stops << KoGradientStop(0.6, KoColor(Qt::green, cs)); stops << KoGradientStop(1.0, KoColor(Qt::white, cs)); stopGradient.setStops(stops); } KisPSDLayerStyleSP style(new KisPSDLayerStyle()); style->outerGlow()->setEffectEnabled(true); style->outerGlow()->setFillType(psd_fill_gradient); style->outerGlow()->setGradient(toQShared(new KoStopGradient(stopGradient))); style->innerGlow()->setEffectEnabled(true); style->innerGlow()->setFillType(psd_fill_gradient); style->innerGlow()->setGradient(toQShared(new KoStopGradient(stopGradient))); style->gradientOverlay()->setEffectEnabled(true); style->gradientOverlay()->setGradient(toQShared(new KoStopGradient(stopGradient))); style->stroke()->setEffectEnabled(true); style->stroke()->setFillType(psd_fill_gradient); style->stroke()->setGradient(toQShared(new KoStopGradient(stopGradient))); { KisAslLayerStyleSerializer s; s.setStyles(QVector<KisPSDLayerStyleSP>() << style); QFile dstFile("test_written_stop_gradient.asl"); dstFile.open(QIODevice::WriteOnly); s.saveToDevice(&dstFile); dstFile.close(); } QString xmlDoc; { QFile resultFile("test_written_stop_gradient.asl"); resultFile.open(QIODevice::ReadOnly); KisAslReader reader; QDomDocument doc = reader.readFile(&resultFile); xmlDoc = doc.toString(); } { // the reference document has stripped "Idnt" field which is random QRegExp rx("<node key=\"Idnt\" type=\"Text\" value=\".+\"/>"); rx.setMinimal(true); int pos = 0; while ((pos = rx.indexIn(xmlDoc, pos)) != -1) { xmlDoc.remove(pos, rx.matchedLength()); } { //QFile xmlFile("reference_gradients.asl.xml"); //xmlFile.open(QIODevice::WriteOnly); //xmlFile.write(xmlDoc.toLatin1()); //xmlFile.close(); } QString refFileName(TestUtil::fetchDataFileLazy("reference_gradients.asl.xml")); QFile refFile(refFileName); refFile.open(QIODevice::ReadOnly); QString refDoc = QString(refFile.readAll()); QCOMPARE(xmlDoc, refDoc); } }
mxAPPLICATION_ENTRY_POINT int mxAppMain() { SetupBaseUtil setupBase; //FileLogUtil fileLog; SetupCoreUtil setupCore; const String srcFileName( "D:/dev/_assets/_diplomarbeit/iryoku-head/Head.sdkmesh" //"D:/research/_current/iryoku-separable-sss-f61b44c/Demo/Media/Head.sdkmesh" //"D:/dev/_assets/Head.sdkmesh" ); FileReader srcFile( srcFileName ); CHK_VRET_X_IF_NOT( srcFile.IsOpen(), -1 ); StaticTriangleMeshData staticMeshData; { SDKMesh sdkMesh; if( FAILED(sdkMesh.Create(mxTO_UNICODE( srcFileName ))) ) { return -1; } const SDKMESH_HEADER& header = *sdkMesh.GetHeader(); (void)header; const UINT numMeshes = sdkMesh.GetNumMeshes(); Assert(numMeshes == 1); const UINT iFirstMesh = 0; const UINT numSubsets = sdkMesh.GetNumSubsets( iFirstMesh ); Assert( numSubsets == 1 ); const UINT iFirstSubset = 0; const SDKMESH_SUBSET* pSubset = sdkMesh.GetSubset( iFirstMesh, iFirstSubset ); const UINT numVertices = pSubset->VertexCount; const UINT numIndices = pSubset->IndexCount; const UINT numVBs = sdkMesh.GetNumVBs(); Assert( numVBs == 1 ); const UINT numIBs = sdkMesh.GetNumIBs(); Assert( numIBs == 1 ); const SDKMeshVertex* srcVertices = (const SDKMeshVertex*) sdkMesh.GetRawVerticesAt(0); const SDKMESH_INDEX_TYPE indexType = sdkMesh.GetIndexType( iFirstMesh ); Assert( indexType == SDKMESH_INDEX_TYPE::IT_16BIT ); const UINT16* srcIndices = (const UINT16*) sdkMesh.GetRawIndicesAt(0); { TList< Vec3D > & positions = staticMeshData.positions; TList< Vec2D > & texCoords = staticMeshData.texCoords; TList< Vec3D > & normals = staticMeshData.normals; //TList< Vec3D > & binormals = staticMeshData.binormals; TList< Vec3D > & tangents = staticMeshData.tangents; positions.SetNum( numVertices ); texCoords.SetNum( numVertices ); normals.SetNum( numVertices ); tangents.SetNum( numVertices ); staticMeshData.localBounds.Clear(); for( UINT iVertex = 0; iVertex < numVertices; iVertex++ ) { const SDKMeshVertex & srcVertex = srcVertices[ iVertex ]; Assert( srcVertex.normal.IsNormalized() ); Assert( srcVertex.tangent.IsNormalized() ); positions[ iVertex ] = srcVertex.position; texCoords[ iVertex ] = srcVertex.texCoord; normals[ iVertex ] = srcVertex.normal; tangents[ iVertex ] = srcVertex.tangent; staticMeshData.localBounds.AddPoint( srcVertex.position ); } staticMeshData.indices.AddBytes( srcIndices, numIndices * sizeof srcIndices[0] ); staticMeshData.indexStride = sizeof srcIndices[0]; MeshPart & firstBatch = staticMeshData.batches.Add(); { firstBatch.baseVertex = pSubset->VertexStart; firstBatch.startIndex = pSubset->IndexStart; firstBatch.indexCount = pSubset->IndexCount; firstBatch.vertexCount = pSubset->VertexCount; } } } const String dstPathName( //"D:/dev/_assets" "R:/" ); String dstFileName( "iryoku-Head" ); //srcFileName.ExtractFileBase( dstFileName ); dstFileName += ".static_mesh"; FileWriter dstFile( dstPathName + dstFileName ); CHK_VRET_X_IF_NOT( dstFile.IsOpen(), -1 ); ArchivePODWriter archive( dstFile ); staticMeshData.Serialize( archive ); return 0; }
// --------------------------------------------------------------------------- // Name: osCopyFile // Description: Copies a file from sourcePath to destinationPath, overwriting if // allowOverwrite is true. Only the file being copied is considered // success (i.e. allowOverwrite = false with an existing // destinationPath is considered a failure). // Return Val: bool - Success / failure. // Author: AMD Developer Tools Team // Date: 8/7/2012 // --------------------------------------------------------------------------- bool osCopyFile(const osFilePath& sourcePath, const osFilePath& destinationPath, bool allowOverwrite) { bool retVal = false; // If the source file exists (and is not a directory, etc): if (!sourcePath.isRegularFile()) { return retVal; } // Check if exist and writable if (destinationPath.isRegularFile()) { if (!allowOverwrite) { return retVal; } else { osFile dstFile(destinationPath); { if (!dstFile.deleteFile()) { return retVal; } } } } // Copy file gtSize_t read = 0; gtSize_t totRead = 0; gtSize_t bufSize = 1024; gtByte buffer[bufSize]; osFile srcFile(sourcePath); unsigned long srcSize(0); osFile dstFile(destinationPath); bool bSrc = srcFile.open(osChannel::OS_BINARY_CHANNEL, osFile::OS_OPEN_TO_READ); bool bDst = dstFile.open(osChannel::OS_BINARY_CHANNEL, osFile::OS_OPEN_TO_WRITE); if (bSrc && bDst) { srcFile.getSize(srcSize); while (srcFile.readAvailableData((gtByte*)&buffer, bufSize, read) && read != 0) { totRead += read; dstFile.write(buffer, read); } } if (bSrc) { srcFile.close(); } if (bDst) { dstFile.close(); } // Verify the output file, allowing 0 size files to be copied if (((totRead != 0) || (0 == srcSize)) && destinationPath.isRegularFile()) { retVal = true; } return retVal; }