Skip to content

Commit 31b26cf

Browse files
committed
Fixed bug in cloning of objects, including cloning of compounds
1 parent eac9ada commit 31b26cf

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

lib/glow/primitives.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -470,35 +470,36 @@
470470
__show_start_face:this.__show_start_face, __show_end_face:this.__show_end_face,
471471
__start_face_color:this.__start_face_color, __end_face_color:this.__end_face_color,
472472
__descender:this.__descender, __shininess:this.__shininess, __emissive:this.__emissive,
473-
__pickable:this.__pickable}
473+
visible:true, __pickable:this.__pickable}
474474
var newtext = new text(newargs)
475475
for (var attr in args) newtext[attr] = args[attr] // apply the args attributes to the clone
476476
newtext.__update()
477477
return newtext
478478
} else if (this instanceof curve) {
479-
var newargs = {origin:this.__origin, pos:this.pos, color:this.__color, radius:this.__radius,
480-
size:this.__size, axis:this.__axis,
481-
shininess:this.__shininess, emissive:this.__emissive,
482-
visible:true, pickable:this.__pickable}
479+
var newargs = {__origin:this.__origin, __pos:this.pos, __color:this.__color,
480+
__radius:this.__radius, __size:this.__size, __axis:this.__axis,
481+
__shininess:this.__shininess, __emissive:this.__emissive,
482+
visible:true, __pickable:this.__pickable}
483483
} else if (this instanceof helix) {
484-
var newargs = {pos:this.pos, color:this.__color,
485-
thickness:this.__thickness, coils:this.__coils,
486-
size:this.__size, axis:this.__axis,
487-
shininess:this.__shininess, emissive:this.__emissive,
488-
visible:true, pickable:this.__pickable}
484+
var newargs = {__pos:this.pos, __color:this.__color,
485+
__thickness:this.__thickness, __coils:this.__coils,
486+
__size:this.__size, __axis:this.__axis,
487+
__shininess:this.__shininess, __emissive:this.__emissive,
488+
visible:true, __pickable:this.__pickable}
489489
} else {
490-
var newargs = {pos:this.__pos, color:this.__color, opacity:this.__opacity,
491-
size:this.__size, axis:this.__axis, __tex:this.__tex,
492-
shininess:this.__shininess, emissive:this.__emissive,
493-
visible:true, pickable:this.__pickable}
490+
var newargs = {__pos:this.__pos, __color:this.__color, __opacity:this.__opacity,
491+
__size:this.__size, __axis:this.__axis, __tex:this.__tex, __up:this.__up,
492+
__shininess:this.__shininess, __emissive:this.__emissive,
493+
visible:true, __pickable:this.__pickable}
494494
if (this instanceof arrow || this instanceof vp_arrow) {
495495
newargs.shaftwidth = this.__shaftwidth
496496
newargs.headwidth = this.__headwidth
497497
newargs.headlength = this.__headlength
498498
}
499499
}
500-
var ret = new this.constructor(newargs) // newargs does NOT contain newargs.up, to avoid up affecting axis in constructor
501-
for (var attr in args) ret[attr] = args[attr] // includes setting up
500+
// The newargs are in terms of __attr to avoid axis/up/size interconnections
501+
var ret = new this.constructor(newargs)
502+
for (var attr in args) ret[attr] = args[attr] // apply the args attributes to the clone
502503
return ret
503504
},
504505
__change: function() { if (this.__id) this.canvas.__changed[this.__id] = this },
@@ -547,12 +548,13 @@
547548
// But when rotating an object, we must break this linkage and rotate both axis and up in the same way.
548549
// The global variable window.__adjustupaxis is normally true, but here we set it temporarilty to false.
549550
// The object axis and up attributes in vectors.js check this global variable.
551+
// (Another way to deal with this would be to set __axis and __up, and then call __update.)
550552
window.__adjustupaxis = false // unlink axis and up temporarily
551553
if (diff_angle(obj.__axis,rotaxis) > 1e-6) {
552554
// change axis, which will also change up
553555
if (isarrow) obj.axis_and_length = obj.axis_and_length.rotate({angle:angle, axis:rotaxis})
554556
else obj.axis = obj.__axis.rotate({angle:angle, axis:rotaxis}) // maintain special character of VPython axis
555-
obj.up = obj.up.rotate({angle:angle, axis:rotaxis})
557+
obj.up = obj.__up.rotate({angle:angle, axis:rotaxis})
556558
} else {
557559
obj.up = obj.__up.rotate({angle:angle, axis:rotaxis})
558560
}
@@ -1441,15 +1443,17 @@
14411443
subclass(compound, box)
14421444
property.declare( compound.prototype, {
14431445
clone: function(args) { // cloning a compound object
1444-
var newargs = {pos:this.__pos, color:this.__color, opacity:this.__opacity,
1445-
size:this.__size, axis:this.__axis, up:this.__up,
1446-
shininess:this.__shininess, emissive:this.__emissive,
1447-
visible:true, pickable:this.__pickable,
1446+
var newargs = {__pos:this.__pos, __color:this.__color, __opacity:this.__opacity,
1447+
__size:this.__size, __axis:this.__axis, __up:this.__up,
1448+
__shininess:this.__shininess, __emissive:this.__emissive,
1449+
visible:true, __pickable:this.__pickable,
14481450
__center:this.__center, __pseudosize:this.__pseudosize}
14491451
if (this.texture.file !== null) newargs.texture = this.texture
1450-
for (var attr in args) newargs[attr] = args[attr]
1452+
// The newargs are in terms of __attr to avoid axis/up/size interconnections
14511453
newargs.__cloning = this.__mesh
1452-
return new this.constructor([], newargs)
1454+
var ret = new this.constructor([], newargs)
1455+
for (var attr in args) ret[attr] = args[attr] // apply the args attributes to the clone
1456+
return ret
14531457
},
14541458
_world_zaxis: function() {
14551459
return this.__axis.cross(this.__up).norm()

0 commit comments

Comments
 (0)