code
stringlengths
0
56.1M
repo_name
stringlengths
3
57
path
stringlengths
2
176
language
stringclasses
672 values
license
stringclasses
8 values
size
int64
0
56.8M
export class Matrix extends Buffer { buffer: any; spec: { channels: any; items: any; width: any; height: any; } | null | undefined; space: { width: number; height: number; history: number; } | undefined; used: { width: number; height: number; } | undefined; storage: string | undefined; passthrough: ((emit: any, x: any, y: any) => any) | undefined; getDimensions(): { items: any; width: number; height: number; depth: number; }; getActiveDimensions(): { items: any; width: number; height: number; depth: any; }; getFutureDimensions(): { items: any; width: number; height: number; depth: number; }; getRawDimensions(): { items: any; width: number; height: number; depth: number; }; items: any; channels: any; unmake(): null | undefined; change(changed: any, touched: any, init: any): any; update(): any; } import { Buffer } from "./buffer.js";
cchudzicki/mathbox
build/esm/primitives/types/data/matrix.d.ts
TypeScript
mit
1,132
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UData from "../../../util/data.js"; import { Buffer } from "./buffer.js"; export class Matrix extends Buffer { static initClass() { this.traits = [ "node", "buffer", "active", "data", "source", "index", "texture", "matrix", "raw", ]; } init() { this.buffer = this.spec = null; this.space = { width: 0, height: 0, history: 0, }; this.used = { width: 0, height: 0, }; this.storage = "matrixBuffer"; this.passthrough = (emit, x, y) => emit(x, y, 0, 0); return super.init(); } sourceShader(shader) { const dims = this.getDimensions(); this.alignShader(dims, shader); return this.buffer.shader(shader); } getDimensions() { return { items: this.items, width: this.space.width, height: this.space.height, depth: this.space.history, }; } getActiveDimensions() { return { items: this.items, width: this.used.width, height: this.used.height, depth: this.buffer.getFilled(), }; } getFutureDimensions() { return { items: this.items, width: this.used.width, height: this.used.height, depth: this.space.history, }; } getRawDimensions() { return { items: this.items, width: this.space.width, height: this.space.height, depth: 1, }; } make() { super.make(); // Read sampling parameters const minFilter = this.minFilter != null ? this.minFilter : this.props.minFilter; const magFilter = this.magFilter != null ? this.magFilter : this.props.magFilter; const type = this.type != null ? this.type : this.props.type; // Read given dimensions const { width } = this.props; const { height } = this.props; const { history } = this.props; const reserveX = this.props.bufferWidth; const reserveY = this.props.bufferHeight; const { channels } = this.props; const { items } = this.props; let dims = (this.spec = { channels, items, width, height }); this.items = dims.items; this.channels = dims.channels; // Init to right size if data supplied const { data } = this.props; dims = UData.getDimensions(data, dims); const { space } = this; space.width = Math.max(reserveX, dims.width || 1); space.height = Math.max(reserveY, dims.height || 1); space.history = history; // Create matrix buffer return (this.buffer = this._renderables.make(this.storage, { width: space.width, height: space.height, history: space.history, channels, items, minFilter, magFilter, type, })); } unmake() { super.unmake(); if (this.buffer) { this.buffer.dispose(); return (this.buffer = this.spec = null); } } change(changed, touched, init) { if (touched["texture"] || changed["matrix.history"] || changed["buffer.channels"] || changed["buffer.items"] || changed["matrix.bufferWidth"] || changed["matrix.bufferHeight"]) { return this.rebuild(); } if (!this.buffer) { return; } if (changed["matrix.width"]) { const { width } = this.props; if (width > this.space.width) { return this.rebuild(); } } if (changed["matrix.height"]) { const { height } = this.props; if (height > this.space.height) { return this.rebuild(); } } if (changed["data.map"] || changed["data.data"] || changed["data.resolve"] || changed["data.expr"] || init) { return this.buffer.setCallback(this.emitter()); } } callback(callback) { if (callback.length <= 3) { return callback; } else { return (emit, i, j) => { return callback(emit, i, j, this.bufferClock, this.bufferStep); }; } } update() { if (!this.buffer) { return; } const { data } = this.props; const { space, used } = this; const w = used.width; const h = used.height; const filled = this.buffer.getFilled(); this.syncBuffer((abort) => { if (data != null) { const dims = UData.getDimensions(data, this.spec); // Grow if needed if (dims.width > space.width || dims.height > space.height) { abort(); return this.rebuild(); } used.width = dims.width; used.height = dims.height; this.buffer.setActive(used.width, used.height); if (typeof this.buffer.callback.rebind === "function") { this.buffer.callback.rebind(data); } return this.buffer.update(); } else { let _w; const width = this.spec.width || 1; const height = this.spec.height || 1; this.buffer.setActive(width, height); const length = this.buffer.update(); used.width = _w = width; used.height = Math.ceil(length / _w); if (used.height === 1) { return (used.width = length); } } }); if (used.width !== w || used.height !== h || filled !== this.buffer.getFilled()) { return this.trigger({ type: "source.resize", }); } } } Matrix.initClass();
cchudzicki/mathbox
build/esm/primitives/types/data/matrix.js
JavaScript
mit
6,682
export class Resolve extends Data { buffer: any; spec: { channels: number; items: number; width: any; height: any; depth: any; } | null | undefined; space: { width: number; height: number; depth: number; } | undefined; used: { width: number; height: number; depth: number; } | undefined; getDimensions(): { items: any; width: number; height: number; depth: number; }; getActiveDimensions(): { items: any; width: number; height: number; depth: number; }; callback(): void; emitter(): any; change(changed: any, touched: any, init: any): any; update(): any; filled: boolean | undefined; } import { Data } from "./data.js";
cchudzicki/mathbox
build/esm/primitives/types/data/resolve.d.ts
TypeScript
mit
836
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UData from "../../../util/data.js"; import { Data } from "./data.js"; export class Resolve extends Data { static initClass() { this.traits = ["node", "data", "active", "source", "index", "voxel"]; } init() { this.buffer = this.spec = null; this.space = { width: 0, height: 0, depth: 0, }; this.used = { width: 0, height: 0, depth: 0, }; return super.init(); } sourceShader(shader) { return this.buffer.shader(shader); } getDimensions() { const { space } = this; return { items: this.items, width: space.width, height: space.height, depth: space.depth, }; } getActiveDimensions() { const { used } = this; return { items: this.items, width: used.width, height: used.height, depth: used.depth * this.buffer.getFilled(), }; } make() { super.make(); // Read given dimensions const { width } = this.props; const { height } = this.props; const { depth } = this.props; const reserveX = this.props.bufferWidth; const reserveY = this.props.bufferHeight; const reserveZ = this.props.bufferDepth; let dims = (this.spec = { channels: 1, items: 1, width, height, depth }); // Init to right size if data supplied const { data } = this.props; dims = UData.getDimensions(data, dims); const { space } = this; space.width = Math.max(reserveX, dims.width || 1); space.height = Math.max(reserveY, dims.height || 1); space.depth = Math.max(reserveZ, dims.depth || 1); if (this.spec.width == null) { this.spec.width = 1; } if (this.spec.height == null) { this.spec.height = 1; } if (this.spec.depth == null) { this.spec.depth = 1; } // Create voxel buffer to hold item state // (enter, exit) return (this.buffer = this._renderables.make("voxelBuffer", { width: space.width, height: space.height, depth: space.depth, channels: 2, items: 1, })); } // Decorate emit callback for a bound source callback() { } // emitter() { return super.emitter(1, 1); } change(changed, touched, init) { super.change(); if (!this.buffer) { return; } if (changed["voxel.width"]) { const { width } = this.props; if (width > this.space.width) { return this.rebuild(); } } if (changed["voxel.height"]) { const { height } = this.props; if (height > this.space.height) { return this.rebuild(); } } if (changed["voxel.depth"]) { const { depth } = this.props; if (depth > this.space.depth) { return this.rebuild(); } } if (changed["data.map"] || changed["data.data"] || changed["data.resolve"] || init) { return this.buffer.setCallback(this.emitter()); } } update() { let length; if (!this.buffer) { return; } const filled = this.buffer.getFilled(); if (!!filled && !this.props.live) { return; } const { data } = this.props; const { space } = this; const { used } = this; const l = used.length; if (data != null) { const dims = UData.getDimensions(data, this.spec); // Grow length if needed if (dims.width > space.length) { this.rebuild(); } used.length = dims.width; this.buffer.setActive(used.length); this.buffer.callback.rebind(data); this.buffer.update(); } else { this.buffer.setActive(this.spec.width); length = this.buffer.update(); used.length = length; } this.filled = true; if (used.length !== l || filled !== this.buffer.getFilled()) { return this.trigger({ type: "source.resize", }); } } } Resolve.initClass();
cchudzicki/mathbox
build/esm/primitives/types/data/resolve.js
JavaScript
mit
4,928
export class Scale extends Source { init(): null; used: any; space: any; scaleAxis: any; sampler: any; rawBuffer(): any; getDimensions(): { items: number; width: any; height: number; depth: number; }; getActiveDimensions(): { items: number; width: any; height: any; depth: number; }; getRawDimensions(): { items: number; width: any; height: number; depth: number; }; make(): any; buffer: any; scaleOffset: any; unmake(): any; change(changed: any, touched: any, init: any): any; updateRanges(): any; } import { Source } from "../base/source.js";
cchudzicki/mathbox
build/esm/primitives/types/data/scale.d.ts
TypeScript
mit
713
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UAxis from "../../../util/axis.js"; import { Source } from "../base/source.js"; export class Scale extends Source { static initClass() { this.traits = [ "node", "source", "index", "interval", "span", "scale", "raw", "origin", ]; } init() { return (this.used = this.space = this.scaleAxis = this.sampler = null); } rawBuffer() { return this.buffer; } sourceShader(shader) { return shader.pipe(this.sampler); } getDimensions() { return { items: 1, width: this.space, height: 1, depth: 1, }; } getActiveDimensions() { return { items: 1, width: this.used, height: this.buffer.getFilled(), depth: 1, }; } getRawDimensions() { return this.getDimensions(); } make() { // Prepare data buffer of tick positions let samples; this.space = samples = this._helpers.scale.divide(""); this.buffer = this._renderables.make("dataBuffer", { width: samples, channels: 1, items: 1, }); // Prepare position shader const positionUniforms = { scaleAxis: this._attributes.make(this._types.vec4()), scaleOffset: this._attributes.make(this._types.vec4()), }; this.scaleAxis = positionUniforms.scaleAxis.value; this.scaleOffset = positionUniforms.scaleOffset.value; // Build sampler const p = (this.sampler = this._shaders.shader()); // Require buffer sampler as callback p.require(this.buffer.shader(this._shaders.shader(), 1)); // Shader to expand scalars to 4D vector on an axis. p.pipe("scale.position", positionUniforms); this._helpers.span.make(); // Monitor view range return this._listen(this, "span.range", this.updateRanges); } unmake() { this.scaleAxis = null; return this._helpers.span.unmake(); } change(changed, touched, init) { if (changed["scale.divide"]) { return this.rebuild(); } if (touched["view"] || touched["interval"] || touched["span"] || touched["scale"] || init) { return this.updateRanges(); } } updateRanges() { const { used } = this; // Fetch range along axis const { axis, origin } = this.props; const range = this._helpers.span.get("", axis); // Calculate scale along axis const min = range.x; const max = range.y; const ticks = this._helpers.scale.generate("", this.buffer, min, max); UAxis.setDimension(this.scaleAxis, axis); UAxis.setOrigin(this.scaleOffset, axis, origin); // Clip to number of ticks this.used = ticks.length; // Notify of resize if (this.used !== used) { return this.trigger({ type: "source.resize", }); } } } Scale.initClass();
cchudzicki/mathbox
build/esm/primitives/types/data/scale.js
JavaScript
mit
3,581
export class Volume extends Voxel { updateSpan(): any; aX: any; aY: any; aZ: any; bX: number | undefined; bY: number | undefined; bZ: number | undefined; callback(callback: any): ((emit: any, i: any, j: any, k: any) => any) | undefined; last: any; _callback: ((emit: any, i: any, j: any, k: any) => any) | undefined; unmake(): any; } import { Voxel } from "./voxel.js";
cchudzicki/mathbox
build/esm/primitives/types/data/volume.d.ts
TypeScript
mit
414
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Voxel } from "./voxel.js"; export class Volume extends Voxel { static initClass() { this.traits = [ "node", "buffer", "active", "data", "source", "index", "texture", "voxel", "span:x", "span:y", "span:z", "volume", "sampler:x", "sampler:y", "sampler:z", "raw", ]; } updateSpan() { let inverseX, inverseY, inverseZ; const dimensions = this.props.axes; let { width } = this.props; let { height } = this.props; let { depth } = this.props; const { centeredX } = this.props; const { centeredY } = this.props; const { centeredZ } = this.props; const padX = this.props.paddingX; const padY = this.props.paddingY; const padZ = this.props.paddingZ; const rangeX = this._helpers.span.get("x.", dimensions[0]); const rangeY = this._helpers.span.get("y.", dimensions[1]); const rangeZ = this._helpers.span.get("z.", dimensions[2]); this.aX = rangeX.x; this.aY = rangeY.x; this.aZ = rangeZ.x; const spanX = rangeX.y - rangeX.x; const spanY = rangeY.y - rangeY.x; const spanZ = rangeZ.y - rangeZ.x; width += padX * 2; height += padY * 2; depth += padZ * 2; if (centeredX) { inverseX = 1 / Math.max(1, width); this.aX += (spanX * inverseX) / 2; } else { inverseX = 1 / Math.max(1, width - 1); } if (centeredY) { inverseY = 1 / Math.max(1, height); this.aY += (spanY * inverseY) / 2; } else { inverseY = 1 / Math.max(1, height - 1); } if (centeredZ) { inverseZ = 1 / Math.max(1, depth); this.aZ += (spanZ * inverseZ) / 2; } else { inverseZ = 1 / Math.max(1, depth - 1); } this.bX = spanX * inverseX; this.bY = spanY * inverseY; this.bZ = spanZ * inverseZ; this.aX += this.bX * padX; this.aY += this.bY * padY; return (this.aZ += this.bZ * padY); } callback(callback) { this.updateSpan(); if (this.last === callback) { return this._callback; } this.last = callback; if (callback.length <= 7) { return (this._callback = (emit, i, j, k) => { const x = this.aX + this.bX * i; const y = this.aY + this.bY * j; const z = this.aZ + this.bZ * k; return callback(emit, x, y, z, i, j, k); }); } else { return (this._callback = (emit, i, j, k) => { const x = this.aX + this.bX * i; const y = this.aY + this.bY * j; const z = this.aZ + this.bZ * k; return callback(emit, x, y, z, i, j, k, this.bufferClock, this.bufferStep); }); } } make() { super.make(); this._helpers.span.make(); return this._listen(this, "span.range", this.updateSpan); } unmake() { super.unmake(); return this._helpers.span.unmake(); } } Volume.initClass();
cchudzicki/mathbox
build/esm/primitives/types/data/volume.js
JavaScript
mit
3,749
export class Voxel extends Buffer { constructor(...args: any[]); update(): any; buffer: any; spec: { channels: any; items: any; width: any; height: any; depth: any; } | null | undefined; space: { width: number; height: number; depth: number; } | undefined; used: { width: number; height: number; depth: number; } | undefined; storage: string | undefined; passthrough: ((emit: any, x: any, y: any, z: any) => any) | undefined; getDimensions(): { items: any; width: number; height: number; depth: number; }; getActiveDimensions(): { items: any; width: number; height: number; depth: number; }; getRawDimensions(): { items: any; width: number; height: number; depth: number; }; items: any; channels: any; unmake(): null | undefined; change(changed: any, touched: any, init: any): any; } import { Buffer } from "./buffer.js";
cchudzicki/mathbox
build/esm/primitives/types/data/voxel.d.ts
TypeScript
mit
1,090
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS002: Fix invalid constructor * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UData from "../../../util/data.js"; import { Buffer } from "./buffer.js"; export class Voxel extends Buffer { constructor(...args) { super(...args); this.update = this.update.bind(this); } static initClass() { this.traits = [ "node", "buffer", "active", "data", "source", "index", "texture", "voxel", "raw", ]; } init() { this.buffer = this.spec = null; this.space = { width: 0, height: 0, depth: 0, }; this.used = { width: 0, height: 0, depth: 0, }; this.storage = "voxelBuffer"; this.passthrough = (emit, x, y, z) => emit(x, y, z, 0); super.init(); } sourceShader(shader) { const dims = this.getDimensions(); this.alignShader(dims, shader); return this.buffer.shader(shader); } getDimensions() { return { items: this.items, width: this.space.width, height: this.space.height, depth: this.space.depth, }; } getActiveDimensions() { return { items: this.items, width: this.used.width, height: this.used.height, depth: this.used.depth * this.buffer.getFilled(), }; } getRawDimensions() { return this.getDimensions(); } make() { super.make(); // Read sampling parameters const minFilter = this.minFilter != null ? this.minFilter : this.props.minFilter; const magFilter = this.magFilter != null ? this.magFilter : this.props.magFilter; const type = this.type != null ? this.type : this.props.type; // Read given dimensions const { width } = this.props; const { height } = this.props; const { depth } = this.props; const reserveX = this.props.bufferWidth; const reserveY = this.props.bufferHeight; const reserveZ = this.props.bufferDepth; const { channels } = this.props; const { items } = this.props; let dims = (this.spec = { channels, items, width, height, depth }); this.items = dims.items; this.channels = dims.channels; // Init to right size if data supplied const { data } = this.props; dims = UData.getDimensions(data, dims); const { space } = this; space.width = Math.max(reserveX, dims.width || 1); space.height = Math.max(reserveY, dims.height || 1); space.depth = Math.max(reserveZ, dims.depth || 1); // Create voxel buffer return (this.buffer = this._renderables.make(this.storage, { width: space.width, height: space.height, depth: space.depth, channels, items, minFilter, magFilter, type, })); } unmake() { super.unmake(); if (this.buffer) { this.buffer.dispose(); return (this.buffer = this.spec = null); } } change(changed, touched, init) { if (touched["texture"] || changed["buffer.channels"] || changed["buffer.items"] || changed["voxel.bufferWidth"] || changed["voxel.bufferHeight"] || changed["voxel.bufferDepth"]) { return this.rebuild(); } if (!this.buffer) { return; } if (changed["voxel.width"]) { const { width } = this.props; if (width > this.space.width) { return this.rebuild(); } } if (changed["voxel.height"]) { const { height } = this.props; if (height > this.space.height) { return this.rebuild(); } } if (changed["voxel.depth"]) { const { depth } = this.props; if (depth > this.space.depth) { return this.rebuild(); } } if (changed["data.map"] || changed["data.data"] || changed["data.resolve"] || changed["data.expr"] || init) { return this.buffer.setCallback(this.emitter()); } } callback(callback) { if (callback.length <= 4) { return callback; } else { return (emit, i, j, k) => { return callback(emit, i, j, k, this.bufferClock, this.bufferStep); }; } } update() { if (!this.buffer) { return; } const { data } = this.props; const { space, used } = this; const w = used.width; const h = used.height; const d = used.depth; const filled = this.buffer.getFilled(); this.syncBuffer((abort) => { if (data != null) { const dims = UData.getDimensions(data, this.spec); // Grow dimensions if needed if (dims.width > space.width || dims.height > space.height || dims.depth > space.depth) { abort(); return this.rebuild(); } used.width = dims.width; used.height = dims.height; used.depth = dims.depth; this.buffer.setActive(used.width, used.height, used.depth); if (typeof this.buffer.callback.rebind === "function") { this.buffer.callback.rebind(data); } return this.buffer.update(); } else { let _h, _w; const width = this.spec.width || 1; const height = this.spec.height || 1; const depth = this.spec.depth || 1; this.buffer.setActive(width, height, depth); const length = this.buffer.update(); used.width = _w = width; used.height = _h = height; used.depth = Math.ceil(length / _w / _h); if (used.depth === 1) { used.height = Math.ceil(length / _w); if (used.height === 1) { return (used.width = length); } } } }); if (used.width !== w || used.height !== h || used.depth !== d || filled !== this.buffer.getFilled()) { return this.trigger({ type: "source.resize", }); } } } Voxel.initClass();
cchudzicki/mathbox
build/esm/primitives/types/data/voxel.js
JavaScript
mit
7,220
export class Axis extends Primitive { axisPosition: any; axisStep: any; resolution: number | null; line: any; arrows: any[] | null; make(): any; unmake(): any; change(changed: any, touched: any, init: any): any; updateRanges(): any; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/axis.d.ts
TypeScript
mit
319
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UAxis from "../../../util/axis.js"; import * as UJS from "../../../util/js.js"; import { Primitive } from "../../primitive.js"; export class Axis extends Primitive { static initClass() { this.traits = [ "node", "object", "visible", "style", "line", "axis", "span", "interval", "arrow", "position", "origin", "shade", ]; this.defaults = { end: true, zBias: -1, }; } constructor(node, context, helpers) { super(node, context, helpers); this.axisPosition = this.axisStep = this.resolution = this.line = this.arrows = null; } make() { // Prepare position shader const positionUniforms = { axisPosition: this._attributes.make(this._types.vec4()), axisStep: this._attributes.make(this._types.vec4()), }; this.axisPosition = positionUniforms.axisPosition.value; this.axisStep = positionUniforms.axisStep.value; // Build transform chain let position = this._shaders.shader(); position.pipe("axis.position", positionUniforms); position = this._helpers.position.pipeline(position); // Prepare bound uniforms const styleUniforms = this._helpers.style.uniforms(); const lineUniforms = this._helpers.line.uniforms(); const arrowUniforms = this._helpers.arrow.uniforms(); const unitUniforms = this._inherit("unit").getUnitUniforms(); // Line geometry const { detail } = this.props; const samples = detail + 1; this.resolution = 1 / detail; // Clip start/end for terminating arrow const { start, end } = this.props; // Stroke style const { stroke, join } = this.props; // Build transition mask lookup let mask = this._helpers.object.mask(); // Build fragment material lookup const material = this._helpers.shade.pipeline() || false; // Indexing by fixed or by given axis const { crossed, axis } = this.props; if (!crossed && mask != null && axis > 1) { const swizzle = ["x000", "y000", "z000", "w000"][axis]; mask = this._helpers.position.swizzle(mask, swizzle); } // Make line renderable const uniforms = UJS.merge(arrowUniforms, lineUniforms, styleUniforms, unitUniforms); this.line = this._renderables.make("line", { uniforms, samples, position, clip: start || end, stroke, join, mask, material, }); // Make arrow renderables this.arrows = []; if (start) { this.arrows.push(this._renderables.make("arrow", { uniforms, flip: true, samples, position, mask, material, })); } if (end) { this.arrows.push(this._renderables.make("arrow", { uniforms, samples, position, mask, material, })); } // Visible, object and span traits this._helpers.visible.make(); this._helpers.object.make(this.arrows.concat([this.line])); this._helpers.span.make(); // Monitor view range return this._listen(this, "span.range", this.updateRanges); } unmake() { this._helpers.visible.unmake(); this._helpers.object.unmake(); return this._helpers.span.unmake(); } change(changed, touched, init) { if (changed["axis.detail"] || changed["line.stroke"] || changed["line.join"] || changed["axis.crossed"] || (changed["interval.axis"] && this.props.crossed)) { return this.rebuild(); } if (touched["interval"] || touched["span"] || touched["view"] || init) { return this.updateRanges(); } } updateRanges() { const { axis, origin } = this.props; const range = this._helpers.span.get("", axis); const min = range.x; const max = range.y; UAxis.setDimension(this.axisPosition, axis).multiplyScalar(min); UAxis.setDimension(this.axisStep, axis).multiplyScalar((max - min) * this.resolution); return UAxis.addOrigin(this.axisPosition, axis, origin); } } Axis.initClass();
cchudzicki/mathbox
build/esm/primitives/types/draw/axis.js
JavaScript
mit
5,130
export class Face extends Primitive { face: any; resize(): any; make(): any; wireZBias: any; line: any; made(): any; unmake(): null; change(changed: any, touched: any, init: any): any; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/face.d.ts
TypeScript
mit
267
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import * as UJS from "../../../util/js.js"; import { Primitive } from "../../primitive.js"; export class Face extends Primitive { static initClass() { this.traits = [ "node", "object", "visible", "style", "line", "mesh", "face", "geometry", "position", "bind", "shade", ]; } constructor(node, context, helpers) { super(node, context, helpers); this.face = null; } resize() { if (this.bind.points == null) { return; } const dims = this.bind.points.getActiveDimensions(); const { items, width, height, depth } = dims; if (this.face) { this.face.geometry.clip(width, height, depth, items); } if (this.line) { this.line.geometry.clip(items, width, height, depth); } if (this.bind.map != null) { const map = this.bind.map.getActiveDimensions(); if (this.face) { return this.face.geometry.map(map.width, map.height, map.depth, map.items); } } } make() { // Bind to attached data sources let color, uniforms; this._helpers.bind.make([ { to: "geometry.points", trait: "source" }, { to: "geometry.colors", trait: "source" }, { to: "mesh.map", trait: "source" }, ]); if (this.bind.points == null) { return; } // Fetch position and transform to view let position = this.bind.points.sourceShader(this._shaders.shader()); position = this._helpers.position.pipeline(position); // Prepare bound uniforms const styleUniforms = this._helpers.style.uniforms(); const lineUniforms = this._helpers.line.uniforms(); const unitUniforms = this._inherit("unit").getUnitUniforms(); // Auto z-bias wireframe over surface const wireUniforms = {}; wireUniforms.styleZBias = this._attributes.make(this._types.number()); this.wireZBias = wireUniforms.styleZBias; // Fetch geometry dimensions const dims = this.bind.points.getDimensions(); const { items, width, height, depth } = dims; // Get display properties const { line, shaded, fill, stroke, join } = this.props; // Build color lookup if (this.bind.colors) { color = this._shaders.shader(); this.bind.colors.sourceShader(color); } // Build transition mask lookup const mask = this._helpers.object.mask(); // Build texture map lookup const map = this._helpers.shade.map(this.bind.map != null ? this.bind.map.sourceShader(this._shaders.shader()) : undefined); // Build fragment material lookup const material = this._helpers.shade.pipeline(); const faceMaterial = material || shaded; const lineMaterial = material || false; const objects = []; // Make line renderable if (line) { // Swizzle face edges into segments const swizzle = this._shaders.shader(); swizzle.pipe(UGLSL.swizzleVec4("yzwx")); swizzle.pipe(position); uniforms = UJS.merge(unitUniforms, lineUniforms, styleUniforms, wireUniforms); this.line = this._renderables.make("line", { uniforms, samples: items, strips: width, ribbons: height, layers: depth, position: swizzle, color, stroke, join, material: lineMaterial, mask, closed: true, }); objects.push(this.line); } // Make face renderable if (fill) { uniforms = UJS.merge(unitUniforms, styleUniforms, {}); this.face = this._renderables.make("face", { uniforms, width, height, depth, items, position, color, material: faceMaterial, mask, map, }); objects.push(this.face); } this._helpers.visible.make(); return this._helpers.object.make(objects); } made() { return this.resize(); } unmake() { this._helpers.bind.unmake(); this._helpers.visible.unmake(); this._helpers.object.unmake(); return (this.face = this.line = null); } change(changed, touched, init) { if (changed["geometry.points"] || touched["mesh"]) { return this.rebuild(); } if (changed["style.zBias"] || changed["mesh.lineBias"] || init) { const { fill, zBias, lineBias } = this.props; return (this.wireZBias.value = zBias + (fill ? lineBias : 0)); } } } Face.initClass();
cchudzicki/mathbox
build/esm/primitives/types/draw/face.js
JavaScript
mit
5,563
export class Grid extends Primitive { axes: any[] | null; make(): any; unmake(): void; updateRanges(): void; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/grid.d.ts
TypeScript
mit
175
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS205: Consider reworking code to avoid use of IIFEs * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UAxis from "../../../util/axis.js"; import * as UJS from "../../../util/js.js"; import { Primitive } from "../../primitive.js"; export class Grid extends Primitive { static initClass() { this.traits = [ "node", "object", "visible", "style", "line", "grid", "area", "position", "origin", "shade", "axis:x", "axis:y", "scale:x", "scale:y", "span:x", "span:y", ]; this.defaults = { width: 1, zBias: -2, }; } constructor(node, context, helpers) { super(node, context, helpers); this.axes = null; } make() { // Build transition mask lookup let axis; let mask = this._helpers.object.mask(); // Build fragment material lookup const material = this._helpers.shade.pipeline() || false; axis = (first, second, transpose) => { // Prepare data buffer of tick positions let position; const detail = this._get(first + "axis.detail"); const samples = detail + 1; const resolution = 1 / detail; const strips = this._helpers.scale.divide(second); const buffer = this._renderables.make("dataBuffer", { width: strips, channels: 1, }); // Prepare position shader const positionUniforms = { gridPosition: this._attributes.make(this._types.vec4()), gridStep: this._attributes.make(this._types.vec4()), gridAxis: this._attributes.make(this._types.vec4()), }; const values = { gridPosition: positionUniforms.gridPosition.value, gridStep: positionUniforms.gridStep.value, gridAxis: positionUniforms.gridAxis.value, }; // Build transform chain const p = (position = this._shaders.shader()); // Align second grid with first in mask space if requested if (transpose != null && mask != null) { mask = this._helpers.position.swizzle(mask, transpose); } // Require buffer sampler as callback p.require(buffer.shader(this._shaders.shader(), 2)); // Calculate grid position p.pipe("grid.position", positionUniforms); // Apply view transform position = this._helpers.position.pipeline(p); // Prepare bound uniforms const styleUniforms = this._helpers.style.uniforms(); const lineUniforms = this._helpers.line.uniforms(); const unitUniforms = this._inherit("unit").getUnitUniforms(); const uniforms = UJS.merge(lineUniforms, styleUniforms, unitUniforms); // Make line renderable const line = this._renderables.make("line", { uniforms, samples, strips, position, stroke, join, mask, material, }); // Store axis object for manipulation later return { first, second, resolution, samples, line, buffer, values }; }; // Generate both line sets const { lineX, lineY, crossed, axes } = this.props; const transpose = ["0000", "x000", "y000", "z000", "w000"][axes[1]]; // Stroke style const { stroke, join } = this.props; this.axes = []; lineX && this.axes.push(axis("x.", "y.", null)); lineY && this.axes.push(axis("y.", "x.", crossed ? null : transpose)); // Register lines const lines = (() => { const result = []; for (axis of this.axes) { result.push(axis.line); } return result; })(); this._helpers.visible.make(); this._helpers.object.make(lines); this._helpers.span.make(); // Monitor view range return this._listen(this, "span.range", this.updateRanges); } unmake() { this._helpers.visible.unmake(); this._helpers.object.unmake(); this._helpers.span.unmake(); for (const axis of this.axes) { axis.buffer.dispose(); } this.axes = null; } change(changed, touched, init) { if (changed["x.axis.detail"] || changed["y.axis.detail"] || changed["x.axis.factor"] || changed["y.axis.factor"] || changed["grid.lineX"] || changed["grid.lineY"] || changed["line.stroke"] || changed["line.join"] || changed["grid.crossed"] || (changed["grid.axes"] && this.props.crossed)) { return this.rebuild(); } if (touched["x"] || touched["y"] || touched["area"] || touched["grid"] || touched["view"] || init) { return this.updateRanges(); } } updateRanges() { const axis = (x, y, range1, range2, axis) => { const { second, resolution, samples, line, buffer, values } = axis; // Set line steps along first axis let min = range1.x; let max = range1.y; UAxis.setDimension(values.gridPosition, x).multiplyScalar(min); UAxis.setDimension(values.gridStep, x).multiplyScalar((max - min) * resolution); // Add origin on remaining two axes UAxis.addOrigin(values.gridPosition, axes, origin); // Calculate scale along second axis min = range2.x; max = range2.y; const ticks = this._helpers.scale.generate(second, buffer, min, max); UAxis.setDimension(values.gridAxis, y); // Clip to number of ticks const n = ticks.length; return line.geometry.clip(samples, n, 1, 1); }; // Fetch grid range in both dimensions const { axes, origin } = this.props; const range1 = this._helpers.span.get("x.", axes[0]); const range2 = this._helpers.span.get("y.", axes[1]); // Update both line sets const { lineX, lineY } = this.props; if (lineX) { axis(axes[0], axes[1], range1, range2, this.axes[0]); } if (lineY) { axis(axes[1], axes[0], range2, range1, this.axes[+lineX]); } window.cake1 = this.axes[0].buffer; window.cake2 = this.axes[1].buffer; window.cake3 = this.axes[0]; } } Grid.initClass();
cchudzicki/mathbox
build/esm/primitives/types/draw/grid.js
JavaScript
mit
7,304
export * from "./axis.js"; export * from "./face.js"; export * from "./grid.js"; export * from "./line.js"; export * from "./point.js"; export * from "./strip.js"; export * from "./surface.js"; export * from "./ticks.js"; export * from "./vector.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/index.d.ts
TypeScript
mit
251
export * from "./axis.js"; export * from "./face.js"; export * from "./grid.js"; export * from "./line.js"; export * from "./point.js"; export * from "./strip.js"; export * from "./surface.js"; export * from "./ticks.js"; export * from "./vector.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/index.js
JavaScript
mit
251
export class Line extends Primitive { line: any; arrows: any[] | null; resize(): any[] | undefined; make(): any; proximity: any; made(): any[] | undefined; unmake(): null; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/line.d.ts
TypeScript
mit
250
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UJS from "../../../util/js.js"; import { Primitive } from "../../primitive.js"; export class Line extends Primitive { static initClass() { this.traits = [ "node", "object", "visible", "style", "line", "arrow", "geometry", "position", "bind", "shade", ]; } constructor(node, context, helpers) { super(node, context, helpers); this.line = this.arrows = null; } resize() { if (this.bind.points == null) { return; } const dims = this.bind.points.getActiveDimensions(); const samples = dims.width; const strips = dims.height; const ribbons = dims.depth; const layers = dims.items; this.line.geometry.clip(samples, strips, ribbons, layers); return Array.from(this.arrows).map((arrow) => arrow.geometry.clip(samples, strips, ribbons, layers)); } make() { // Bind to attached data sources let color; this._helpers.bind.make([ { to: "geometry.points", trait: "source" }, { to: "geometry.colors", trait: "source" }, ]); if (this.bind.points == null) { return; } // Build transform chain let position = this._shaders.shader(); // Fetch position position = this.bind.points.sourceShader(position); // Transform position to view position = this._helpers.position.pipeline(position); // Prepare bound uniforms const styleUniforms = this._helpers.style.uniforms(); const lineUniforms = this._helpers.line.uniforms(); const arrowUniforms = this._helpers.arrow.uniforms(); const unitUniforms = this._inherit("unit").getUnitUniforms(); // Clip start/end for terminating arrow const { start, end } = this.props; // Stroke style const { stroke, join, proximity } = this.props; this.proximity = proximity; // Fetch geometry dimensions const dims = this.bind.points.getDimensions(); const samples = dims.width; const strips = dims.height; const ribbons = dims.depth; const layers = dims.items; // Build color lookup if (this.bind.colors) { color = this._shaders.shader(); this.bind.colors.sourceShader(color); } // Build transition mask lookup const mask = this._helpers.object.mask(); // Build fragment material lookup const material = this._helpers.shade.pipeline() || false; // Make line renderable const uniforms = UJS.merge(arrowUniforms, lineUniforms, styleUniforms, unitUniforms); this.line = this._renderables.make("line", { uniforms, samples, strips, ribbons, layers, position, color, clip: start || end, stroke, join, proximity, mask, material, }); // Make arrow renderables this.arrows = []; if (start) { this.arrows.push(this._renderables.make("arrow", { uniforms, flip: true, samples, strips, ribbons, layers, position, color, mask, material, })); } if (end) { this.arrows.push(this._renderables.make("arrow", { uniforms, samples, strips, ribbons, layers, position, color, mask, material, })); } this._helpers.visible.make(); return this._helpers.object.make(this.arrows.concat([this.line])); } made() { return this.resize(); } unmake() { this._helpers.bind.unmake(); this._helpers.visible.unmake(); this._helpers.object.unmake(); return (this.line = this.arrows = null); } change(changed, _touched, _init) { if (changed["geometry.points"] || changed["line.stroke"] || changed["line.join"] || changed["arrow.start"] || changed["arrow.end"]) { return this.rebuild(); } if (changed["line.proximity"]) { if ((this.proximity != null) !== (this.props.proximity != null)) { return this.rebuild(); } } } } Line.initClass();
cchudzicki/mathbox
build/esm/primitives/types/draw/line.js
JavaScript
mit
5,190
export class Point extends Primitive { point: any; resize(): any; made(): any; unmake(): void; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/point.d.ts
TypeScript
mit
161
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UJS from "../../../util/js.js"; import { Primitive } from "../../primitive.js"; export class Point extends Primitive { static initClass() { this.traits = [ "node", "object", "visible", "style", "point", "geometry", "position", "bind", "shade", ]; } constructor(node, context, helpers) { super(node, context, helpers); this.point = null; } resize() { if (this.bind.points == null) { return; } const dims = this.bind.points.getActiveDimensions(); const { items, width, height, depth } = dims; return this.point.geometry.clip(width, height, depth, items); } make() { // Bind to attached data sources let color, size; this._helpers.bind.make([ { to: "geometry.points", trait: "source" }, { to: "geometry.colors", trait: "source" }, { to: "point.sizes", trait: "source" }, ]); if (this.bind.points == null) { return; } // Build transform chain let position = this._shaders.shader(); // Fetch position and transform to view position = this.bind.points.sourceShader(position); position = this._helpers.position.pipeline(position); // Fetch geometry dimensions const dims = this.bind.points.getDimensions(); const { items, width, height, depth } = dims; // Prepare bound uniforms const styleUniforms = this._helpers.style.uniforms(); const pointUniforms = this._helpers.point.uniforms(); const unitUniforms = this._inherit("unit").getUnitUniforms(); // Build color lookup if (this.bind.colors) { color = this._shaders.shader(); this.bind.colors.sourceShader(color); } // Build size lookup if (this.bind.sizes) { size = this._shaders.shader(); this.bind.sizes.sourceShader(size); } // Build transition mask lookup const mask = this._helpers.object.mask(); // Build fragment material lookup const material = this._helpers.shade.pipeline() || false; // Point style const { shape } = this.props; const { fill } = this.props; const { optical } = this.props; // Make point renderable const uniforms = UJS.merge(unitUniforms, pointUniforms, styleUniforms); this.point = this._renderables.make("point", { uniforms, width, height, depth, items, position, color, size, shape, optical, fill, mask, material, }); this._helpers.visible.make(); this._helpers.object.make([this.point]); } made() { return this.resize(); } unmake() { this._helpers.bind.unmake(); this._helpers.visible.unmake(); this._helpers.object.unmake(); this.point = null; } change(changed, _touched, _init) { if (changed["geometry.points"] || changed["point.shape"] || changed["point.fill"]) { return this.rebuild(); } } } Point.initClass();
cchudzicki/mathbox
build/esm/primitives/types/draw/point.js
JavaScript
mit
3,814
export class Strip extends Primitive { strip: any; resize(): any; make(): any; wireZBias: any; line: any; made(): any; unmake(): null; change(changed: any, touched: any, init: any): any; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/strip.d.ts
TypeScript
mit
269
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import * as UJS from "../../../util/js.js"; import { Primitive } from "../../primitive.js"; export class Strip extends Primitive { static initClass() { this.traits = [ "node", "object", "visible", "style", "line", "mesh", "strip", "geometry", "position", "bind", "shade", ]; } constructor(node, context, helpers) { super(node, context, helpers); this.strip = null; } resize() { if (this.bind.points == null) { return; } const dims = this.bind.points.getActiveDimensions(); const { items, width, height, depth } = dims; if (this.strip) { this.strip.geometry.clip(width, height, depth, items); } if (this.line) { this.line.geometry.clip(items, width, height, depth); } if (this.bind.map != null) { const map = this.bind.map.getActiveDimensions(); if (this.strip) { return this.strip.geometry.map(map.width, map.height, map.depth, map.items); } } } make() { // Bind to attached data sources let color, uniforms; this._helpers.bind.make([ { to: "geometry.points", trait: "source" }, { to: "geometry.colors", trait: "source" }, { to: "mesh.map", trait: "source" }, ]); if (this.bind.points == null) { return; } // Build transform chain let position = this._shaders.shader(); // Fetch position position = this.bind.points.sourceShader(position); // Transform position to view position = this._helpers.position.pipeline(position); // Prepare bound uniforms const styleUniforms = this._helpers.style.uniforms(); const lineUniforms = this._helpers.line.uniforms(); const unitUniforms = this._inherit("unit").getUnitUniforms(); // Get display properties const { line, shaded, fill, stroke, join } = this.props; // Auto z-bias wireframe over surface const wireUniforms = {}; wireUniforms.styleZBias = this._attributes.make(this._types.number()); this.wireZBias = wireUniforms.styleZBias; // Fetch geometry dimensions const dims = this.bind.points.getDimensions(); const { items, width, height, depth } = dims; // Build color lookup if (this.bind.colors) { color = this._shaders.shader(); color = this.bind.colors.sourceShader(color); } // Build transition mask lookup const mask = this._helpers.object.mask(); // Build texture map lookup this._helpers.shade.map(this.bind.map != null ? this.bind.map.sourceShader(this._shaders.shader()) : undefined); // Build fragment material lookup const material = this._helpers.shade.pipeline(); const faceMaterial = material || shaded; const lineMaterial = material || false; const objects = []; // Make line renderable if (line) { // Swizzle strip edges into segments const swizzle = this._shaders.shader(); swizzle.pipe(UGLSL.swizzleVec4("yzwx")); swizzle.pipe(position); uniforms = UJS.merge(unitUniforms, lineUniforms, styleUniforms, wireUniforms); this.line = this._renderables.make("line", { uniforms, samples: items, strips: width, ribbons: height, layers: depth, position: swizzle, color, stroke, join, mask, material: lineMaterial, }); objects.push(this.line); } // Make strip renderable if (fill) { uniforms = UJS.merge(styleUniforms, {}); this.strip = this._renderables.make("strip", { uniforms, width, height, depth, items, position, color, material: faceMaterial, }); objects.push(this.strip); } this._helpers.visible.make(); return this._helpers.object.make(objects); } made() { return this.resize(); } unmake() { this._helpers.bind.unmake(); this._helpers.visible.unmake(); this._helpers.object.unmake(); return (this.strip = null); } change(changed, touched, init) { if (changed["geometry.points"] || touched["mesh"]) { return this.rebuild(); } if (changed["style.zBias"] || changed["mesh.lineBias"] || init) { const { fill, zBias, lineBias } = this.props; return (this.wireZBias.value = zBias + (fill ? lineBias : 0)); } } } Strip.initClass();
cchudzicki/mathbox
build/esm/primitives/types/draw/strip.js
JavaScript
mit
5,552
export class Surface extends Primitive { lineX: any; lineY: any; surface: any; resize(): any; make(): any; wireColor: any; wireZBias: any; wireScratch: any; proximity: any; made(): any; unmake(): null; _convertGammaToLinear(color: any, gammaFactor?: number): any; _convertLinearToGamma(color: any, gammaFactor?: number): any; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/surface.d.ts
TypeScript
mit
428
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UJS from "../../../util/js.js"; import { Color } from "three/src/math/Color.js"; import { Primitive } from "../../primitive.js"; export class Surface extends Primitive { static initClass() { this.traits = [ "node", "object", "visible", "style", "line", "mesh", "geometry", "surface", "position", "grid", "bind", "shade", ]; this.defaults = { lineX: false, lineY: false, }; } constructor(node, context, helpers) { super(node, context, helpers); this.lineX = this.lineY = this.surface = null; } resize() { if (this.bind.points == null) { return; } const dims = this.bind.points.getActiveDimensions(); const { width, height, depth, items } = dims; if (this.surface) { this.surface.geometry.clip(width, height, depth, items); } if (this.lineX) { this.lineX.geometry.clip(width, height, depth, items); } if (this.lineY) { this.lineY.geometry.clip(height, width, depth, items); } if (this.bind.map != null) { const map = this.bind.map.getActiveDimensions(); if (this.surface) { return this.surface.geometry.map(map.width, map.height, map.depth, map.items); } } } make() { // Bind to attached data sources let color; this._helpers.bind.make([ { to: "geometry.points", trait: "source" }, { to: "geometry.colors", trait: "source" }, { to: "mesh.map", trait: "source" }, ]); if (this.bind.points == null) { return; } // Build transform chain let position = this._shaders.shader(); // Fetch position and transform to view position = this.bind.points.sourceShader(position); position = this._helpers.position.pipeline(position); // Prepare bound uniforms const styleUniforms = this._helpers.style.uniforms(); const wireUniforms = this._helpers.style.uniforms(); const lineUniforms = this._helpers.line.uniforms(); const surfaceUniforms = this._helpers.surface.uniforms(); const unitUniforms = this._inherit("unit").getUnitUniforms(); // Darken wireframe if needed for contrast // Auto z-bias wireframe over surface wireUniforms.styleColor = this._attributes.make(this._types.color()); wireUniforms.styleZBias = this._attributes.make(this._types.number()); this.wireColor = wireUniforms.styleColor.value; this.wireZBias = wireUniforms.styleZBias; this.wireScratch = new Color(); // Fetch geometry dimensions const dims = this.bind.points.getDimensions(); const { width, height, depth, items } = dims; // Get display properties const { shaded, fill, lineX, lineY, closedX, closedY, stroke, join, proximity, crossed, } = this.props; const objects = []; this.proximity = proximity; // Build color lookup if (this.bind.colors) { color = this._shaders.shader(); this.bind.colors.sourceShader(color); } // Build transition mask lookup const mask = this._helpers.object.mask(); // Build texture map lookup const map = this._helpers.shade.map(this.bind.map != null ? this.bind.map.sourceShader(this._shaders.shader()) : undefined); // Build fragment material lookup const material = this._helpers.shade.pipeline(); const faceMaterial = material || shaded; const lineMaterial = material || false; // Make line and surface renderables const { swizzle, swizzle2 } = this._helpers.position; let uniforms = UJS.merge(unitUniforms, lineUniforms, styleUniforms, wireUniforms); const zUnits = lineX || lineY ? -50 : 0; if (lineX) { this.lineX = this._renderables.make("line", { uniforms, samples: width, strips: height, ribbons: depth, layers: items, position, color, zUnits: -zUnits, stroke, join, mask, material: lineMaterial, proximity, closed: closedX || closed, }); objects.push(this.lineX); } if (lineY) { this.lineY = this._renderables.make("line", { uniforms, samples: height, strips: width, ribbons: depth, layers: items, position: swizzle2(position, "yxzw", "yxzw"), color: swizzle(color, "yxzw"), zUnits: -zUnits, stroke, join, mask: swizzle(mask, crossed ? "xyzw" : "yxzw"), material: lineMaterial, proximity, closed: closedY || closed, }); objects.push(this.lineY); } if (fill) { uniforms = UJS.merge(unitUniforms, surfaceUniforms, styleUniforms); this.surface = this._renderables.make("surface", { uniforms, width, height, surfaces: depth, layers: items, position, color, zUnits, stroke, material: faceMaterial, mask, map, intUV: true, closedX: closedX || closed, closedY: closedY || closed, }); objects.push(this.surface); } this._helpers.visible.make(); return this._helpers.object.make(objects); } made() { return this.resize(); } unmake() { this._helpers.bind.unmake(); this._helpers.visible.unmake(); this._helpers.object.unmake(); return (this.lineX = this.lineY = this.surface = null); } _convertGammaToLinear(color, gammaFactor = 2.0) { color.r = Math.pow(color.r, gammaFactor); color.g = Math.pow(color.g, gammaFactor); color.b = Math.pow(color.b, gammaFactor); return color; } _convertLinearToGamma(color, gammaFactor = 2.0) { const safeInverse = gammaFactor > 0 ? 1.0 / gammaFactor : 1.0; color.r = Math.pow(color.r, safeInverse); color.g = Math.pow(color.g, safeInverse); color.b = Math.pow(color.b, safeInverse); return color; } change(changed, touched, init) { if (changed["geometry.points"] || changed["mesh.shaded"] || changed["mesh.fill"] || changed["line.stroke"] || changed["line.join"] || touched["grid"]) { return this.rebuild(); } if (changed["style.color"] || changed["style.zBias"] || changed["mesh.fill"] || changed["mesh.lineBias"] || init) { const { fill, color, zBias, lineBias } = this.props; this.wireZBias.value = zBias + (fill ? lineBias : 0); this.wireColor.copy(color); if (fill) { const c = this.wireScratch; c.setRGB(color.x, color.y, color.z); this._convertLinearToGamma(this._convertGammaToLinear(c).multiplyScalar(0.75)); this.wireColor.x = c.r; this.wireColor.y = c.g; this.wireColor.z = c.b; } } if (changed["line.proximity"]) { if ((this.proximity != null) !== (this.props.proximity != null)) { return this.rebuild(); } } } } Surface.initClass();
cchudzicki/mathbox
build/esm/primitives/types/draw/surface.js
JavaScript
mit
8,497
export class Ticks extends Primitive { init(): null; tickStrip: any; line: any; resize(): any; make(): any; made(): any; unmake(): any; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/ticks.d.ts
TypeScript
mit
214
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UJS from "../../../util/js.js"; import { Primitive } from "../../primitive.js"; export class Ticks extends Primitive { static initClass() { this.traits = [ "node", "object", "visible", "style", "line", "ticks", "geometry", "position", "bind", "shade", ]; } init() { return (this.tickStrip = this.line = null); } resize() { if (this.bind.points == null) { return; } const dims = this.bind.points.getActiveDimensions(); const active = +(dims.items > 0); const strips = dims.width * active; const ribbons = dims.height * active; const layers = dims.depth * active; this.line.geometry.clip(2, strips, ribbons, layers); return this.tickStrip.set(0, strips - 1); } make() { // Bind to attached data sources let color, position; this._helpers.bind.make([ { to: "geometry.points", trait: "source" }, { to: "geometry.colors", trait: "source" }, ]); if (this.bind.points == null) { return; } // Prepare bound uniforms const styleUniforms = this._helpers.style.uniforms(); const lineUniforms = this._helpers.line.uniforms(); const unitUniforms = this._inherit("unit").getUnitUniforms(); const uniforms = UJS.merge(lineUniforms, styleUniforms, unitUniforms); // Prepare position shader const positionUniforms = { tickEpsilon: this.node.attributes["ticks.epsilon"], tickSize: this.node.attributes["ticks.size"], tickNormal: this.node.attributes["ticks.normal"], tickStrip: this._attributes.make(this._types.vec2(0, 0)), worldUnit: uniforms.worldUnit, focusDepth: uniforms.focusDepth, }; this.tickStrip = positionUniforms.tickStrip.value; // Build transform chain const p = (position = this._shaders.shader()); // Require buffer sampler as callback p.require(this.bind.points.sourceShader(this._shaders.shader())); // Require view transform as callback p.require(this._helpers.position.pipeline(this._shaders.shader())); // Link to tick shader p.pipe("ticks.position", positionUniforms); // Stroke style const { stroke, join } = this.props; // Fetch geometry dimensions const dims = this.bind.points.getDimensions(); const strips = dims.width; const ribbons = dims.height; const layers = dims.depth; // Build color lookup if (this.bind.colors) { color = this._shaders.shader(); this.bind.colors.sourceShader(color); } // Build transition mask lookup const mask = this._helpers.object.mask(); // Build fragment material lookup const material = this._helpers.shade.pipeline() || false; // Make line renderable const { swizzle } = this._helpers.position; this.line = this._renderables.make("line", { uniforms, samples: 2, strips, ribbons, layers, position, color, stroke, join, mask: swizzle(mask, "yzwx"), material, }); this._helpers.visible.make(); return this._helpers.object.make([this.line]); } made() { return this.resize(); } unmake() { this.line = null; this._helpers.visible.unmake(); return this._helpers.object.unmake(); } change(changed, _touched, _init) { if (changed["geometry.points"] || changed["line.stroke"] || changed["line.join"]) { return this.rebuild(); } } } Ticks.initClass();
cchudzicki/mathbox
build/esm/primitives/types/draw/ticks.js
JavaScript
mit
4,387
export class Vector extends Primitive { line: any; arrows: any[] | null; resize(): any[] | undefined; make(): any; proximity: any; made(): any[] | undefined; unmake(): null; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/draw/vector.d.ts
TypeScript
mit
252
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UJS from "../../../util/js.js"; import { Primitive } from "../../primitive.js"; export class Vector extends Primitive { static initClass() { this.traits = [ "node", "object", "visible", "style", "line", "arrow", "geometry", "position", "bind", "shade", ]; } constructor(node, context, helpers) { super(node, context, helpers); this.line = this.arrows = null; } resize() { if (this.bind.points == null) { return; } const dims = this.bind.points.getActiveDimensions(); const samples = dims.items; const strips = dims.width; const ribbons = dims.height; const layers = dims.depth; this.line.geometry.clip(samples, strips, ribbons, layers); return Array.from(this.arrows).map((arrow) => arrow.geometry.clip(samples, strips, ribbons, layers)); } make() { // Bind to attached data sources let color; this._helpers.bind.make([ { to: "geometry.points", trait: "source" }, { to: "geometry.colors", trait: "source" }, ]); if (this.bind.points == null) { return; } // Build transform chain let position = this._shaders.shader(); // Fetch position this.bind.points.sourceShader(position); // Transform position to view this._helpers.position.pipeline(position); // Prepare bound uniforms const styleUniforms = this._helpers.style.uniforms(); const lineUniforms = this._helpers.line.uniforms(); const arrowUniforms = this._helpers.arrow.uniforms(); const unitUniforms = this._inherit("unit").getUnitUniforms(); // Clip start/end for terminating arrow const { start, end } = this.props; // Stroke style const { stroke, join, proximity } = this.props; this.proximity = proximity; // Fetch geometry dimensions const dims = this.bind.points.getDimensions(); const samples = dims.items; const strips = dims.width; const ribbons = dims.height; const layers = dims.depth; // Build color lookup if (this.bind.colors) { color = this._shaders.shader(); this.bind.colors.sourceShader(color); } // Build transition mask lookup let mask = this._helpers.object.mask(); // Build fragment material lookup let material = this._helpers.shade.pipeline() || false; // Swizzle vector to line const { swizzle, swizzle2 } = this._helpers.position; position = swizzle2(position, "yzwx", "yzwx"); color = swizzle(color, "yzwx"); mask = swizzle(mask, "yzwx"); material = swizzle(material, "yzwx"); // Make line renderable const uniforms = UJS.merge(arrowUniforms, lineUniforms, styleUniforms, unitUniforms); this.line = this._renderables.make("line", { uniforms, samples, ribbons, strips, layers, position, color, clip: start || end, stroke, join, proximity, mask, material, }); // Make arrow renderables this.arrows = []; if (start) { this.arrows.push(this._renderables.make("arrow", { uniforms, flip: true, samples, ribbons, strips, layers, position, color, mask, material, })); } if (end) { this.arrows.push(this._renderables.make("arrow", { uniforms, samples, ribbons, strips, layers, position, color, mask, material, })); } this._helpers.visible.make(); return this._helpers.object.make(this.arrows.concat([this.line])); } made() { return this.resize(); } unmake() { this._helpers.bind.unmake(); this._helpers.visible.unmake(); this._helpers.object.unmake(); return (this.line = this.arrows = null); } change(changed, _touched, _init) { if (changed["geometry.points"] || changed["line.stroke"] || changed["line.join"] || changed["arrow.start"] || changed["arrow.end"]) { return this.rebuild(); } if (changed["line.proximity"]) { if ((this.proximity != null) !== (this.props.proximity != null)) { return this.rebuild(); } } } } Vector.initClass();
cchudzicki/mathbox
build/esm/primitives/types/draw/vector.js
JavaScript
mit
5,443
export function Helpers(object: any, traits: any): {};
cchudzicki/mathbox
build/esm/primitives/types/helpers.d.ts
TypeScript
mit
55
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining * DS104: Avoid inline assignments * DS205: Consider reworking code to avoid use of IIFEs * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../util/glsl.js"; import * as UTicks from "../../util/ticks.js"; import { NormalBlending } from "three/src/constants.js"; import { Vector2 } from "three/src/math/Vector2.js"; import { Vector3 } from "three/src/math/Vector3.js"; /* This is the general dumping ground for trait behavior. Helpers are auto-attached to primitives that have the matching trait */ const helpers = { bind: { make(slots) { if (this.bind == null) { this.bind = {}; } if (this.bound == null) { this.bound = []; } // Fetch attached objects and bind to them // Attach rebuild watcher for DOM changes to bound nodes for (const slot of Array.from(slots)) { let { callback } = slot; const { to, trait, optional, unique, multiple } = slot; if (callback == null) { callback = this.rebuild; } const name = to.split(/\./g).pop(); const selector = this._get(to); // Find by selector let source = null; if (selector != null) { let start = this; let done = false; while (!done) { // Keep scanning back until a new node is found start = source = this._attach(selector, trait, callback, this, start, optional, multiple); const isUnique = unique && (source == null || this.bound.indexOf(source) < 0); done = multiple || optional || !unique || isUnique; } } // Monitor source for reallocation / resize if (source != null) { if (this.resize != null) { this._listen(source, "source.resize", this.resize); } if (callback) { this._listen(source, "source.rebuild", callback); } if (multiple) { for (const s of Array.from(source)) { this.bound.push(s); } } else { this.bound.push(source); } } this.bind[name] = source; } return null; }, unmake() { if (!this.bind) { return; } delete this.bind; return delete this.bound; }, }, span: { make() { // Look up nearest view to inherit from // Monitor size changes this.spanView = this._inherit("view"); return this._listen("view", "view.range", () => this.trigger({ type: "span.range" })); }, unmake() { return delete this.spanView; }, get: (function () { const def = new Vector2(-1, 1); return function (prefix, dimension) { // Return literal range let left; const range = this._get(prefix + "span.range"); if (range != null) { return range; } // Inherit from view return (left = this.spanView != null ? this.spanView.axis(dimension) : undefined) != null ? left : def; }; })(), }, scale: { // Divisions to allocate on scale divide(prefix) { const divide = this._get(prefix + "scale.divide"); const factor = this._get(prefix + "scale.factor"); return Math.round((divide * 2.5) / factor); }, // Generate ticks on scale generate(prefix, buffer, min, max) { const mode = this._get(prefix + "scale.mode"); const divide = this._get(prefix + "scale.divide"); const unit = this._get(prefix + "scale.unit"); const base = this._get(prefix + "scale.base"); const factor = this._get(prefix + "scale.factor"); const start = this._get(prefix + "scale.start"); const end = this._get(prefix + "scale.end"); const zero = this._get(prefix + "scale.zero"); const nice = this._get(prefix + "scale.nice"); const ticks = UTicks.make(mode, min, max, divide, unit, base, factor, start, end, zero, nice); buffer.copy(ticks); return ticks; }, }, style: { // Return bound style uniforms uniforms() { return { styleColor: this.node.attributes["style.color"], styleOpacity: this.node.attributes["style.opacity"], styleZBias: this.node.attributes["style.zBias"], styleZIndex: this.node.attributes["style.zIndex"], }; }, }, arrow: { // Return bound arrow style uniforms uniforms() { const { start } = this.props; const { end } = this.props; const space = this._attributes.make(this._types.number(1.25 / (start + end))); const style = this._attributes.make(this._types.vec2(+start, +end)); const size = this.node.attributes["arrow.size"]; return { clipStyle: style, clipRange: size, clipSpace: space, arrowSpace: space, arrowSize: size, }; }, }, point: { // Return bound point style uniforms uniforms() { return { pointSize: this.node.attributes["point.size"], pointDepth: this.node.attributes["point.depth"], }; }, }, line: { // Return bound line style uniforms uniforms() { return { lineWidth: this.node.attributes["line.width"], lineDepth: this.node.attributes["line.depth"], lineProximity: this.node.attributes["line.proximity"], }; }, }, surface: { // Return bound surface style uniforms uniforms() { return {}; }, }, shade: { pipeline(shader) { if (!this._inherit("fragment")) { return shader; } if (shader == null) { shader = this._shaders.shader(); } for (let pass = 0; pass <= 2; pass++) { shader = __guard__(this._inherit("fragment"), (x) => x.fragment(shader, pass)); } shader.pipe("fragment.map.rgba"); return shader; }, map(shader) { if (!shader) { return shader; } return (shader = this._shaders .shader() .pipe("mesh.map.uvwo") .pipe(shader)); }, }, position: { pipeline(shader) { if (!this._inherit("vertex")) { return shader; } if (shader == null) { shader = this._shaders.shader(); } for (let pass = 0; pass <= 3; pass++) { shader = __guard__(this._inherit("vertex"), (x) => x.vertex(shader, pass)); } return shader; }, swizzle(shader, order) { if (shader) { return this._shaders .shader() .pipe(UGLSL.swizzleVec4(order)) .pipe(shader); } }, swizzle2(shader, order1, order2) { if (shader) { return this._shaders .shader() .split() .pipe(UGLSL.swizzleVec4(order1)) .next() .pipe(UGLSL.swizzleVec4(order2)) .join() .pipe(shader); } }, }, visible: { make() { const e = { type: "visible.change" }; let visible = null; this.setVisible = function (vis) { if (vis != null) { visible = vis; } return onVisible(); }; const onVisible = () => { let left; const last = this.isVisible; let self = (left = visible != null ? visible : this._get("object.visible")) != null ? left : true; if (visibleParent != null) { if (self) { self = visibleParent.isVisible; } } this.isVisible = self; if (last !== this.isVisible) { return this.trigger(e); } }; const visibleParent = this._inherit("visible"); if (visibleParent) { this._listen(visibleParent, "visible.change", onVisible); } if (this.is("object")) { this._listen(this.node, "change:object", onVisible); } return onVisible(); }, unmake() { return delete this.isVisible; }, }, active: { make() { const e = { type: "active.change" }; let active = null; this.setActive = function (act) { if (act != null) { active = act; } return onActive(); }; const onActive = () => { let left; const last = this.isActive; let self = (left = active != null ? active : this._get("entity.active")) != null ? left : true; if (activeParent != null) { if (self) { self = activeParent.isActive; } } this.isActive = self; if (last !== this.isActive) { return this.trigger(e); } }; const activeParent = this._inherit("active"); if (activeParent) { this._listen(activeParent, "active.change", onActive); } if (this.is("entity")) { this._listen(this.node, "change:entity", onActive); } return onActive(); }, unmake() { return delete this.isActive; }, }, object: { // Generic 3D renderable wrapper, handles the fiddly Three.js bits that require a 'style recalculation'. // // Pass renderables to nearest root for rendering // Track visibility from parent and notify children // Track blends / transparency for three.js materials make(objects) { // Aggregate rendered three objects for reference let blending, zOrder; if (objects == null) { objects = []; } this.objects = objects; this.renders = this.objects.reduce((a, b) => a.concat(b.renders), []); const objectScene = this._inherit("scene"); let opacity = (blending = zOrder = null); const hasStyle = Array.from(this.traits).includes("style"); opacity = 1; blending = NormalBlending; let zWrite = true; let zTest = true; if (hasStyle) { ({ opacity } = this.props); ({ blending } = this.props); ({ zOrder } = this.props); ({ zWrite } = this.props); ({ zTest } = this.props); } const onChange = (event) => { const { changed } = event; let refresh = null; if (changed["style.opacity"]) { refresh = opacity = this.props.opacity; } if (changed["style.blending"]) { refresh = blending = this.props.blending; } if (changed["style.zOrder"]) { refresh = zOrder = this.props.zOrder; } if (changed["style.zWrite"]) { refresh = zWrite = this.props.zWrite; } if (changed["style.zTest"]) { refresh = zTest = this.props.zTest; } if (refresh != null) { return onVisible(); } }; const onVisible = () => { const order = zOrder != null ? -zOrder : this.node.order; const visible = (this.isVisible != null ? this.isVisible : true) && opacity > 0; if (visible) { if (hasStyle) { return (() => { const result = []; for (const o of Array.from(this.objects)) { o.show(opacity < 1, blending, order); result.push(o.depth(zWrite, zTest)); } return result; })(); } else { return (() => { const result1 = []; for (const o of Array.from(this.objects)) { result1.push(o.show(true, blending, order)); } return result1; })(); } } else { return (() => { const result2 = []; for (const o of Array.from(this.objects)) { result2.push(o.hide()); } return result2; })(); } }; this._listen(this.node, "change:style", onChange); this._listen(this.node, "reindex", onVisible); this._listen(this, "visible.change", onVisible); for (const object of Array.from(this.objects)) { objectScene.adopt(object); } return onVisible(); }, unmake(dispose) { let object; if (dispose == null) { dispose = true; } if (!this.objects) { return; } const objectScene = this._inherit("scene"); for (object of Array.from(this.objects)) { objectScene.unadopt(object); } if (dispose) { return (() => { const result = []; for (object of Array.from(this.objects)) { result.push(object.dispose()); } return result; })(); } }, mask() { let mask, shader; if (!(mask = this._inherit("mask"))) { return; } return (shader = mask.mask(shader)); }, }, unit: { make() { let focusDepth, pixelRatio, pixelUnit, renderAspect, renderHeight, renderOdd, renderScale, renderScaleInv, renderWidth, viewHeight, viewWidth, worldUnit; let π = Math.PI; this.unitUniforms = { renderScaleInv: (renderScaleInv = this._attributes.make(this._types.number(1))), renderScale: (renderScale = this._attributes.make(this._types.number(1))), renderAspect: (renderAspect = this._attributes.make(this._types.number(1))), renderWidth: (renderWidth = this._attributes.make(this._types.number(0))), renderHeight: (renderHeight = this._attributes.make(this._types.number(0))), viewWidth: (viewWidth = this._attributes.make(this._types.number(0))), viewHeight: (viewHeight = this._attributes.make(this._types.number(0))), pixelRatio: (pixelRatio = this._attributes.make(this._types.number(1))), pixelUnit: (pixelUnit = this._attributes.make(this._types.number(1))), worldUnit: (worldUnit = this._attributes.make(this._types.number(1))), focusDepth: (focusDepth = this._attributes.make(this._types.number(1))), renderOdd: (renderOdd = this._attributes.make(this._types.vec2())), }; const top = new Vector3(); const bottom = new Vector3(); const handler = () => { let camera, size; if ((size = root != null ? root.getSize() : undefined) == null) { return; } π = Math.PI; const { scale } = this.props; const { fov } = this.props; const focus = this.props.focus != null ? this.props.focus : this.inherit("unit").props.focus; const isAbsolute = scale === null; // Measure live FOV to be able to accurately predict anti-aliasing in // perspective let measure = 1; if ((camera = root != null ? root.getCamera() : undefined)) { const m = camera.projectionMatrix; // Measure top to bottom top.set(0, -0.5, 1).applyMatrix4(m); bottom.set(0, 0.5, 1).applyMatrix4(m); top.sub(bottom); measure = top.y; } // Calculate device pixel ratio const dpr = size.renderHeight / size.viewHeight; // Calculate correction for fixed on-screen size regardless of FOV const fovtan = fov != null ? measure * Math.tan((fov * π) / 360) : 1; // Calculate device pixels per virtual pixel const pixel = isAbsolute ? dpr : (size.renderHeight / scale) * fovtan; // Calculate device pixels per world unit const rscale = (size.renderHeight * measure) / 2; // Calculate world units per virtual pixel const world = pixel / rscale; viewWidth.value = size.viewWidth; viewHeight.value = size.viewHeight; renderWidth.value = size.renderWidth; renderHeight.value = size.renderHeight; renderAspect.value = size.aspect; renderScale.value = rscale; renderScaleInv.value = 1 / rscale; pixelRatio.value = dpr; pixelUnit.value = pixel; worldUnit.value = world; focusDepth.value = focus; return renderOdd.value .set(size.renderWidth % 2, size.renderHeight % 2) .multiplyScalar(0.5); }; //console.log 'worldUnit', world, pixel, rscale, isAbsolute const root = this.is("root") ? this : this._inherit("root"); //@_listen root, 'root.resize', handler //@_listen root, 'root.camera', handler //@_listen @node, 'change:unit', handler this._listen(root, "root.update", handler); return handler(); }, unmake() { return delete this.unitUniforms; }, get() { const u = {}; for (const k in this.unitUniforms) { const v = this.unitUniforms[k]; u[k] = v.value; } return u; }, uniforms() { return this.unitUniforms; }, }, }; export const Helpers = function (object, traits) { const h = {}; for (const trait of Array.from(traits)) { let methods; if (!(methods = helpers[trait])) { continue; } h[trait] = {}; for (const key in methods) { const method = methods[key]; h[trait][key] = method.bind(object); } } return h; }; function __guard__(value, transform) { return typeof value !== "undefined" && value !== null ? transform(value) : undefined; }
cchudzicki/mathbox
build/esm/primitives/types/helpers.js
JavaScript
mit
21,352
export * from "./classes.js"; export * from "./traits"; export * from "./helpers.js"; export { Types } from "./types_typed";
cchudzicki/mathbox
build/esm/primitives/types/index.d.ts
TypeScript
mit
125
export * from "./classes.js"; export { Types } from "./types_typed"; export * from "./traits"; export * from "./helpers.js";
cchudzicki/mathbox
build/esm/primitives/types/index.js
JavaScript
mit
125
export class Clamp extends Operator { clampLimit: any; operator: any; resize(): any; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/clamp.d.ts
TypeScript
mit
141
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Operator } from "./operator.js"; export class Clamp extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "clamp"]; } indexShader(shader) { shader.pipe(this.operator); return super.indexShader(shader); } sourceShader(shader) { shader.pipe(this.operator); return super.sourceShader(shader); } make() { super.make(); if (this.bind.source == null) { return; } // Max index on all 4 dimensions const uniforms = { clampLimit: this._attributes.make(this._types.vec4()) }; this.clampLimit = uniforms.clampLimit; // Build shader to clamp along all dimensions const transform = this._shaders.shader(); transform.pipe("clamp.position", uniforms); return (this.operator = transform); } unmake() { return super.unmake(); } resize() { if (this.bind.source != null) { const dims = this.bind.source.getActiveDimensions(); this.clampLimit.value.set(dims.width - 1, dims.height - 1, dims.depth - 1, dims.items - 1); } return super.resize(); } change(changed, touched, _init) { if (touched["operator"] || touched["clamp"]) { return this.rebuild(); } } } Clamp.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/clamp.js
JavaScript
mit
1,799
export class Grow extends Operator { growMask: any; growAnchor: any; operator: any; resize(): any; update(): any[]; change(changed: any, touched: any, _init: any): void | any[]; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/grow.d.ts
TypeScript
mit
246
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS205: Consider reworking code to avoid use of IIFEs * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Operator } from "./operator.js"; export class Grow extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "grow"]; } sourceShader(shader) { return shader.pipe(this.operator); } make() { super.make(); if (this.bind.source == null) { return; } // Uniforms const uniforms = { growScale: this.node.attributes["grow.scale"], growMask: this._attributes.make(this._types.vec4()), growAnchor: this._attributes.make(this._types.vec4()), }; this.growMask = uniforms.growMask.value; this.growAnchor = uniforms.growAnchor.value; // Build shader to spread data on one dimension const transform = this._shaders.shader(); transform.require(this.bind.source.sourceShader(this._shaders.shader())); transform.pipe("grow.position", uniforms); return (this.operator = transform); } unmake() { return super.unmake(); } resize() { this.update(); return super.resize(); } update() { // Size to fit to include future history const dims = this.bind.source.getFutureDimensions(); const order = ["width", "height", "depth", "items"]; const m = (d, anchor) => ((d || 1) - 1) * (0.5 - anchor * 0.5); return (() => { const result = []; for (let i = 0; i < order.length; i++) { const key = order[i]; const anchor = this.props[key]; this.growMask.setComponent(i, +(anchor == null)); result.push(this.growAnchor.setComponent(i, anchor != null ? m(dims[key], anchor) : 0)); } return result; })(); } change(changed, touched, _init) { if (touched["operator"]) { return this.rebuild(); } if (touched["grow"]) { return this.update(); } } } Grow.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/grow.js
JavaScript
mit
2,511
export * from "./clamp.js"; export * from "./grow.js"; export * from "./join.js"; export * from "./lerp.js"; export * from "./memo.js"; export * from "./readback.js"; export * from "./resample.js"; export * from "./repeat.js"; export * from "./swizzle.js"; export * from "./spread.js"; export * from "./split.js"; export * from "./slice.js"; export * from "./subdivide.js"; export * from "./transpose.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/index.d.ts
TypeScript
mit
406
export * from "./clamp.js"; export * from "./grow.js"; export * from "./join.js"; export * from "./lerp.js"; export * from "./memo.js"; export * from "./readback.js"; export * from "./resample.js"; export * from "./repeat.js"; export * from "./swizzle.js"; export * from "./spread.js"; export * from "./split.js"; export * from "./slice.js"; export * from "./subdivide.js"; export * from "./transpose.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/index.js
JavaScript
mit
406
export class Join extends Operator { getDimensions(): {}; getActiveDimensions(): {}; getFutureDimensions(): {}; getIndexDimensions(): {}; _resample(dims: any): {}; make(): number | undefined; operator: any; order: any; axis: any; overlap: any; length: any; stride: number | undefined; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/join.d.ts
TypeScript
mit
377
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS104: Avoid inline assignments * DS205: Consider reworking code to avoid use of IIFEs * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import { Operator } from "./operator.js"; /* split: order: Types.transpose('wxyz') axis: Types.axis() overlap: Types.int(0) */ export class Join extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "join"]; } indexShader(shader) { shader.pipe(this.operator); return super.indexShader(shader); } sourceShader(shader) { shader.pipe(this.operator); return super.sourceShader(shader); } getDimensions() { return this._resample(this.bind.source.getDimensions()); } getActiveDimensions() { return this._resample(this.bind.source.getActiveDimensions()); } getFutureDimensions() { return this._resample(this.bind.source.getFutureDimensions()); } getIndexDimensions() { return this._resample(this.bind.source.getIndexDimensions()); } _resample(dims) { let left; let dim; const { order, axis, stride } = this; const labels = ["width", "height", "depth", "items"]; const mapped = order.map((x) => labels[x - 1]); const index = order.indexOf(axis); let set = (() => { const result = []; for (dim of Array.from(mapped)) { result.push(dims[dim]); } return result; })(); const product = ((left = set[index + 1]) != null ? left : 1) * stride; set.splice(index, 2, product); set = set.slice(0, 3); set.push(1); const out = {}; for (let i = 0; i < mapped.length; i++) { dim = mapped[i]; out[dim] = set[i]; } //console.log 'join', order, axis, length, stride //console.log dims, out return out; } make() { super.make(); if (this.bind.source == null) { return; } const { order } = this.props; let { axis } = this.props; let { overlap } = this.props; /* Calculate index transform order: wxyz length: 3 overlap: 1 axis: w index: 0 rest: 00xy axis: x index: 1 rest: w00y axis: y index: 2 rest: wx00 axis: z index: 3 rest: wxy0 */ const permute = order.join(""); if (axis == null) { axis = order[0]; } const index = permute.indexOf(axis); const rest = permute.replace(axis, "00").substring(0, 4); const labels = [null, "width", "height", "depth", "items"]; const major = labels[axis]; // Prepare uniforms const dims = this.bind.source.getDimensions(); const length = dims[major]; overlap = Math.min(length - 1, overlap); const stride = length - overlap; const uniforms = { joinStride: this._attributes.make(this._types.number(stride)), joinStrideInv: this._attributes.make(this._types.number(1 / stride)), }; // Build shader to split a dimension into two const transform = this._shaders.shader(); transform.require(UGLSL.swizzleVec4(axis, 1)); transform.require(UGLSL.swizzleVec4(rest, 4)); transform.require(UGLSL.injectVec4([index, index + 1])); transform.pipe("join.position", uniforms); transform.pipe(UGLSL.invertSwizzleVec4(order)); this.operator = transform; this.order = order; this.axis = axis; this.overlap = overlap; this.length = length; return (this.stride = stride); } unmake() { return super.unmake(); } change(changed, touched, _init) { if (touched["join"] || touched["operator"]) { return this.rebuild(); } } } Join.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/join.js
JavaScript
mit
4,509
export class Lerp extends Operator { _resample(dims: any): any; make(): boolean | undefined; resampled: {} | undefined; centered: {} | undefined; padding: {} | undefined; resampleFactor: any; resampleBias: any; operator: any; indexer: any; relativeSize: boolean | undefined; unmake(): null; resize(): any; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/lerp.d.ts
TypeScript
mit
398
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import { Operator } from "./operator.js"; export class Lerp extends Operator { static initClass() { this.traits = [ "node", "bind", "operator", "source", "index", "lerp", "sampler:x", "sampler:y", "sampler:z", "sampler:w", ]; } indexShader(shader) { shader.pipe(this.indexer); return super.indexShader(shader); } sourceShader(shader) { return shader.pipe(this.operator); } getDimensions() { return this._resample(this.bind.source.getDimensions()); } getActiveDimensions() { return this._resample(this.bind.source.getActiveDimensions()); } getFutureDimensions() { return this._resample(this.bind.source.getFutureDimensions()); } getIndexDimensions() { return this._resample(this.bind.source.getIndexDimensions()); } _resample(dims) { const r = this.resampled; const c = this.centered; const p = this.padding; if (this.relativeSize) { if (!c.items) { dims.items--; } if (!c.width) { dims.width--; } if (!c.height) { dims.height--; } if (!c.depth) { dims.depth--; } if (r.items != null) { dims.items *= r.items; } if (r.width != null) { dims.width *= r.width; } if (r.height != null) { dims.height *= r.height; } if (r.depth != null) { dims.depth *= r.depth; } if (!c.items) { dims.items++; } if (!c.width) { dims.width++; } if (!c.height) { dims.height++; } if (!c.depth) { dims.depth++; } dims.items -= p.items * 2; dims.width -= p.width * 2; dims.height -= p.height * 2; dims.depth -= p.depth * 2; } else { if (r.items != null) { dims.items = r.items; } if (r.width != null) { dims.width = r.width; } if (r.height != null) { dims.height = r.height; } if (r.depth != null) { dims.depth = r.depth; } } dims.items = Math.max(0, Math.floor(dims.items)); dims.width = Math.max(0, Math.floor(dims.width)); dims.height = Math.max(0, Math.floor(dims.height)); dims.depth = Math.max(0, Math.floor(dims.depth)); return dims; } make() { let i, key; super.make(); if (this.bind.source == null) { return; } // Get resampled dimensions const { size, items, width, height, depth } = this.props; // Sampler behavior const relativeSize = size === this.node.attributes["lerp.size"].enum.relative; this.resampled = {}; if (items != null) { this.resampled.items = items; } if (width != null) { this.resampled.width = width; } if (height != null) { this.resampled.height = height; } if (depth != null) { this.resampled.depth = depth; } this.centered = {}; this.centered.items = this.props.centeredW; this.centered.width = this.props.centeredX; this.centered.height = this.props.centeredY; this.centered.depth = this.props.centeredZ; this.padding = {}; this.padding.items = this.props.paddingW; this.padding.width = this.props.paddingX; this.padding.height = this.props.paddingY; this.padding.depth = this.props.paddingZ; // Build shader to resample data const operator = this._shaders.shader(); const indexer = this._shaders.shader(); // Uniforms const uniforms = { resampleFactor: this._attributes.make(this._types.vec4(0, 0, 0, 0)), resampleBias: this._attributes.make(this._types.vec4(0, 0, 0, 0)), }; this.resampleFactor = uniforms.resampleFactor; this.resampleBias = uniforms.resampleBias; // Has resize props? const resize = items != null || width != null || height != null || depth != null; // Add padding operator.pipe("resample.padding", uniforms); // Prepare centered sampling offset const vec = []; let any = false; const iterable = ["width", "height", "depth", "items"]; for (i = 0; i < iterable.length; i++) { key = iterable[i]; const centered = this.centered[key]; if (!any) { any = centered; } vec[i] = centered ? "0.5" : "0.0"; } let vec4; // Add centered sampling offset (from source) if (any && resize) { vec4 = `vec4(${vec})`; operator.pipe(UGLSL.binaryOperator(4, "+", vec4)); indexer.pipe(UGLSL.binaryOperator(4, "+", vec4)); } // Addressing relative to target if (resize) { operator.pipe("resample.relative", uniforms); indexer.pipe("resample.relative", uniforms); } else { operator.pipe(UGLSL.identity("vec4")); indexer.pipe(UGLSL.identity("vec4")); } // Remove centered sampling offset (to target) if (any && resize) { operator.pipe(UGLSL.binaryOperator(4, "-", vec4)); indexer.pipe(UGLSL.binaryOperator(4, "-", vec4)); } // Make sampler let sampler = this.bind.source.sourceShader(this._shaders.shader()); // Iterate over dimensions (items, width, height, depth) const iterable1 = ["width", "height", "depth", "items"]; for (i = 0; i < iterable1.length; i++) { key = iterable1[i]; const id = `lerp.${key}`; if (this.props[key] != null) { sampler = this._shaders.shader().require(sampler); sampler.pipe(id, uniforms); } } // Combine operator and composite lerp sampler operator.pipe(sampler); this.operator = operator; this.indexer = indexer; return (this.relativeSize = relativeSize); } unmake() { super.unmake(); return (this.operator = null); } resize() { if (this.bind.source == null) { return; } const dims = this.bind.source.getActiveDimensions(); const target = this.getActiveDimensions(); const axis = (key) => { const centered = this.centered[key]; const pad = this.padding[key]; target[key] += pad * 2; const res = centered ? dims[key] / Math.max(1, target[key]) : Math.max(1, dims[key] - 1) / Math.max(1, target[key] - 1); return [res, pad]; }; const [rw, bw] = Array.from(axis("width")); const [rh, bh] = Array.from(axis("height")); const [rd, bd] = Array.from(axis("depth")); const [ri, bi] = Array.from(axis("items")); this.resampleFactor.value.set(rw, rh, rd, ri); this.resampleBias.value.set(bw, bh, bd, bi); return super.resize(); } change(changed, touched, _init) { if (touched["operator"] || touched["lerp"] || touched["sampler"]) { return this.rebuild(); } } } Lerp.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/lerp.js
JavaScript
mit
8,328
export class Memo extends Operator { memo: any; compose: any; objects: any[] | undefined; renders: any; unmake(): null | undefined; update(): any; resize(): any; } import { Operator } from "./operator";
cchudzicki/mathbox
build/esm/primitives/types/operator/memo.d.ts
TypeScript
mit
231
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Operator } from "./operator"; export class Memo extends Operator { static initClass() { this.traits = [ "node", "bind", "active", "operator", "source", "index", "texture", "memo", ]; } sourceShader(shader) { return this.memo.shaderAbsolute(shader, 1); } make() { super.make(); if (this.bind.source == null) { return; } // Listen for updates this._helpers.active.make(); this._listen("root", "root.update", () => { if (this.isActive) { return this.update(); } }); // Read sampling parameters const { minFilter, magFilter, type } = this.props; // Fetch geometry dimensions const dims = this.bind.source.getDimensions(); const { items, width, height, depth } = dims; // Prepare memoization RTT this.memo = this._renderables.make("memo", { items, width, height, depth, minFilter, magFilter, type, }); // Build shader to remap data (do it after RTT creation to allow feedback) const operator = this._shaders.shader(); this.bind.source.sourceShader(operator); // Make screen renderable inside RTT scene this.compose = this._renderables.make("memoScreen", { map: operator, items, width, height, depth, }); this.memo.adopt(this.compose); this.objects = [this.compose]; return (this.renders = this.compose.renders); } unmake() { super.unmake(); if (this.bind.source != null) { this._helpers.active.unmake(); this.memo.unadopt(this.compose); this.memo.dispose(); return (this.memo = this.compose = null); } } update() { return this.memo != null ? this.memo.render() : undefined; } resize() { if (this.bind.source == null) { return; } // Fetch geometry dimensions const dims = this.bind.source.getActiveDimensions(); const { width, height, depth } = dims; // Cover only part of the RTT viewport this.compose.cover(width, height, depth); return super.resize(); } change(changed, touched, _init) { if (touched["texture"] || touched["operator"]) { return this.rebuild(); } } } Memo.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/memo.js
JavaScript
mit
3,053
export class Operator extends Source { getDimensions(): any; getFutureDimensions(): any; getActiveDimensions(): any; getIndexDimensions(): any; init(): { to: string; trait: string; }[]; sourceSpec: { to: string; trait: string; }[] | undefined; make(): any; unmake(): any; resize(_rebuild: any): any; } import { Source } from "../base/source";
cchudzicki/mathbox
build/esm/primitives/types/operator/operator.d.ts
TypeScript
mit
419
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining * DS206: Consider reworking classes to avoid initClass * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Source } from "../base/source"; export class Operator extends Source { static initClass() { this.traits = ["node", "bind", "operator", "source", "index"]; } indexShader(shader) { return __guardMethod__(this.bind.source, "indexShader", (o) => o.indexShader(shader)); } sourceShader(shader) { return __guardMethod__(this.bind.source, "sourceShader", (o) => o.sourceShader(shader)); } getDimensions() { return this.bind.source.getDimensions(); } getFutureDimensions() { return this.bind.source.getFutureDimensions(); } getActiveDimensions() { return this.bind.source.getActiveDimensions(); } getIndexDimensions() { return this.bind.source.getIndexDimensions(); } init() { return (this.sourceSpec = [{ to: "operator.source", trait: "source" }]); } make() { super.make(); // Bind to attached data sources return this._helpers.bind.make(this.sourceSpec); } made() { this.resize(); return super.made(); } unmake() { return this._helpers.bind.unmake(); } resize(_rebuild) { return this.trigger({ type: "source.resize", }); } } Operator.initClass(); function __guardMethod__(obj, methodName, transform) { if (typeof obj !== "undefined" && obj !== null && typeof obj[methodName] === "function") { return transform(obj, methodName); } else { return undefined; } }
cchudzicki/mathbox
build/esm/primitives/types/operator/operator.js
JavaScript
mit
2,002
export class Readback extends Primitive { init(): {}; emitter: any; root: any; active: {} | undefined; readback: any; unmake(): any; update(): void; resize(): number | undefined; strideI: any; strideJ: number | undefined; strideK: number | undefined; change(changed: any, _touched: any, _init: any): any; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/readback.d.ts
TypeScript
mit
403
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Primitive } from "../../primitive.js"; export class Readback extends Primitive { static initClass() { this.traits = ["node", "bind", "operator", "readback", "entity", "active"]; this.finals = { channels: 4 }; } init() { this.emitter = this.root = null; return (this.active = {}); } make() { super.make(); this._compute("readback.data", () => this.readback != null ? this.readback.data : undefined); this._compute("readback.items", () => this.readback != null ? this.readback.items : undefined); this._compute("readback.width", () => this.readback != null ? this.readback.width : undefined); this._compute("readback.height", () => this.readback != null ? this.readback.height : undefined); this._compute("readback.depth", () => this.readback != null ? this.readback.depth : undefined); // Bind to attached objects this._helpers.bind.make([{ to: "operator.source", trait: "source" }]); if (this.bind.source == null) { return; } // Sampler props const { type, channels, expr } = this.props; // Listen for updates this.root = this._inherit("root"); this._listen("root", "root.update", this.update); // Fetch source dimensions const { items, width, height, depth } = this.bind.source.getDimensions(); // Build shader to sample source data const sampler = this.bind.source.sourceShader(this._shaders.shader()); // Prepare readback/memo RTT this.readback = this._renderables.make("readback", { map: sampler, items, width, height, depth, channels, type, }); // Prepare readback consumer if (expr != null) { this.readback.setCallback(expr); } this._helpers.active.make(); } unmake() { if (this.readback != null) { this.readback.dispose(); this.readback = null; this.root = null; this.emitter = null; this.active = {}; } this._helpers.active.unmake(); return this._helpers.bind.unmake(); } update() { if (this.readback == null) { return; } if (this.isActive) { this.readback.update(this.root != null ? this.root.getCamera() : undefined); this.readback.post(); if (this.props.expr != null) { this.readback.iterate(); } } } resize() { let sI, sJ; if (this.readback == null) { return; } // Fetch geometry/html dimensions const { items, width, height, depth } = this.bind.source.getActiveDimensions(); // Limit readback to active area this.readback.setActive(items, width, height, depth); // Recalculate iteration strides this.strideI = sI = items; this.strideJ = sJ = sI * width; return (this.strideK = sJ * height); } change(changed, _touched, _init) { if (changed["readback.type"]) { return this.rebuild(); } if (changed["readback.expr"] && this.readback) { return this.readback.setCallback(this.props.expr); } } } Readback.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/readback.js
JavaScript
mit
3,810
export class Repeat extends Operator { getDimensions(): { items: number; width: number; height: number; depth: number; }; getActiveDimensions(): { items: number; width: number; height: number; depth: number; }; getFutureDimensions(): { items: number; width: number; height: number; depth: number; }; getIndexDimensions(): { items: number; width: number; height: number; depth: number; }; _resample(dims: any): { items: number; width: number; height: number; depth: number; }; resample: {} | undefined; repeatModulus: any; operator: any; resize(): any; change(changed: any, touched: any, init: any): void | any[]; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/repeat.d.ts
TypeScript
mit
877
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Operator } from "./operator.js"; export class Repeat extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "repeat"]; } indexShader(shader) { shader.pipe(this.operator); return super.indexShader(shader); } sourceShader(shader) { shader.pipe(this.operator); return super.sourceShader(shader); } getDimensions() { return this._resample(this.bind.source.getDimensions()); } getActiveDimensions() { return this._resample(this.bind.source.getActiveDimensions()); } getFutureDimensions() { return this._resample(this.bind.source.getFutureDimensions()); } getIndexDimensions() { return this._resample(this.bind.source.getIndexDimensions()); } _resample(dims) { const r = this.resample; return { items: r.items * dims.items, width: r.width * dims.width, height: r.height * dims.height, depth: r.depth * dims.depth, }; } make() { super.make(); if (this.bind.source == null) { return; } // Repeat multipliers this.resample = {}; // Modulus on all 4 dimensions const uniforms = { repeatModulus: this._attributes.make(this._types.vec4()), }; this.repeatModulus = uniforms.repeatModulus; // Build shader to repeat along all dimensions const transform = this._shaders.shader(); transform.pipe("repeat.position", uniforms); return (this.operator = transform); } unmake() { return super.unmake(); } resize() { if (this.bind.source != null) { const dims = this.bind.source.getActiveDimensions(); this.repeatModulus.value.set(dims.width, dims.height, dims.depth, dims.items); } return super.resize(); } change(changed, touched, init) { if (touched["operator"] || touched["repeat"]) { return this.rebuild(); } if (init) { return ["items", "width", "height", "depth"].map((key) => (this.resample[key] = this.props[key])); } } } Repeat.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/repeat.js
JavaScript
mit
2,680
export class Resample extends Operator { _resample(dims: any): any; make(): boolean | undefined; resampled: {} | undefined; centered: {} | undefined; padding: {} | undefined; dataResolution: any; dataSize: any; targetResolution: any; targetSize: any; resampleFactor: any; resampleBias: any; operator: any; indexer: any; indices: any; relativeSample: boolean | undefined; relativeSize: boolean | undefined; unmake(): null; resize(): any; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/resample.d.ts
TypeScript
mit
553
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import { Operator } from "./operator.js"; export class Resample extends Operator { static initClass() { this.traits = [ "node", "bind", "operator", "source", "index", "resample", "sampler:x", "sampler:y", "sampler:z", "sampler:w", "include", ]; } indexShader(shader) { shader.pipe(this.indexer); return super.indexShader(shader); } sourceShader(shader) { return shader.pipe(this.operator); } getDimensions() { return this._resample(this.bind.source.getDimensions()); } getActiveDimensions() { return this._resample(this.bind.source.getActiveDimensions()); } getFutureDimensions() { return this._resample(this.bind.source.getFutureDimensions()); } getIndexDimensions() { return this._resample(this.bind.source.getIndexDimensions()); } _resample(dims) { const r = this.resampled; const c = this.centered; const p = this.padding; if (this.relativeSize) { if (!c.items) { dims.items--; } if (!c.width) { dims.width--; } if (!c.height) { dims.height--; } if (!c.depth) { dims.depth--; } if (r.items != null) { dims.items *= r.items; } if (r.width != null) { dims.width *= r.width; } if (r.height != null) { dims.height *= r.height; } if (r.depth != null) { dims.depth *= r.depth; } if (!c.items) { dims.items++; } if (!c.width) { dims.width++; } if (!c.height) { dims.height++; } if (!c.depth) { dims.depth++; } dims.items -= p.items * 2; dims.width -= p.width * 2; dims.height -= p.height * 2; dims.depth -= p.depth * 2; } else { if (r.items != null) { dims.items = r.items; } if (r.width != null) { dims.width = r.width; } if (r.height != null) { dims.height = r.height; } if (r.depth != null) { dims.depth = r.depth; } } dims.items = Math.max(0, Math.floor(dims.items)); dims.width = Math.max(0, Math.floor(dims.width)); dims.height = Math.max(0, Math.floor(dims.height)); dims.depth = Math.max(0, Math.floor(dims.depth)); return dims; } make() { super.make(); if (this.bind.source == null) { return; } // Bind to attached shader this._helpers.bind.make([ { to: "include.shader", trait: "shader", optional: true }, ]); // Get custom shader const { indices, channels } = this.props; const { shader } = this.bind; // Get resampled dimensions (if any) const { sample, size, items, width, height, depth } = this.props; // Sampler behavior const relativeSample = sample === this.node.attributes["resample.sample"].enum.relative; const relativeSize = size === this.node.attributes["resample.size"].enum.relative; this.resampled = {}; if (items != null) { this.resampled.items = items; } if (width != null) { this.resampled.width = width; } if (height != null) { this.resampled.height = height; } if (depth != null) { this.resampled.depth = depth; } this.centered = {}; this.centered.items = this.props.centeredW; this.centered.width = this.props.centeredX; this.centered.height = this.props.centeredY; this.centered.depth = this.props.centeredZ; this.padding = {}; this.padding.items = this.props.paddingW; this.padding.width = this.props.paddingX; this.padding.height = this.props.paddingY; this.padding.depth = this.props.paddingZ; // Build shader to resample data const operator = this._shaders.shader(); const indexer = this._shaders.shader(); // Uniforms const type = [ null, this._types.number, this._types.vec2, this._types.vec3, this._types.vec4, ][indices]; const uniforms = { dataSize: this._attributes.make(type(0, 0, 0, 0)), dataResolution: this._attributes.make(type(0, 0, 0, 0)), targetSize: this._attributes.make(type(0, 0, 0, 0)), targetResolution: this._attributes.make(type(0, 0, 0, 0)), resampleFactor: this._attributes.make(this._types.vec4(0, 0, 0, 0)), resampleBias: this._attributes.make(this._types.vec4(0, 0, 0, 0)), }; this.dataResolution = uniforms.dataResolution; this.dataSize = uniforms.dataSize; this.targetResolution = uniforms.targetResolution; this.targetSize = uniforms.targetSize; this.resampleFactor = uniforms.resampleFactor; this.resampleBias = uniforms.resampleBias; // Has resize props? const resize = items != null || width != null || height != null || depth != null; // Add padding operator.pipe("resample.padding", uniforms); // Add centered sampling offset let vec = []; let any = false; const iterable = ["width", "height", "depth", "items"]; for (let i = 0; i < iterable.length; i++) { const key = iterable[i]; const centered = this.centered[key]; if (!any) { any = centered; } vec[i] = centered ? "0.5" : "0.0"; } if (any) { vec = `vec4(${vec})`; // TODO is this right? seems like copy paste. operator.pipe(UGLSL.binaryOperator(4, "+", vec)); if (resize) { indexer.pipe(UGLSL.binaryOperator(4, "+", vec)); } } if (relativeSample) { // Addressing relative to target if (resize) { operator.pipe("resample.relative", uniforms); indexer.pipe("resample.relative", uniforms); } else { indexer.pipe(UGLSL.identity("vec4")); } } if (shader != null) { if (indices !== 4) { operator.pipe(UGLSL.truncateVec(4, indices)); } operator.callback(); if (indices !== 4) { operator.pipe(UGLSL.extendVec(indices, 4)); } if (any) { operator.pipe(UGLSL.binaryOperator(4, "-", vec)); } operator.pipe(this.bind.source.sourceShader(this._shaders.shader())); if (channels !== 4) { operator.pipe(UGLSL.truncateVec(4, channels)); } operator.join(); if (this.bind.shader != null) { operator.pipe(this.bind.shader.shaderBind(uniforms)); } if (channels !== 4) { operator.pipe(UGLSL.extendVec(channels, 4)); } } else { if (any) { operator.pipe(UGLSL.binaryOperator(4, "-", vec)); } operator.pipe(this.bind.source.sourceShader(this._shaders.shader())); } if (any && resize) { indexer.pipe(UGLSL.binaryOperator(4, "-", vec)); } this.operator = operator; this.indexer = indexer; this.indices = indices; this.relativeSample = relativeSample; return (this.relativeSize = relativeSize); } unmake() { super.unmake(); return (this.operator = null); } resize() { if (this.bind.source == null) { return; } const dims = this.bind.source.getActiveDimensions(); const target = this.getActiveDimensions(); const axis = (key) => { const centered = this.centered[key]; const pad = this.padding[key]; target[key] += pad * 2; const res = centered ? dims[key] / Math.max(1, target[key]) : Math.max(1, dims[key] - 1) / Math.max(1, target[key] - 1); return [res, pad]; }; const [rw, bw] = Array.from(axis("width")); const [rh, bh] = Array.from(axis("height")); const [rd, bd] = Array.from(axis("depth")); const [ri, bi] = Array.from(axis("items")); if (this.indices === 1) { this.dataResolution.value = 1 / dims.width; this.targetResolution.value = 1 / target.width; this.dataSize.value = dims.width; this.targetSize.value = target.width; } else { this.dataResolution.value.set(1 / dims.width, 1 / dims.height, 1 / dims.depth, 1 / dims.items); this.targetResolution.value.set(1 / target.width, 1 / target.height, 1 / target.depth, 1 / target.items); this.dataSize.value.set(dims.width, dims.height, dims.depth, dims.items); this.targetSize.value.set(target.width, target.height, target.depth, target.items); } this.resampleFactor.value.set(rw, rh, rd, ri); this.resampleBias.value.set(bw, bh, bd, bi); return super.resize(); } change(changed, touched, _init) { if (touched["operator"] || touched["resample"] || touched["sampler"] || touched["include"]) { return this.rebuild(); } } } Resample.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/resample.js
JavaScript
mit
10,583
export class Slice extends Operator { _resolve(key: any, dims: any): any[]; _resample(dims: any): any; make(): { sliceOffset: any; } | undefined; uniforms: { sliceOffset: any; } | undefined; resize(): any; change(changed: any, touched: any, _init: any): any; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/slice.d.ts
TypeScript
mit
351
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Operator } from "./operator.js"; export class Slice extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "slice"]; } getDimensions() { return this._resample(this.bind.source.getDimensions()); } getActiveDimensions() { return this._resample(this.bind.source.getActiveDimensions()); } getFutureDimensions() { return this._resample(this.bind.source.getFutureDimensions()); } getIndexDimensions() { return this._resample(this.bind.source.getIndexDimensions()); } sourceShader(shader) { shader.pipe("slice.position", this.uniforms); return this.bind.source.sourceShader(shader); } _resolve(key, dims) { const range = this.props[key]; const dim = dims[key]; if (range == null) { return [0, dim]; } const index = function (i, dim) { if (i < 0) { return dim + i; } else { return i; } }; const start = index(Math.round(range.x), dim); let end = index(Math.round(range.y), dim); end = Math.max(start, end); return [start, end - start]; } _resample(dims) { dims.width = this._resolve("width", dims)[1]; dims.height = this._resolve("height", dims)[1]; dims.depth = this._resolve("depth", dims)[1]; dims.items = this._resolve("items", dims)[1]; return dims; } make() { super.make(); if (this.bind.source == null) { return; } return (this.uniforms = { sliceOffset: this._attributes.make(this._types.vec4()), }); } unmake() { return super.unmake(); } resize() { if (this.bind.source == null) { return; } const dims = this.bind.source.getActiveDimensions(); this.uniforms.sliceOffset.value.set(this._resolve("width", dims)[0], this._resolve("height", dims)[0], this._resolve("depth", dims)[0], this._resolve("items", dims)[0]); return super.resize(); } change(changed, touched, _init) { if (touched["operator"]) { return this.rebuild(); } if (touched["slice"]) { return this.resize(); } } } Slice.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/slice.js
JavaScript
mit
2,811
export class Split extends Operator { getDimensions(): {}; getActiveDimensions(): {}; getFutureDimensions(): {}; getIndexDimensions(): {}; _resample(dims: any): {}; make(): number | undefined; operator: any; order: any; axis: any; overlap: any; length: any; stride: number | undefined; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/split.d.ts
TypeScript
mit
378
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS104: Avoid inline assignments * DS205: Consider reworking code to avoid use of IIFEs * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import { Operator } from "./operator.js"; /* split: order: Types.transpose('wxyz') axis: Types.axis() length: Types.int(1) overlap: Types.int(0) */ export class Split extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "split"]; } indexShader(shader) { shader.pipe(this.operator); return super.indexShader(shader); } sourceShader(shader) { shader.pipe(this.operator); return super.sourceShader(shader); } getDimensions() { return this._resample(this.bind.source.getDimensions()); } getActiveDimensions() { return this._resample(this.bind.source.getActiveDimensions()); } getFutureDimensions() { return this._resample(this.bind.source.getFutureDimensions()); } getIndexDimensions() { return this._resample(this.bind.source.getIndexDimensions()); } _resample(dims) { let dim; const { order } = this; const { axis } = this; const { overlap } = this; const { length } = this; const { stride } = this; const labels = ["width", "height", "depth", "items"]; const mapped = order.map((x) => labels[x - 1]); const index = order.indexOf(axis); let set = (() => { const result = []; for (dim of Array.from(mapped)) { result.push(dims[dim]); } return result; })(); const remain = Math.floor((set[index] - overlap) / stride); set.splice(index, 1, length, remain); set = set.slice(0, 4); const out = {}; for (let i = 0; i < mapped.length; i++) { dim = mapped[i]; out[dim] = set[i]; } //console.log 'split', order, axis, length, stride //console.log dims, out return out; } make() { let left; super.make(); if (this.bind.source == null) { return; } const { order } = this.props; let { axis } = this.props; let { overlap } = this.props; const { length } = this.props; /* Calculate index transform order: wxyz length: 3 overlap: 1 axis: w index: 0 split: wx rest: 0yz0 s axis: x index: 1 split: xy rest: w0z0 s axis: y index: 2 split: yz rest: wx00 s axis: z index: 3 split: z0 rest: wxy0 s */ const permute = order.join(""); if (axis == null) { axis = order[0]; } const index = permute.indexOf(axis); const split = permute[index] + ((left = permute[index + 1]) != null ? left : 0); const rest = permute.replace(split[1], "").replace(split[0], "0") + "0"; // Prepare uniforms overlap = Math.min(length - 1, overlap); const stride = length - overlap; const uniforms = { splitStride: this._attributes.make(this._types.number(stride)), }; // Build shader to split a dimension into two const transform = this._shaders.shader(); transform.require(UGLSL.swizzleVec4(split, 2)); transform.require(UGLSL.swizzleVec4(rest, 4)); transform.require(UGLSL.injectVec4(index)); transform.pipe("split.position", uniforms); transform.pipe(UGLSL.invertSwizzleVec4(order)); this.operator = transform; this.order = order; this.axis = axis; this.overlap = overlap; this.length = length; return (this.stride = stride); } unmake() { return super.unmake(); } change(changed, touched, _init) { if (changed["split.axis"] || changed["split.order"] || touched["operator"]) { return this.rebuild(); } } } Split.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/split.js
JavaScript
mit
4,693
export class Spread extends Operator { spreadMatrix: any; spreadOffset: any; operator: any; resize(): any; update(): any[][]; change(changed: any, touched: any, _init: any): void | any[][]; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/spread.d.ts
TypeScript
mit
258
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS104: Avoid inline assignments * DS205: Consider reworking code to avoid use of IIFEs * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Operator } from "./operator.js"; export class Spread extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "spread"]; } sourceShader(shader) { return shader.pipe(this.operator); } make() { super.make(); if (this.bind.source == null) { return; } // Uniforms const uniforms = { spreadMatrix: this._attributes.make(this._types.mat4()), spreadOffset: this._attributes.make(this._types.vec4()), }; this.spreadMatrix = uniforms.spreadMatrix; this.spreadOffset = uniforms.spreadOffset; // Build shader to spread data on one dimension const transform = this._shaders.shader(); transform.require(this.bind.source.sourceShader(this._shaders.shader())); transform.pipe("spread.position", uniforms); return (this.operator = transform); } unmake() { return super.unmake(); } resize() { this.update(); return super.resize(); } update() { // Size to fit to include future history let key, i, k, v; const dims = this.bind.source.getFutureDimensions(); const matrix = this.spreadMatrix.value; const els = matrix.elements; const order = ["width", "height", "depth", "items"]; const align = ["alignWidth", "alignHeight", "alignDepth", "alignItems"]; const { unit } = this.props; const unitEnum = this.node.attributes["spread.unit"].enum; const map = (() => { switch (unit) { case unitEnum.relative: return (key, i, k, v) => (els[i * 4 + k] = v / Math.max(1, dims[key] - 1)); case unitEnum.absolute: return (key, i, k, v) => (els[i * 4 + k] = v); } })(); return (() => { const result = []; for (i = 0; i < order.length; i++) { let offset; key = order[i]; const spread = this.props[key]; const anchor = this.props[align[i]]; if (spread != null) { const d = dims[key] != null ? dims[key] : 1; offset = -(d - 1) * (0.5 - anchor * 0.5); } else { offset = 0; } this.spreadOffset.value.setComponent(i, offset); result.push((() => { const result1 = []; for (k = 0; k <= 3; k++) { let left; v = (left = spread != null ? spread.getComponent(k) : undefined) != null ? left : 0; result1.push((els[i * 4 + k] = map(key, i, k, v))); } return result1; })()); } return result; })(); } change(changed, touched, _init) { if (touched["operator"]) { return this.rebuild(); } if (touched["spread"]) { return this.update(); } } } Spread.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/spread.js
JavaScript
mit
3,824
export class Subdivide extends Operator { _resample(dims: any): any; resampled: {} | undefined; resampleFactor: any; resampleBias: any; operator: any; indexer: any; unmake(): null; resize(): any; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/subdivide.d.ts
TypeScript
mit
272
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import { Operator } from "./operator.js"; export class Subdivide extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "subdivide"]; } indexShader(shader) { shader.pipe(this.indexer); return super.indexShader(shader); } sourceShader(shader) { return shader.pipe(this.operator); } getDimensions() { return this._resample(this.bind.source.getDimensions()); } getActiveDimensions() { return this._resample(this.bind.source.getActiveDimensions()); } getFutureDimensions() { return this._resample(this.bind.source.getFutureDimensions()); } getIndexDimensions() { return this._resample(this.bind.source.getIndexDimensions()); } _resample(dims) { const r = this.resampled; dims.items--; dims.width--; dims.height--; dims.depth--; if (r.items != null) { dims.items *= r.items; } if (r.width != null) { dims.width *= r.width; } if (r.height != null) { dims.height *= r.height; } if (r.depth != null) { dims.depth *= r.depth; } dims.items++; dims.width++; dims.height++; dims.depth++; return dims; } make() { super.make(); if (this.bind.source == null) { return; } // Get resampled dimensions let { lerp } = this.props; const { items, width, height, depth } = this.props; this.resampled = {}; if (items != null) { this.resampled.items = items; } if (width != null) { this.resampled.width = width; } if (height != null) { this.resampled.height = height; } if (depth != null) { this.resampled.depth = depth; } // Build shader to resample data const operator = this._shaders.shader(); const indexer = this._shaders.shader(); // Uniforms const uniforms = { resampleFactor: this._attributes.make(this._types.vec4(0, 0, 0, 0)), subdivideBevel: this.node.attributes["subdivide.bevel"], }; this.resampleFactor = uniforms.resampleFactor; this.resampleBias = uniforms.resampleBias; // Has resize props? const resize = items != null || width != null || height != null || depth != null; // Addressing relative to target if (resize) { operator.pipe("resample.relative", uniforms); indexer.pipe("resample.relative", uniforms); } else { operator.pipe(UGLSL.identity("vec4")); indexer.pipe(UGLSL.identity("vec4")); } // Make sampler let sampler = this.bind.source.sourceShader(this._shaders.shader()); lerp = lerp ? ".lerp" : ""; // Iterate over dimensions (items, width, height, depth) const iterable = ["width", "height", "depth", "items"]; for (let i = 0; i < iterable.length; i++) { const key = iterable[i]; const id = `subdivide.${key}${lerp}`; if (this.props[key] != null) { sampler = this._shaders.shader().require(sampler); sampler.pipe(id, uniforms); } } // Combine operator and composite lerp sampler operator.pipe(sampler); this.operator = operator; return (this.indexer = indexer); } unmake() { super.unmake(); return (this.operator = null); } resize() { if (this.bind.source == null) { return; } const dims = this.bind.source.getActiveDimensions(); const target = this.getActiveDimensions(); const axis = (key) => Math.max(1, dims[key] - 1) / Math.max(1, target[key] - 1); const rw = axis("width"); const rh = axis("height"); const rd = axis("depth"); const ri = axis("items"); this.resampleFactor.value.set(rw, rh, rd, ri); return super.resize(); } change(changed, touched, _init) { if (touched["operator"] || touched["subdivide"]) { return this.rebuild(); } } } Subdivide.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/subdivide.js
JavaScript
mit
4,821
export class Swizzle extends Operator { make(): string | undefined; swizzler: string | null | undefined; unmake(): null; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/swizzle.d.ts
TypeScript
mit
177
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import { Operator } from "./operator.js"; export class Swizzle extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "swizzle"]; } sourceShader(shader) { shader = super.sourceShader(shader); if (this.swizzler) { shader.pipe(this.swizzler); } return shader; } make() { super.make(); if (this.bind.source == null) { return; } // Swizzling order const { order } = this.props; if (order.join() !== "1234") { return (this.swizzler = UGLSL.swizzleVec4(order, 4)); } } unmake() { super.unmake(); return (this.swizzler = null); } change(changed, touched, _init) { if (touched["swizzle"] || touched["operator"]) { return this.rebuild(); } } } Swizzle.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/swizzle.js
JavaScript
mit
1,382
export class Transpose extends Operator { getDimensions(): {}; getActiveDimensions(): {}; getFutureDimensions(): {}; getIndexDimensions(): {}; _remap(transpose: any, dims: any): {}; swizzler: string | null | undefined; transpose: any; unmake(): null; } import { Operator } from "./operator.js";
cchudzicki/mathbox
build/esm/primitives/types/operator/transpose.d.ts
TypeScript
mit
327
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import { Operator } from "./operator.js"; const labels = { 1: "width", 2: "height", 3: "depth", 4: "items", }; export class Transpose extends Operator { static initClass() { this.traits = ["node", "bind", "operator", "source", "index", "transpose"]; } indexShader(shader) { if (this.swizzler) { shader.pipe(this.swizzler); } return super.indexShader(shader); } sourceShader(shader) { if (this.swizzler) { shader.pipe(this.swizzler); } return super.sourceShader(shader); } getDimensions() { return this._remap(this.transpose, this.bind.source.getDimensions()); } getActiveDimensions() { return this._remap(this.transpose, this.bind.source.getActiveDimensions()); } getFutureDimensions() { return this._remap(this.transpose, this.bind.source.getFutureDimensions()); } getIndexDimensions() { return this._remap(this.transpose, this.bind.source.getIndexDimensions()); } _remap(transpose, dims) { // Map dimensions onto their new axis const out = {}; for (let i = 0; i <= 3; i++) { const dst = labels[i + 1]; const src = labels[transpose[i]]; out[dst] = dims[src] != null ? dims[src] : 1; } return out; } make() { super.make(); if (this.bind.source == null) { return; } // Transposition order const { order } = this.props; if (order.join() !== "1234") { this.swizzler = UGLSL.invertSwizzleVec4(order); } this.transpose = order; // Notify of reallocation return this.trigger({ type: "source.rebuild", }); } unmake() { super.unmake(); return (this.swizzler = null); } change(changed, touched, _init) { if (touched["transpose"] || touched["operator"]) { return this.rebuild(); } } } Transpose.initClass();
cchudzicki/mathbox
build/esm/primitives/types/operator/transpose.js
JavaScript
mit
2,521
export class DOM extends Primitive { emitter: { (x: any, y: any, z: any, w: any, i: any, j: any, k: any, l: any): number; reset(): "auto" | undefined; nodes(): any[]; } | null | undefined; root: any; active: {} | undefined; readback: any; dom: any; unmake(): void; update(): void; post(): void; callback(data: any): { (x: any, y: any, z: any, w: any, i: any, j: any, k: any, l: any): number; reset(): "auto" | undefined; nodes(): any[]; }; resize(): void; strideI: any; strideJ: number | undefined; strideK: number | undefined; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/overlay/dom.d.ts
TypeScript
mit
686
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Primitive } from "../../primitive.js"; export class DOM extends Primitive { static initClass() { this.traits = [ "node", "bind", "object", "visible", "overlay", "dom", "attach", "position", ]; } init() { this.emitter = this.root = null; this.active = {}; } make() { super.make(); // Bind to attached objects this._helpers.bind.make([ { to: "dom.html", trait: "html" }, { to: "dom.points", trait: "source" }, ]); if (this.bind.points == null || this.bind.html == null) { return; } // Listen for updates this.root = this._inherit("root"); this._listen("root", "root.update", this.update); this._listen("root", "root.post", this.post); // Fetch geometry dimensions const pointDims = this.bind.points.getDimensions(); const htmlDims = this.bind.html.getDimensions(); const items = Math.min(pointDims.items, htmlDims.items); const width = Math.min(pointDims.width, htmlDims.width); const height = Math.min(pointDims.height, htmlDims.height); const depth = Math.min(pointDims.depth, htmlDims.depth); // Build shader to sample position data let position = this.bind.points.sourceShader(this._shaders.shader()); // Transform data into screen space position = this._helpers.position.pipeline(position); // Apply global projection const projection = this._shaders.shader({ globals: ["projectionMatrix"] }); projection.pipe("project.readback"); position.pipe(projection); // Build nop index shader const indexer = this._shaders.shader(); // Prepare readback/memo RTT this.readback = this._renderables.make("readback", { map: position, indexer, items, width, height, depth, channels: 4, stpq: true, }); // Prepare overlay container VDOM this.dom = this._overlays.make("dom"); this.dom.hint(items * width * height * depth * 2); // Make sure we have enough for wrapping each given element once // Prepare readback consumer this.emitter = this.callback(this.bind.html.nodes()); this.readback.setCallback(this.emitter); this._helpers.visible.make(); } unmake() { if (this.readback != null) { this.readback.dispose(); this.dom.dispose(); this.readback = this.dom = null; this.root = null; this.emitter = null; this.active = {}; } this._helpers.bind.unmake(); this._helpers.visible.unmake(); } update() { if (this.readback == null) { return; } if (this.props.visible) { this.readback.update(this.root != null ? this.root.getCamera() : undefined); this.readback.post(); this.readback.iterate(); } } post() { if (this.readback == null) { return; } this.dom.render(this.isVisible ? this.emitter.nodes() : null); } callback(data) { // Create static consumer for the readback let strideJ, strideK; const uniforms = this._inherit("unit").getUnitUniforms(); const width = uniforms.viewWidth; const height = uniforms.viewHeight; const attr = this.node.attributes["dom.attributes"]; const size = this.node.attributes["dom.size"]; const zoom = this.node.attributes["dom.zoom"]; const color = this.node.attributes["dom.color"]; const outline = this.node.attributes["dom.outline"]; const pointer = this.node.attributes["dom.pointerEvents"]; const opacity = this.node.attributes["overlay.opacity"]; const zIndex = this.node.attributes["overlay.zIndex"]; const offset = this.node.attributes["attach.offset"]; const depth = this.node.attributes["attach.depth"]; const snap = this.node.attributes["attach.snap"]; const { el } = this.dom; let nodes = []; let styles = null; let className = null; let strideI = (strideJ = strideK = 0); let colorString = ""; const f = function (x, y, z, w, i, j, k, l) { // Get HTML item by offset let v; const index = l + strideI * i + strideJ * j + strideK * k; const children = data[index]; // Clip behind camera or when invisible const clip = w < 0; // Depth blending const iw = 1 / w; const flatZ = 1 + (iw - 1) * depth.value; const scale = clip ? 0 : flatZ; // GL to CSS coordinate transform const ox = +offset.value.x * scale; const oy = +offset.value.y * scale; let xx = (x + 1) * width.value * 0.5 + ox; let yy = (y - 1) * height.value * 0.5 + oy; // Handle zoom/scale xx /= zoom.value; yy /= zoom.value; // Snap to pixel if (snap.value) { xx = Math.round(xx); yy = Math.round(yy); } // Clip and apply opacity const alpha = Math.min(0.999, clip ? 0 : opacity.value); // Generate div const props = { className, style: { transform: `translate3d(${xx}px, ${-yy}px, ${1 - w}px) translate(-50%, -50%) scale(${scale},${scale})`, opacity: alpha, }, }; for (k in styles) { v = styles[k]; props.style[k] = v; } // Merge in external attributes const a = attr.value; if (a != null) { const s = a.style; for (k in a) { v = a[k]; if (!["style", "className"].includes(k)) { props[k] = v; } } if (s != null) { for (k in s) { v = s[k]; props.style[k] = v; } } } props.className += " " + ((a != null ? a.className : undefined) != null ? a != null ? a.className : undefined : "mathbox-label"); // Push node onto list return nodes.push(el("div", props, children)); }; f.reset = () => { nodes = []; [strideI, strideJ, strideK] = Array.from([ this.strideI, this.strideJ, this.strideK, ]); const c = color.value; const m = (x) => Math.floor(x * 255); colorString = c ? `rgb(${[m(c.x), m(c.y), m(c.z)]})` : ""; className = `mathbox-outline-${Math.round(outline.value)}`; styles = {}; if (c) { styles.color = colorString; } styles.fontSize = `${size.value}px`; if (zoom.value !== 1) { styles.zoom = zoom.value; } if (zIndex.value > 0) { styles.zIndex = zIndex.value; } if (pointer.value) { return (styles.pointerEvents = "auto"); } }; f.nodes = () => nodes; return f; } resize() { let sI, sJ; if (this.readback == null) { return; } // Fetch geometry/html dimensions const pointDims = this.bind.points.getActiveDimensions(); const htmlDims = this.bind.html.getActiveDimensions(); const items = Math.min(pointDims.items, htmlDims.items); const width = Math.min(pointDims.width, htmlDims.width); const height = Math.min(pointDims.height, htmlDims.height); const depth = Math.min(pointDims.depth, htmlDims.depth); // Limit readback to active area this.readback.setActive(items, width, height, depth); // Recalculate iteration strides this.strideI = sI = htmlDims.items; this.strideJ = sJ = sI * htmlDims.width; this.strideK = sJ * htmlDims.height; } change(changed, _touched, _init) { if (changed["dom.html"] || changed["dom.points"]) { return this.rebuild(); } } } DOM.initClass();
cchudzicki/mathbox
build/esm/primitives/types/overlay/dom.js
JavaScript
mit
9,260
export class HTML extends Voxel { dom: any; nodes(): any; callback(callback: any): (emit: any, i: any, j: any, k: any, l: any) => any; } import { Voxel } from "../data/voxel.js";
cchudzicki/mathbox
build/esm/primitives/types/overlay/html.d.ts
TypeScript
mit
191
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Voxel } from "../data/voxel.js"; export class HTML extends Voxel { static initClass() { this.traits = ["node", "buffer", "active", "data", "voxel", "html"]; this.finals = { channels: 1 }; } init() { super.init(); this.storage = "pushBuffer"; } make() { super.make(); // Get our own size const { items, width, height, depth } = this.getDimensions(); // Prepare DOM element factory this.dom = this._overlays.make("dom"); return this.dom.hint(items * width * height * depth); } unmake() { super.unmake(); if (this.dom != null) { this.dom.dispose(); return (this.dom = null); } } update() { return super.update(); } change(changed, touched, init) { if (touched["html"]) { return this.rebuild(); } return super.change(changed, touched, init); } nodes() { return this.buffer.read(); } callback(callback) { const { el } = this.dom; if (callback.length <= 6) { return (emit, i, j, k, l) => callback(emit, el, i, j, k, l); } else { return (emit, i, j, k, l) => { return callback(emit, el, i, j, k, l, this.bufferClock, this.bufferStep); }; } } } HTML.initClass();
cchudzicki/mathbox
build/esm/primitives/types/overlay/html.js
JavaScript
mit
1,815
export * from "./html.js"; export * from "./dom.js";
cchudzicki/mathbox
build/esm/primitives/types/overlay/index.d.ts
TypeScript
mit
53
export * from "./html.js"; export * from "./dom.js";
cchudzicki/mathbox
build/esm/primitives/types/overlay/index.js
JavaScript
mit
53
export * from "./move.js"; export * from "./play.js"; export * from "./present.js"; export * from "./reveal.js"; export * from "./slide.js"; export * from "./step.js";
cchudzicki/mathbox
build/esm/primitives/types/present/index.d.ts
TypeScript
mit
168
export * from "./move.js"; export * from "./play.js"; export * from "./present.js"; export * from "./reveal.js"; export * from "./slide.js"; export * from "./step.js";
cchudzicki/mathbox
build/esm/primitives/types/present/index.js
JavaScript
mit
168
export class Move extends Transition { make(): void; vertex(shader: any, pass: any): any; } import { Transition } from "./transition.js";
cchudzicki/mathbox
build/esm/primitives/types/present/move.d.ts
TypeScript
mit
146
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining * DS104: Avoid inline assignments * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Transition } from "./transition.js"; export class Move extends Transition { static initClass() { this.traits = ["node", "transition", "vertex", "move", "visible", "active"]; } make() { super.make(); const object = { moveFrom: this.node.attributes["move.from"], moveTo: this.node.attributes["move.to"], }; for (const k in object) { const v = object[k]; this.uniforms[k] = v; } } vertex(shader, pass) { let left; if (pass === this.props.pass) { shader.pipe("move.position", this.uniforms); } return (left = __guard__(this._inherit("vertex"), (x) => x.vertex(shader, pass))) != null ? left : shader; } } Move.initClass(); function __guard__(value, transform) { return typeof value !== "undefined" && value !== null ? transform(value) : undefined; }
cchudzicki/mathbox
build/esm/primitives/types/present/move.js
JavaScript
mit
1,507
export class Play extends Track { skew: number | null | undefined; reset(go: any): null; make(): any; } import { Track } from "./track.js";
cchudzicki/mathbox
build/esm/primitives/types/present/play.d.ts
TypeScript
mit
152
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Track } from "./track.js"; export class Play extends Track { static initClass() { this.traits = ["node", "track", "trigger", "play", "bind"]; } init() { super.init(); this.skew = null; return (this.start = null); } reset(go) { if (go == null) { go = true; } this.skew = go ? 0 : null; return (this.start = null); } make() { super.make(); // Start on slide, or immediately if not inside slide this._listen("slide", "slide.step", (e) => { const { trigger } = this.props; if (trigger != null && e.index === trigger) { return this.reset(); } if (trigger != null && e.index === 0) { return this.reset(false); } }); if (!this.props.trigger || this._inherit("slide") == null) { this.reset(); } // Find parent clock const parentClock = this._inherit("clock"); // Update clock return this._listen(parentClock, "clock.tick", () => { const { from, to, speed, pace, delay, realtime } = this.props; const time = parentClock.getTime(); if (this.skew != null) { const now = realtime ? time.time : time.clock; const delta = realtime ? time.delta : time.step; const ratio = speed / pace; if (this.start == null) { this.start = now; } this.skew += delta * (ratio - 1); let offset = Math.max(0, now - this.start + this.skew - delay * ratio); if (this.props.loop) { offset = offset % (to - from); } this.playhead = Math.min(to, from + offset); } else { this.playhead = 0; } return this.update(); }); } update() { return super.update(); } change(changed, touched, init) { if (changed["trigger.trigger"] || changed["play.realtime"]) { return this.rebuild(); } return super.change(changed, touched, init); } } Play.initClass();
cchudzicki/mathbox
build/esm/primitives/types/present/play.js
JavaScript
mit
2,689
export class Present extends Parent { make(): any; nodes: any; steps: any[] | undefined; length: number | undefined; last: any; index: any; dirty: any[] | undefined; adopt(controller: any): number; unadopt(controller: any): number; update(): never[] | undefined; slideLatch(controller: any, enabled: any, step: any): any; slideStep(controller: any, index: any, step: any): any; slideRelease(controller: any, _step: any): any; slideReset(controller: any): any; mapIndex(controller: any, index: any): number; process(nodes: any): {}[]; go(index: any): void; } import { Parent } from "../base/parent.js";
cchudzicki/mathbox
build/esm/primitives/types/present/present.d.ts
TypeScript
mit
670
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS104: Avoid inline assignments * DS202: Simplify dynamic range loops * DS205: Consider reworking code to avoid use of IIFEs * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Parent } from "../base/parent.js"; export class Present extends Parent { static initClass() { this.traits = ["node", "present"]; } init() { } make() { this.nodes = []; this.steps = []; this.length = 0; this.last = []; this.index = 0; this.dirty = []; this._listen("root", "root.update", this.update); return this._compute("present.length", () => this.length); } adopt(controller) { const { node } = controller; if (this.nodes.indexOf(controller) < 0) { this.nodes.push(node); } return this.dirty.push(controller); } unadopt(controller) { this.nodes = this.nodes.filter((x) => x !== controller); return this.dirty.push(controller); } update() { if (!this.dirty.length) { return; } for (const controller of Array.from(this.dirty)) { this.slideReset(controller); } [this.steps, this.indices] = Array.from(this.process(this.nodes)); this.length = this.steps.length; this.index = null; this.go(this.props.index); return (this.dirty = []); } slideLatch(controller, enabled, step) { return controller.slideLatch(enabled, step); } slideStep(controller, index, step) { return controller.slideStep(this.mapIndex(controller, index), step); } slideRelease(controller, _step) { return controller.slideRelease(); } slideReset(controller) { return controller.slideReset(); } mapIndex(controller, index) { return index - this.indices[controller.node._id]; } process(nodes) { // Grab nodes' path of slide parents const slides = (nodes) => Array.from(nodes).map((el) => parents(el).filter(isSlide)); const traverse = (map) => (el) => (() => { let ref, ref1; const result = []; while (el && (([el, ref] = Array.from((ref1 = [map(el), el]))), ref1)) { result.push(ref); } return result; })(); const parents = traverse(function (el) { if (el.parent.traits.hash.present) { return null; } else { return el.parent; } }); // Helpers const isSlide = (el) => nodes.indexOf(el) >= 0; // Order paths (leaf -> parent slide -> ...) const order = (paths) => paths.sort(function (a, b) { // Path lengths const c = a.length; const d = b.length; // Compare from outside in let e = Math.min(c, d); for (let i = 1, end = e, asc = 1 <= end; asc ? i <= end : i >= end; asc ? i++ : i--) { // inclusive end const nodeA = a[c - i]; const nodeB = b[d - i]; // Explicit sibling order (natural) const f = nodeA.props.order; const g = nodeB.props.order; if (f != null || g != null) { if (f != null && g != null && (e = f - g) !== 0) { return e; } if (f != null) { return -1; } if (g != null) { return 1; } } // Document sibling order (inverted) if (nodeB.order !== nodeA.order) { return nodeB.order - nodeA.order; } } // Different tree level e = c - d; if (e !== 0) { return e; } // Equal return 0; }); const split = function (steps) { const relative = []; const absolute = []; for (const step of Array.from(steps)) { (step[0].props.steps != null ? relative : absolute).push(step); } return [relative, absolute]; }; const expand = function (lists) { let step; const [relative, absolute] = Array.from(lists); const limit = 100; const indices = {}; let steps = []; const slide = function (step, index) { let node; const { props } = (node = step[0]); const parent = step[1]; const parentIndex = parent != null ? indices[parent._id] : 0; //throw "parent index missing" if !parentIndex? const childIndex = index; let from = props.from != null ? parentIndex + props.from : childIndex - props.early; let to = props.to != null ? parentIndex + props.to : childIndex + props.steps + props.late; from = Math.max(0, from); to = Math.min(limit, to); if (indices[node._id] == null) { indices[node._id] = from; } for (let i = from, end = to, asc = from <= end; asc ? i < end : i > end; asc ? i++ : i--) { steps[i] = (steps[i] != null ? steps[i] : (steps[i] = [])).concat(step); } return props.steps; }; let i = 0; for (step of Array.from(relative)) { i += slide(step, i); } for (step of Array.from(absolute)) { slide(step, 0); } // Dedupe and order steps = (() => { const result = []; for (step of Array.from(steps)) { result.push(finalize(dedupe(step))); } return result; })(); return [steps, indices]; }; // Remove duplicates const dedupe = function (step) { if (step) { return (() => { const result = []; for (let i = 0; i < step.length; i++) { const node = step[i]; if (step.indexOf(node) === i) { result.push(node); } } return result; })(); } else { return []; } }; // Finalize individual step by document order const finalize = (step) => step.sort((a, b) => a.order - b.order); const paths = slides(nodes); const steps = order(paths); return expand(split(steps)); } go(index) { // Pad with an empty slide before and after for initial enter/final exit let left; let node; index = Math.max(0, Math.min(this.length + 1, +index || 0)); const active = (left = this.steps[index - 1]) != null ? left : []; const step = this.props.directed ? index - this.index : 1; this.index = index; const enter = (() => { const result = []; for (node of Array.from(active)) { if (this.last.indexOf(node) < 0) { result.push(node); } } return result; })(); const exit = (() => { const result1 = []; for (node of Array.from(this.last)) { if (active.indexOf(node) < 0) { result1.push(node); } } return result1; })(); const stay = (() => { const result2 = []; for (node of Array.from(active)) { if (enter.indexOf(node) < 0 && exit.indexOf(node) < 0) { result2.push(node); } } return result2; })(); const ascend = (nodes) => nodes.sort((a, b) => a.order - b.order); const descend = (nodes) => nodes.sort((a, b) => b.order - a.order); //const toStr = (x) => x.toString(); //console.log '============================================================' //console.log 'go', index, {enter: enter.map(toStr), stay: stay.map(toStr), exit: exit.map(toStr)} for (node of Array.from(ascend(enter))) { this.slideLatch(node.controller, true, step); } for (node of Array.from(ascend(stay))) { this.slideLatch(node.controller, null, step); } for (node of Array.from(ascend(exit))) { this.slideLatch(node.controller, false, step); } for (node of Array.from(enter)) { this.slideStep(node.controller, index, step); } for (node of Array.from(stay)) { this.slideStep(node.controller, index, step); } for (node of Array.from(exit)) { this.slideStep(node.controller, index, step); } for (node of Array.from(descend(enter))) { this.slideRelease(node.controller); } for (node of Array.from(descend(stay))) { this.slideRelease(node.controller); } for (node of Array.from(descend(exit))) { this.slideRelease(node.controller); } this.last = active; } change(changed, touched, init) { if (changed["present.index"] || init) { return this.go(this.props.index); } } } Present.initClass();
cchudzicki/mathbox
build/esm/primitives/types/present/present.js
JavaScript
mit
10,205
export class Reveal extends Transition { mask(shader: any): any; } import { Transition } from "./transition.js";
cchudzicki/mathbox
build/esm/primitives/types/present/reveal.d.ts
TypeScript
mit
117
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining * DS104: Avoid inline assignments * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as UGLSL from "../../../util/glsl.js"; import { Transition } from "./transition.js"; export class Reveal extends Transition { static initClass() { this.traits = ["node", "transition", "mask", "visible", "active"]; } mask(shader) { let left, s; if (shader) { s = this._shaders.shader(); s.pipe(UGLSL.identity("vec4")); s.fan(); s.pipe(shader, this.uniforms); s.next(); s.pipe("reveal.mask", this.uniforms); s.end(); s.pipe("float combine(float a, float b) { return min(a, b); }"); } else { s = this._shaders.shader(); s.pipe("reveal.mask", this.uniforms); } return (left = __guard__(this._inherit("mask"), (x) => x.mask(s))) != null ? left : s; } } Reveal.initClass(); function __guard__(value, transform) { return typeof value !== "undefined" && value !== null ? transform(value) : undefined; }
cchudzicki/mathbox
build/esm/primitives/types/present/reveal.js
JavaScript
mit
1,584
export class Slide extends Parent { make(): any; unmake(): any; slideLatch(enabled: any, step: any): any; slideStep(index: any, step: any): any; slideRelease(): any; slideReset(): any; _instant(enabled: any): any; } import { Parent } from "../base/parent.js";
cchudzicki/mathbox
build/esm/primitives/types/present/slide.d.ts
TypeScript
mit
288
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Parent } from "../base/parent.js"; export class Slide extends Parent { static initClass() { this.traits = ["node", "slide", "visible", "active"]; } make() { this._helpers.visible.make(); this._helpers.active.make(); if (!this._inherit("present")) { throw new Error(`${this.node.toString()} must be placed inside <present></present>`); } return this._inherit("present").adopt(this); } unmake() { this._helpers.visible.unmake(); this._helpers.active.unmake(); return this._inherit("present").unadopt(this); } change(changed, _touched, _init) { if (changed["slide.early"] || changed["slide.late"] || changed["slide.steps"] || changed["slide.from"] || changed["slide.to"]) { return this.rebuild(); } } slideLatch(enabled, step) { //console.log 'slide:latch', @node.toString(), enabled, step this.trigger({ type: "transition.latch", step: step, }); if (enabled != null) { return this._instant(enabled); } } slideStep(index, step) { //console.log 'slide:step', @node.toString(), index, step return this.trigger({ type: "slide.step", index: index, step: step, }); } slideRelease() { //console.log 'slide:release', @node.toString() return this.trigger({ type: "transition.release", }); } slideReset() { this._instant(false); return this.trigger({ type: "slide.reset", }); } _instant(enabled) { //console.log 'slide:instant', @node.toString(), enabled this.setVisible(enabled); return this.setActive(enabled); } } Slide.initClass();
cchudzicki/mathbox
build/esm/primitives/types/present/slide.js
JavaScript
mit
2,312
export class Step extends Track { make(): any; actualIndex: any; animateIndex: any; lastIndex: number | null | undefined; animateStep: any; stops: any; made(): any; } import { Track } from "./track.js";
cchudzicki/mathbox
build/esm/primitives/types/present/step.d.ts
TypeScript
mit
231
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS104: Avoid inline assignments * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Track } from "./track.js"; export class Step extends Track { static initClass() { this.traits = ["node", "track", "step", "trigger", "bind"]; } make() { super.make(); const clock = this._inherit("clock"); if (this.actualIndex == null) { this.actualIndex = null; } this.animateIndex = this._animator.make(this._types.number(0), { clock, realtime: this.props.realtime, step: (value) => { return (this.actualIndex = value); }, }); if (this.lastIndex == null) { this.lastIndex = null; } this.animateStep = this._animator.make(this._types.number(0), { clock, realtime: this.props.realtime, step: (value) => { this.playhead = value; return this.update(); }, }); this.stops = this.props.stops != null ? this.props.stops : __range__(0, this.script.length, false); // Seek instantly after reset this._listen("slide", "slide.reset", (_e) => { return (this.lastIndex = null); }); // Update playhead in response to slide change return this._listen("slide", "slide.step", (e) => { let left; let { duration } = this.props; const { delay, pace, speed, playback, rewind, skip, trigger } = this.props; // Note: enter phase is from index 0 to 1 const i = Math.max(0, Math.min(this.stops.length - 1, e.index - trigger)); // Animation range const from = this.playhead; const to = this.stops[i]; // Seek if first step after reset if (this.lastIndex == null && trigger) { this.lastIndex = i; this.animateStep.set(to); this.animateIndex.set(i); return; } // Calculate actual step from current offset (may be still animating) let last = (left = this.actualIndex != null ? this.actualIndex : this.lastIndex) != null ? left : 0; const step = i - last; // Don't count duped stops const skips = this.stops.slice(Math.min(last, i), Math.max(last, i)); let free = 0; last = skips.shift(); for (const stop of Array.from(skips)) { if (last === stop) { free++; } last = stop; } // Remember last intended stop this.lastIndex = i; // Apply rewind factor let factor = speed * (e.step >= 0 ? 1 : rewind); // Pass through multiple steps at faster rate if skip is enabled factor *= skip ? Math.max(1, Math.abs(step) - free) : 1; // Apply pace duration += (Math.abs(to - from) * pace) / factor; if (from !== to) { this.animateIndex.immediate(i, { delay, duration, ease: playback }); return this.animateStep.immediate(to, { delay, duration, ease: playback, }); } }); } made() { return this.update(); } unmake() { this.animateIndex.dispose(); this.animateStep.dispose(); this.animateIndex = this.animateStep = null; return super.unmake(); } change(changed, touched, init) { if (changed["step.stops"] || changed["step.realtime"]) { return this.rebuild(); } return super.change(changed, touched, init); } } Step.initClass(); function __range__(left, right, inclusive) { const range = []; const ascending = left < right; const end = !inclusive ? right : ascending ? right + 1 : right - 1; for (let i = left; ascending ? i < end : i > end; ascending ? i++ : i--) { range.push(i); } return range; }
cchudzicki/mathbox
build/esm/primitives/types/present/step.js
JavaScript
mit
4,622
export class Track extends Primitive { init(): null; handlers: {} | undefined; script: any; values: any; playhead: number | undefined; velocity: any; section: any; expr: any; make(): any[]; targetNode: any; unmake(): number; start: any; end: any; bindExpr(expr: any): any; measure: (() => number | undefined) | null | undefined; unbindExpr(): null; _process(object: any, script: any): any[]; update(): any; change(changed: any, touched: any, init: any): any; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/present/track.d.ts
TypeScript
mit
585
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS104: Avoid inline assignments * DS205: Consider reworking code to avoid use of IIFEs * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import * as Ease from "../../../util/ease.js"; import { Primitive } from "../../primitive.js"; const deepCopy = function (x) { const out = {}; for (const k in x) { const v = x[k]; if (v instanceof Array) { out[k] = v.slice(); } else if (v != null && typeof v === "object") { out[k] = deepCopy(v); } else { out[k] = v; } } return out; }; export class Track extends Primitive { static initClass() { this.traits = ["node", "track", "seek", "bind"]; } init() { this.handlers = {}; this.script = null; this.values = null; this.playhead = 0; this.velocity = null; this.section = null; return (this.expr = null); } make() { // Bind to attached data sources let ref; this._helpers.bind.make([ { to: "track.target", trait: "node", callback: null }, ]); const { script } = this.props; const { node } = this.bind.target; this.targetNode = node; return (([this.script, this.values, this.start, this.end] = Array.from((ref = this._process(node, script)))), ref); } unmake() { this.unbindExpr(); this._helpers.bind.unmake(); this.script = this.values = this.start = this.end = this.section = this.expr = null; return (this.playhead = 0); } // Bind animated expressions bindExpr(expr) { this.unbindExpr(); this.expr = expr; this.targetNode.bind(expr, true); // Measure playhead velocity on attribute computation const { clock } = this.targetNode; const self = this; return this._attributes.bind((this.measure = (function () { let playhead = null; return () => { const { step } = clock.getTime(); if (playhead != null) { self.velocity = (self.playhead - playhead) / step; } return (playhead = self.playhead); }; })())); } unbindExpr() { if (this.expr != null) { this.targetNode.unbind(this.expr, true); } if (this.measure != null) { this._attributes.unbind(this.measure); } return (this.expr = this.measure = null); } // Process script steps by filling out missing props _process(object, script) { let k, key, last, message, s, step, v; if (script instanceof Array) { // Normalize array to numbered dict s = {}; for (let i = 0; i < script.length; i++) { step = script[i]; s[i] = step; } script = s; } // Normalize keyed steps to array of step objects s = []; for (key in script) { step = script[key]; if (step == null) { step = []; } if (step instanceof Array) { // [props, expr] array step = { key: +key, props: step[0] != null ? deepCopy(step[0]) : {}, expr: step[1] != null ? deepCopy(step[1]) : {}, }; } else { if (step.key == null && !step.props && !step.expr) { // Direct props object (iffy, but people will do this anyhow) step = { props: deepCopy(step) }; } else { // Proper step step = deepCopy(step); } // Prepare step object step.key = step.key != null ? +step.key : +key; if (step.props == null) { step.props = {}; } if (step.expr == null) { step.expr = {}; } } s.push(step); } script = s; if (!script.length) { return [[], {}, 0, 0]; } // Sort by keys script.sort((a, b) => a.key - b.key); const start = script[0].key; const end = script[script.length - 1].key; // Connect steps for (key in script) { step = script[key]; if (last != null) { last.next = step; } last = step; } // Last step leads to itself last.next = last; script = s; // Determine starting props const props = {}; const values = {}; for (key in script) { step = script[key]; for (k in step.props) { v = step.props[k]; props[k] = true; } } for (key in script) { step = script[key]; for (k in step.expr) { v = step.expr[k]; props[k] = true; } } for (k in props) { props[k] = object.get(k); } try { // Need two sources and one destination value for correct mixing of live expressions for (k in props) { values[k] = [ object.attribute(k).T.make(), object.attribute(k).T.make(), object.attribute(k).T.make(), ]; } } catch (error) { console.warn(this.node.toMarkup()); message = `${this.node.toString()} - Target ${object} has no \`${k}\` property`; throw new Error(message); } const result = []; // Normalize script props, insert held values for (step of Array.from(script)) { for (k in props) { v = props[k]; v = object.validate(k, step.props[k] != null ? step.props[k] : v); props[k] = step.props[k] = v; if (step.expr[k] != null && typeof step.expr[k] !== "function") { console.warn(this.node.toMarkup()); message = `${this.node.toString()} - Expression \`${step.expr[k]}\` on property \`${k}\` is not a function`; throw new Error(message); } } result.push(step); } return [result, values, start, end]; } update() { let { playhead } = this; const { script } = this; const { ease, seek } = this.props; const node = this.targetNode; if (seek != null) { playhead = seek; } if (script.length) { let k; const find = function () { let last = script[0]; for (let i = 0; i < script.length; i++) { const step = script[i]; if (step.key > playhead) { break; } last = step; } return last; }; let { section } = this; if (!section || playhead < section.key || playhead > section.next.key) { section = find(script, playhead); } if (section === this.section) { return; } this.section = section; const from = section; const to = section.next; const start = from.key; const end = to.key; // Easing of playhead along track const easeMethod = (() => { switch (ease) { case "linear": case 0: return Ease.clamp; case "cosine": case 1: return Ease.cosine; case "binary": case 2: return Ease.binary; case "hold": case 3: return Ease.hold; default: return Ease.cosine; } })(); // Callback for live playhead interpolator (linear approx time travel) const { clock } = node; const getPlayhead = (time) => { if (this.velocity == null) { return this.playhead; } const now = clock.getTime(); return this.playhead + this.velocity * (time - now.time); }; const getLerpFactor = (function () { const scale = 1 / Math.max(0.0001, end - start); return (time) => easeMethod((getPlayhead(time) - start) * scale, 0, 1); })(); // Create prop expression interpolator const live = (key) => { const fromE = from.expr[key]; const toE = to.expr[key]; const fromP = from.props[key]; const toP = to.props[key]; const invalid = function () { console.warn(node.toMarkup()); throw new Error(`${this.node.toString()} - Invalid expression result on track \`${key}\``); }; const attr = node.attribute(key); const values = this.values[key]; const animator = this._animator; // Lerp between two expressions if (fromE && toE) { return ((values, _from, _to) => function (time, delta) { let _from, _to; values[0] = _from = attr.T.validate(fromE(time, delta), values[0], invalid); values[1] = _to = attr.T.validate(toE(time, delta), values[1], invalid); return (values[2] = animator.lerp(attr.T, _from, _to, getLerpFactor(time), values[2])); })(values, from, to); // Lerp between an expression and a constant } else if (fromE) { return ((values, _from, _to) => function (time, delta) { let _from; values[0] = _from = attr.T.validate(fromE(time, delta), values[0], invalid); return (values[1] = animator.lerp(attr.T, _from, toP, getLerpFactor(time), values[1])); })(values, from, to); // Lerp between a constant and an expression } else if (toE) { return ((values, _from, _to) => function (time, delta) { let _to; values[0] = _to = attr.T.validate(toE(time, delta), values[0], invalid); return (values[1] = animator.lerp(attr.T, fromP, _to, getLerpFactor(time), values[1])); })(values, from, to); // Lerp between two constants } else { return ((values, _from, _to) => (time, _delta) => (values[0] = animator.lerp(attr.T, fromP, toP, getLerpFactor(time), values[0])))(values, from, to); } }; // Handle expr / props on both ends const expr = {}; for (k in from.expr) { if (expr[k] == null) { expr[k] = live(k); } } for (k in to.expr) { if (expr[k] == null) { expr[k] = live(k); } } for (k in from.props) { if (expr[k] == null) { expr[k] = live(k); } } for (k in to.props) { if (expr[k] == null) { expr[k] = live(k); } } // Bind node props return this.bindExpr(expr); } } change(changed, touched, init) { if (changed["track.target"] || changed["track.script"] || changed["track.mode"]) { return this.rebuild(); } if (changed["seek.seek"] || init) { return this.update(); } } } Track.initClass();
cchudzicki/mathbox
build/esm/primitives/types/present/track.js
JavaScript
mit
12,983
export class Transition extends Parent { init(): null; animate: any; uniforms: { transitionFrom: any; transitionTo: any; transitionActive: any; transitionScale: any; transitionBias: any; transitionEnter: any; transitionExit: any; transitionSkew: any; } | null | undefined; state: { isVisible: boolean; isActive: boolean; enter: number; exit: number; } | undefined; latched: { isVisible: boolean; isActive: boolean; step: any; } | null | undefined; locked: { isVisible: boolean; isActive: boolean; } | null | undefined; make(): boolean; move: boolean | undefined; unmake(): any; latch(step: any): any; release(): any; complete(done: any): any; update(): any; isVisible: any; isActive: any; change(changed: any, touched: any, init: any): any; } import { Parent } from "../base/parent.js";
cchudzicki/mathbox
build/esm/primitives/types/present/transition.d.ts
TypeScript
mit
1,003
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Parent } from "../base/parent.js"; export class Transition extends Parent { static initClass() { this.traits = [ "node", "transition", "transform", "mask", "visible", "active", ]; } init() { this.animate = null; this.uniforms = null; this.state = { isVisible: true, isActive: true, enter: 1, exit: 1, }; this.latched = null; return (this.locked = null); } make() { this.uniforms = { transitionFrom: this._attributes.make(this._types.vec4()), transitionTo: this._attributes.make(this._types.vec4()), transitionActive: this._attributes.make(this._types.bool()), transitionScale: this._attributes.make(this._types.vec4()), transitionBias: this._attributes.make(this._types.vec4()), transitionEnter: this._attributes.make(this._types.number()), transitionExit: this._attributes.make(this._types.number()), transitionSkew: this._attributes.make(this._types.number()), }; const slideParent = this._inherit("slide"); const visibleParent = this._inherit("visible"); const activeParent = this._inherit("active"); this._listen(slideParent, "transition.latch", (e) => this.latch(e.step)); this._listen(slideParent, "transition.release", () => this.release()); this._listen(visibleParent, "visible.change", () => { //console.log @node.toString(), 'visible.change ^', visibleParent.isVisible return this.update((this.state.isVisible = visibleParent.isVisible)); }); this._listen(activeParent, "active.change", () => { //console.log @node.toString(), 'active.change ^', activeParent.isActive return this.update((this.state.isActive = activeParent.isActive)); }); this.animate = this._animator.make(this._types.vec2(1, 1), { step: (value) => { this.state.enter = value.x; this.state.exit = value.y; return this.update(); }, complete: (done) => this.complete(done), }); return (this.move = this.props.from != null || this.props.to != null); } //@_helpers.visible.make() //@_helpers.active.make() unmake() { return this.animate.dispose(); } //@_helpers.visible.unmake() //@_helpers.active.unmake() latch(step) { let latched; this.locked = null; this.latched = latched = { isVisible: this.state.isVisible, isActive: this.state.isActive, step, }; // Reset enter/exit animation if invisible const visible = this.isVisible; if (!visible) { const forward = latched.step >= 0; const [enter, exit] = Array.from(forward ? [0, 1] : [1, 0]); return this.animate.set(enter, exit); } } //console.log @node.toString(), 'transition::latch', @latched, enter, exit release() { // Get before/after and unlatch state const { latched } = this; const { state } = this; this.latched = null; //console.log @node.toString(), 'transition::release', JSON.parse JSON.stringify {latched, state} //p = @; console.log '-> ', p.node.toString(), p.isVisible while p = p._inherit 'visible' // Transition if visibility state change if (latched.isVisible !== state.isVisible) { // Maintain step direction const forward = latched.step >= 0; const visible = state.isVisible; const [enter, exit] = Array.from(visible ? [1, 1] : forward ? [1, 0] : [0, 1]); // Get duration let { duration, durationEnter, durationExit } = this.props; if (durationEnter == null) { durationEnter = duration; } if (durationExit == null) { durationExit = duration; } duration = visible * durationEnter + !visible * durationExit; // Get delay let { delay, delayEnter, delayExit } = this.props; if (delayEnter == null) { delayEnter = delay; } if (delayExit == null) { delayExit = delay; } delay = visible * delayEnter + !visible * delayExit; // Animate enter/exit //console.log @node.toString(), '@animate.immediate', {x: enter, y: exit}, {duration, delay, ease: 'linear'} this.animate.immediate({ x: enter, y: exit }, { duration, delay, ease: "linear" }); // Lock visibility and active open during transition this.locked = { isVisible: true, isActive: latched.isActive || state.isActive, }; } return this.update(); } complete(done) { if (!done) { return; } this.locked = null; return this.update(); } update() { if (this.latched != null) { return; } // latched let { enter, exit } = this.props; // Resolve transition state if (enter == null) { ({ enter } = this.state); } if (exit == null) { ({ exit } = this.state); } const level = enter * exit; let visible = level > 0; const partial = level < 1; this.uniforms.transitionEnter.value = enter; this.uniforms.transitionExit.value = exit; this.uniforms.transitionActive.value = partial; // Resolve visibility state if (visible) { visible = !!this.state.isVisible; } if (this.locked != null) { visible = this.locked.isVisible; } if (this.isVisible !== visible) { this.isVisible = visible; this.trigger({ type: "visible.change" }); } // Resolve active state const active = !!(this.state.isActive || (this.locked != null ? this.locked.isActive : undefined)); if (this.isActive !== active) { this.isActive = active; return this.trigger({ type: "active.change" }); } } //console.log 'transition update', 'enter', enter, 'exit', exit, 'visible', visible, 'active', active change(changed, touched, init) { if (changed["transition.enter"] || changed["transition.exit"] || init) { this.update(); } if (changed["transition.stagger"] || init) { const { stagger } = this.props; // Precompute shader constants const flipX = stagger.x < 0; const flipY = stagger.y < 0; const flipZ = stagger.z < 0; const flipW = stagger.w < 0; const staggerX = Math.abs(stagger.x); const staggerY = Math.abs(stagger.y); const staggerZ = Math.abs(stagger.z); const staggerW = Math.abs(stagger.w); this.uniforms.transitionSkew.value = staggerX + staggerY + staggerZ + staggerW; this.uniforms.transitionScale.value.set((1 - flipX * 2) * staggerX, (1 - flipY * 2) * staggerY, (1 - flipZ * 2) * staggerZ, (1 - flipW * 2) * staggerW); return this.uniforms.transitionBias.value.set(flipX * staggerX, flipY * staggerY, flipZ * staggerZ, flipW * staggerW); } } } Transition.initClass();
cchudzicki/mathbox
build/esm/primitives/types/present/transition.js
JavaScript
mit
8,096
export class Compose extends Primitive { init(): null; compose: any; resize(): any; make(): any; remapUVScale: any; made(): any; unmake(): any; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/rtt/compose.d.ts
TypeScript
mit
222
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Primitive } from "../../primitive.js"; export class Compose extends Primitive { static initClass() { this.traits = [ "node", "bind", "object", "visible", "operator", "style", "compose", ]; this.defaults = { zWrite: false, zTest: false, color: "#ffffff", }; } init() { return (this.compose = null); } //rebuild: () -> // console.log 'compose.rebuild', @node.get(null, true), @bind.source? // super() resize() { if (!this.compose || !this.bind.source) { return; } const dims = this.bind.source.getActiveDimensions(); const { width } = dims; const { height } = dims; return this.remapUVScale.set(width, height); } make() { // Bind to attached data sources this._helpers.bind.make([{ to: "operator.source", trait: "source" }]); if (this.bind.source == null) { return; } // Prepare uniforms for remapping to absolute coords on the fly const resampleUniforms = { remapUVScale: this._attributes.make(this._types.vec2()), }; this.remapUVScale = resampleUniforms.remapUVScale.value; // Build fragment shader let fragment = this._shaders.shader(); const { alpha } = this.props; if (this.bind.source.is("image")) { // Sample image directly in 2D UV fragment.pipe("screen.pass.uv", resampleUniforms); fragment = this.bind.source.imageShader(fragment); } else { // Sample data source in 4D fragment.pipe("screen.map.xy", resampleUniforms); fragment = this.bind.source.sourceShader(fragment); } // Force pixels to solid if requested if (!alpha) { fragment.pipe("color.opaque"); } // Make screen renderable const composeUniforms = this._helpers.style.uniforms(); this.compose = this._renderables.make("screen", { map: fragment, uniforms: composeUniforms, linear: true, }); this._helpers.visible.make(); return this._helpers.object.make([this.compose]); } made() { return this.resize(); } unmake() { this._helpers.bind.unmake(); this._helpers.visible.unmake(); return this._helpers.object.unmake(); } change(changed, _touched, _init) { if (changed["operator.source"] || changed["compose.alpha"]) { return this.rebuild(); } } } Compose.initClass();
cchudzicki/mathbox
build/esm/primitives/types/rtt/compose.js
JavaScript
mit
3,142
export * from "./rtt.js"; export * from "./compose.js";
cchudzicki/mathbox
build/esm/primitives/types/rtt/index.d.ts
TypeScript
mit
56
export * from "./rtt.js"; export * from "./compose.js";
cchudzicki/mathbox
build/esm/primitives/types/rtt/index.js
JavaScript
mit
56
export class RTT extends Parent { init(): null; rtt: any; scene: any; camera: any; width: any; height: any; history: any; rootSize: any; size: any; indexShader(shader: any): any; imageShader(shader: any): any; sourceShader(shader: any): any; getDimensions(): { items: number; width: any; height: any; depth: any; }; getActiveDimensions(): { items: number; width: any; height: any; depth: any; }; make(): { renderWidth: any; renderHeight: any; aspect: any; viewWidth: any; viewHeight: any; pixelRatio: number; } | undefined; parentRoot: any; aspect: number | undefined; made(): any; unmake(rebuild: any): null | undefined; change(changed: any, touched: any, init: any): any; adopt(renderable: any): any[]; unadopt(renderable: any): any[]; resize(size: any): void; select(selector: any): any; watch(selector: any, handler: any): any; unwatch(handler: any): any; pre(e: any): any; update(e: any): any; render(e: any): any; post(e: any): any; setCamera(): any; getOwnCamera(): any; getCamera(): any; vertex(shader: any, pass: any): any; } import { Parent } from "../base/parent.js";
cchudzicki/mathbox
build/esm/primitives/types/rtt/rtt.d.ts
TypeScript
mit
1,339
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining * DS104: Avoid inline assignments * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Parent } from "../base/parent.js"; export class RTT extends Parent { static initClass() { this.traits = [ "node", "root", "scene", "vertex", "texture", "rtt", "source", "index", "image", ]; this.defaults = { minFilter: "linear", magFilter: "linear", type: "unsignedByte", }; } init() { return (this.rtt = this.scene = this.camera = this.width = this.height = this.history = this.rootSize = this.size = null); } indexShader(shader) { return shader; } imageShader(shader) { return this.rtt.shaderRelative(shader); } sourceShader(shader) { return this.rtt.shaderAbsolute(shader, this.history); } getDimensions() { return { items: 1, width: this.width, height: this.height, depth: this.history, }; } getActiveDimensions() { return this.getDimensions(); } make() { let aspect; this.parentRoot = this._inherit("root"); this.rootSize = this.parentRoot.getSize(); this._listen(this.parentRoot, "root.pre", this.pre); this._listen(this.parentRoot, "root.update", this.update); this._listen(this.parentRoot, "root.render", this.render); this._listen(this.parentRoot, "root.post", this.post); this._listen(this.parentRoot, "root.camera", this.setCamera); this._listen(this.parentRoot, "root.resize", function (event) { return this.resize(event.size); }); if (this.rootSize == null) { return; } const { minFilter, magFilter, type } = this.props; const { width, height, history, size } = this.props; const relativeSize = size === this.node.attributes["rtt.size"].enum.relative; const widthFactor = relativeSize ? this.rootSize.renderWidth : 1; const heightFactor = relativeSize ? this.rootSize.renderHeight : 1; this.width = Math.round(width != null ? width * widthFactor : this.rootSize.renderWidth); this.height = Math.round(height != null ? height * heightFactor : this.rootSize.renderHeight); this.history = history; this.aspect = aspect = this.width / this.height; if (this.scene == null) { this.scene = this._renderables.make("scene"); } this.rtt = this._renderables.make("renderToTexture", { scene: this.scene, camera: this._context.defaultCamera, width: this.width, height: this.height, frames: this.history, minFilter, magFilter, type, }); aspect = width || height ? aspect : this.rootSize.aspect; const viewWidth = width != null ? width : this.rootSize.viewWidth; const viewHeight = height != null ? height : this.rootSize.viewHeight; return (this.size = { renderWidth: this.width, renderHeight: this.height, aspect, viewWidth, viewHeight, pixelRatio: this.height / viewHeight, }); } made() { // Notify of buffer reallocation this.trigger({ type: "source.rebuild", }); if (this.size) { return this.trigger({ type: "root.resize", size: this.size, }); } } unmake(rebuild) { if (this.rtt == null) { return; } this.rtt.dispose(); if (!rebuild) { this.scene.dispose(); } return (this.rtt = this.width = this.height = this.history = null); } change(changed, touched, init) { if (touched["texture"] || changed["rtt.width"] || changed["rtt.height"]) { return this.rebuild(); } if (changed["root.camera"] || init) { this._unattach(); this._attach(this.props.camera, "camera", this.setCamera, this, this, true); return this.setCamera(); } } adopt(renderable) { return Array.from(renderable.renders).map((object) => this.scene.add(object)); } unadopt(renderable) { return Array.from(renderable.renders).map((object) => this.scene.remove(object)); } resize(size) { let height, width; this.rootSize = size; ({ width, height, size } = this.props); const relativeSize = size === this.node.attributes["rtt.size"].enum.relative; if (!this.rtt || width == null || height == null || relativeSize) { return this.rebuild(); } } select(selector) { return this._root.node.model.select(selector, [this.node]); } watch(selector, handler) { return this._root.node.model.watch(selector, handler); } unwatch(handler) { return this._root.node.model.unwatch(handler); } pre(e) { return this.trigger(e); } update(e) { let camera; if ((camera = this.getOwnCamera()) != null) { camera.aspect = this.aspect || 1; camera.updateProjectionMatrix(); } return this.trigger(e); } render(e) { this.trigger(e); return this.rtt != null ? this.rtt.render(this.getCamera()) : undefined; } post(e) { return this.trigger(e); } setCamera() { const camera = __guard__(this.select(this.props.camera)[0], (x) => x.controller); if (this.camera !== camera) { this.camera = camera; this.rtt.camera = this.getCamera(); return this.trigger({ type: "root.camera" }); } else if (!this.camera) { return this.trigger({ type: "root.camera" }); } } getOwnCamera() { return this.camera != null ? this.camera.getCamera() : undefined; } getCamera() { let left; return (left = this.getOwnCamera()) != null ? left : this._inherit("root").getCamera(); } // End transform chain here vertex(shader, pass) { if (pass === 2) { return shader.pipe("view.position"); } if (pass === 3) { return shader.pipe("root.position"); } return shader; } } RTT.initClass(); function __guard__(value, transform) { return typeof value !== "undefined" && value !== null ? transform(value) : undefined; }
cchudzicki/mathbox
build/esm/primitives/types/rtt/rtt.js
JavaScript
mit
7,415
export * from "./shader.js";
cchudzicki/mathbox
build/esm/primitives/types/shader/index.d.ts
TypeScript
mit
29
export * from "./shader.js";
cchudzicki/mathbox
build/esm/primitives/types/shader/index.js
JavaScript
mit
29
export class Shader extends Primitive { init(): null; shader: any; make(): any; made(): any; unmake(): null; shaderBind(uniforms: any): any; } import { Primitive } from "../../primitive.js";
cchudzicki/mathbox
build/esm/primitives/types/shader/shader.d.ts
TypeScript
mit
215
// TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. /* * decaffeinate suggestions: * DS101: Remove unnecessary use of Array.from * DS102: Remove unnecessary code created because of implicit returns * DS206: Consider reworking classes to avoid initClass * DS207: Consider shorter variations of null checks * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ import { Primitive } from "../../primitive.js"; export class Shader extends Primitive { static initClass() { this.traits = ["node", "bind", "shader"]; this.freeform = true; } init() { return (this.shader = null); } make() { const { language, code } = this.props; if (language !== "glsl") { throw new Error("GLSL required"); } // Bind to attached data sources this._helpers.bind.make([ { to: "shader.sources", trait: "source", multiple: true }, ]); // Parse snippet w/ shadergraph (will do implicit DOM script tag by ID // lookup if simple selector or ID given) const snippet = this._shaders.fetch(code); // Convert uniforms to attributes const types = this._types; const uniforms = {}; const make = (type) => { let t; switch (type) { case "i": return types.int(); case "f": return types.number(); case "v2": return types.vec2(); case "v3": return types.vec3(); case "v4": return types.vec4(); case "m3": return types.mat3(); case "m4": return types.mat4(); case "t": return types.object(); default: t = type.split(""); if (t.pop() === "v") { return types.array(make(t.join(""))); } else { return null; } } }; for (const def of Array.from(snippet._signatures.uniform)) { let type; if ((type = make(def.type))) { uniforms[def.name] = type; } } // Reconfigure node model return this.reconfigure({ props: { uniform: uniforms } }); } made() { // Notify of shader reallocation return this.trigger({ type: "source.rebuild", }); } unmake() { return (this.shader = null); } change(changed, _touched, _init) { if (changed["shader.uniforms"] || changed["shader.code"] || changed["shader.language"]) { return this.rebuild(); } } shaderBind(uniforms) { let k, u, v; if (uniforms == null) { uniforms = {}; } const { code } = this.props; // Merge in prop attributes as uniforms for (k in this.node.attributes) { v = this.node.attributes[k]; if (v.type != null && v.short != null && v.ns === "uniform") { if (uniforms[v.short] == null) { uniforms[v.short] = v; } } } // Merge in explicit uniform object if set if ((u = this.props.uniforms) != null) { for (k in u) { v = u[k]; uniforms[k] = v; } } // New shader const s = this._shaders.shader(); // Require sources if (this.bind.sources != null) { for (const source of Array.from(this.bind.sources)) { s.require(source.sourceShader(this._shaders.shader())); } } // Build bound shader return s.pipe(code, uniforms); } } Shader.initClass();
cchudzicki/mathbox
build/esm/primitives/types/shader/shader.js
JavaScript
mit
4,050