Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
BlocksCAD
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
BlocksCAD
Commits
41119552
Commit
41119552
authored
Apr 05, 2016
by
Jennie Yoder
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'development' into pics_lightgl
parents
e931b028
b4c2e2d0
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
207 additions
and
15 deletions
+207
-15
blockly/blockly_compressed.js
blockly/blockly_compressed.js
+5
-4
blockly/blocks/primitives.js
blockly/blocks/primitives.js
+99
-0
blockly/blocks_compressed.js
blockly/blocks_compressed.js
+12
-8
blockly/generators/openscad/primitives.js
blockly/generators/openscad/primitives.js
+56
-0
blockly/openscad_compressed.js
blockly/openscad_compressed.js
+3
-0
blockscad/csg.js
blockscad/csg.js
+11
-1
blockscad/toolbox.js
blockscad/toolbox.js
+17
-0
examples/trefoil_knot_param_eq.xml
examples/trefoil_knot_param_eq.xml
+4
-2
No files found.
blockly/blockly_compressed.js
View file @
41119552
This diff is collapsed.
Click to expand it.
blockly/blocks/primitives.js
View file @
41119552
...
...
@@ -1166,6 +1166,105 @@ Blockly.Blocks['color'] = {
}
};
Blockly
.
Blocks
[
'
color_rgb
'
]
=
{
init
:
function
()
{
this
.
category
=
'
COLOR
'
;
this
.
setHelpUrl
(
'
http://www.example.com/
'
);
this
.
setColourHex
(
Blockscad
.
Toolbox
.
HEX_TRANSFORM
);
this
.
appendDummyInput
()
.
appendField
(
'
Color
'
);
var
dropdown
=
new
Blockly
.
FieldDropdown
([[
'
RGB
'
,
'
RGB
'
],
[
'
HSV
'
,
'
HSV
'
]],
function
(
option
)
{
var
isRGB
=
(
option
==
'
RGB
'
);
this
.
sourceBlock_
.
optUpdateShape_
(
isRGB
);
});
this
.
appendDummyInput
()
.
appendField
(
dropdown
,
'
SCHEME
'
)
.
setAlign
(
Blockly
.
ALIGN_RIGHT
);
this
.
appendValueInput
(
'
RED
'
)
.
setCheck
(
'
Number
'
)
.
appendField
(
'
red
'
,
'
1
'
)
.
setAlign
(
Blockly
.
ALIGN_RIGHT
);
this
.
appendValueInput
(
'
GREEN
'
)
.
setCheck
(
'
Number
'
)
.
appendField
(
'
green
'
,
'
2
'
)
.
setAlign
(
Blockly
.
ALIGN_RIGHT
);
this
.
appendValueInput
(
'
BLUE
'
)
.
setCheck
(
'
Number
'
)
.
appendField
(
'
blue
'
,
'
3
'
)
.
setAlign
(
Blockly
.
ALIGN_RIGHT
);
this
.
appendStatementInput
(
'
A
'
)
.
setCheck
(
'
CSG
'
);
this
.
setInputsInline
(
true
);
this
.
setPreviousStatement
(
true
,
'
CSG
'
);
this
.
setTooltip
(
'
Apply a color by specifying the red, blue, and green components. Each value should be between 0 and 100.
'
);
// try to set up a mutator - Jennie
this
.
setMutatorPlus
(
new
Blockly
.
MutatorPlus
(
this
));
this
.
plusCount_
=
0
;
this
.
optUpdateShape_
();
},
mutationToDom
:
function
()
{
if
(
!
this
.
plusCount_
)
{
return
null
;
}
var
container
=
document
.
createElement
(
'
mutation
'
);
if
(
this
.
plusCount_
)
{
container
.
setAttribute
(
'
plus
'
,
this
.
plusCount_
);
}
return
container
;
},
domToMutation
:
function
(
xmlElement
)
{
this
.
plusCount_
=
parseInt
(
xmlElement
.
getAttribute
(
'
plus
'
),
10
);
var
mytype
=
this
.
getInput
(
'
A
'
).
connection
.
check_
;
for
(
var
x
=
1
;
x
<=
this
.
plusCount_
;
x
++
)
{
this
.
appendStatementInput
(
'
PLUS
'
+
x
)
.
setCheck
(
mytype
);
}
if
(
this
.
plusCount_
>=
1
)
{
this
.
setMutatorMinus
(
new
Blockly
.
MutatorMinus
(
this
));
}
},
updateShape_
:
function
(
num
)
{
if
(
num
==
1
)
{
this
.
plusCount_
++
;
var
mytype
=
this
.
getInput
(
'
A
'
).
connection
.
check_
;
var
plusInput
=
this
.
appendStatementInput
(
'
PLUS
'
+
this
.
plusCount_
)
.
setCheck
(
mytype
);
}
else
if
(
num
==
-
1
)
{
this
.
removeInput
(
'
PLUS
'
+
this
.
plusCount_
);
this
.
plusCount_
--
;
}
if
(
this
.
plusCount_
>=
1
)
{
if
(
this
.
plusCount_
==
1
)
{
this
.
setMutatorMinus
(
new
Blockly
.
MutatorMinus
(
this
));
this
.
render
();
}
}
else
{
this
.
mutatorMinus
.
dispose
();
this
.
mutatorMinus
=
null
;
this
.
render
();
}
}
,
// if change the labels on the value inputs based on if this is RGB or HSV
optUpdateShape_
:
function
(
isRGB
)
{
// Add or remove a Value Input.
var
one
=
this
.
getField
(
'
1
'
);
var
two
=
this
.
getField
(
'
2
'
);
var
three
=
this
.
getField
(
'
3
'
);
if
(
isRGB
)
{
one
.
setText
(
'
red
'
);
two
.
setText
(
'
green
'
);
three
.
setText
(
'
blue
'
);
}
else
{
one
.
setText
(
'
hue
'
);
two
.
setText
(
'
saturation
'
);
three
.
setText
(
'
value
'
);
}
}
};
Blockly
.
Blocks
[
'
$fn
'
]
=
{
init
:
function
()
{
this
.
category
=
'
TRANSFORM
'
;
...
...
blockly/blocks_compressed.js
View file @
41119552
This diff is collapsed.
Click to expand it.
blockly/generators/openscad/primitives.js
View file @
41119552
...
...
@@ -228,6 +228,62 @@ Blockly.OpenSCAD['color'] = function(block) {
return
code
;
};
Blockly
.
OpenSCAD
[
'
color_rgb
'
]
=
function
(
block
)
{
var
statements_a
=
Blockly
.
OpenSCAD
.
statementToCode
(
block
,
'
A
'
);
var
scheme
=
block
.
getFieldValue
(
'
SCHEME
'
);
var
red
=
Blockly
.
OpenSCAD
.
valueToCode
(
block
,
'
RED
'
,
Blockly
.
OpenSCAD
.
ORDER_COMMA
)
||
0
;
var
green
=
Blockly
.
OpenSCAD
.
valueToCode
(
block
,
'
GREEN
'
,
Blockly
.
OpenSCAD
.
ORDER_COMMA
)
||
0
;
var
blue
=
Blockly
.
OpenSCAD
.
valueToCode
(
block
,
'
BLUE
'
,
Blockly
.
OpenSCAD
.
ORDER_COMMA
)
||
0
;
if
(
statements_a
!=
''
)
statements_a
+=
'
\n
'
;
for
(
var
n
=
0
;
n
<=
block
.
plusCount_
;
n
++
)
{
var
statements_b
=
Blockly
.
OpenSCAD
.
statementToCode
(
block
,
'
PLUS
'
+
n
);
if
(
statements_b
!=
''
)
statements_a
+=
statements_b
+
'
\n
'
;
}
var
code
=
''
;
if
(
$
.
isNumeric
(
red
))
{
if
(
red
<
0
)
red
=
0
;
if
(
red
>
100
)
red
=
100
;
}
if
(
$
.
isNumeric
(
blue
))
{
if
(
blue
<
0
)
blue
=
0
;
if
(
blue
>
100
)
blue
=
100
;
}
if
(
$
.
isNumeric
(
green
))
{
if
(
green
<
0
)
green
=
0
;
if
(
green
>
100
)
green
=
100
;
}
if
(
scheme
==
'
RGB
'
)
{
code
+=
'
color([ .01 * (
'
+
red
+
'
), .01 * (
'
+
green
+
'
), .01 * (
'
+
blue
+
'
)])
'
;
code
+=
'
{
\n
'
+
statements_a
+
'
}
'
;
}
// Thanks to Hypher for the implementation of hsv to rgb in openscad!
// http://forum.openscad.org/An-HSV-HSB-to-RGB-Color-function-in-OpenSCAD-td9835.html
else
if
(
scheme
==
'
HSV
'
)
{
var
hsvHelper
=
Blockly
.
OpenSCAD
.
provideFunction_
(
'
doHsvMatrix
'
,
[
'
function
'
+
Blockly
.
OpenSCAD
.
FUNCTION_NAME_PLACEHOLDER_
+
'
(h,s,v,p,q,t,a=1)=[h<1?v:h<2?q:h<3?p:h<4?p:h<5?t:v,h<1?t:h<2?v:h<3?v:h<4?q:h<5?p:p,h<1?p:h<2?p:h<3?t:h<4?v:h<5?v:q,a];
'
]);
var
hsvFunction
=
Blockly
.
OpenSCAD
.
provideFunction_
(
'
hsv
'
,
[
'
function
'
+
Blockly
.
OpenSCAD
.
FUNCTION_NAME_PLACEHOLDER_
+
'
(h, s=1, v=1,a=1)=doHsvMatrix((h%1)*6,s<0?0:s>1?1:s,v<0?0:v>1?1:v,v*(1-s),v*(1-s*((h%1)*6-floor((h%1)*6))),v*(1-s*(1-((h%1)*6-floor((h%1)*6)))),a);
'
]);
code
+=
'
color(hsv(.01 * (
'
+
red
+
'
), .01 * (
'
+
green
+
'
), .01 * (
'
+
blue
+
'
)))
'
;
code
+=
'
{
\n
'
+
statements_a
+
'
}
'
;
}
else
console
.
log
(
"
got weirdo color scheme?
"
);
return
code
;
};
Blockly
.
OpenSCAD
[
'
$fn
'
]
=
function
(
block
)
{
var
statements_a
=
Blockly
.
OpenSCAD
.
statementToCode
(
block
,
'
A
'
);
var
type
=
block
.
previousConnection
.
check_
[
0
];
...
...
blockly/openscad_compressed.js
View file @
41119552
...
...
@@ -79,6 +79,9 @@ d?"scale(["+b+", "+c+", "+e+"]){\n"+f+"}":"scale(["+b+", "+c+", 1]){\n"+f+"}"};
Blockly
.
OpenSCAD
.
translate
=
function
(
a
){
var
b
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
XVAL
"
,
Blockly
.
OpenSCAD
.
ORDER_ATOMIC
),
c
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
YVAL
"
,
Blockly
.
OpenSCAD
.
ORDER_ATOMIC
),
d
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
ZVAL
"
,
Blockly
.
OpenSCAD
.
ORDER_ATOMIC
),
e
=
a
.
previousConnection
.
check_
[
0
],
f
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
A
"
);
b
&&
c
&&
(
d
||
"
CSG
"
!=
e
)
||
Blockscad
.
missingFields
.
push
(
a
.
id
);
""
!=
f
&&
(
f
+=
"
\n
"
);
for
(
var
g
=
0
;
g
<=
a
.
plusCount_
;
g
++
){
var
h
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
PLUS
"
+
g
);
""
!=
h
&&
(
f
+=
h
+
"
\n
"
)}
return
"
CAG
"
!=
e
?
"
translate([
"
+
b
+
"
,
"
+
c
+
"
,
"
+
d
+
"
]){
\n
"
+
f
+
"
}
"
:
"
translate([
"
+
b
+
"
,
"
+
c
+
"
, 0]){
\n
"
+
f
+
"
}
"
};
Blockly
.
OpenSCAD
.
color
=
function
(
a
){
var
b
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
A
"
);
""
!=
b
&&
(
b
+=
"
\n
"
);
for
(
var
c
=
0
;
c
<=
a
.
plusCount_
;
c
++
){
var
d
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
PLUS
"
+
c
);
""
!=
d
&&
(
b
+=
d
+
"
\n
"
)}
c
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
COLOR
"
,
Blockly
.
OpenSCAD
.
ORDER_ATOMIC
);
!
c
&&
Blockscad
.
stackIsShape
(
a
)
&&
Blockscad
.
missingFields
.
push
(
a
.
id
);
a
=
""
;
if
(
c
){
var
d
=
hexToR
(
c
),
e
=
hexToG
(
c
),
c
=
hexToB
(
c
);
a
+=
"
color([
"
+
d
+
"
,
"
+
e
+
"
,
"
+
c
+
"
])
"
}
return
a
+
(
"
{
\n
"
+
b
+
"
}
"
)};
Blockly
.
OpenSCAD
.
color_rgb
=
function
(
a
){
var
b
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
A
"
),
c
=
a
.
getFieldValue
(
"
SCHEME
"
),
d
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
RED
"
,
Blockly
.
OpenSCAD
.
ORDER_COMMA
)
||
0
,
e
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
GREEN
"
,
Blockly
.
OpenSCAD
.
ORDER_COMMA
)
||
0
,
f
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
BLUE
"
,
Blockly
.
OpenSCAD
.
ORDER_COMMA
)
||
0
;
""
!=
b
&&
(
b
+=
"
\n
"
);
for
(
var
g
=
0
;
g
<=
a
.
plusCount_
;
g
++
){
var
h
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
PLUS
"
+
g
);
""
!=
h
&&
(
b
+=
h
+
"
\n
"
)}
a
=
""
;
$
.
isNumeric
(
d
)
&&
(
0
>
d
&&
(
d
=
0
),
100
<
d
&&
(
d
=
100
));
$
.
isNumeric
(
f
)
&&
(
0
>
f
&&
(
f
=
0
),
100
<
f
&&
(
f
=
100
));
$
.
isNumeric
(
e
)
&&
(
0
>
e
&&
(
e
=
0
),
100
<
e
&&
(
e
=
100
));
"
RGB
"
==
c
?
a
=
a
+
(
"
color([ .01 * (
"
+
d
+
"
), .01 * (
"
+
e
+
"
), .01 * (
"
+
f
+
"
)])
"
)
+
(
"
{
\n
"
+
b
+
"
}
"
):
"
HSV
"
==
c
?(
Blockly
.
OpenSCAD
.
provideFunction_
(
"
doHsvMatrix
"
,[
"
function
"
+
Blockly
.
OpenSCAD
.
FUNCTION_NAME_PLACEHOLDER_
+
"
(h,s,v,p,q,t,a=1)=[h<1?v:h<2?q:h<3?p:h<4?p:h<5?t:v,h<1?t:h<2?v:h<3?v:h<4?q:h<5?p:p,h<1?p:h<2?p:h<3?t:h<4?v:h<5?v:q,a];
"
]),
Blockly
.
OpenSCAD
.
provideFunction_
(
"
hsv
"
,[
"
function
"
+
Blockly
.
OpenSCAD
.
FUNCTION_NAME_PLACEHOLDER_
+
"
(h, s=1, v=1,a=1)=doHsvMatrix((h%1)*6,s<0?0:s>1?1:s,v<0?0:v>1?1:v,v*(1-s),v*(1-s*((h%1)*6-floor((h%1)*6))),v*(1-s*(1-((h%1)*6-floor((h%1)*6)))),a);
"
]),
a
+=
"
color(hsv(.01 * (
"
+
d
+
"
), .01 * (
"
+
e
+
"
), .01 * (
"
+
f
+
"
)))
"
,
a
+=
"
{
\n
"
+
b
+
"
}
"
):
console
.
log
(
"
got weirdo color scheme?
"
);
return
a
};
Blockly
.
OpenSCAD
.
$fn
=
function
(
a
){
var
b
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
A
"
);
""
!=
b
&&
(
b
+=
"
\n
"
);
for
(
var
c
=
0
;
c
<=
a
.
plusCount_
;
c
++
){
var
d
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
PLUS
"
+
c
);
""
!=
d
&&
(
b
+=
d
+
"
\n
"
)}
c
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
SIDES
"
,
Blockly
.
OpenSCAD
.
ORDER_ATOMIC
);
c
?
isNaN
(
c
)
||
(
c
=
Math
.
floor
(
c
),
3
>
c
&&
(
c
=
3
)):
Blockscad
.
missingFields
.
push
(
a
.
id
);
return
"
assign($fn=
"
+
c
+
"
){
\n
"
+
b
+
"
}
"
};
Blockly
.
OpenSCAD
.
fancymirror
=
function
(
a
){
var
b
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
XVAL
"
,
Blockly
.
OpenSCAD
.
ORDER_ATOMIC
),
c
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
YVAL
"
,
Blockly
.
OpenSCAD
.
ORDER_ATOMIC
),
d
=
Blockly
.
OpenSCAD
.
valueToCode
(
a
,
"
ZVAL
"
,
Blockly
.
OpenSCAD
.
ORDER_ATOMIC
),
e
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
A
"
);
""
!=
e
&&
(
e
+=
"
\n
"
);
for
(
var
f
=
0
;
f
<=
a
.
plusCount_
;
f
++
){
var
g
=
Blockly
.
OpenSCAD
.
statementToCode
(
a
,
"
PLUS
"
+
f
);
""
!=
g
&&
(
e
+=
g
+
"
\n
"
)}
b
&&
c
&&
d
||
Blockscad
.
missingFields
.
push
(
a
.
id
);
return
"
mirror([
"
+
b
+
"
,
"
+
c
+
"
,
"
+
d
+
"
]){
\n
"
+
e
+
"
}
"
};
...
...
blockscad/csg.js
View file @
41119552
...
...
@@ -400,6 +400,12 @@ for solid CAD anyway.
}
return
points
;
}
var
getColor
=
function
(
csgs
)
{
// get the color from the first polygon of the first shape.
var
color
=
csgs
[
0
].
polygons
[
0
].
shared
.
color
;
return
color
;
}
var
top_guy
=
this
;
var
other_csgs
=
csg
;
...
...
@@ -422,6 +428,8 @@ for solid CAD anyway.
var
points
=
getPoints
(
csgs
);
// console.log("points for hull are:",points);
var
color
=
getColor
(
csgs
);
var
qhull
=
new
CSG
.
quickHull3D
();
var
faces
=
qhull
.
build
(
points
);
...
...
@@ -439,7 +447,9 @@ for solid CAD anyway.
}
// console.log("points for polygons");
// console.log(pp);
polygons
.
push
(
new
CSG
.
Polygon
.
createFromPoints
(
pp
));
// var thispoly = new CSG.Polygon.createFromPoints(pp).setColor(color);
polygons
.
push
(
new
CSG
.
Polygon
.
createFromPoints
(
pp
).
setColor
(
color
));
}
// console.log("polygons");
// console.log(polygons);
...
...
blockscad/toolbox.js
View file @
41119552
...
...
@@ -273,6 +273,23 @@ Blockscad.Toolbox.catTransform = '<category name="Transforms">' +
'
</block>
'
+
'
</value>
'
+
'
</block>
'
+
'
<block type="color_rgb">
'
+
'
<value name="RED">
'
+
'
<block type="math_number">
'
+
'
<field name="NUM">100</field>
'
+
'
</block>
'
+
'
</value>
'
+
'
<value name="GREEN">
'
+
'
<block type="math_number">
'
+
'
<field name="NUM">100</field>
'
+
'
</block>
'
+
'
</value>
'
+
'
<value name="BLUE">
'
+
'
<block type="math_number">
'
+
'
<field name="NUM">100</field>
'
+
'
</block>
'
+
'
</value>
'
+
'
</block>
'
+
'
<block type="$fn">
'
+
'
<value name="SIDES">
'
+
'
<block type="math_number">
'
+
...
...
examples/trefoil_knot_param_eq.xml
View file @
41119552
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment