Skip to content

Commit 1b1768b

Browse files
authored
Merge pull request #22 from martinRenou/warp
Add Warp support
2 parents 3f6d7dd + af63d11 commit 1b1768b

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

ipygany/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
PolyMesh, TetraMesh, PointCloud,
99
Scene,
1010
Data, Component,
11-
Alpha, IsoColor, Threshold, IsoSurface
11+
Alpha, IsoColor, Threshold, IsoSurface, Warp
1212
)
1313
from ._version import __version__, version_info # noqa
1414

ipygany/ipygany.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,21 @@ def __init__(self, parent, **kwargs):
371371
super(Effect, self).__init__(parent=parent, **kwargs)
372372

373373

374+
class Warp(Effect):
375+
"""A warp effect to another block."""
376+
377+
_model_name = Unicode('WarpModel').tag(sync=True)
378+
379+
input = Union((Tuple(trait=Unicode, minlen=2, maxlen=2), Unicode(), CFloat(0.))).tag(sync=True)
380+
381+
offset = Union((Tuple(trait=Unicode, minlen=3, maxlen=3), CFloat(0.)), default_value=0.).tag(sync=True)
382+
factor = Union((Tuple(trait=Unicode, minlen=3, maxlen=3), CFloat(0.)), default_value=1.).tag(sync=True)
383+
384+
@default('input')
385+
def _default_input(self):
386+
return self.parent.data[0].name
387+
388+
374389
class Alpha(Effect):
375390
"""An transparency effect to another block."""
376391

src/widget.ts

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
Data, Component,
2424
Block, Effect,
2525
PolyMesh, TetraMesh, PointCloud,
26-
Alpha, IsoColor, IsoSurface, Threshold
26+
Warp, Alpha, IsoColor, IsoSurface, Threshold
2727
} from 'ganyjs';
2828

2929

@@ -347,6 +347,57 @@ abstract class EffectModel extends BlockModel {
347347
}
348348

349349

350+
export
351+
class WarpModel extends EffectModel {
352+
353+
defaults() {
354+
return {...super.defaults(),
355+
_model_name: WarpModel.model_name,
356+
};
357+
}
358+
359+
get input () {
360+
return this.get('input');
361+
}
362+
363+
get offset () : THREE.Vector3 {
364+
const offset = this.get('offset');
365+
366+
if (typeof offset == 'number') {
367+
return new THREE.Vector3(offset, offset, offset);
368+
} else {
369+
return new THREE.Vector3(offset[0], offset[1], offset[2]);
370+
}
371+
}
372+
373+
get factor () {
374+
const factor = this.get('factor');
375+
376+
if (typeof factor == 'number') {
377+
return new THREE.Vector3(factor, factor, factor);
378+
} else {
379+
return new THREE.Vector3(factor[0], factor[1], factor[2]);;
380+
}
381+
}
382+
383+
createBlock () {
384+
return new Warp(this.parent.block, this.input, this.factor, this.offset);
385+
}
386+
387+
initEventListeners () : void {
388+
super.initEventListeners();
389+
390+
this.on('change:factor', () => { this.block.factor = this.factor; });
391+
this.on('change:offset', () => { this.block.offset = this.offset; });
392+
}
393+
394+
block: Warp;
395+
396+
static model_name = 'WarpModel';
397+
398+
}
399+
400+
350401
export
351402
class AlphaModel extends EffectModel {
352403

@@ -405,8 +456,8 @@ class IsoColorModel extends EffectModel {
405456
initEventListeners () : void {
406457
super.initEventListeners();
407458

408-
this.on('change:min', () => { this.block.min = this.min });
409-
this.on('change:max', () => { this.block.max = this.max });
459+
this.on('change:min', () => { this.block.min = this.min; });
460+
this.on('change:max', () => { this.block.max = this.max; });
410461
}
411462

412463
block: IsoColor;

0 commit comments

Comments
 (0)