Skip to content

Commit

Permalink
Merge pull request #22 from martinRenou/warp
Browse files Browse the repository at this point in the history
Add Warp support
  • Loading branch information
martinRenou authored Dec 14, 2019
2 parents 3f6d7dd + af63d11 commit 1b1768b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ipygany/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PolyMesh, TetraMesh, PointCloud,
Scene,
Data, Component,
Alpha, IsoColor, Threshold, IsoSurface
Alpha, IsoColor, Threshold, IsoSurface, Warp
)
from ._version import __version__, version_info # noqa

Expand Down
15 changes: 15 additions & 0 deletions ipygany/ipygany.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,21 @@ def __init__(self, parent, **kwargs):
super(Effect, self).__init__(parent=parent, **kwargs)


class Warp(Effect):
"""A warp effect to another block."""

_model_name = Unicode('WarpModel').tag(sync=True)

input = Union((Tuple(trait=Unicode, minlen=2, maxlen=2), Unicode(), CFloat(0.))).tag(sync=True)

offset = Union((Tuple(trait=Unicode, minlen=3, maxlen=3), CFloat(0.)), default_value=0.).tag(sync=True)
factor = Union((Tuple(trait=Unicode, minlen=3, maxlen=3), CFloat(0.)), default_value=1.).tag(sync=True)

@default('input')
def _default_input(self):
return self.parent.data[0].name


class Alpha(Effect):
"""An transparency effect to another block."""

Expand Down
57 changes: 54 additions & 3 deletions src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
Data, Component,
Block, Effect,
PolyMesh, TetraMesh, PointCloud,
Alpha, IsoColor, IsoSurface, Threshold
Warp, Alpha, IsoColor, IsoSurface, Threshold
} from 'ganyjs';


Expand Down Expand Up @@ -347,6 +347,57 @@ abstract class EffectModel extends BlockModel {
}


export
class WarpModel extends EffectModel {

defaults() {
return {...super.defaults(),
_model_name: WarpModel.model_name,
};
}

get input () {
return this.get('input');
}

get offset () : THREE.Vector3 {
const offset = this.get('offset');

if (typeof offset == 'number') {
return new THREE.Vector3(offset, offset, offset);
} else {
return new THREE.Vector3(offset[0], offset[1], offset[2]);
}
}

get factor () {
const factor = this.get('factor');

if (typeof factor == 'number') {
return new THREE.Vector3(factor, factor, factor);
} else {
return new THREE.Vector3(factor[0], factor[1], factor[2]);;
}
}

createBlock () {
return new Warp(this.parent.block, this.input, this.factor, this.offset);
}

initEventListeners () : void {
super.initEventListeners();

this.on('change:factor', () => { this.block.factor = this.factor; });
this.on('change:offset', () => { this.block.offset = this.offset; });
}

block: Warp;

static model_name = 'WarpModel';

}


export
class AlphaModel extends EffectModel {

Expand Down Expand Up @@ -405,8 +456,8 @@ class IsoColorModel extends EffectModel {
initEventListeners () : void {
super.initEventListeners();

this.on('change:min', () => { this.block.min = this.min });
this.on('change:max', () => { this.block.max = this.max });
this.on('change:min', () => { this.block.min = this.min; });
this.on('change:max', () => { this.block.max = this.max; });
}

block: IsoColor;
Expand Down

0 comments on commit 1b1768b

Please sign in to comment.