Skip to content

Commit aade13f

Browse files
committed
tidy up
1 parent ae6a10d commit aade13f

File tree

2 files changed

+68
-83
lines changed

2 files changed

+68
-83
lines changed

src/framework/components/element/text-element.js

Lines changed: 67 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Object.assign(pc, function () {
103103

104104
this._outlineColor = new pc.Color(0, 0, 0, 1);
105105
this._outlineColorUniform = new Float32Array(4);
106-
this._outlineThicknessScale = 0.2; // coefficient to map editor range of 0 - 1 to shader value
106+
this._outlineThicknessScale = 0.2; // 0.2 coefficient to map editor range of 0 - 1 to shader value
107107
this._outlineThickness = 0.0;
108108

109109
this._multiPassEnabled = false; // when true multi pass text rendering is enabled for correct thicker outline rendering
@@ -114,8 +114,6 @@ Object.assign(pc, function () {
114114
this._shadowOffset = new pc.Vec2(0, 0);
115115
this._shadowOffsetUniform = new Float32Array(2);
116116

117-
this._zeroColorUniform = new Float32Array(4);
118-
119117
this._enableMarkup = false;
120118

121119
// initialize based on screen
@@ -461,20 +459,16 @@ Object.assign(pc, function () {
461459

462460
meshInfo.count = l;
463461

464-
switch (this._meshInfo[i].renderPass) {
465-
case RenderPass.TEXT:
466-
case RenderPass.ALL_IN_ONE:
467-
meshInfo.positions.length = meshInfo.normals.length = l * 3 * 4;
468-
meshInfo.indices.length = l * 3 * 2;
469-
meshInfo.uvs.length = l * 2 * 4;
470-
meshInfo.colors.length = l * 4 * 4;
471-
break;
472-
default:
473-
meshInfo.positions.length = meshInfo.normals.length = 0;
474-
meshInfo.indices.length = 0;
475-
meshInfo.uvs.length = 0;
476-
meshInfo.colors.length = 0;
477-
break;
462+
if (!this._multiPassEnabled || this._meshInfo[i].renderPass == RenderPass.TEXT) {
463+
meshInfo.positions.length = meshInfo.normals.length = l * 3 * 4;
464+
meshInfo.indices.length = l * 3 * 2;
465+
meshInfo.uvs.length = l * 2 * 4;
466+
meshInfo.colors.length = l * 4 * 4;
467+
} else {
468+
meshInfo.positions.length = meshInfo.normals.length = 0;
469+
meshInfo.indices.length = 0;
470+
meshInfo.uvs.length = 0;
471+
meshInfo.colors.length = 0;
478472
}
479473

480474
// destroy old mesh
@@ -491,48 +485,44 @@ Object.assign(pc, function () {
491485

492486
var mesh = null;
493487

494-
switch (this._meshInfo[i].renderPass) {
495-
case RenderPass.TEXT:
496-
case RenderPass.ALL_IN_ONE:
497-
// set up indices and normals whose values don't change when we call _updateMeshes
498-
for (var v = 0; v < l; v++) {
499-
// create index and normal arrays since they don't change
500-
// if the length doesn't change
501-
meshInfo.indices[v * 3 * 2 + 0] = v * 4;
502-
meshInfo.indices[v * 3 * 2 + 1] = v * 4 + 1;
503-
meshInfo.indices[v * 3 * 2 + 2] = v * 4 + 3;
504-
meshInfo.indices[v * 3 * 2 + 3] = v * 4 + 2;
505-
meshInfo.indices[v * 3 * 2 + 4] = v * 4 + 3;
506-
meshInfo.indices[v * 3 * 2 + 5] = v * 4 + 1;
507-
508-
meshInfo.normals[v * 4 * 3 + 0] = 0;
509-
meshInfo.normals[v * 4 * 3 + 1] = 0;
510-
meshInfo.normals[v * 4 * 3 + 2] = -1;
511-
512-
meshInfo.normals[v * 4 * 3 + 3] = 0;
513-
meshInfo.normals[v * 4 * 3 + 4] = 0;
514-
meshInfo.normals[v * 4 * 3 + 5] = -1;
515-
516-
meshInfo.normals[v * 4 * 3 + 6] = 0;
517-
meshInfo.normals[v * 4 * 3 + 7] = 0;
518-
meshInfo.normals[v * 4 * 3 + 8] = -1;
519-
520-
meshInfo.normals[v * 4 * 3 + 9] = 0;
521-
meshInfo.normals[v * 4 * 3 + 10] = 0;
522-
meshInfo.normals[v * 4 * 3 + 11] = -1;
523-
}
524-
mesh = pc.createMesh(this._system.app.graphicsDevice,
525-
meshInfo.positions,
526-
{
527-
uvs: meshInfo.uvs,
528-
normals: meshInfo.normals,
529-
colors: meshInfo.colors,
530-
indices: meshInfo.indices
531-
});
532-
break;
533-
default:
534-
mesh = this._model.meshInstances[ti].mesh;
535-
break;
488+
if (!this._multiPassEnabled || this._meshInfo[i].renderPass == RenderPass.TEXT) {
489+
// set up indices and normals whose values don't change when we call _updateMeshes
490+
for (var v = 0; v < l; v++) {
491+
// create index and normal arrays since they don't change
492+
// if the length doesn't change
493+
meshInfo.indices[v * 3 * 2 + 0] = v * 4;
494+
meshInfo.indices[v * 3 * 2 + 1] = v * 4 + 1;
495+
meshInfo.indices[v * 3 * 2 + 2] = v * 4 + 3;
496+
meshInfo.indices[v * 3 * 2 + 3] = v * 4 + 2;
497+
meshInfo.indices[v * 3 * 2 + 4] = v * 4 + 3;
498+
meshInfo.indices[v * 3 * 2 + 5] = v * 4 + 1;
499+
500+
meshInfo.normals[v * 4 * 3 + 0] = 0;
501+
meshInfo.normals[v * 4 * 3 + 1] = 0;
502+
meshInfo.normals[v * 4 * 3 + 2] = -1;
503+
504+
meshInfo.normals[v * 4 * 3 + 3] = 0;
505+
meshInfo.normals[v * 4 * 3 + 4] = 0;
506+
meshInfo.normals[v * 4 * 3 + 5] = -1;
507+
508+
meshInfo.normals[v * 4 * 3 + 6] = 0;
509+
meshInfo.normals[v * 4 * 3 + 7] = 0;
510+
meshInfo.normals[v * 4 * 3 + 8] = -1;
511+
512+
meshInfo.normals[v * 4 * 3 + 9] = 0;
513+
meshInfo.normals[v * 4 * 3 + 10] = 0;
514+
meshInfo.normals[v * 4 * 3 + 11] = -1;
515+
}
516+
mesh = pc.createMesh(this._system.app.graphicsDevice,
517+
meshInfo.positions,
518+
{
519+
uvs: meshInfo.uvs,
520+
normals: meshInfo.normals,
521+
colors: meshInfo.colors,
522+
indices: meshInfo.indices
523+
});
524+
} else {
525+
mesh = this._model.meshInstances[ti].mesh;
536526
}
537527

538528
var mi = new pc.MeshInstance(this._node, mesh, this._material);
@@ -565,6 +555,7 @@ Object.assign(pc, function () {
565555
this._colorUniform[2] = this._color.b;
566556
}
567557
mi.setParameter("material_emissive", this._colorUniform);
558+
mi.setParameter("material_opacity", this._color.a);
568559
mi.setParameter("font_sdfIntensity", this._font.intensity);
569560
mi.setParameter("font_pxrange", this._getPxRange(this._font));
570561
mi.setParameter("font_textureWidth", this._font.data.info.maps[ti].width);
@@ -573,30 +564,22 @@ Object.assign(pc, function () {
573564
this._outlineColorUniform[1] = this._outlineColor.g;
574565
this._outlineColorUniform[2] = this._outlineColor.b;
575566
this._outlineColorUniform[3] = this._outlineColor.a;
576-
567+
mi.setParameter("outline_color", this._outlineColorUniform);
577568
mi.setParameter("outline_thickness", this._outlineThicknessScale * this._outlineThickness);
578569

579570
this._shadowColorUniform[0] = this._shadowColor.r;
580571
this._shadowColorUniform[1] = this._shadowColor.g;
581572
this._shadowColorUniform[2] = this._shadowColor.b;
582573
this._shadowColorUniform[3] = this._shadowColor.a;
574+
mi.setParameter("shadow_color", this._shadowColorUniform);
583575

584576
var ratio = this._font.data.info.maps[ti].width / this._font.data.info.maps[ti].height;
585577
this._shadowOffsetUniform[0] = this._shadowOffsetScale * this._shadowOffset.x;
586578
this._shadowOffsetUniform[1] = ratio * this._shadowOffsetScale * this._shadowOffset.y;
587579
mi.setParameter("shadow_offset", this._shadowOffsetUniform);
588580

589-
this._zeroColorUniform[0] = 0.0;
590-
this._zeroColorUniform[1] = 0.0;
591-
this._zeroColorUniform[2] = 0.0;
592-
this._zeroColorUniform[3] = 0.0;
593-
594581
mi.setParameter("render_pass", this._meshInfo[i].renderPass);
595582

596-
mi.setParameter("material_opacity", this._color.a);
597-
mi.setParameter("outline_color", this._outlineColorUniform);
598-
mi.setParameter("shadow_color", this._shadowColorUniform);
599-
600583
meshInfo.meshInstance = mi;
601584

602585
this._model.meshInstances.push(mi);
@@ -1393,15 +1376,17 @@ Object.assign(pc, function () {
13931376

13941377
var i, len;
13951378

1396-
for (i = 0, len = (this._multiPassEnabled) ? 1 : this._meshInfo.length; i < len; i++) {
1397-
var start = startChars[i] || 0;
1398-
var end = endChars[i] || 0;
1399-
var instance = this._meshInfo[i].meshInstance;
1400-
if (instance) {
1401-
var mesh = instance.mesh;
1402-
if (mesh) {
1403-
mesh.primitive[0].base = start * 3 * 2;
1404-
mesh.primitive[0].count = (end - start) * 3 * 2;
1379+
for (i = 0, len = this._meshInfo.length; i < len; i++) {
1380+
if (!this._multiPassEnabled || this._meshInfo[i].renderPass == RenderPass.TEXT) {
1381+
var start = startChars[i] || 0;
1382+
var end = endChars[i] || 0;
1383+
var instance = this._meshInfo[i].meshInstance;
1384+
if (instance) {
1385+
var mesh = instance.mesh;
1386+
if (mesh) {
1387+
mesh.primitive[0].base = start * 3 * 2;
1388+
mesh.primitive[0].count = (end - start) * 3 * 2;
1389+
}
14051390
}
14061391
}
14071392
}
@@ -1492,9 +1477,9 @@ Object.assign(pc, function () {
14921477
this._color.a = value;
14931478

14941479
if (this._model) {
1495-
for (var i = 0; i < this._model.meshInstances.length; i++) {
1480+
for (var i = 0, len = this._model.meshInstances.length; i < len; i++) {
14961481
var mi = this._model.meshInstances[i];
1497-
mi.setParameter("material_opacity", this._color.a);
1482+
mi.setParameter('material_opacity', value);
14981483
}
14991484
}
15001485
}
@@ -1799,7 +1784,7 @@ Object.assign(pc, function () {
17991784

18001785
if (opaquenessChanged) this._updateText();
18011786

1802-
for (var i = 0; i < this._model.meshInstances.length; i++) {
1787+
for (var i = 0, len = this._model.meshInstances.length; i < len; i++) {
18031788
var mi = this._model.meshInstances[i];
18041789
mi.setParameter("outline_color", this._outlineColorUniform);
18051790
}
@@ -1822,7 +1807,7 @@ Object.assign(pc, function () {
18221807

18231808
for (var i = 0, len = this._model.meshInstances.length; i < len; i++) {
18241809
var mi = this._model.meshInstances[i];
1825-
mi.setParameter("outline_thickness", this._outlineThicknessScale * Math.min(this._outlineThickness, (this._font.data.version == 3) ? 1.0 : 5.0));
1810+
mi.setParameter("outline_thickness", this._outlineThicknessScale * Math.min(this._outlineThickness, (this._font.data.version >= 4) ? 5.0 : 1.0));
18261811
}
18271812
}
18281813
}

src/graphics/program-lib/chunks/msdf.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,5 @@ vec4 applyMsdf(vec4 color) {
112112
}
113113
#endif
114114

115-
return vec4(tcolor.rgb,tcolor.a);
115+
return tcolor;
116116
}

0 commit comments

Comments
 (0)