Coder Social home page Coder Social logo

jscad / openjscad.org Goto Github PK

View Code? Open in Web Editor NEW
2.6K 125.0 505.0 55.85 MB

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.

Home Page: https://openjscad.xyz/

License: MIT License

Perl 0.12% JavaScript 96.60% CSS 0.93% HTML 0.66% PHP 0.04% OpenSCAD 1.07% Yacc 0.53% TypeScript 0.02% GLSL 0.04%
javascript 3d-design openjscad jscad stl dxf obj amf svg x3d

openjscad.org's Introduction

JSCAD (previously known as OpenJSCAD)

JSCAD is a set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code.

There are many ways to use JSCAD:

An online version, self hostable web based ui, as CLI (command-line interface) for server-side computations with Node.js, as well as an experimental desktop app or individual Node.js packages!!

This repository is a monorepo (container of multiple packages and tools) maintained with Lerna

Build Status Stability All Dependencies

User Group Lerna JavaScript Style Guide

Backers Sponsors

Open Collective

Table of Contents

Usage

There are different 'flavors' of JSCAD that you can use based on your needs

  • web: online (no install) simply go to https://openjscad.xyz/
  • web: self hosted: can be found here
  • cli: command line interface : can be found here
  • desktop app: pre pre alpha work in progress can be found here!
  • node.js: custom mix and match of packages
    • all the packages are available on NPM under the '@jscad' name

Immediate Use (no installation)

Go to OpenJSCAD.xyz (Tested browsers include Chrome, Edge, Firefox, Opera, Safari)

Use within a Web Site (pre built files, from GitHub)

Please see here for details

Use as Command Line Interface (CLI)

Please see here for details

Use of components and viewer in websites

Please see here for details

Use of the different modular components directly

From version 1.0.0 onwards, almost all the individual parts of this project are available directly as scoped NPM packages, and can be used independently from the main repository. The full list of these is available here and here

One example of what can be achieved with this can be found here This means you can :

  • easily create your own renderer for the 3D and 2D geometries
  • create custom UIs
  • use the specific packages as part of Node.js or Browserify projects
  • cherry pick formats you want to use for input/output without needing the dependencies of all packages
  • lots more !

This will be expanded upon in the future, and is the backbone of the newer, modular JSCAD project.

Documentation

Contributing

The various JSCAD packages and all source code are part of the JSCAD Organization, and maintained by a group of volunteers. We welcome and encourage anyone to pitch in but please take a moment to read the following guidelines.

  • If you want to submit a bug report please make sure to follow the Reporting Issues guide. Bug reports are accepted as Issues via GitHub.

  • If you want to submit a change or a patch, please read the Contributing Guide. New contributions are accepted as Pull Requests via GitHub.

  • We only accept bug reports and pull requests on GitHub.

  • If you have a question about how to use JSCAD, then please start a conversation at the JSCAD User Group. You might find the answer in the JSCAD User Guide.

  • If you have a change or new feature in mind, please start a conversation with the Core Developers and start contributing changes.

Small Note: If editing this README, please conform to the standard-readme specification.

A BIG THANKS to all the people who have already contributed to the JSCAD project! Open Collective

Community

Discuss designs or issues

Or chat with other users

HUGE THANKS and SHOUTOUT to nodeBB for hosting our (awesome) forum for free ! Thanks a lot !

Acknowledgements

JSCAD and all sub components are built upon great open source packages, and contributions.

Early CSG Library by:

  • Evan Wallace,
  • Eduard Bespalov,
  • Joost Nieuwenhuijse,
  • Alexandre Girard

XML parsing:

Tooling:

and many more!

Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]

Sponsors

This project has some awesome sponsors! [Become a sponsor] Your logo will show up here with a link to your website.

License

The MIT License (MIT) (unless specified otherwise)

See Also

  • OpenJsCAD, starting point of JSCAD
  • OpenSCAD.net, another place of inspiration, where the OpenSCAD translator was adapted from

That's all for now,

The JSCAD Organization

openjscad.org's People

Contributors

achirita avatar ahdinosaur avatar alexose avatar andreasplesch avatar apla avatar arkteknik avatar brettle avatar derrickoswald avatar donhatch avatar erikdebruijn avatar fishorbear avatar garyhodgson avatar hrgdavor avatar jamesgt avatar johnwebbcole avatar kaosat-dev avatar loosetooth avatar nilskrause avatar nmattia avatar paulftw avatar paulhayes avatar platypii avatar richievos avatar samuelwang48 avatar simonclark avatar spiritdude avatar tedbeer avatar tsdexter avatar wojciechczerniak avatar z3dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openjscad.org's Issues

WebGL not supported on Chrome or IE10?

Someone posted on G+:

"Error: WebGL not supported

OpenJsCad currently requires Google Chrome with WebGL enabled"

Using Ubuntu 12.10 and google-chrome directly from google. WebGL works on other sites. Any tips?

Minus vector

The printed gear bearing scad file:

http://www.thingiverse.com/thing:53451

when converted has an error because of this line:

translate(-[3,2.5])union(){

which cause a barf in the translate() method because of an invalid value.

This can be fixed by distributing the minus sign into the vector:

translate([-3,-2.5])union(){

but the better way would be to have the converter change it to a minus() operator or something.

Limitations on zoom - cannot view large or small sized objects.

If I load an STL file of something that is small - the page will not let me zoom enough to see it proper (just a spec on the grid).

Likewise, if I make something too large, I cannot zoom out enough to see it. (In this case it was an openSCAD file of a table).

Partitioning of STL Parsing

I'm really loving OpenJSCAD, and have another suggestion.

The routines that parse the STL binary and Ascii file streams is returning a set of normals, wrapped by "return main() { ... }". I really think that the wrapping should occur in the calling routing, parseSTL(). This would make those routines useable inside other calling routines, i.e. libraries, jscad scripts, etc. For example, creating a script that can control color, scaling, etc.

The changes:

  • Change parseBinarySTL( stl, fn ) to create source for "function getNormals()"
  • Change parseAsciiSTL( stl, fn ) to create source for "function getNormals()"
  • Change parseSTL( stl, fn )
    • var src = "";
    • if(!!isAscii) {
      • src += parseBinarySTL( ... );
    • } else {
      • src += parseAscciSTL( ... );
    • }
    • src += "function main() { return getNormals(); }";

That's a short version.

Generated stl object is non manifold

I have generated stl on web site from the following simplest code:

function main() {
   return difference(
         cube({size: 3, center: true}),
         cylinder({r:1, h:3, center: true}).rotateX(90)
      );
}

Then downloaded it and imported to Blender and checked for manifold.

2015-03-05 20 26 45

Rotation with mouse button

I am left-handed mouse user, so the mouse buttons are switched. (btw, consider using "main/secondary" in replace of "left/mouse" to describe the mouse buttons).

The instruction says that [Right mouse] for xy rotation and [Left mouse] for xz. In my case, it is the [Left mouse] button (the physical right button) controls rotations of all directions, and the [Right mouse] button (the physical left button) has no function at all.

Don't know if this is just me. I am using Linux Mint running Chrome. It'd be great if the 2nd button (the [Right mouse]) is set for panning like OpenCad does. In the current setting, the panning is set to either [Middle mouse](which doesn't work in my case, either 'cos it's the wheel in the middle and pushing in resulting in zooming) or Shift-[Left mouse], which works but needs both hands.

Accessing privelage / public methods from object instance

I have modified the involute gear demo to create several gear objects. How do I reference the pitchRadius property of each gear instance to dynamically modify the location coordinates? Everything I have tried so far has failed.


// Here we define the user editable parameters: 
function getParameterDefinitions() {
  return [
    { name: 'circularPitch', caption: 'Circular pitch:', type: 'float', initial: 5 },
    { name: 'pressureAngle', caption: 'Pressure angle:', type: 'float', initial: 20 },
    { name: 'clearance', caption: 'Clearance:', type: 'float', initial: 0 },
    { name: 'thickness', caption: 'Thickness of transmission gears:', type: 'float', initial: 5 },
    { name: 'spurTeeth', caption: 'Number of spur teeth:', type: 'int', initial: 32 },
    { name: 'pinionTeeth', caption: 'Number of pinion teeth:', type: 'int', initial: 14 },
    { name: 'bore', caption: 'Radius of shaft:', type: 'float', initial: 5 }
  ];
}

 // Main function
 function main(params)
{
  // declare parts
  spurGear = new makeSpur(params);
  pinionGear = new makePinion(params);

  // assemble parts
  // spurGear = spurGear.translate([-pinionGear.getpitchRadius(), 0, -20]);
  // pinionGear = pinionGear.translate([spurGear.getpitchRadius(), 0, 20]);

  return [spurGear,pinionGear];
}

// Spur Gear
function makeSpur(params)
{
  var gear = new involuteGear(
    params.spurTeeth,
    params.circularPitch,
    params.pressureAngle,
    params.clearance,
    params.thickness,
    params.bore
  );
  if(params.bore > 0)
  {
    var bore = CSG.cylinder({start: [0,0,-params.thickness], end: [0,0,params.thickness], radius: params.bore, resolution: 16});
    gear = gear.subtract(bore).rotateX(90);
  }
  return gear;
}

// Pinion Gear
function makePinion(params)
{
  var gear = new involuteGear(
    params.pinionTeeth,
    params.circularPitch,
    params.pressureAngle,
    params.clearance,
    params.thickness,
    params.bore
  );
  if(params.bore > 0)
  {
    var bore = CSG.cylinder({start: [0,0,-params.thickness], end: [0,0,params.thickness], radius: params.bore, resolution: 16});
    gear = gear.subtract(bore).rotateX(90);
  }
  return gear;
}

// title: Gear
// author: Joost Nieuwenhuijse
// license: MIT License

/*
  For gear terminology see: 
    http://www.astronomiainumbria.org/advanced_internet_files/meccanica/easyweb.easynet.co.uk/_chrish/geardata.htm
  Algorithm based on:
    http://www.cartertools.com/involute.html

  circularPitch: The distance between adjacent teeth measured at the pitch circle
*/ 
function involuteGear(numTeeth, circularPitch, pressureAngle, clearance, thickness)
{
  // default values:
  if(arguments.length < 3) pressureAngle = 20;
  if(arguments.length < 4) clearance = 0;
  if(arguments.length < 4) thickness = 1;

  var addendum = circularPitch / Math.PI;
  var dedendum = addendum + clearance;

  // radiuses of the 4 circles:
  var pitchRadius = numTeeth * circularPitch / (2 * Math.PI);
  // this.getpitchRadius = function() {
    //return pitchRadius;
  //};
  var baseRadius = pitchRadius * Math.cos(Math.PI * pressureAngle / 180);
  var outerRadius = pitchRadius + addendum;
  var rootRadius = pitchRadius - dedendum;

  var maxtanlength = Math.sqrt(outerRadius*outerRadius - baseRadius*baseRadius);
  var maxangle = maxtanlength / baseRadius;

  var tl_at_pitchcircle = Math.sqrt(pitchRadius*pitchRadius - baseRadius*baseRadius);
  var angle_at_pitchcircle = tl_at_pitchcircle / baseRadius;
  var diffangle = angle_at_pitchcircle - Math.atan(angle_at_pitchcircle);
  var angularToothWidthAtBase = Math.PI / numTeeth + 2*diffangle;

  // build a single 2d tooth in the 'points' array:
  var resolution = 5;
  var points = [new CSG.Vector2D(0,0)];
  for(var i = 0; i <= resolution; i++)
  {
    // first side of the tooth:
    var angle = maxangle * i / resolution;
    var tanlength = angle * baseRadius;
    var radvector = CSG.Vector2D.fromAngle(angle);    
    var tanvector = radvector.normal();
    var p = radvector.times(baseRadius).plus(tanvector.times(tanlength));
    points[i+1] = p;

    // opposite side of the tooth:
    radvector = CSG.Vector2D.fromAngle(angularToothWidthAtBase - angle);    
    tanvector = radvector.normal().negated();
    p = radvector.times(baseRadius).plus(tanvector.times(tanlength));
    points[2 * resolution + 2 - i] = p;
  }

  // create the polygon and extrude into 3D:
  var tooth3d = new CSG.Polygon2D(points).extrude({offset: [0, 0, thickness]});

  var allteeth = new CSG();
  for(var j = 0; j < numTeeth; j++)
  {
    var ang = j*360/numTeeth;
    var rotatedtooth = tooth3d.rotateZ(ang);
    allteeth = allteeth.unionForNonIntersecting(rotatedtooth);
  }

  // build the root circle:  
  points = [];
  var toothAngle = 2 * Math.PI / numTeeth;
  var toothCenterAngle = 0.5 * angularToothWidthAtBase; 
  for(var k = 0; k < numTeeth; k++)
  {
    var angl = toothCenterAngle + k * toothAngle;
    var p1 = CSG.Vector2D.fromAngle(angl).times(rootRadius);
    points.push(p1);
  }

  // create the polygon and extrude into 3D:
  var rootcircle = new CSG.Polygon2D(points).extrude({offset: [0, 0, thickness]});

  var result = rootcircle.union(allteeth);

  // center at origin:
  result = result.translate([0, 0, -thickness/2]);

  return result;
}

Bad facet normals in .stl from csg.js based export (web & cli)

Right now csg.js, in more concrete fixTJunctions() in the export chain to create .stl creates (edit: in few cases) bad facet normals, e.g. 'NaN' in the ascii export (both web or cli). E.g. when csg.toSTLString() without fixTJunction() then the .stl looks fine.

It wouldn't be such a big problem as most slicers disregard the normals, but OpenJSCAD relies (at least for now) on proper set normals in order to determine the orientation of the triangles (cw vs ccw) and correct them (which means also, stl with bad normals cannot imported in general).

Unable to use on Chrome Mobile

I've been trying to use this on my mobile device, both tablet and phone. I've noticed that it requires WebGL to be enabled and have gone into the flags to make enable it. Despite enabling WebGL in Chrome on my mobile device non of the code that is type is in ever visualized like it is on laptop or desktop computer. Is there a simple solution that I could be missing?

Viewer Width and Height on Safari iOS

Guys,
There's a simple fix for the view width and height, which will allow OpenJsCad to display correctly on devices running iOS.

Reference:
http://www.w3schools.com/js/js_window.asp

Fix createElements()...
var myWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var myHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;

FYI, these values change if the window is resized.

Feature request: Editor font size

The font in the editor is tiny! It's small on a regular display. At 12px it must be invisible on high DPI displays. Please make it bigger by default or make the CSS responsive or make it customizable.

No Clear documentation on for loops

While I see them mentioned there is no clear documentation on how to use them or if the openscad version of a for loop will work. Can you please add specific directions about them. or direct me to the specific documentation in the user guide.

include() for libraries

Support for include() to include 3rd party libraries, must work on

  • web-browser
  • nodejs script (openjscad)

OpenJSCAD exports incorrectly-formed STL

When I export STL from the program (using the openjscad.org site)

function main() {
   return difference(
         cube({size: 3, center: true}),
         cylinder({r:1, h:3, center: true}).rotateX(90)
      ).translate([0,0,1.5]).scale(10);
}

I get an mesh that looks like this:

bad_example

Note that the face with the hole has a bunch of triangles that do not share two vertexes with each neighboring triangle, in violation of the page at http://www.ennex.com/~fabbers/StL.asp, which is the most authoritative page I can find on the STL format.

If I use tinkercad.com to create the equivalent object, I get a mesh that looks like

good_example

which correctly ensures that each neighboring triangle shares two vertexes.

Normally, I'd consider this a nit-pick, but my slicer I'm developing is choking on the input that violates the STL format because I'm using an optimization that's only possible with well-formed files.

Enhancement: ECMAScript 6/7 support

It would be really nice to get some of the new language features. Browsers are gearing up their support right now, and it would be really nice if JsCad didn't get stuck on older versions of Js.

Specifically, it would be nice to see support for iterators, generators, and proxy objects so that we can create better part design libraries.

too much recursion

On an example with simple lasercut box, you quickly hit 'too much recursion'
Unclear why this would be complicated.

Is there a way to program around this limitation. As the aim is lasercutting, having lines which should not be lasercut is a not acceptable, so I need a full side, but for a box, I will need 6 sides.

Test file that hits this limitation: https://gist.github.com/bmcage/a6c6b234911971bc390a
To make it work: at the bottom of this file, comment out two of four the for loops

At the top of the file you see:

var shape1 = new CSG.Polygon2D( polypoints ).extrude({offset: [0, 0, thick]});
//var shape1 = CAG.fromPoints( polypoints );

Both fail. Idea is to show the box nicely and allow dxf output for lasercutting

adding joostn csg.js to openjscad - open questions

  1. AMF support - says experimental/rudimentary in many places in code - what's the overall status on current support? How well are import, export supported?
  2. STL - there's an addition to toStlBinary func - can you give some context on what this is needed for? I don't fully grasp the comment there:
    as binary string blobbing gives bad blob in web, we need binary string for CLI
    perhaps there is a way to make it working (see openjscad for stlb)

Enhancement: SVG export

Having a direct SVG export feature would be helpful - it allows using the generated file directly in e.g. jscut. OpenSCAD also recently gained an SVG export, perhaps that might be useful to look at?

Swap mouse buttons perhaps?

Hi,

Maybe it's just me but I expected the actions of the left and right mouse buttons to be the other way around, i.e. left mouse rotates XZ.

G.

cylinder diameter ignored

I noticed this while testing simple openscad script
cylinder({h:4.5, d:9});
and
cylinder({h:4.5, r:4.5})
should be the same, but seems diameter "d" is not supported (only "r" is)

equivalent openscad code does not work too (the version with diameter "d" param)

simple openjscad test

function main() {
return [
cylinder({h:4.5, d:9}),
translate([20,0,0],cylinder({h:4.5, r:4.5}))
];
}

OpenSCAD interpreted incorrectly

The following OpenSCAD code gets rendered incorrectly:

//!OpenSCAD
// Ball bearing spool holder for the Replicator1
// Written by Joe Cabana  1/2/2013
// You are free to use and/or modify this software for non-comercial
// uses as long as you retain this message. Thanks.

// Spool dimensions
SpoolCnt = 18;  // Number of spool sizes
SpoolWid = [97, 93, 89, 85, 81, 77, 73, 69, 65, 61, 57, 53, 49, 45, 41, 37, 33, 29];  // Width of filament spool the first one must be the biggest, and the last one the smallest.
SpoolSpace = 1;  // Extra space on each side of the spool

// Bearing mount dimensions
SplShdDia = 30;  // Diameter of spool guiding shoulder
SplShdThk = 2;  // Thickness of spool guiding shoulder

// Bracket dimensions
InBrkThk = 12;  // Thickness of bracket on back of replicator
OutBrkThk = 8;  // Thickness of bracket on outside
BrkWid = 100; // Width of bracket on back of replicator
InBrkHgt = 150;  // Height of bracket on back or replicator
OutBrkHgt = 30;  // Height of outside bracket
SlotDepth = 3; // Depth of slots to hold outer bracket
SlotWidth = 2; // Width of slots to hold outer bracket
SlotClear = .2;  // Clearance for outer bracket slots
ArmWid = (2 * SplShdThk) + (2 * OutBrkThk) + InBrkThk + SpoolWid[0] + SpoolSpace + SlotWidth + 1;  // Width of outer bracket arms
ArmThk = 3;  // Thickness of outer bracket arms

    // Outer bracket mounting arms
    translate([-OutBrkHgt*1.5,-(ArmWid/2+InBrkThk),0])
        Arm(0);
    translate([OutBrkHgt/2+5,ArmWid/2-InBrkThk,ArmThk])
        rotate([180,0,0])
            Arm(1);


// Routine to draw the outer bracket mounting arm
module Arm(Invert = 0)
{
    SlotBlockWid = SpoolWid[0]-SpoolWid[SpoolCnt-1]+(3*SlotWidth) + 1.5;  // Width of block to hold slots

    difference()
    {
        // Arm
        union()
        {
            cube([OutBrkHgt,ArmWid,ArmThk]);  // Arm
            if (Invert)
                translate([0,ArmWid-SlotBlockWid-OutBrkThk-.5,-(SlotDepth-SlotClear)])
                    cube([OutBrkHgt,SlotBlockWid,ArmThk+SlotDepth-SlotClear]);  // Outer bracket support
            else
                translate([0,ArmWid-SlotBlockWid-OutBrkThk-.5,0])
                    cube([OutBrkHgt,SlotBlockWid,ArmThk+SlotDepth-SlotClear]);  // Outer bracket support
        }

        // Outer bracket slots
        for (cnt = [0 : (SpoolCnt-1)])
            if (Invert)
                translate([SlotWidth-SlotClear,(2*SplShdThk)+OutBrkThk+InBrkThk+SpoolWid[cnt]+SpoolSpace-(SlotWidth+(2*SlotClear)),-(ArmThk+1)])
                    cube([OutBrkHgt,SlotWidth+(2*SlotClear),SlotDepth+1]);  // Outer bracket support
            else
                translate([SlotWidth-SlotClear,(2*SplShdThk)+OutBrkThk+InBrkThk+SpoolWid[cnt]+SpoolSpace-(SlotWidth+(2*SlotClear)),ArmThk])
                    cube([OutBrkHgt,SlotWidth+(2*SlotClear),SlotDepth+1]);  // Outer bracket support
    }
}

The second arm should be simply a rotated version of the first (with the "teeth" pointing outward). It so renders in OpenSCAD but not in OpenJSCAD.

Feature Request โ€“ Support 'HTTP/1.1 301 Moved Permanently' - response

~$ curl -i https://gist.github.com/koppi/5423648/raw/2fc3700d4ef051af1cbbaa7ca294917ddd610452/openlab-logo-02.js

leads to

HTTP/1.1 200 OK
...

and openjscad.org displays the file just fine.

~$ curl -i http://gist.github.com/koppi/5423648/raw/2fc3700d4ef051af1cbbaa7ca294917ddd610452/openlab-logo-02.js

leads to

HTTP/1.1 301 Moved Permanently
...
Connection: close
Location: https://gist.github.com/koppi/5423648/raw/2fc3700d4ef051af1cbbaa7ca294917ddd610452/openlab-logo-02.js
Vary: Accept-Encoding

<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

and openjscad.org does not display the file.

Steps to re-produce: Open an url that has a HTTP redirect response in it, like

http://openjscad.org/#http://gist.github.com/koppi/5423648/raw/2fc3700d4ef051af1cbbaa7ca294917ddd610452/openlab-logo-02.js

Feature Request โ€“ Add Hypertext Transfer Protocol Secure Support

HTTP urls just work

http://openjscad.org/#http://lab.koppi.me/openlab-logo.jscad

HTTPS urls do not work. Steps to re-produce: Open

http://openjscad.org/#https://gist.github.com/koppi/5423648/raw/d1dda9ca3e1a99b1b5f458b5c133698ee200182d/openlab-logo-02.js

In addition, it would be nice, if openjscard.org would support gist.github.com urls, something like

http://openjscad.org/#gist.github.com/koppi/5423648

Import failure for presumably valid SCAD

Importing a scad file (via drag and drop file upload) results in no model and the following error:

Error: wrong arguments
at Object.CSG.Vector3D (http://openjscad.org/csg.js:2164:10)
at Function.CSG.Matrix4x4.scaling (http://openjscad.org/csg.js:3708:12)
at Object.prot.scale (http://openjscad.org/csg.js:5045:39)
at main (eval at <anonymous> (blob:http%3A//openjscad.org/a1eafbe3-df81-4050-b0b9-7c5886a0a967:8:12), <anonymous>:4:491)
at Function.OpenJsCad.runMainInWorker (http://openjscad.org/openjscad.js:418:18)
at DedicatedWorkerContext.<anonymous> (blob:http%3A//openjscad.org/a1eafbe3-df81-4050-b0b9-7c5886a0a967:47:96)

The STL exported by OpenSCAD renders fine.

Enhancement: Show Compass

I would like to request a feature. Could a X/Y/Z compass (arrows in the positive direction) be displayed in the render panel. This would be very helpful. Thank you.

rotate_extrude (torus etc)

linear_extrude() is implemented, but we miss the rotate_extrude() still (OpenSCAD equivalent), e.g. we like to have

torus = rotate_extrude({ fn = 100 }, circle({r: 1, fn: 100).translate([2,0,0));

Bug in hull()

Hi
Whilst doing a quick experiment on hull(), I seem to have uncovered a bug:

function main() {
   return hull(
        CAG.circle({radius:2}).translate([-1,0]),
        CAG.circle().translate([1,0]),
        CAG.circle().translate([0,1])
    ).extrude({offset:[0,0,10]});
}

this generates an error:
RangeError: Maximum call stack size exceeded

...but if you reduce the radius of the first circle to 1, then it works ok. Similarly, if you translate one of the other circles to say [2,0], then it works ok.

Enhancement: Improve text support

Currently, there is basic text rendering support. I can see two ways to improve this:

  1. Better integration with the 2D subsystem.
  2. Somewhat normalize the font size of rendered text.
  3. Allow rendering different fonts.

2D integration

It makes sense to let the text functions return Path2D objects instead of an array with point coordinates. This makes them easier to use, and makes them useful for a 2D drawing as well. In this case, instead of having a rectangular_extrude that works on an array of points, users can just call the Path2D.rectangularExtrude directly.

Having a way to easily transform an array of Path2D objects could be easy as well (e.g. to scale a piece of text). Perhaps calling addTransformationMethodsToPrototype on the array prototype (and adding an appropriate transform implementation for array) might be useful in general? Alternatively, adding a Paths2D object and appropriate Path2D.union implementation could be useful? The latter could allow to add other methods as well (like rectangularExtrude or expandToCAG to quickly work with text or multiple paths in general).

Normalize font sizes

Regarding the font sizes, it seems that the concept of "font size" is not entirely well-defined. In general, though, it seems that the font size should be at least as big as the biggest character, and often includes a bit of spacing as well (though with modern fonts, it depends on the font itself what the "font size" actually measures. In the hershey font used, the biggest characters ((, / and [ it seems) range from -7 to 25, so they are 32 "units" high. I wonder if it would make sense to scale this so that text returned is always 1 high? Then callers can just scale afterwards to whatever size they need (and add any extra linespacing if needed).

Rendering default fonts

It seems that opentype.js might be useful to do the grunt work for this?

When picking an API for this, it is interesting to note that the current text functions return characters as unclosed paths, so they trace the character once. When support for other fonts is added, these would return closed paths that would need to be filled, which requires different processing. Even if custom fonts aren't implemented now, it would be good to somehow make the API future-proof in this regard?

Render 2d paths

Currently, the rendering result can only be CAG/CSG objects. However, I want to mark some lines using a laser cutter, for which 2d paths seem a perfect match. However, it's not currently possible to return these paths, even though it should be possible to represent them in a DXF file.

Feature Request โ€“ Add Support for Eagle BRD files

CadSoft's EAGLE PCB Design Software

CadSoft's EAGLE PCB Design Software speaks XML since version 6.

โ€“ Feature Request: add support for Eagle BRD files

Part 001 โ€“ The Board's outline

arduino_Uno_Rev3-02-TH.brd (Arduino UNO reference design) looks like follows

<?xml version="1.0" encoding="utf-8"?>
  <!DOCTYPE eagle SYSTEM "eagle.dtd">
  <eagle version="6.1">
  <drawing>

    <layers>
      <layer number="20" name="Dimension" color="15" fill="1" visible="yes" active="yes"/>
    </layers>

    <board>
      <plain>
        <wire x1="64.516" y1="53.34" x2="66.04" y2="51.816" width="0.254" layer="20"/>
        <wire x1="66.04" y1="40.386" x2="68.58" y2="37.846" width="0.254" layer="20"/>
        <wire x1="68.58" y1="37.846" x2="68.58" y2="5.08" width="0.254" layer="20"/>
...
      </plain>
    </board>
  </drawing>
</eagle>

โ€“ Steps to reproduce: Open openjscad.org/#arduino_Uno_Rev3-02-TH.brd. The Board's outline is shown.

Part 002 โ€“

transparency issue in setColor()

I'm about to merge the alpha args in setColor into the joostn/csg.js rep. But there appears to be an issue with transparency. To reproduce:

function main() {
var red = CSG.cube({radius:10}).setColor(1, 0, 0, 0.5);
var green = CSG.cube({radius:10}).translate([3, 3, 3]).setColor(0, 1, 0, 0.5);
return [red, green];
// --> green is transparent, red is not transparent but should be.
}
Could you check this?

mirror(vec, object) doesn't properly mirror

The behavior of mirror doesn't reflect what OpenSCAD does, nor what I would expect it to do. I actually think the entire mirror function needs to be reimplemented. I'm guessing when this was implemented it was a copy-paste of rotate (note the comment) and it doesn't actually work correctly like rotate. I have not yet tried rotate though, so I don't know if that is broken.

Existing code:

function mirror(v,o) { 
   var a = arguments, v,o,i = 1, r = 0;
   if(arguments.length==3) {  // mirror(r,[x,y,z],o)
      r = a[0];
      v = a[1];
      i = 2;
      if(a[2].length) { a = a[2]; i = 0; }

   } else {                   // rotate([x,y,z],o)
      v = a[0];
      i = 1;
      if(a[1].length) { a = a[1]; i = 0; }
   }
   for(o=a[i++]; i<a.length; i++) { 
      o = o.union(a[i]);
   } 
   if(r!=1) {
      return o.mirroredX(v[0]*r).mirroredY(v[1]*r).mirroredZ(v[2]*r);
   } else {
      return o.mirroredX(v[0]).mirroredY(v[1]).mirroredZ(v[2]); 
   }
}

Notes:

  • AFAICT these mirrored{X,Y,Z} functions don't take a parameter like that, so the whole r calc doesn't apply
  • additionally, since those params don't matter, the code is always doing 3 mirrors
  • OpenSCAD mirror doesn't have 3 cases like what is described here. It has just a vec and objects

I believe the code should really be:

function mirror(v) { 
   var o = null,
       i = 0,
       a = arguments.slice(1, arguments.length - 1);
   for(o=a[i++]; i<a.length; i++) { 
      o = o.union(a[i]);
   }

   var plane = new CSG.Plane(new CSG.Vector3D(v[0], v[1], v[2]), 0);
   return o.mirrored(plane);
}

Which I'll PR over in a bit, once I've finished testing.

checkIfConvex for transformed polygon is failing

The next piece of code will fail with "Not convex" exception:

function main() {
   var points = [ 
            [ 1,  1, 0],
            [-1,  1, 0],
            [-1, -1, 0],
            [ 1, -1, 0]
    ]
   var p = CSG.Polygon.createFromPoints(points);
   var m = CSG.Matrix4x4.rotation([0,0,0], [-0.56, 0.83, 0.00], 110);

   p.transform(m).checkIfConvex();

   return cube([0,0,0], 2)
}

It looks that it is failing whenever the polygon's normal vector is changing it's sign relatively to the original plane. But I am not sure.

Params callback functions

Perhaps it's a good idea to allow callback functions or at least regexes to validate content passed through the parameters div input controls or for the ones passed by URL. This will prevent parse errors in many cases. Right now javascript errors are thrown, but it's better to allow people to define friendly messages, perhaps even things like "The wall thickness cannot be negative".

{
  name: 'shape',
  type: 'choice',
  values: ["TRI", "SQU", "CIR"],               // these are the values that will be supplied to your script
  captions: ["Triangle", "Square", "Circle"],  // optional, these values are shown in the listbox
                                               // if omitted, the items in the 'values' array are used
  caption: 'Shape:',                           // optional, displayed left of the input field
  initial: "SQU",                              // optional, default selected value
                                               // if omitted, the first item is selected by default
                                               // NOTE: parameter "default" is deprecated
  validate: shapeValidate
}

An example to clarify:

function validate(parameterDefinitions,paramName,paramValue){
if(paramValue == "circular") && parameterDefinitions['height'].value > 10)
  status("The "+paramValue+" shape can only be used when the height is more than 10.");
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.