Skip to content

Commit

Permalink
fix src
Browse files Browse the repository at this point in the history
  • Loading branch information
sritchie committed Apr 18, 2022
1 parent 19c80b3 commit 198273c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const π = Math.PI;
export const τ = π * 2;
export const e = Math.E;
export const Context = ctx;
export const version = ctx.version;
export const version = ctx.Version;
export const Model = model;
export const Overlay = overlay;
export const Primitives = primitives;
Expand Down
3 changes: 2 additions & 1 deletion src/primitives/types/data/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class Buffer extends Data {
make() {
super.make();

return (this.clockParent = this._inherit("latch"));
this.clockParent = this._inherit("clock");
this.latchParent = this._inherit("latch");
}

unmake() {
Expand Down
156 changes: 92 additions & 64 deletions src/primitives/types/operator/reverse.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,92 @@
// Operator = require './operator'
// Util = require '../../../util'

// class Reverse extends Operator
// @traits = ['node', 'bind', 'operator', 'source', 'index', 'reverse']

// getDimensions: () -> @bind.source.getDimensions()
// getActiveDimensions: () -> @bind.source.getActiveDimensions()
// getFutureDimensions: () -> @bind.source.getFutureDimensions()
// getIndexDimensions: () -> @bind.source.getIndexDimensions()

// sourceShader: (shader) ->
// shader.pipe 'reverse.position', @uniforms
// @bind.source.sourceShader shader

// _resolveScale: (key, dims) ->
// range = @props[key]
// dim = dims[key]
// if range then -1 else 1

// _resolveOffset: (key, dims) ->
// range = @props[key]
// dim = dims[key]
// if range then dim - 1 else 0

// make: () ->
// super
// return unless @bind.source?

// @uniforms =
// reverseScale: @_attributes.make @_types.vec4()
// reverseOffset: @_attributes.make @_types.vec4()

// unmake: () ->
// super

// resize: () ->
// return unless @bind.source?

// dims = @bind.source.getActiveDimensions()

// @uniforms.reverseScale.value.set(
// @_resolveScale('width', dims),
// @_resolveScale('height', dims),
// @_resolveScale('depth', dims),
// @_resolveScale('items', dims),
// )

// @uniforms.reverseOffset.value.set(
// @_resolveOffset('width', dims),
// @_resolveOffset('height', dims),
// @_resolveOffset('depth', dims),
// @_resolveOffset('items', dims),
// )

// super

// change: (changed, touched, init) ->
// return @rebuild() if touched['operator']

// if touched['reverse']
// @resize()

// module.exports = Reverse
import { Operator } from "./operator.js";

export class Reverse extends Operator {
static initClass() {
this.traits = ["node", "bind", "operator", "source", "index", "reverse"];
}

getDimensions() {
return this.bind.source.getDimensions();
}
getActiveDimensions() {
return this.bind.source.getActiveDimensions();
}
getFutureDimensions() {
return this.bind.source.getFutureDimensions();
}
getIndexDimensions() {
return this.bind.source.getIndexDimensions();
}

sourceShader(shader) {
shader.pipe("reverse.position", this.uniforms);
return this.bind.source.sourceShader(shader);
}

_resolveScale(key, dims) {
const range = this.props[key];
const dim = dims[key];
return range ? -1 : 1;
}

_resolveOffset(key, dims) {
const range = this.props[key];
const dim = dims[key];
if (range) {
return dim - 1;
} else {
return 0;
}
}

make() {
super.make(...arguments);
if (this.bind.source == null) {
return;
}

return (this.uniforms = {
reverseScale: this._attributes.make(this._types.vec4()),
reverseOffset: this._attributes.make(this._types.vec4()),
});
}

unmake() {
return super.unmake(...arguments);
}

resize() {
if (this.bind.source == null) {
return;
}

const dims = this.bind.source.getActiveDimensions();

this.uniforms.reverseScale.value.set(
this._resolveScale("width", dims),
this._resolveScale("height", dims),
this._resolveScale("depth", dims),
this._resolveScale("items", dims)
);

this.uniforms.reverseOffset.value.set(
this._resolveOffset("width", dims),
this._resolveOffset("height", dims),
this._resolveOffset("depth", dims),
this._resolveOffset("items", dims)
);

return super.resize(...arguments);
}

change(changed, touched, init) {
if (touched["operator"]) {
return this.rebuild();
}

if (touched["reverse"]) {
return this.resize();
}
}
}
Reverse.initClass();
4 changes: 4 additions & 0 deletions src/shaders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import repeatposition from "./glsl/repeat.position";
import resamplepadding from "./glsl/resample.padding";
import resamplerelative from "./glsl/resample.relative";
import revealmask from "./glsl/reveal.mask";
import reverseposition from "./glsl/reverse.position";
import rootposition from "./glsl/root.position";
import sample2d from "./glsl/sample.2d";
import scaleposition from "./glsl/scale.position";
Expand Down Expand Up @@ -104,6 +105,7 @@ import subdividewidthlerp from "./glsl/subdivide.width.lerp";
import surfacemaskhollow from "./glsl/surface.mask.hollow";
import surfaceposition from "./glsl/surface.position";
import surfacepositionnormal from "./glsl/surface.position.normal";
import surfacepositionshaded from "./glsl/surface.position.shaded";
import ticksposition from "./glsl/ticks.position";
import transform3position from "./glsl/transform3.position";
import transform4position from "./glsl/transform4.position";
Expand Down Expand Up @@ -185,6 +187,7 @@ export const Snippets = {
"resample.padding": resamplepadding,
"resample.relative": resamplerelative,
"reveal.mask": revealmask,
"reverse.position": reverseposition,
"root.position": rootposition,
"sample.2d": sample2d,
"scale.position": scaleposition,
Expand Down Expand Up @@ -216,6 +219,7 @@ export const Snippets = {
"surface.mask.hollow": surfacemaskhollow,
"surface.position": surfaceposition,
"surface.position.normal": surfacepositionnormal,
"surface.position.shaded": surfacepositionshaded,
"ticks.position": ticksposition,
"transform3.position": transform3position,
"transform4.position": transform4position,
Expand Down

0 comments on commit 198273c

Please sign in to comment.