JSCAD User Group
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    A design projects template

    Scheduled Pinned Locked Moved General Discussions
    1 Posts 1 Posters 1.1k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • faithhackF Offline
      faithhack
      last edited by

      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?

      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • First post
        Last post
      Powered by NodeBB | Contributors