개발 / / 2024. 4. 25. 19:36

CREO Sculptor type export 3MF로 변경

반응형

목적

MarchingCubesAppend.cpp
    else if (format == e3mf)
    {
        mkdir((filepath + filename + "3MF").c_str());
        generateContentTypes(filepath + filename + "3MF");
        mkdir((filepath + filename + "3MF" + "/_rels").c_str());
        generateRelations(filepath + filename + "3MF" + "/_rels");
        mkdir((filepath + filename + "3MF" + "/3D").c_str());
        generate3DModel(filepath + filename + "3MF" + "/3D", vertexVectors, faceVectors);
    }

CREO의 file을 3MF type으로 export할 때 xml파일들을 추가하도록 되어있다.

3MF 형식 안에는 세 종류의 xml 코드가 들어갈 것인데, generate로 시작하는 세 함수가 그것이다.

 

void generateContentTypes(const std::string& filePath) {
    std::ofstream outFile(filePath + "/[Content_Types].xml");
    outFile << R"(<?xml version="1.0" encoding="UTF-8"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
    <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
    <Default Extension="model" ContentType="application/vnd.ms-package.3dmanufacturing-3dmodel+xml" />
</Types>
    )";
}

void generateRelations(const std::string& filePath) {
    std::ofstream outFile(filePath + "/.rels");
    outFile << R"(<?xml version="1.0" encoding="UTF-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
    <Relationship Type="http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel" Target="3DModel.model" Id="rel0"/>
</Relationships>
    )";
}

void generate3DModel(const std::string& filePath, vector<vertex>** vertexVectors, vector<face>** faceVectors) {
    std::ofstream outFile(filePath + "/3DModel.model");
    outFile << R"(<?xml version="1.0" encoding="UTF-8"?>
<model unit="millimeter" xml:lang="en-US" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02">
    <resources>
        <object id="1" type="model">
            <mesh>
                <vertices>
    )";
    // Write vertices
    for (unsigned int i = 0; i < (*vertexVectors)->size(); ++i) {
        outFile << "                    <vertex x=\"" << (**vertexVectors)[i].x << "\" y=\"" <<
            (**vertexVectors)[i].y << "\" z=\"" << (**vertexVectors)[i].z << "\" />\n";
    }
    outFile << R"(              </vertices>
                <triangles>
    )";
    // Write triangles
    for (unsigned int i = 0; i < (*faceVectors)->size(); ++i) {
        outFile << "                    <triangle v1=\"" << (**faceVectors)[i].indices[0] <<
            "\" v2=\"" << (**faceVectors)[i].indices[1] << "\" v3=\"" <<
            (**faceVectors)[i].indices[2] << "\" />\n";
    }

    outFile << R"(
                </triangles>
            </mesh>
        </object>
    </resources>
    <build>
        <item objectid="1" transform="1 0 0 0 1 0 0 0 1 0 0 0" />
    </build>
</model>
    )";

}

위 세 함수를 거쳐서 3MF로 export하기 위한 xml 세팅을 마치고

모델 생성 엔진 프로젝트에서 export를 한다.

 

 

creo sculptor export engine
int main()
{
    CCreoSculptor* m_pCreoSculptorMgr = new CCreoSculptor();
   
    if (m_pCreoSculptorMgr->Initialize())
    {  
        MessageBox(NULL, L"Please attach to this process", L"Ready for debugging", MB_OK);

        CreoSculptor_MeshInfo* stMeshInfo = new CreoSculptor_MeshInfo();
        memset(stMeshInfo, 0, sizeof(CreoSculptor_MeshInfo));

        bool initailized = m_pCreoSculptorMgr->ExecuteInitialize(stMeshInfo);

        if (initailized == true)
        {

            FILE* fp = fopen("MakeMaskedVolume200.raw", "rb");

            int imageSize = 200;

            unsigned char* maskedInput = new unsigned char[imageSize * imageSize * imageSize];

            int ret = fread(maskedInput, 1, imageSize * imageSize * imageSize, fp);
            fclose(fp);

            CreoSculptor_MeshInfo* stMeshInfoforExport = new CreoSculptor_MeshInfo();
            memset(stMeshInfoforExport, 0, sizeof(CreoSculptor_MeshInfo));

            stMeshInfoforExport->xSize = imageSize;
            stMeshInfoforExport->ySize = imageSize;
            stMeshInfoforExport->zSize = imageSize;
            stMeshInfoforExport->meshType = CREO_SCULPTOR_MESH_TYPE_FULL;
            stMeshInfoforExport->fileType = CREO_SCULPTOR_FILE_TYPE_STL;
            stMeshInfoforExport->quality = CREO_SCULPTOR_QUALITY_HIGH;
            stMeshInfoforExport->smoothnessFactor = 5;
            stMeshInfoforExport->lowThreshold = 40;
            stMeshInfoforExport->transparency =0;
            stMeshInfoforExport->orientation = 270;

            char* ChFilePath = "D:\\Sample.stl";
            
            m_pCreoSculptorMgr->ExecuteExport3DMesh(stMeshInfoforExport, maskedInput, ChFilePath);

            CreoSculptor_MeshInfo* stMeshInfoforFinalize = new CreoSculptor_MeshInfo();
            memset(stMeshInfoforFinalize, 0, sizeof(CreoSculptor_MeshInfo));

            m_pCreoSculptorMgr->ExecuteFinalize(stMeshInfoforFinalize);
        }

    }

    m_pCreoSculptorMgr->Finalize();
}

위 코드에서

 

stMeshInfoforExport->xSize = imageSize;
stMeshInfoforExport->ySize = imageSize;
stMeshInfoforExport->zSize = imageSize;
stMeshInfoforExport->meshType = CREO_SCULPTOR_MESH_TYPE_FULL;
stMeshInfoforExport->fileType = CREO_SCULPTOR_FILE_TYPE_STL; // STL -> 3MF
stMeshInfoforExport->quality = CREO_SCULPTOR_QUALITY_HIGH;
stMeshInfoforExport->smoothnessFactor = 5;
stMeshInfoforExport->lowThreshold = 40;
stMeshInfoforExport->transparency =0;
stMeshInfoforExport->orientation = 270;

fileType을 3MF로 변경해서 export 해준다.

 

모델 생성 엔진을 실행시 D드라이브 경로에 output이 나오도록 되어있다.

지금은 보면 디렉토리로 나오는데 이걸 3mf 형태로 바꾸기 위해서는 zip 형태에서 확장자를 바꾸는 방안을 고려하고 있는 것이다.

그래서 디렉토리가 아니라 zip 형태로 우선 바꾸기 위해서 

 

 

libzippp 라이브러리 바로가기

 

 

libzippp 라이브러리를 사용한다.

    else if (format == e3mf)
    {
        mkdir((filepath + filename + "3MF").c_str());
        generateContentTypes(filepath + filename + "3MF");
        mkdir((filepath + filename + "3MF" + "/_rels").c_str());
        generateRelations(filepath + filename + "3MF" + "/_rels");
        mkdir((filepath + filename + "3MF" + "/3D").c_str());
        generate3DModel(filepath + filename + "3MF" + "/3D", vertexVectors, faceVectors);

        // 
        libzippp::ZipArchive zip("test.zip");
        zip.open(libzippp::ZipArchive::New);
        //zip.addFile("example.txt", filepath); 
        zip.addEntry(filepath + filename + "/[Content_Types].xml");
        zip.addEntry(filepath + filename + "/.rels");
        zip.addEntry(filepath + filename + "/3DModel.model");

        zip.close();
    }

이렇게 libzippp 라이브러리를 이용해서 zip 파일을 생성하려고 하니까. 

빌드 오류가 생긴다. LNK에러 즉 제대로 라이브러리 함수를 사용할 수 없는 것이다.

쉽게 말해 라이브러리 세팅이 잘못된 것. 이전에 한 번 테스트를 했었던 것 같은데, 그때 실행하지 않는 함수 안에다가 코드를 넣고 테스트했었나보다...

 

반응형
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유