A design projects template



  • How does everyone do their new project layouts?

    I use OpenJSCAD for 3D printing, mostly, and have been tracking V2 and able to make the things I needs without too much issue. I have a package.json with:
    "main": "index.js"

    Then an index.js like:

    //include your script here:
    var inc = require('./mypart')
    
    const getParameterDefinitions = () => {
        return inc.getParameterDefinitions()
    }
    
    const main = (params) => {
        return inc.main(params)
    }
    
    module.exports = { main, getParameterDefinitions }
    

    The do my parts like:

    /* All the csg API functions: */
    const { cube, sphere, cylinder, geodesicSphere, torus, polyhedron } = require('@jscad/csg/api').primitives3d
    const { circle, square, polygon, triangle  } = require('@jscad/csg/api').primitives2d
    const { difference, union, intersection } = require('@jscad/csg/api').booleanOps
    const { translate, center, scale, rotate, transform, mirror, expand, contract, minkowski, hull, chain_hull } = require('@jscad/csg/api').transformations
    const { extrudeInOrthonormalBasis, extrudeInPlane, extrude, linear_extrude, rotate_extrude, rotateExtrude, rectangular_extrude } = require('@jscad/csg/api').extrusions
    const { css2rgb, color, rgb2hsl, hsl2rgb, rgb2hsv, hsv2rgb, html2rgb, rgb2html } = require('@jscad/csg/api').color
    const { sin, cos, asin, acos, tan, atan, atan2, ceil, floor, abs, min, max, rands, log, lookup, pow, sign, sqrt, round } = require('@jscad/csg/api').maths
    const { vector_char, vector_text, vectorChar, vectorText } = require('@jscad/csg/api').text
    //const { echo } = require('@jscad/csg/api').echo
    const {CAG, CSG} = require('@jscad/csg/api').csg
    const { extrude_text } = require('./fonts/index.js')
    
    const paramDefaults = {size: 10}
    
    const getParameterDefinitions = () => {
      return [{ name: 'size', type: 'int', initial: 10, caption: 'Size?' }]
    }
    
    const main = (params) => {
    	params = Object.assign({}, paramDefaults, params)
    
    	let results = []
            // replace this
            myPart = cube(params.size)
    	results.push(myPart)
    	myText = extrude_text("Blank Project", 1, 1.5, {height:5, font:'camBamStick1Font'})
    	myText = translate([-45,-10,0], myText) 
    	results.push(myText)
    
    	//
    
    	return results 
    }
    module.exports = { main, getParameterDefinitions, paramDefaults }
    

    Then I just drag the folder to my browser running the web application.
    The "extrude_text" include is my integrating the single-line fonts from https://github.com/lautr3k/jscad-vector-fonts

    Now that a lot of the csg integration to packages/modeling has happened (Thanks kaosat-dev!) it works for me to replace stuff like:

    const { cube, sphere } = require('@jscad/csg/api').primitives3d
    

    with:

    const modeling = require('@jscad/modeling')
    const { cube, sphere } = require('@jscad/modeling').primitives
    

    Is there a "recommended" project layout out there on a wiki somewhere? Would it be helpful for others if I post my "blank project" to github?