csg: size instead radius possible. openjscad,simple.html: use <base>

This commit is contained in:
Denis Knauf 2012-03-19 23:24:29 +01:00
parent a91c07c68d
commit 5a6b976506
3 changed files with 36 additions and 15 deletions

6
csg.js
View file

@ -1017,7 +1017,8 @@ CSG.parseOptionAsBool = function(options, optionname, defaultvalue) {
// }); // });
CSG.cube = function(options) { CSG.cube = function(options) {
var c = CSG.parseOptionAs3DVector(options, "center", [0,0,0]); var c = CSG.parseOptionAs3DVector(options, "center", [0,0,0]);
var r = CSG.parseOptionAs3DVector(options, "radius", [1,1,1]); var s = CSG.parseOptionAs3DVector(options, "size", [2,2,2]);
var r = CSG.parseOptionAs3DVector(options, "radius", [s.x/2,s.y/2,s.z/2]);
var result = CSG.fromPolygons([ var result = CSG.fromPolygons([
[[0, 4, 6, 2], [-1, 0, 0]], [[0, 4, 6, 2], [-1, 0, 0]],
[[1, 3, 7, 5], [+1, 0, 0]], [[1, 3, 7, 5], [+1, 0, 0]],
@ -1307,7 +1308,8 @@ CSG.roundedCylinder = function(options) {
// }); // });
CSG.roundedCube = function(options) { CSG.roundedCube = function(options) {
var center = CSG.parseOptionAs3DVector(options, "center", [0,0,0]); var center = CSG.parseOptionAs3DVector(options, "center", [0,0,0]);
var cuberadius = CSG.parseOptionAs3DVector(options, "radius", [1,1,1]); var cubesize = CSG.parseOptionAs3DVector(options, "size", [2,2,2]);
var cuberadius = CSG.parseOptionAs3DVector(options, "radius", [cubesize.x/2,cubesize.y/2,cubesize.z/2]);
var resolution = CSG.parseOptionAsFloat(options, "resolution", 8); var resolution = CSG.parseOptionAsFloat(options, "resolution", 8);
if(resolution < 4) resolution = 4; if(resolution < 4) resolution = 4;
var roundradius = CSG.parseOptionAsFloat(options, "roundradius", 0.2); var roundradius = CSG.parseOptionAsFloat(options, "roundradius", 0.2);

View file

@ -320,10 +320,16 @@ OpenJsCad.javaScriptToSolidSync = function(script, mainParameters, debugging) {
// callback: should be function(error, csg) // callback: should be function(error, csg)
OpenJsCad.javaScriptToSolidASync = function(script, mainParameters, callback) { OpenJsCad.javaScriptToSolidASync = function(script, mainParameters, callback) {
var baselibraries = [ var baselibraries = [
"../csg.js", "csg.js",
"../openjscad.js" "openjscad.js"
]; ];
var baseurl = document.location + ""; var baseurl = document.location + '';
var base = document.getElementsByTagName('base');
if( base) {
base = base.getAttribute('href');
if( base)
baseurl = OpenJsCad.makeAbsoluteUrl(baseurl, base);
}
var workerscript = ""; var workerscript = "";
workerscript += script; workerscript += script;
workerscript += "\n\n\n\n//// The following code is added by OpenJsCad:\n"; workerscript += "\n\n\n\n//// The following code is added by OpenJsCad:\n";

View file

@ -1,12 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<script src="../lightgl.js"></script> <base href="../" />
<script src="../csg.js"></script> <script src="lightgl.js"></script>
<script src="../openjscad.js"></script> <script src="csg.js"></script>
<script src="../jquery.js"></script> <script src="openjscad.js"></script>
<script src="../coffee-script.js"></script> <script src="jquery.js"></script>
<script src="../Math.uuid.js"></script> <script src="coffee-script.js"></script>
<script src="Math.uuid.js"></script>
<style> <style>
body { body {
font: 14px/20px 'Helvetica Neue Light', HelveticaNeue-Light, 'Helvetica Neue', Helvetica, Arial, sans-serif; font: 14px/20px 'Helvetica Neue Light', HelveticaNeue-Light, 'Helvetica Neue', Helvetica, Arial, sans-serif;
@ -20,6 +21,10 @@
margin: 0; margin: 0;
color: #555; color: #555;
} }
body > * {
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
pre { pre {
padding: 10px; padding: 10px;
width: 100%; width: 100%;
@ -48,8 +53,14 @@
margin: 2em 0 0 0; margin: 2em 0 0 0;
padding: 0; padding: 0;
} }
#viewer > .statusdiv + div {
overflow: auto;
box-sizing: border-box;
-webkit-box-sizing: border-box;
width: 800px;
}
</style> </style>
<link rel="stylesheet" href="../openjscad.css" type="text/css"> <link rel="stylesheet" href="openjscad.css" type="text/css">
<script type="text/coffeescript"> <script type="text/coffeescript">
window.DelayedCall = (fun, delay = 250) -> window.DelayedCall = (fun, delay = 250) ->
self = (args...) -> self = (args...) ->
@ -111,8 +122,10 @@
currentFilename: -> /\/([^\/]*?)$/.exec(window.location.pathname)[1] currentFilename: -> /\/([^\/]*?)$/.exec(window.location.pathname)[1]
loadFile: (fn) -> loadFile: (fn) ->
rev = localStorage[fn] if rev = localStorage[fn]
JSON.parse localStorage[rev] JSON.parse localStorage[rev]
else
[fn, null, 'CoffeeScript', "main = ->\n\tCSG.cube radius: 1"]
writeFile: (fn, lang, code) -> writeFile: (fn, lang, code) ->
rev = Math.uuid() rev = Math.uuid()