Skip to content

Commit 02bd060

Browse files
committed
Gizmo fixes (#7956)
* fix: correct alpha channel usage in fragment color output * fix: optimize visibility setter to prevent unnecessary updates * fix: add alpha channel check to discard transparent fragments in unlit shader * fix: update alpha channel threshold for fragment discard in unlit shader * fix: add axis flipping functionality in ScaleGizmo based on camera direction
1 parent 1526212 commit 02bd060

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/extras/gizmo/scale-gizmo.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,16 @@ class ScaleGizmo extends TransformGizmo {
580580
}
581581

582582
// mirror axes
583-
const cameraDir = this.cameraDir;
584-
const rot = tmpQ1.copy(this._rootStartRot);
585-
let dot = cameraDir.dot(rot.transformVector(Vec3.RIGHT, tmpV1));
586-
point.x *= dot < 0 ? -1 : 1;
587-
dot = cameraDir.dot(rot.transformVector(Vec3.UP, tmpV1));
588-
point.y *= dot < 0 ? -1 : 1;
589-
dot = cameraDir.dot(rot.transformVector(Vec3.FORWARD, tmpV1));
590-
point.z *= dot > 0 ? -1 : 1;
583+
if (this.flipAxes) {
584+
const cameraDir = this.cameraDir;
585+
const rot = tmpQ1.copy(this._rootStartRot);
586+
let dot = cameraDir.dot(rot.transformVector(Vec3.RIGHT, tmpV1));
587+
point.x *= dot < 0 ? -1 : 1;
588+
dot = cameraDir.dot(rot.transformVector(Vec3.UP, tmpV1));
589+
point.y *= dot < 0 ? -1 : 1;
590+
dot = cameraDir.dot(rot.transformVector(Vec3.FORWARD, tmpV1));
591+
point.z *= dot > 0 ? -1 : 1;
592+
}
591593

592594
// uniform scaling for planes
593595
if (this._uniform && isPlane) {

src/extras/gizmo/shaders.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export const unlitShader = {
2929
uniform vec4 uColor;
3030
3131
void main(void) {
32-
gl_FragColor = vec4(gammaCorrectOutput(decodeGamma(uColor)), uColor.w);
32+
if (uColor.a < 1.0 / 255.0) {
33+
discard;
34+
}
35+
gl_FragColor = vec4(gammaCorrectOutput(decodeGamma(uColor)), uColor.a);
3336
#if DEPTH_WRITE == 0
3437
gl_FragDepth = 0.0;
3538
#endif
@@ -58,7 +61,10 @@ export const unlitShader = {
5861
@fragment
5962
fn fragmentMain(input: FragmentInput) -> FragmentOutput {
6063
var output: FragmentOutput;
61-
output.color = vec4f(gammaCorrectOutput(decodeGamma(uniform.uColor)), uniform.uColor.w);
64+
if (uniform.uColor.a < 1.0 / 255.0) {
65+
discard;
66+
}
67+
output.color = vec4f(gammaCorrectOutput(decodeGamma(uniform.uColor)), uniform.uColor.a);
6268
#if DEPTH_WRITE == 0
6369
output.fragDepth = 0.0;
6470
#endif

src/extras/gizmo/shape/shape.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ class Shape {
230230
* @type {boolean}
231231
*/
232232
set visible(value) {
233+
if (value === this._visible) {
234+
return;
235+
}
233236
for (let i = 0; i < this.meshInstances.length; i++) {
234237
this.meshInstances[i].visible = value;
235238
}

0 commit comments

Comments
 (0)