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