All files / app/codeCharta/services/3DExports/generateXML build3mfModel.ts

100% Statements 18/18
100% Branches 0/0
100% Functions 5/5
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 466x 3x 3x 3x 3x   3x       3x                   3x 3x 235x   3x 3x       3x 3x 450x   3x 3x       3x              
export function getXMLmodel(vertices: string[], triangles: string[]): string {
    const modelHeader = _getXMLModelHeader()
    const verticesString = _getXMLModelVertices(vertices)
    const trianglesString = _getXMLModelTriangles(triangles)
    const modelFooter = _getXMLModelFooter()
 
    return modelHeader + verticesString + trianglesString + modelFooter
}
 
function _getXMLModelHeader(): string {
    return `<?xml version="1.0" encoding="UTF-8"?>
<model unit="millimeter" xml:lang="en-US" xmlns="http://schemas.microsoft.com/3dmanufacturing/core/2015/02" xmlns:slic3rpe="http://schemas.slic3r.org/3mf/2017/06">
  <metadata name="Application">PrusaSlicer-2.7.2</metadata>
  <resources>
    <object id="1" type="model">
      <mesh>
`
}
 
function _getXMLModelVertices(vertices: string[]): string {
    let verticesString = `        <vertices>\n`
    for (const vertex of vertices) {
        verticesString += `          ${vertex}\n`
    }
    verticesString += `        </vertices>\n`
    return verticesString
}
 
function _getXMLModelTriangles(triangles: string[]): string {
    let trianglesString = `        <triangles>\n`
    for (const triangle of triangles) {
        trianglesString += `          ${triangle}\n`
    }
    trianglesString += `        </triangles>\n`
    return trianglesString
}
 
function _getXMLModelFooter(): string {
    return `      </mesh>
    </object>
  </resources>
  <build> <item objectid="1"/> </build>
</model>
`
}