How to use @jscad/core - 10 common examples

To help you get started, we’ve selected a few @jscad/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jscad / OpenJSCAD.org / packages / cli / cli.js View on Github external
} else if (args[i].match(/.+\.(jscad|js|scad|stl|amf|obj|gcode|svg|json)$/i)) {
      inputFile = args[i]
      inputFormat = RegExp.$1
      if (!fs.statSync(inputFile).isFile()) {
        console.log('ERROR: cannot open input file/directory <' + inputFile + '>')
        process.exit(1)
      }
    } else if (args[i].match(/^-v$/)) { // show the version and the environment information
      env()
      console.log('OpenSCAD Compatibility (' + version + ')')
    } else {
      inputFile = args[i]
      if (fs.statSync(inputFile).isDirectory()) {
        inputFile = args[i]
        // get actual design entry point if applicable (if passed a folder as input etc)
        inputFile = getDesignEntryPoint(inputFile)
        inputFormat = require('path').extname(inputFile).substring(1)
      } else {
        console.log('ERROR: invalid file name or argument <' + args[i] + '>')
        console.log("Type 'openjscad' for help")
        process.exit(1)
      }
    }
  }
  // exit if a input file was not provided
  if (inputFile === null) process.exit(1)

  if (!outputFormat && !outputFile) {
    outputFormat = 'stla'
  }

  return {
github jscad / jscad-desktop / src / ui / design / reducers.js View on Github external
const setDesignPath = (state, paths) => {
  // console.log('setDesignPath')
  const mainPath = getDesignEntryPoint(paths)
  const filePath = paths[0]
  const designName = getDesignName(paths)
  const designPath = path.dirname(filePath)

  const design = Object.assign({}, state.design, {
    name: designName,
    path: designPath,
    mainPath
  })

  // we want the viewer to focus on new entities for our 'session' (until design change)
  const viewer = Object.assign({}, state.viewer, {behaviours: {resetViewOn: ['new-entities']}})
  return Object.assign({}, state, {busy: true, viewer, design})
}
github jscad / OpenJSCAD.org / packages / web / src / ui / flow / design.js View on Github external
setDesignContent: (state, payload) => {
    console.log('design: set content', state, state.design, payload)
    // all our available data (specific to web)
    const { filesAndFolders } = payload
    const makeFakeFs = require('@jscad/core/code-loading/makeFakeFs')
    const fakeFs = makeFakeFs(filesAndFolders)
    const rootPath = filesAndFolders[0].fullPath
    const mainPath = getDesignEntryPoint(fakeFs, rootPath)
    const designName = getDesignName(fakeFs, rootPath)
    const designPath = path.dirname(rootPath)
    console.log('BLAA', rootPath, designName, designPath)

    let design = state.design
    // to track computation time
    const debug = Object.assign({ }, state.design.debug, { startTime: new Date() })

    design = Object.assign({}, design, {
      name: designName,
      path: designPath,
      mainPath,
      filesAndFolders,
      debug
    })
github jscad / jscad-desktop / src / ui / design / reducers.js View on Github external
const setDesignPath = (state, paths) => {
  // console.log('setDesignPath')
  const mainPath = getDesignEntryPoint(paths)
  const filePath = paths[0]
  const designName = getDesignName(paths)
  const designPath = path.dirname(filePath)

  const design = Object.assign({}, state.design, {
    name: designName,
    path: designPath,
    mainPath
  })

  // we want the viewer to focus on new entities for our 'session' (until design change)
  const viewer = Object.assign({}, state.viewer, {behaviours: {resetViewOn: ['new-entities']}})
  return Object.assign({}, state, {busy: true, viewer, design})
}
github jscad / OpenJSCAD.org / packages / web / src / ui / flow / design.js View on Github external
setDesignContent: (state, payload) => {
    console.log('design: set content', state, state.design, payload)
    // all our available data (specific to web)
    const { filesAndFolders } = payload
    const makeFakeFs = require('@jscad/core/code-loading/makeFakeFs')
    const fakeFs = makeFakeFs(filesAndFolders)
    const rootPath = filesAndFolders[0].fullPath
    const mainPath = getDesignEntryPoint(fakeFs, rootPath)
    const designName = getDesignName(fakeFs, rootPath)
    const designPath = path.dirname(rootPath)
    console.log('BLAA', rootPath, designName, designPath)

    let design = state.design
    // to track computation time
    const debug = Object.assign({ }, state.design.debug, { startTime: new Date() })

    design = Object.assign({}, design, {
      name: designName,
      path: designPath,
      mainPath,
      filesAndFolders,
      debug
    })

    const viewer = Object.assign({}, state.viewer, { behaviours: { resetViewOn: [''], zoomToFitOn: ['new-entities'] } })
github jscad / OpenJSCAD.org / packages / web / src / ui / flow / design.js View on Github external
.map(url => {
        const params = getAllUriParams(url)
        const useProxy = params.proxyUrl !== undefined || url.match(/#(https?:\/\/\S+)$/) !== null
        const documentUri = fetchUriParams(url, 'uri', undefined) || nth(1, url.match(/#(https?:\/\/\S+)$/)) || nth(1, document.URL.match(/#(examples\/\S+)$/))
        const baseUri = window.location.origin // location.protocol + '//' + location.host + location.pathname
        // console.log('useProxy', useProxy, documentUri, baseUri)
        if (!documentUri) {
          return undefined
        }
        const urlData = new URL(documentUri)
        console.log('urlData', urlData, params, documentUri)
        const documentUris = documentUri ? [documentUri] : undefined
        const { protocol, origin, pathname } = urlData
        return { documentUris, protocol: protocol.replace(':', ''), origin, path: pathname }
      })
  ])
github jscad / OpenJSCAD.org / packages / web / src / jscad / processor.js View on Github external
currentObjectsToBlob: function () {
    var startpoint = this.selectStartPoint
    var endpoint = this.selectEndPoint
    if (startpoint > endpoint) { startpoint = this.selectEndPoint; endpoint = this.selectStartPoint }

    const format = this.selectedFormat()

    // if output format is jscad or js , use that, otherwise use currentObjects
    const objects = (format === 'jscad' || format === 'js') ? this.script : this.currentObjects.slice(startpoint, endpoint + 1)

    return convertToBlob(prepareOutput(objects, {format}))
  },
github jscad / OpenJSCAD.org / packages / cli / generateOutputData.js View on Github external
.then(function (objects) {
      // Buffer.from(outputData.data),{encoding: outputData.mimeType},
      return convertToBlob(prepareOutput(objects, {format: outputFormat}))
    })
github jscad / OpenJSCAD.org / packages / web / src / ui / dragDrop / walkFileTree.js View on Github external
export function isSupportedFormat (file) {
  var e = file.name.toLowerCase().match(/\.(\w+)$/i)
  e = RegExp.$1
  return conversionFormats.indexOf(e) >= 0
  // NOTE: was incrementing memFsTotal++ ONLY if format is valid, not needed anymore as far as I know
}
github jscad / OpenJSCAD.org / packages / web / src / jscad / processor.js View on Github external
errtxt += '\nStack trace:\n' + err.stack
        //    var errtxt = err.toString()
        }
        that.setStatus('error', err)// 'Error.'
        that.state = 3 // incomplete

      } else {
        that.setCurrentObjects(objects)
        that.setStatus('ready')
        that.state = 2 // complete
      }
      that.enableItems()
    }

    if (this.opts.useAsync) {
      this.builder = rebuildSolidsInWorker(script, fullurl, parameters, (err, objects) => {
        if (err && that.opts.useSync) {
          this.builder = rebuildSolids(script, fullurl, parameters, callback, options)
        } else (callback(undefined, objects))
      }, options)
    } else if (this.opts.useSync) {
      this.builder = rebuildSolids(script, fullurl, parameters, callback, options)
    }
  },