Skip to content

Commit

Permalink
Merge branch 'sritchie/pr_fixes' into 'master'
Browse files Browse the repository at this point in the history
Apply fixes from backlogged PRs

See merge request unconed/mathbox!16
  • Loading branch information
Sam Ritchie committed Feb 17, 2022
2 parents 0c13279 + 5eaf4fc commit 271f9cc
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 42 deletions.
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
### MathBox Changelog

2.1.1

!16 applies JS-ported patches from the following open merge requests:

- https://gitgud.io/unconed/mathbox/-/merge_requests/11/
- https://gitgud.io/unconed/mathbox/-/merge_requests/10
- https://gitgud.io/unconed/mathbox/-/merge_requests/9
- https://gitgud.io/unconed/mathbox/-/merge_requests/8
- https://gitgud.io/unconed/mathbox/-/merge_requests/7
- https://gitgud.io/unconed/mathbox/-/merge_requests/6
- https://gitgud.io/unconed/mathbox/-/merge_requests/5

Thanks to @bobqwatsonsapphire, @carl00s01 and @Beddington for these fixes.

0.0.5

- ⚠️ Rename array `length` to `width` for consistency.
Expand Down
28 changes: 18 additions & 10 deletions build/mathbox-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/mathbox-bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/mathbox.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/mathbox.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/shaders.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions docs/primitives.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
* *points* = `<` (select) - Points data source
* *proximity* = `null` (nullable number) - Proximity threshold, e.g. `10`
* *shaded* = `false` (bool) - Shade mesh
* *size* = `2` (positive number) - Line width
* *width* = `2` (positive number) - Line width
* *stroke* = `"solid"` (stroke) - Line stroke (solid, dotted, dashed)
* *visible* = `true` (bool) - Visibility for rendering
* *zBias* = `0` (positive number) - Z-Bias (3D stacking)
Expand Down Expand Up @@ -424,7 +424,7 @@
* *proximity* = `null` (nullable number) - Proximity threshold, e.g. `10`
* *rangeX* = `[-1, 1]` (vec2) - Range on axis
* *rangeY* = `[-1, 1]` (vec2) - Range on axis
* *size* = `2` (positive number) - Line width
* *width* = `2` (positive number) - Line width
* *startX* = `true` (bool) - Include start
* *startY* = `true` (bool) - Include start
* *stroke* = `"solid"` (stroke) - Line stroke (solid, dotted, dashed)
Expand Down Expand Up @@ -1322,4 +1322,3 @@
* *realtime* = `false` (bool) - Run on real time, not clock time
* *type* = `"float"` (type) - Texture data type
* *width* = `1` (nullable number) - Voxel width

5 changes: 5 additions & 0 deletions src/overlay/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export class DOM extends Overlay {
el = this.el("div", null, el);
}

// Create empty div if el is null
if (el == null) {
el = this.el("div");
}

// See if it can be mounted directly
const naked = el.type === "div";

Expand Down
13 changes: 7 additions & 6 deletions src/primitives/types/operator/lerp.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ export class Lerp extends Operator {
vec[i] = centered ? "0.5" : "0.0";
}

let vec4;

// Add centered sampling offset (from source)
if (any && resize) {
vec = `vec4(${vec})`;
// TODO is this right? it was vec4 before.
operator.pipe(UGLSL.binaryOperator(4, "+", vec));
indexer.pipe(UGLSL.binaryOperator(4, "+", vec));
vec4 = `vec4(${vec})`;
operator.pipe(UGLSL.binaryOperator(4, "+", vec4));
indexer.pipe(UGLSL.binaryOperator(4, "+", vec4));
}

// Addressing relative to target
Expand All @@ -214,8 +215,8 @@ export class Lerp extends Operator {

// Remove centered sampling offset (to target)
if (any && resize) {
operator.pipe(UGLSL.binaryOperator(4, "-", vec));
indexer.pipe(UGLSL.binaryOperator(4, "-", vec));
operator.pipe(UGLSL.binaryOperator(4, "-", vec4));
indexer.pipe(UGLSL.binaryOperator(4, "-", vec4));
}

// Make sampler
Expand Down
2 changes: 1 addition & 1 deletion src/primitives/types/overlay/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class DOM extends Primitive {
if (this.readback == null) {
return;
}
this.dom.render(this.isVisible ? this.emitter.nodes() : []);
this.dom.render(this.isVisible ? this.emitter.nodes() : null);
}

callback(data) {
Expand Down
2 changes: 1 addition & 1 deletion src/render/buffer/readback.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export class Readback extends Renderable {

post() {
const currentTarget = this.renderer.getRenderTarget();
this.renderer.setRenderTarget(this.byteMemo.target.write);
this.renderer.setRenderTarget(this.byteMemo.target.targets[0]);
this.gl.readPixels(
0,
0,
Expand Down
42 changes: 26 additions & 16 deletions src/shaders/glsl/line.position.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ uniform float focusDepth;
uniform vec4 geometryClip;
attribute vec4 position4;

// (Start/mid/end -1/0/1, top/bottom -1,1)
// (Start/mid/end -1/0/1, top/bottom -1,1)
attribute vec2 line;

// 0...1 for round or bevel joins
Expand Down Expand Up @@ -72,20 +72,25 @@ void clipEnds(vec4 xyzw, vec3 center, vec3 pos) {
float z = max(0.00001, -end.z);
depth = mix(z, focusDepth, lineDepth);
}

// Absolute arrow length
float size = arrowSize * depth;

// Adjust clip range
// Approach linear scaling with cubic ease the smaller we get
float mini = clamp(1.0 - l / size * .333, 0.0, 1.0);
float scale = 1.0 - mini * mini * mini;
float scale = 1.0 - mini * mini * mini;
float invrange = 1.0 / (size * scale);

// Clip end
diff = normalize(end - center);
float d = dot(end - pos, diff);
vClipEnds.x = d * invrange - 1.0;
diff = end - center;
if(diff == vec3(0.0))
vClipEnds.x = -1.0;
else {
diff = normalize(end - center);
float d = dot(end - pos, diff);
vClipEnds.x = d * invrange - 1.0;
}
}

if (clipStyle.x > 0.0) {
Expand All @@ -95,20 +100,25 @@ void clipEnds(vec4 xyzw, vec3 center, vec3 pos) {
float z = max(0.00001, -start.z);
depth = mix(z, focusDepth, lineDepth);
}

// Absolute arrow length
float size = arrowSize * depth;

// Adjust clip range
// Approach linear scaling with cubic ease the smaller we get
float mini = clamp(1.0 - l / size * .333, 0.0, 1.0);
float scale = 1.0 - mini * mini * mini;
float scale = 1.0 - mini * mini * mini;
float invrange = 1.0 / (size * scale);

// Clip start
diff = normalize(center - start);
float d = dot(pos - start, diff);
vClipEnds.y = d * invrange - 1.0;

// Clip start
diff = center - start;
if(diff == vec3(0.0))
vClipEnds.y = -1.0;
else {
diff = normalize(center - start);
float d = dot(pos - start, diff);
vClipEnds.y = d * invrange - 1.0;
}
}


Expand Down Expand Up @@ -171,7 +181,7 @@ vec3 getLineJoin(float edge, bool odd, vec3 left, vec3 center, vec3 right, float
float l2 = dot(d.zw, d.zw);

if (l1 + l2 > 0.0) {

if (edge > 0.5 || l2 == 0.0) {
vec2 nl = normalize(d.xy);
vec2 tl = vec2(nl.y, -nl.x);
Expand Down Expand Up @@ -226,7 +236,7 @@ vec3 getLineJoin(float edge, bool odd, vec3 left, vec3 center, vec3 right, float
// Average tangent
vec2 tc = normalize(tl + tr);
#endif

// Miter join
float cosA = dot(nl, tc);
float sinA = max(0.1, abs(dot(tl, tc)));
Expand Down
2 changes: 2 additions & 0 deletions src/stage/animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export class Animator {
const emitter = type.emitter(from, to);
from.emitterFrom = emitter;
to.emitterTo = emitter;
emitter.lerp(f);
return emitter;
}

// Generic binary operator
Expand Down
2 changes: 1 addition & 1 deletion src/stage/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class API {

off() {
const args = arguments;
this._targets.map((x) => x.on.apply(x, args));
this._targets.map((x) => x.off.apply(x, args));
return this;
}

Expand Down

0 comments on commit 271f9cc

Please sign in to comment.