OpenJSCAD.org icon indicating copy to clipboard operation
OpenJSCAD.org copied to clipboard

OpenSCAD importer improvements

Open apla opened this issue 2 years ago • 8 comments

I did some OpenSCAD improvements to generate human readable results.

scad file:

module m3head()
{
    intersection()
    {
        translate([30,5,9])cylinder(r=3.1,h = 25, $fn=30); // head cut
        translate([30,5,17-3.5]) cube([6.2,3.4,1], center=true);
    }
    translate([30,5,17-4]) cube([3.4,3.4,1], center=true);
    translate([30,5,17-3.5])cylinder(r=3.1,h = 20, $fn=30); // head cut
}

m3head()

jscad

onst jscad = require('@jscad/modeling') // modeling comes from the included MODELING library
const { transforms,primitives,booleans } = jscad;
const { intersect,union,subtract } = booleans
const { cylinder,cuboid } = primitives
const { translate,translateX,translateY,translateZ,rotate,rotateX,rotateY,rotateZ } = transforms

function m3head() {
	return [

		intersect(
			translate([30,5,9], cylinder({radius: 3.1, height: 25, center: [0, 0, 12.5], resolution: 30})),
			translate([30,5,13.5], cuboid({size: [6.2,3.4,1]}))
		),
		translate([30,5,13], cuboid({size: [3.4,3.4,1]})),
		translate([30,5,13.5], cylinder({radius: 3.1, height: 20, center: [0, 0, 10], resolution: 30}))
	
	]

}

function main() {
    
	return m3head();
    

}

module.exports = {main};

It's still WIP, but allows me to convert some files from Prusa i3 printer repo.

Can't show my fork at this time; instead of using last version from git I've used last version from npm. It will take some time to commit my changes.

This issue just for indication I'm working on this part.

apla avatar Aug 12 '21 22:08 apla

Excellent, let me know if you will need help.

Join discord if you are in a mood to discuss jscad related stuff. Beware, tho, I am rather chatty and opinionated. https://discord.gg/UXtQcA6

hrgdavor avatar Aug 13 '21 08:08 hrgdavor

not sure if you changed your jscad impl, but current master branch param name for precision is segments

cylinder({radius: 3.1, height: 20, center: [0, 0, 10], resolution: 30}))

-->

cylinder({radius: 3.1, height: 20, center: [0, 0, 10], segments: 30}))

hrgdavor avatar Aug 13 '21 09:08 hrgdavor

No, I haven't changed anything in jscad. I'll fix it.

apla avatar Aug 13 '21 09:08 apla

This is my modifications https://github.com/protobor/OpenJSCAD.org/commit/d0e49bebe4b243af984047c7b09947eafdfd9f60

If somebody wants to try it out, I test changes with simple script

// const parser = require('@jscad/openscad-openjscad-translator');

const parser = require('scad-deserializer');

const fs = require('fs').promises;

fs.readFile(process.argv[2], "UTF8").then (openSCADText => {
    const openJSCADResult = parser.parse(openSCADText);
    const jscadFilename = process.argv[2].replace (/\.scad$/, '.jscad');
    return fs.writeFile (jscadFilename, openJSCADResult);
});

as an input file I'm using x-carriage-back.scad from Prusa i3 repo

apla avatar Aug 13 '21 09:08 apla

Some related issues just in case you feel motivated. 😃

#188 #370 #392 #447

z3dev avatar Aug 13 '21 15:08 z3dev

@z3dev I've already found some bugs in jison file, some valid constructs like one below cannot be processed:

module selective_infill()
mirror([0,1,0]) translate([-50, -33, 0.6])
{ ... }

User needs to wrap module contents with {} like this

module selective_infill() {
mirror([0,1,0]) translate([-50, -33, 0.6])
{ ... }
}

So, jison grammar should be modified. Problem is — output is unreadable. Even slightest modification impossible. I modified the output to return same constructs in JSCAD. Now it lookalike and can be hacked by other people.

Adding diameter for cylinder #392 is trivial, others probably not.

apla avatar Aug 13 '21 15:08 apla

@apla Did you manage to create a new version of the serializer? Any chance that we can play with it and give some feedback?

z3dev avatar Sep 06 '21 07:09 z3dev

@z3dev I haven't touched scad converter for a while. Tried to convert some designs from thingiverse, but when those designs have global variables, result is ugly. You can try to play with my fork, but it is incomplete.

apla avatar Oct 03 '21 13:10 apla