()
| 283 | } |
| 284 | |
| 285 | export(){ |
| 286 | let unitScalar, precision; |
| 287 | switch ( this.config.units ){ |
| 288 | case 'm': |
| 289 | unitScalar = 1; |
| 290 | precision = 3; |
| 291 | break; |
| 292 | case 'cm': |
| 293 | unitScalar = 0.01; |
| 294 | precision = 5; |
| 295 | break; |
| 296 | case 'mm': |
| 297 | unitScalar = 0.001; |
| 298 | precision = 6; |
| 299 | break; |
| 300 | } |
| 301 | let str = "const shape = new THREE.Shape();\n"; |
| 302 | |
| 303 | this.nodes.forEach( node => { |
| 304 | switch( node.tool ){ |
| 305 | case "moveTo": |
| 306 | str = `${str}shape.moveTo( ${(node.x * unitScalar).toFixed( precision )} , ${(-node.y * unitScalar).toFixed( precision ) });\n`; |
| 307 | break; |
| 308 | case "lineTo": |
| 309 | str = `${str}shape.lineTo( ${(node.x * unitScalar).toFixed( precision )}, ${(-node.y * unitScalar).toFixed( precision ) });\n`; |
| 310 | break; |
| 311 | case "quadraticCurveTo": |
| 312 | str = `${str}shape.quadraticCurveTo( ${(node.options.ctrlA.x * unitScalar).toFixed( precision )}, ${(-node.options.ctrlA.y * unitScalar).toFixed( precision )}, ${(node.x * unitScalar).toFixed( precision )}, ${(-node.y * unitScalar).toFixed( precision ) };\n`; |
| 313 | break; |
| 314 | case "bezierCurveTo": |
| 315 | str = `${str}shape.bezierCurveTo( ${(node.options.ctrlA.x * unitScalar).toFixed( precision )}, ${(-node.options.ctrlA.y * unitScalar).toFixed( precision )}, ${(node.options.ctrlB.x * unitScalar).toFixed( precision )}, ${(-node.options.ctrlB.y * unitScalar).toFixed( precision )}, ${(node.x * unitScalar).toFixed( precision )}, ${(-node.y * unitScalar).toFixed( precision ) });\n`; |
| 316 | break; |
| 317 | case 'arc': |
| 318 | str = `${str}shape.absarc( ${(node.x * unitScalar).toFixed( precision )}, ${(-node.y * unitScalar).toFixed( precision )}, ${(node.options.radius * unitScalar).toFixed( precision )}, ${-node.options.start.toFixed( 3 )}, ${-node.options.end.toFixed( 3 )}, ${(node.options.clockwise) ? 'true' : 'false'} );\n`; |
| 319 | const pt = Geometry.calcPointOnCircle( node.x, node.y, node.options.radius, node.options.end ); |
| 320 | str = `${str}shape.moveTo( ${(pt.x* unitScalar).toFixed( precision )}, ${(-pt.y * unitScalar).toFixed( precision )} );\n`; |
| 321 | break; |
| 322 | } |
| 323 | }) |
| 324 | |
| 325 | if (this.config.holes){ |
| 326 | let index = 1; |
| 327 | |
| 328 | for( const [key, nodes] of Object.entries( this.ghosts.paths)){ |
| 329 | const path = `path${index++}`; |
| 330 | str = `${str}const ${path} = new THREE.Path()\n`; |
| 331 | |
| 332 | nodes.forEach( node => { |
| 333 | switch( node.tool ){ |
| 334 | case "moveTo": |
| 335 | str = `${str}${path}.moveTo( ${(node.x * unitScalar).toFixed( precision )} , ${(-node.y * unitScalar).toFixed( precision ) });\n`; |
| 336 | break; |
| 337 | case "lineTo": |
| 338 | str = `${str}${path}.lineTo( ${(node.x * unitScalar).toFixed( precision )}, ${(-node.y * unitScalar).toFixed( precision ) });\n`; |
| 339 | break; |
| 340 | case "quadraticCurveTo": |
| 341 | str = `${str}${path}.quadraticCurveTo( ${(node.options.ctrlA.x * unitScalar).toFixed( precision )}, ${(-node.options.ctrlA.y * unitScalar).toFixed( precision )}, ${(node.x * unitScalar).toFixed( precision )}, ${(-node.y * unitScalar).toFixed( precision ) });\n`; |
| 342 | break; |
no test coverage detected