Skip to content

Commit

Permalink
Merge pull request #738 from jonobr1/736-webgl-negative-scale
Browse files Browse the repository at this point in the history
Improvement to WebGL Rendering: Handle Negative Scales
  • Loading branch information
jonobr1 authored Sep 21, 2024
2 parents 3e63c35 + a1bd382 commit 6b2684a
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 46 deletions.
44 changes: 29 additions & 15 deletions build/two.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ var Two = (() => {
canvas: "CanvasRenderer"
},
Version: "v0.8.15",
PublishDate: "2024-07-09T17:21:48.285Z",
PublishDate: "2024-09-21T04:27:00.542Z",
Identifier: "two-",
Resolution: 12,
AutoCalculateImportedMatrices: true,
Expand Down Expand Up @@ -9475,13 +9475,16 @@ var Two = (() => {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.x = this._scale.x * parent._renderer.scale.x;
this._renderer.scale.y = this._scale.y * parent._renderer.scale.y;
sx = this._scale.x * parent._renderer.scale.x;
sy = this._scale.y * parent._renderer.scale.y;
} else {
this._renderer.scale.x = this._scale * parent._renderer.scale.x;
this._renderer.scale.y = this._scale * parent._renderer.scale.y;
sx = this._scale * parent._renderer.scale.x;
sy = this._scale * parent._renderer.scale.y;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;
if (parentChanged) {
this._renderer.parent = parent;
}
Expand Down Expand Up @@ -9671,13 +9674,16 @@ var Two = (() => {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.x = this._scale.x * parent._renderer.scale.x;
this._renderer.scale.y = this._scale.y * parent._renderer.scale.y;
sx = this._scale.x * parent._renderer.scale.x;
sy = this._scale.y * parent._renderer.scale.y;
} else {
this._renderer.scale.x = this._scale * parent._renderer.scale.x;
this._renderer.scale.y = this._scale * parent._renderer.scale.y;
sx = this._scale * parent._renderer.scale.x;
sy = this._scale * parent._renderer.scale.y;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;
if (parentChanged) {
this._renderer.parent = parent;
}
Expand Down Expand Up @@ -9970,13 +9976,16 @@ var Two = (() => {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.x = this._scale.x * parent._renderer.scale.x;
this._renderer.scale.y = this._scale.y * parent._renderer.scale.y;
sx = this._scale.x * parent._renderer.scale.x;
sy = this._scale.y * parent._renderer.scale.y;
} else {
this._renderer.scale.x = this._scale * parent._renderer.scale.x;
this._renderer.scale.y = this._scale * parent._renderer.scale.y;
sx = this._scale * parent._renderer.scale.x;
sy = this._scale * parent._renderer.scale.y;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;
if (parentChanged) {
this._renderer.parent = parent;
}
Expand Down Expand Up @@ -10147,11 +10156,16 @@ var Two = (() => {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.copy(this._scale);
sx = this._scale.x;
sy = this._scale.y;
} else {
this._renderer.scale.set(this._scale, this._scale);
sx = this._scale;
sy = this._scale;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;
}
return this.flagReset();
}
Expand Down
4 changes: 2 additions & 2 deletions build/two.min.js

Large diffs are not rendered by default.

44 changes: 29 additions & 15 deletions build/two.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ var Constants = {
canvas: "CanvasRenderer"
},
Version: "v0.8.15",
PublishDate: "2024-07-09T17:21:48.285Z",
PublishDate: "2024-09-21T04:27:00.542Z",
Identifier: "two-",
Resolution: 12,
AutoCalculateImportedMatrices: true,
Expand Down Expand Up @@ -9456,13 +9456,16 @@ var webgl = {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.x = this._scale.x * parent._renderer.scale.x;
this._renderer.scale.y = this._scale.y * parent._renderer.scale.y;
sx = this._scale.x * parent._renderer.scale.x;
sy = this._scale.y * parent._renderer.scale.y;
} else {
this._renderer.scale.x = this._scale * parent._renderer.scale.x;
this._renderer.scale.y = this._scale * parent._renderer.scale.y;
sx = this._scale * parent._renderer.scale.x;
sy = this._scale * parent._renderer.scale.y;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;
if (parentChanged) {
this._renderer.parent = parent;
}
Expand Down Expand Up @@ -9652,13 +9655,16 @@ var webgl = {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.x = this._scale.x * parent._renderer.scale.x;
this._renderer.scale.y = this._scale.y * parent._renderer.scale.y;
sx = this._scale.x * parent._renderer.scale.x;
sy = this._scale.y * parent._renderer.scale.y;
} else {
this._renderer.scale.x = this._scale * parent._renderer.scale.x;
this._renderer.scale.y = this._scale * parent._renderer.scale.y;
sx = this._scale * parent._renderer.scale.x;
sy = this._scale * parent._renderer.scale.y;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;
if (parentChanged) {
this._renderer.parent = parent;
}
Expand Down Expand Up @@ -9951,13 +9957,16 @@ var webgl = {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.x = this._scale.x * parent._renderer.scale.x;
this._renderer.scale.y = this._scale.y * parent._renderer.scale.y;
sx = this._scale.x * parent._renderer.scale.x;
sy = this._scale.y * parent._renderer.scale.y;
} else {
this._renderer.scale.x = this._scale * parent._renderer.scale.x;
this._renderer.scale.y = this._scale * parent._renderer.scale.y;
sx = this._scale * parent._renderer.scale.x;
sy = this._scale * parent._renderer.scale.y;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;
if (parentChanged) {
this._renderer.parent = parent;
}
Expand Down Expand Up @@ -10128,11 +10137,16 @@ var webgl = {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.copy(this._scale);
sx = this._scale.x;
sy = this._scale.y;
} else {
this._renderer.scale.set(this._scale, this._scale);
sx = this._scale;
sy = this._scale;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;
}
return this.flagReset();
}
Expand Down
42 changes: 28 additions & 14 deletions src/renderers/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,16 @@ const webgl = {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.x = this._scale.x * parent._renderer.scale.x;
this._renderer.scale.y = this._scale.y * parent._renderer.scale.y;
sx = this._scale.x * parent._renderer.scale.x;
sy = this._scale.y * parent._renderer.scale.y;
} else {
this._renderer.scale.x = this._scale * parent._renderer.scale.x;
this._renderer.scale.y = this._scale * parent._renderer.scale.y;
sx = this._scale * parent._renderer.scale.x;
sy = this._scale * parent._renderer.scale.y;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;

if (parentChanged) {
this._renderer.parent = parent;
Expand Down Expand Up @@ -839,13 +842,16 @@ const webgl = {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.x = this._scale.x * parent._renderer.scale.x;
this._renderer.scale.y = this._scale.y * parent._renderer.scale.y;
sx = this._scale.x * parent._renderer.scale.x;
sy = this._scale.y * parent._renderer.scale.y;
} else {
this._renderer.scale.x = this._scale * parent._renderer.scale.x;
this._renderer.scale.y = this._scale * parent._renderer.scale.y;
sx = this._scale * parent._renderer.scale.x;
sy = this._scale * parent._renderer.scale.y;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;

if (parentChanged) {
this._renderer.parent = parent;
Expand Down Expand Up @@ -1270,13 +1276,16 @@ const webgl = {
if (!(this._renderer.scale instanceof Vector)) {
this._renderer.scale = new Vector();
}
let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.x = this._scale.x * parent._renderer.scale.x;
this._renderer.scale.y = this._scale.y * parent._renderer.scale.y;
sx = this._scale.x * parent._renderer.scale.x;
sy = this._scale.y * parent._renderer.scale.y;
} else {
this._renderer.scale.x = this._scale * parent._renderer.scale.x;
this._renderer.scale.y = this._scale * parent._renderer.scale.y;
sx = this._scale * parent._renderer.scale.x;
sy = this._scale * parent._renderer.scale.y;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;

if (parentChanged) {
this._renderer.parent = parent;
Expand Down Expand Up @@ -1516,11 +1525,16 @@ const webgl = {
this._renderer.scale = new Vector();
}

let sx, sy;
if (this._scale instanceof Vector) {
this._renderer.scale.copy(this._scale);
sx = this._scale.x;
sy = this._scale.y;
} else {
this._renderer.scale.set(this._scale, this._scale);
sx = this._scale;
sy = this._scale;
}
this._renderer.scale.x = sx < 0 ? -sx : sx;
this._renderer.scale.y = sy < 0 ? -sy : sy;
}

return this.flagReset();
Expand Down
1 change: 1 addition & 0 deletions wiki/changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. The format

## Nightly

+ `Two.WebGLRenderer` correctly handles negative scale values
+ `Two.Path.noStroke`, `Two.Text.noStroke`, and derivative methods now include setting both the stroke color to `"none"` and the line width to 0
+ Fixed `Two.Arc` flag behavior for `Two.Arc.width` and `Two.Arc.height` properties

Expand Down

0 comments on commit 6b2684a

Please sign in to comment.