|
110 | 110 | // We have to initialize ALL vector attributes here, because they need pointers back to "this" :-(
|
111 | 111 | if (args.pos === undefined) obj.pos = obj.pos
|
112 | 112 | if (args.color === undefined) obj.color = obj.color
|
| 113 | + if (constructor == curve || constructor == extrusion) obj.origin = obj.origin |
113 | 114 | if (constructor != points) {
|
114 | 115 | if (constructor == arrow) {
|
115 | 116 | if (args.axis !== undefined) throw new Error("arrow does not have axis; replace with axis_and_length")
|
|
1488 | 1489 | */
|
1489 | 1490 | }
|
1490 | 1491 |
|
1491 |
| - function extrusion(args) { |
| 1492 | + function make_extrusion(args) { |
1492 | 1493 | var center, pos, shapelist, col, up, opacity
|
1493 | 1494 | pos = (args.pos === undefined) ? vec(0,0,0) : args.pos
|
1494 | 1495 | if (args.shape === undefined) {
|
|
1610 | 1611 | }
|
1611 | 1612 | return compound(quads)
|
1612 | 1613 | }
|
| 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 | + }) |
1613 | 1687 |
|
1614 | 1688 | function ring(args) {return initObject(this, ring, args) }
|
1615 | 1689 | subclass(ring, box)
|
|
1622 | 1696 | __hasPosAtCenter: true,
|
1623 | 1697 | __size: new attributeVector(null, 0.1, 1, 1), // exception to size (1,1,1)
|
1624 | 1698 | __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)) { |
1626 | 1701 | this.__comp.visible = false
|
1627 | 1702 | delete this.__comp // Do we need to delete this model from the list of models?
|
1628 | 1703 | this.__initialize = true
|
1629 | 1704 | }
|
1630 | 1705 |
|
1631 | 1706 | 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)}), |
1633 | 1708 | shape:shapes.circle({radius:0.5*this.__size.x}), color:this.__color, opacity:this.__opacity} )
|
1634 | 1709 | this.__lastsize = this.__size
|
1635 | 1710 | this.__lastcolor = this.__color
|
| 1711 | + this.__lastopacity = this.__opacity |
1636 | 1712 | this.__initialize = false
|
1637 | 1713 | }
|
1638 | 1714 |
|
|
0 commit comments