Navigation

    JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    1. Home
    2. Robert Olson
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Robert Olson

    @Robert Olson

    0
    Reputation
    1
    Posts
    2
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Robert Olson Follow

    Best posts made by Robert Olson

    This user hasn't posted anything yet.

    Latest posts made by Robert Olson

    • how to compile a JsCad script from string instead of file?

      Hello everyone! I've been enjoying JsCad, but have found myself unable to move forward in my project that uses it.

      First some background:

      For my own learning I've been working on a project where I can write JsCad code in half of a window and display its output in the other half of the same window. I was using the @jscad/openjscad npm module which was working well, but I wanted it to respond faster when drawing the same solid multiple times.

      Therefore my primary goal is to compile This caused me to run across https://www.npmjs.com/package/@jscad/vtree which looked like it would provide some speed ups. It wasn't entirely clear to me how to make use of this module with my setup. I came across the @jscad/desktop module (https://www.npmjs.com/package/@jscad/desktop) which described how to use the @jscad/vtree module in a way that didn't match my intended implementation.

      I'm compiling the output from strings, not files using jscad.compile(script, params). I noticed on this forum that V2 is now available on npm, so I've tried using it as well, as it appears I can enable the use of vtree. However I cannot figure out how I can compile a script that is contained within a string in the manner that I was before. I believe the @jscad/core's code-evaluation.rebuildGeometryCli.js is the intended method, but I am not certain if I am going down the correct path with this as I cannot get that to work either.

      My primary issue that I want to address is speed. I've been testing with the following script:

      function main () {
      	return getLogos();
      }
      
      function getLogos() {
      	let size = 1;
      	let space = 0.65;
      
      	let arr = [];
      
      	for(let i = 0; i < size; i++) {
      		for(let j = 0; j < size; j++) {
      			for(let k = 0; k < size; k++) {
      				arr.push(getLogo().translate([i * space, j * space, k * space]));
      			}
      		}
      	}
      
      	return union(arr);
      }
      
      function getLogo() {
      	return union(
      		difference(
      			cube({size: 3, center: true}),
      			sphere({r: 2, center: true})
      		),
      			intersection(
      			sphere({r: 1.3, center: true}),
      			cube({size: 2.1, center: true})
      		)
      	).scale(0.2).translate([0, 0.3, 0]);
      }
      

      As I increase the size variable in the getLogos() function, it takes exponentially longer to compile something that I can draw.

      My questions are:
      Am I correct in my interpretation that the @jscad/vtree module would help with this when used correctly?
      Given that I want to load jscad scripts from strings and not files, how can I do this with the @jscad/vtree module used correctly in both V1 and V2?

      Thank you!

      posted in Development Discussions
      Robert Olson
      Robert Olson