Skip to content

Commit 5721026

Browse files
committed
Cleanup and generalization of extrusion; also fixed bug in curve.origin
1 parent a529199 commit 5721026

File tree

5 files changed

+85
-7
lines changed

5 files changed

+85
-7
lines changed

docs/GlowScriptDocs/extrusion.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<p class="Normal">Currently a path must be closed. That is, the last point must be the same as the first point.</p>
7070
<p class="Normal"><strong>3)</strong> Create an extrusion object to extrude your shape along your path. For example, using paths and shapes defined above,</p>
7171
<p class="program">extrusion(pos=circpath, shape=rect) </p>
72+
<p class="Normal"><strong>Point positions are relative:</strong> A point whose pos is <span class="program">vector</span>(2, 1, 0) is of course normally displayed at location <span class="program">vector</span>(2, 1, 0). However, the position of a point is <em>relative</em> to an extrusion's own <span class="attribute">origin</span> value, which by default is <span class="program">vector</span>(0, 0, 0). If you change the extrusion's <span class="attribute">origin</span> value to <span class="program">vector</span>(10, 6, 5), the point is displayed at the location <span class="program">vector</span>(12, 7, 5); that is, the point is displayed 2 to the right, 6 above, and 0 in front of the extrusion's position <span class="program">vector</span>(10, 6, 5). Another way of saying this is that the display location is the vector sum, <span class="program">vector</span>(10, 6, 5) + <span class="program">vector</span>(2, 1, 0). This means that you can quickly and efficiently move the entire extrusion just by changing the extrusion's <span class="attribute">origin</span> value. The <span class="attribute">pos</span> value of an individual point does not change; it's just that the point is displayed in a shifted position. As a result, moving an entire extrusion is very fast.</p>
7273
<div>
7374
<div>
7475
<div>

docs/VPythonDocs/extrusion.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<p class="Normal">Currently a path must be closed. That is, the last point must be the same as the first point.</p>
7474
<p class="Normal"><strong>3)</strong> Create an extrusion object to extrude your shape along your path. For example, using paths and shapes defined above,</p>
7575
<p class="program">extrusion(pos=circpath, shape=rect)</p>
76+
<p class="Normal"><strong>Point positions are relative:</strong> A point whose pos is <span class="program">vector</span>(2, 1, 0) is of course normally displayed at location <span class="program">vector</span>(2, 1, 0). However, the position of a point is <em>relative</em> to an extrusion's own <span class="attribute">origin</span> value, which by default is <span class="program">vector</span>(0, 0, 0). If you change the extrusion's <span class="attribute">origin</span> value to <span class="program">vector</span>(10, 6, 5), the point is displayed at the location <span class="program">vector</span>(12, 7, 5); that is, the point is displayed 2 to the right, 6 above, and 0 in front of the extrusion's position <span class="program">vector</span>(10, 6, 5). Another way of saying this is that the display location is the vector sum, <span class="program">vector</span>(10, 6, 5) + <span class="program">vector</span>(2, 1, 0). This means that you can quickly and efficiently move the entire extrusion just by changing the extrusion's <span class="attribute">origin</span> value. The <span class="attribute">pos</span> value of an individual point does not change; it's just that the point is displayed in a shifted position. As a result, moving an entire extrusion is very fast.</p>
7677
<div>
7778
<div>
7879
<div>
@@ -84,7 +85,7 @@
8485
<p class="Normal">The paths in the paths library all go counterclockwise in the xz plane, as seen from above. That is, if starting from a position on the x axis, they head in the -z direction and bend toward the left. If your shape has something sticking out on the right, it will be on the outer side of the extrusion, whereas something sticking out on the left will be on the inner side of the extrusion.</p>
8586
<div>
8687
<div></div>
87-
</div>
88+
</div>
8889
<p class="Normal"><strong><font color="#0000a0">Dynamic change of attributes</font></strong> </p>
8990
<div>
9091
<div></div>

ide/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2>glowscript.org</h2>
6666
Here at glowscript.org, you can write and run GlowScript programs right in your browser, store them in the
6767
cloud for free, and easily share them with others.</p>
6868

69-
<p><b>New in GlowScript 1.1: Extrusion object now available in limited form.</b></p>
69+
<p><b>New in GlowScript 1.1: extrusion; private folders.</b></p>
7070
</div>
7171

7272
The Help explains which browsers support GlowScript and provides full documentation.

lib/glow/primitives.js

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
// We have to initialize ALL vector attributes here, because they need pointers back to "this" :-(
111111
if (args.pos === undefined) obj.pos = obj.pos
112112
if (args.color === undefined) obj.color = obj.color
113+
if (constructor == curve || constructor == extrusion) obj.origin = obj.origin
113114
if (constructor != points) {
114115
if (constructor == arrow) {
115116
if (args.axis !== undefined) throw new Error("arrow does not have axis; replace with axis_and_length")
@@ -1488,7 +1489,7 @@
14881489
*/
14891490
}
14901491

1491-
function extrusion(args) {
1492+
function make_extrusion(args) {
14921493
var center, pos, shapelist, col, up, opacity
14931494
pos = (args.pos === undefined) ? vec(0,0,0) : args.pos
14941495
if (args.shape === undefined) {
@@ -1610,6 +1611,79 @@
16101611
}
16111612
return compound(quads)
16121613
}
1614+
1615+
function extrusion(args) {return initObject(this, extrusion, args) }
1616+
subclass(extrusion, curve)
1617+
property.declare( extrusion.prototype, {
1618+
texture: {
1619+
get: function() {throw new Error("Textures are not available for extrusion objects.")},
1620+
set: function(val) {throw new Error("Textures are not available for extrusion objects.")}
1621+
},
1622+
radius: {
1623+
get: function() {throw new Error("An extrusion has no radius.")},
1624+
set: function(val) {throw new Error("An extrusion has no radius.")}
1625+
},
1626+
origin: new attributeVector(null, 0,0,0),
1627+
__initialize: true,
1628+
pos: {
1629+
get: function() {return this.__pos},
1630+
set: function(p) {
1631+
this.__pos = p
1632+
this.__change()
1633+
}
1634+
},
1635+
shape: {
1636+
get: function() {return this.__shape},
1637+
set: function(s) {
1638+
this.__shape = s
1639+
this.__change()
1640+
}
1641+
},
1642+
color: {
1643+
get: function() {return this.__color},
1644+
set: function(value) {
1645+
this.__color = value
1646+
this.__change()
1647+
}
1648+
},
1649+
opacity: {
1650+
get: function() { return this.__opacity },
1651+
set: function(value) {
1652+
if (value == this.__opacity) return
1653+
if ( (this.__opacity < 1 && value == 1) || (this.__opacity == 1 && value < 1) ) {
1654+
this.__opacity_change = true
1655+
}
1656+
this.__opacity = value
1657+
this.__change()
1658+
}
1659+
},
1660+
__get_extent: function (ext) {
1661+
if (this.__comp) this.__comp.__get_extent()
1662+
},
1663+
__update: function() {
1664+
if (!this.__initialize && (!this.__size.equals(this.__lastsize) ||
1665+
!this.__color.equals(this.__lastcolor) || this.__opacity !== this.__lastopacity)) {
1666+
this.__comp.visible = false
1667+
delete this.__comp // Do we need to delete this model from the list of models?
1668+
this.__initialize = true
1669+
}
1670+
1671+
if (this.__initialize) {
1672+
this.__comp = make_extrusion({pos:this.__pos, shape:this.__shape, color:this.__color, opacity:this.__opacity})
1673+
this.__lastsize = this.__size
1674+
this.__lastcolor = this.__color
1675+
this.__lastopacity = this.__opacity
1676+
this.__initialize = false
1677+
}
1678+
1679+
this.__comp.__pos = this.__origin
1680+
this.__comp.__axis = this.__axis
1681+
this.__comp.__up = this.__up
1682+
this.__comp.__opacity = this.__opacity
1683+
this.__comp.visible = this.visible
1684+
this.__comp.__update()
1685+
}
1686+
})
16131687

16141688
function ring(args) {return initObject(this, ring, args) }
16151689
subclass(ring, box)
@@ -1622,17 +1696,19 @@
16221696
__hasPosAtCenter: true,
16231697
__size: new attributeVector(null, 0.1, 1, 1), // exception to size (1,1,1)
16241698
__update: function() {
1625-
if (!this.__initialize && (!this.__size.equals(this.__lastsize) || !this.__color.equals(this.__lastcolor))) {
1699+
if (!this.__initialize && (!this.__size.equals(this.__lastsize) ||
1700+
!this.__color.equals(this.__lastcolor) || this.__opacity !== this.__lastopacity)) {
16261701
this.__comp.visible = false
16271702
delete this.__comp // Do we need to delete this model from the list of models?
16281703
this.__initialize = true
16291704
}
16301705

16311706
if (this.__initialize) {
1632-
this.__comp = extrusion( {pos:paths.circle({make_ring:true, radius:0.5*(this.__size.y-this.__size.x)}),
1707+
this.__comp = make_extrusion( {pos:paths.circle({make_ring:true, radius:0.5*(this.__size.y-this.__size.x)}),
16331708
shape:shapes.circle({radius:0.5*this.__size.x}), color:this.__color, opacity:this.__opacity} )
16341709
this.__lastsize = this.__size
16351710
this.__lastcolor = this.__color
1711+
this.__lastopacity = this.__opacity
16361712
this.__initialize = false
16371713
}
16381714

package/glow.1.1.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)