JSCAD User Group

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

    Robert Olson

    @Robert Olson

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

    Robert Olson Unfollow Follow

    Latest posts made by Robert Olson

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

      It has been a while since I first asked this question as I got preoccupied with work for my day job. However, I am now able to devote time to my hobby project again and I just wanted to say thank you to everyone who responded. 🙂 All of you input showed me how I could write the script I had to be more efficient. I've changed it to create the object and store it in a variable for reuse outside of the loops which has been a huge speed improvement.

      I am still curious if I could be pointed in the right direction for the @jscad/core equivalent to the jscad.compile(script, params) function that I was using from @jscad/openjscad.

      Thanks in advance!

      posted in Development Discussions
      Robert Olson
      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