meshwriter-cudu 3.0.2 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/meshwriter.cjs.js +112 -39
- package/dist/meshwriter.cjs.js.map +1 -1
- package/dist/meshwriter.esm.js +112 -39
- package/dist/meshwriter.esm.js.map +1 -1
- package/dist/meshwriter.min.js +1 -1
- package/dist/meshwriter.min.js.map +1 -1
- package/dist/meshwriter.umd.js +112 -39
- package/dist/meshwriter.umd.js.map +1 -1
- package/dist/src/fogPlugin.d.ts +35 -4
- package/fonts/baked/atkinson-hyperlegible-next-200.js +1973 -0
- package/fonts/baked/atkinson-hyperlegible-next-200.json +1 -1
- package/fonts/baked/atkinson-hyperlegible-next-300.js +1995 -0
- package/fonts/baked/atkinson-hyperlegible-next-300.json +1 -1
- package/fonts/baked/atkinson-hyperlegible-next-400.js +1949 -0
- package/fonts/baked/atkinson-hyperlegible-next-400.json +1 -1
- package/fonts/baked/atkinson-hyperlegible-next-500.js +1981 -0
- package/fonts/baked/atkinson-hyperlegible-next-500.json +1 -1
- package/fonts/baked/atkinson-hyperlegible-next-600.js +1982 -0
- package/fonts/baked/atkinson-hyperlegible-next-600.json +1 -1
- package/fonts/baked/atkinson-hyperlegible-next-700.js +1974 -0
- package/fonts/baked/atkinson-hyperlegible-next-700.json +1 -1
- package/fonts/baked/atkinson-hyperlegible-next-800.js +1977 -0
- package/fonts/baked/atkinson-hyperlegible-next-800.json +1 -1
- package/fonts/baked/manifest.json +10 -28
- package/package.json +3 -2
- package/src/fogPlugin.js +100 -30
- package/src/material.js +12 -9
- package/fonts/baked/atkinson-hyperlegible-next-250.json +0 -1
- package/fonts/baked/atkinson-hyperlegible-next-350.json +0 -1
- package/fonts/baked/atkinson-hyperlegible-next-450.json +0 -1
- package/fonts/baked/atkinson-hyperlegible-next-550.json +0 -1
- package/fonts/baked/atkinson-hyperlegible-next-650.json +0 -1
- package/fonts/baked/atkinson-hyperlegible-next-750.json +0 -1
package/dist/meshwriter.cjs.js
CHANGED
|
@@ -520,17 +520,20 @@ function getCSGLib() {
|
|
|
520
520
|
}
|
|
521
521
|
|
|
522
522
|
/**
|
|
523
|
-
* TextFogPlugin - MaterialPluginBase that applies fog to
|
|
523
|
+
* TextFogPlugin - MaterialPluginBase that applies fog to text materials
|
|
524
524
|
*
|
|
525
|
-
* Babylon's
|
|
526
|
-
*
|
|
527
|
-
*
|
|
525
|
+
* Since we disable Babylon's built-in fog (material.fogEnabled = false) to avoid
|
|
526
|
+
* double-fogging of diffuse colors, this plugin handles ALL fog application.
|
|
527
|
+
* It supplies its own uniforms and varyings to calculate fog distance and blend.
|
|
528
|
+
*
|
|
529
|
+
* This ensures text (with emissive colors) fades into fog at the same rate as
|
|
530
|
+
* terrain (which uses only diffuse colors with standard fog).
|
|
528
531
|
*/
|
|
529
532
|
|
|
530
533
|
|
|
531
534
|
/**
|
|
532
|
-
* Plugin that applies scene fog to text materials
|
|
533
|
-
*
|
|
535
|
+
* Plugin that applies scene fog to text materials uniformly.
|
|
536
|
+
* Handles fog for both diffuse and emissive components in one pass.
|
|
534
537
|
*/
|
|
535
538
|
class TextFogPlugin extends materialPluginBase.MaterialPluginBase {
|
|
536
539
|
/**
|
|
@@ -551,6 +554,7 @@ class TextFogPlugin extends materialPluginBase.MaterialPluginBase {
|
|
|
551
554
|
*/
|
|
552
555
|
prepareDefines(defines, scene, mesh) {
|
|
553
556
|
// Enable when scene has any fog mode set (1=LINEAR, 2=EXP, 3=EXP2)
|
|
557
|
+
// This is independent of material.fogEnabled since we handle fog ourselves
|
|
554
558
|
defines['MESHWRITER_TEXT_FOG'] = scene.fogMode !== 0;
|
|
555
559
|
}
|
|
556
560
|
|
|
@@ -558,10 +562,53 @@ class TextFogPlugin extends materialPluginBase.MaterialPluginBase {
|
|
|
558
562
|
return 'TextFogPlugin';
|
|
559
563
|
}
|
|
560
564
|
|
|
565
|
+
/**
|
|
566
|
+
* Define our own fog uniforms since material.fogEnabled = false
|
|
567
|
+
* means Babylon's built-in fog uniforms won't be available.
|
|
568
|
+
*
|
|
569
|
+
* - ubo: Used when Uniform Buffer Objects are enabled (Safari)
|
|
570
|
+
* - fragment: Used when UBOs are disabled (Chrome) - provides standalone declarations
|
|
571
|
+
*
|
|
572
|
+
* Babylon.js chooses between these based on engine capabilities.
|
|
573
|
+
*/
|
|
561
574
|
getUniforms() {
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
575
|
+
return {
|
|
576
|
+
ubo: [
|
|
577
|
+
{ name: 'textFogInfos', size: 4, type: 'vec4' },
|
|
578
|
+
{ name: 'textFogColor', size: 3, type: 'vec3' }
|
|
579
|
+
],
|
|
580
|
+
vertex: '',
|
|
581
|
+
fragment: `
|
|
582
|
+
uniform vec4 textFogInfos;
|
|
583
|
+
uniform vec3 textFogColor;
|
|
584
|
+
`
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Bind fog values from the scene to our custom uniforms
|
|
590
|
+
* @param {import('@babylonjs/core/Materials/uniformBuffer').UniformBuffer} uniformBuffer
|
|
591
|
+
* @param {import('@babylonjs/core/scene').Scene} scene
|
|
592
|
+
* @param {import('@babylonjs/core/Engines/engine').Engine} engine
|
|
593
|
+
* @param {import('@babylonjs/core/Meshes/subMesh').SubMesh} subMesh
|
|
594
|
+
*/
|
|
595
|
+
bindForSubMesh(uniformBuffer, scene, engine, subMesh) {
|
|
596
|
+
if (scene.fogMode === 0) return;
|
|
597
|
+
|
|
598
|
+
// textFogInfos: x=fogMode, y=fogStart, z=fogEnd, w=fogDensity
|
|
599
|
+
uniformBuffer.updateFloat4(
|
|
600
|
+
'textFogInfos',
|
|
601
|
+
scene.fogMode,
|
|
602
|
+
scene.fogStart,
|
|
603
|
+
scene.fogEnd,
|
|
604
|
+
scene.fogDensity
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
// textFogColor: RGB color of the fog
|
|
608
|
+
uniformBuffer.updateColor3(
|
|
609
|
+
'textFogColor',
|
|
610
|
+
scene.fogColor
|
|
611
|
+
);
|
|
565
612
|
}
|
|
566
613
|
|
|
567
614
|
/**
|
|
@@ -572,47 +619,70 @@ class TextFogPlugin extends materialPluginBase.MaterialPluginBase {
|
|
|
572
619
|
}
|
|
573
620
|
|
|
574
621
|
/**
|
|
575
|
-
* Inject shader code to
|
|
622
|
+
* Inject shader code to calculate fog distance and apply fog blending
|
|
576
623
|
* @param {string} shaderType - 'vertex' or 'fragment'
|
|
577
624
|
*/
|
|
578
625
|
getCustomCode(shaderType) {
|
|
626
|
+
if (shaderType === 'vertex') {
|
|
627
|
+
return {
|
|
628
|
+
// Declare our varying for fog distance
|
|
629
|
+
'CUSTOM_VERTEX_DEFINITIONS': `
|
|
630
|
+
#ifdef MESHWRITER_TEXT_FOG
|
|
631
|
+
varying vec3 textFogDistance;
|
|
632
|
+
#endif
|
|
633
|
+
`,
|
|
634
|
+
// Calculate fog distance in view space at end of vertex shader
|
|
635
|
+
// finalWorld and positionUpdated are Babylon's built-in variables
|
|
636
|
+
'CUSTOM_VERTEX_MAIN_END': `
|
|
637
|
+
#ifdef MESHWRITER_TEXT_FOG
|
|
638
|
+
vec4 textWorldPos = finalWorld * vec4(positionUpdated, 1.0);
|
|
639
|
+
textFogDistance = (view * textWorldPos).xyz;
|
|
640
|
+
#endif
|
|
641
|
+
`
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
|
|
579
645
|
if (shaderType === 'fragment') {
|
|
580
646
|
return {
|
|
581
|
-
//
|
|
582
|
-
//
|
|
583
|
-
//
|
|
584
|
-
//
|
|
647
|
+
// Declare varying in fragment shader
|
|
648
|
+
// Note: textFogInfos and textFogColor uniforms come from the Material UBO
|
|
649
|
+
// (defined in getUniforms). Don't redeclare them here - Safari's strict
|
|
650
|
+
// GLSL compiler rejects duplicate declarations.
|
|
651
|
+
'CUSTOM_FRAGMENT_DEFINITIONS': `
|
|
652
|
+
#ifdef MESHWRITER_TEXT_FOG
|
|
653
|
+
varying vec3 textFogDistance;
|
|
654
|
+
#endif
|
|
655
|
+
`,
|
|
656
|
+
// Apply fog to the entire fragment color before final output
|
|
657
|
+
// This runs just before gl_FragColor is set
|
|
585
658
|
'CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR': `
|
|
586
659
|
#ifdef MESHWRITER_TEXT_FOG
|
|
587
|
-
|
|
588
|
-
//
|
|
589
|
-
// vFogInfos: x=fogMode, y=fogStart, z=fogEnd, w=fogDensity
|
|
590
|
-
// vFogColor: fog RGB color
|
|
591
|
-
// vFogDistance: vec3 distance from camera (set by vertex shader)
|
|
660
|
+
// textFogInfos: x=fogMode, y=fogStart, z=fogEnd, w=fogDensity
|
|
661
|
+
// Fog modes: 1=LINEAR, 2=EXP, 3=EXP2
|
|
592
662
|
|
|
593
663
|
float textFogFactor = 1.0;
|
|
594
|
-
float textFogDist = length(
|
|
664
|
+
float textFogDist = length(textFogDistance);
|
|
595
665
|
|
|
596
|
-
if (
|
|
666
|
+
if (textFogInfos.x == 1.0) {
|
|
597
667
|
// Linear fog: factor = (end - dist) / (end - start)
|
|
598
|
-
textFogFactor = clamp((
|
|
599
|
-
} else if (
|
|
668
|
+
textFogFactor = clamp((textFogInfos.z - textFogDist) / (textFogInfos.z - textFogInfos.y), 0.0, 1.0);
|
|
669
|
+
} else if (textFogInfos.x == 2.0) {
|
|
600
670
|
// Exponential fog: factor = exp(-dist * density)
|
|
601
|
-
textFogFactor = clamp(exp(-textFogDist *
|
|
602
|
-
} else if (
|
|
671
|
+
textFogFactor = clamp(exp(-textFogDist * textFogInfos.w), 0.0, 1.0);
|
|
672
|
+
} else if (textFogInfos.x == 3.0) {
|
|
603
673
|
// Exponential squared fog: factor = exp(-(dist * density)^2)
|
|
604
|
-
float fogDistDensity = textFogDist *
|
|
674
|
+
float fogDistDensity = textFogDist * textFogInfos.w;
|
|
605
675
|
textFogFactor = clamp(exp(-fogDistDensity * fogDistDensity), 0.0, 1.0);
|
|
606
676
|
}
|
|
607
677
|
|
|
608
|
-
// Blend the entire fragment (
|
|
678
|
+
// Blend the entire fragment (diffuse + emissive) toward fog color
|
|
609
679
|
// textFogFactor: 1.0 = no fog (full color), 0.0 = full fog
|
|
610
|
-
color.rgb = mix(
|
|
611
|
-
#endif
|
|
680
|
+
color.rgb = mix(textFogColor, color.rgb, textFogFactor);
|
|
612
681
|
#endif
|
|
613
|
-
|
|
682
|
+
`
|
|
614
683
|
};
|
|
615
684
|
}
|
|
685
|
+
|
|
616
686
|
return null;
|
|
617
687
|
}
|
|
618
688
|
}
|
|
@@ -677,15 +747,17 @@ function makeMaterial(scene, letters, emissive, ambient, specular, diffuse, opac
|
|
|
677
747
|
// Emissive-only materials should be self-lit and not affected by fog
|
|
678
748
|
if (emissiveOnly) {
|
|
679
749
|
material.fogEnabled = false;
|
|
750
|
+
} else if (fogEnabled) {
|
|
751
|
+
// IMPORTANT: Disable Babylon's built-in fog when using TextFogPlugin.
|
|
752
|
+
// Built-in fog only affects diffuse/ambient, not emissive.
|
|
753
|
+
// If we left fogEnabled=true, diffuse would be fogged twice (once by Babylon,
|
|
754
|
+
// once by the plugin), while emissive would only be fogged once by the plugin.
|
|
755
|
+
// By disabling built-in fog and handling ALL fog in the plugin, we get uniform
|
|
756
|
+
// fog application to the entire fragment (matching terrain behavior).
|
|
757
|
+
material.fogEnabled = false;
|
|
758
|
+
material._textFogPlugin = new TextFogPlugin(material);
|
|
680
759
|
} else {
|
|
681
|
-
material.fogEnabled =
|
|
682
|
-
// Attach fog plugin to properly blend emissive color with fog
|
|
683
|
-
// Babylon's standard fog only affects diffuse/ambient, not emissive.
|
|
684
|
-
// The plugin re-fogs the entire fragment output so emissive fades properly.
|
|
685
|
-
// (The slight double-fog on diffuse/ambient is negligible since text is primarily emissive)
|
|
686
|
-
if (fogEnabled) {
|
|
687
|
-
material._textFogPlugin = new TextFogPlugin(material);
|
|
688
|
-
}
|
|
760
|
+
material.fogEnabled = false;
|
|
689
761
|
}
|
|
690
762
|
|
|
691
763
|
return material;
|
|
@@ -711,7 +783,8 @@ function makeFaceMaterial(scene, letters, emissive, opac, fogEnabled = true) {
|
|
|
711
783
|
material.disableLighting = true;
|
|
712
784
|
material.alpha = opac;
|
|
713
785
|
material.backFaceCulling = false;
|
|
714
|
-
|
|
786
|
+
// Disable Babylon's built-in fog - TextFogPlugin handles all fog uniformly
|
|
787
|
+
material.fogEnabled = false;
|
|
715
788
|
if (fogEnabled) {
|
|
716
789
|
material._textFogPlugin = new TextFogPlugin(material);
|
|
717
790
|
}
|