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.umd.js
CHANGED
|
@@ -468,17 +468,20 @@
|
|
|
468
468
|
}
|
|
469
469
|
|
|
470
470
|
/**
|
|
471
|
-
* TextFogPlugin - MaterialPluginBase that applies fog to
|
|
471
|
+
* TextFogPlugin - MaterialPluginBase that applies fog to text materials
|
|
472
472
|
*
|
|
473
|
-
* Babylon's
|
|
474
|
-
*
|
|
475
|
-
*
|
|
473
|
+
* Since we disable Babylon's built-in fog (material.fogEnabled = false) to avoid
|
|
474
|
+
* double-fogging of diffuse colors, this plugin handles ALL fog application.
|
|
475
|
+
* It supplies its own uniforms and varyings to calculate fog distance and blend.
|
|
476
|
+
*
|
|
477
|
+
* This ensures text (with emissive colors) fades into fog at the same rate as
|
|
478
|
+
* terrain (which uses only diffuse colors with standard fog).
|
|
476
479
|
*/
|
|
477
480
|
|
|
478
481
|
|
|
479
482
|
/**
|
|
480
|
-
* Plugin that applies scene fog to text materials
|
|
481
|
-
*
|
|
483
|
+
* Plugin that applies scene fog to text materials uniformly.
|
|
484
|
+
* Handles fog for both diffuse and emissive components in one pass.
|
|
482
485
|
*/
|
|
483
486
|
class TextFogPlugin extends materialPluginBase.MaterialPluginBase {
|
|
484
487
|
/**
|
|
@@ -499,6 +502,7 @@
|
|
|
499
502
|
*/
|
|
500
503
|
prepareDefines(defines, scene, mesh) {
|
|
501
504
|
// Enable when scene has any fog mode set (1=LINEAR, 2=EXP, 3=EXP2)
|
|
505
|
+
// This is independent of material.fogEnabled since we handle fog ourselves
|
|
502
506
|
defines['MESHWRITER_TEXT_FOG'] = scene.fogMode !== 0;
|
|
503
507
|
}
|
|
504
508
|
|
|
@@ -506,10 +510,53 @@
|
|
|
506
510
|
return 'TextFogPlugin';
|
|
507
511
|
}
|
|
508
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Define our own fog uniforms since material.fogEnabled = false
|
|
515
|
+
* means Babylon's built-in fog uniforms won't be available.
|
|
516
|
+
*
|
|
517
|
+
* - ubo: Used when Uniform Buffer Objects are enabled (Safari)
|
|
518
|
+
* - fragment: Used when UBOs are disabled (Chrome) - provides standalone declarations
|
|
519
|
+
*
|
|
520
|
+
* Babylon.js chooses between these based on engine capabilities.
|
|
521
|
+
*/
|
|
509
522
|
getUniforms() {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
523
|
+
return {
|
|
524
|
+
ubo: [
|
|
525
|
+
{ name: 'textFogInfos', size: 4, type: 'vec4' },
|
|
526
|
+
{ name: 'textFogColor', size: 3, type: 'vec3' }
|
|
527
|
+
],
|
|
528
|
+
vertex: '',
|
|
529
|
+
fragment: `
|
|
530
|
+
uniform vec4 textFogInfos;
|
|
531
|
+
uniform vec3 textFogColor;
|
|
532
|
+
`
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Bind fog values from the scene to our custom uniforms
|
|
538
|
+
* @param {import('@babylonjs/core/Materials/uniformBuffer').UniformBuffer} uniformBuffer
|
|
539
|
+
* @param {import('@babylonjs/core/scene').Scene} scene
|
|
540
|
+
* @param {import('@babylonjs/core/Engines/engine').Engine} engine
|
|
541
|
+
* @param {import('@babylonjs/core/Meshes/subMesh').SubMesh} subMesh
|
|
542
|
+
*/
|
|
543
|
+
bindForSubMesh(uniformBuffer, scene, engine, subMesh) {
|
|
544
|
+
if (scene.fogMode === 0) return;
|
|
545
|
+
|
|
546
|
+
// textFogInfos: x=fogMode, y=fogStart, z=fogEnd, w=fogDensity
|
|
547
|
+
uniformBuffer.updateFloat4(
|
|
548
|
+
'textFogInfos',
|
|
549
|
+
scene.fogMode,
|
|
550
|
+
scene.fogStart,
|
|
551
|
+
scene.fogEnd,
|
|
552
|
+
scene.fogDensity
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
// textFogColor: RGB color of the fog
|
|
556
|
+
uniformBuffer.updateColor3(
|
|
557
|
+
'textFogColor',
|
|
558
|
+
scene.fogColor
|
|
559
|
+
);
|
|
513
560
|
}
|
|
514
561
|
|
|
515
562
|
/**
|
|
@@ -520,47 +567,70 @@
|
|
|
520
567
|
}
|
|
521
568
|
|
|
522
569
|
/**
|
|
523
|
-
* Inject shader code to
|
|
570
|
+
* Inject shader code to calculate fog distance and apply fog blending
|
|
524
571
|
* @param {string} shaderType - 'vertex' or 'fragment'
|
|
525
572
|
*/
|
|
526
573
|
getCustomCode(shaderType) {
|
|
574
|
+
if (shaderType === 'vertex') {
|
|
575
|
+
return {
|
|
576
|
+
// Declare our varying for fog distance
|
|
577
|
+
'CUSTOM_VERTEX_DEFINITIONS': `
|
|
578
|
+
#ifdef MESHWRITER_TEXT_FOG
|
|
579
|
+
varying vec3 textFogDistance;
|
|
580
|
+
#endif
|
|
581
|
+
`,
|
|
582
|
+
// Calculate fog distance in view space at end of vertex shader
|
|
583
|
+
// finalWorld and positionUpdated are Babylon's built-in variables
|
|
584
|
+
'CUSTOM_VERTEX_MAIN_END': `
|
|
585
|
+
#ifdef MESHWRITER_TEXT_FOG
|
|
586
|
+
vec4 textWorldPos = finalWorld * vec4(positionUpdated, 1.0);
|
|
587
|
+
textFogDistance = (view * textWorldPos).xyz;
|
|
588
|
+
#endif
|
|
589
|
+
`
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
|
|
527
593
|
if (shaderType === 'fragment') {
|
|
528
594
|
return {
|
|
529
|
-
//
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
//
|
|
595
|
+
// Declare varying in fragment shader
|
|
596
|
+
// Note: textFogInfos and textFogColor uniforms come from the Material UBO
|
|
597
|
+
// (defined in getUniforms). Don't redeclare them here - Safari's strict
|
|
598
|
+
// GLSL compiler rejects duplicate declarations.
|
|
599
|
+
'CUSTOM_FRAGMENT_DEFINITIONS': `
|
|
600
|
+
#ifdef MESHWRITER_TEXT_FOG
|
|
601
|
+
varying vec3 textFogDistance;
|
|
602
|
+
#endif
|
|
603
|
+
`,
|
|
604
|
+
// Apply fog to the entire fragment color before final output
|
|
605
|
+
// This runs just before gl_FragColor is set
|
|
533
606
|
'CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR': `
|
|
534
607
|
#ifdef MESHWRITER_TEXT_FOG
|
|
535
|
-
|
|
536
|
-
//
|
|
537
|
-
// vFogInfos: x=fogMode, y=fogStart, z=fogEnd, w=fogDensity
|
|
538
|
-
// vFogColor: fog RGB color
|
|
539
|
-
// vFogDistance: vec3 distance from camera (set by vertex shader)
|
|
608
|
+
// textFogInfos: x=fogMode, y=fogStart, z=fogEnd, w=fogDensity
|
|
609
|
+
// Fog modes: 1=LINEAR, 2=EXP, 3=EXP2
|
|
540
610
|
|
|
541
611
|
float textFogFactor = 1.0;
|
|
542
|
-
float textFogDist = length(
|
|
612
|
+
float textFogDist = length(textFogDistance);
|
|
543
613
|
|
|
544
|
-
if (
|
|
614
|
+
if (textFogInfos.x == 1.0) {
|
|
545
615
|
// Linear fog: factor = (end - dist) / (end - start)
|
|
546
|
-
textFogFactor = clamp((
|
|
547
|
-
} else if (
|
|
616
|
+
textFogFactor = clamp((textFogInfos.z - textFogDist) / (textFogInfos.z - textFogInfos.y), 0.0, 1.0);
|
|
617
|
+
} else if (textFogInfos.x == 2.0) {
|
|
548
618
|
// Exponential fog: factor = exp(-dist * density)
|
|
549
|
-
textFogFactor = clamp(exp(-textFogDist *
|
|
550
|
-
} else if (
|
|
619
|
+
textFogFactor = clamp(exp(-textFogDist * textFogInfos.w), 0.0, 1.0);
|
|
620
|
+
} else if (textFogInfos.x == 3.0) {
|
|
551
621
|
// Exponential squared fog: factor = exp(-(dist * density)^2)
|
|
552
|
-
float fogDistDensity = textFogDist *
|
|
622
|
+
float fogDistDensity = textFogDist * textFogInfos.w;
|
|
553
623
|
textFogFactor = clamp(exp(-fogDistDensity * fogDistDensity), 0.0, 1.0);
|
|
554
624
|
}
|
|
555
625
|
|
|
556
|
-
// Blend the entire fragment (
|
|
626
|
+
// Blend the entire fragment (diffuse + emissive) toward fog color
|
|
557
627
|
// textFogFactor: 1.0 = no fog (full color), 0.0 = full fog
|
|
558
|
-
color.rgb = mix(
|
|
628
|
+
color.rgb = mix(textFogColor, color.rgb, textFogFactor);
|
|
559
629
|
#endif
|
|
560
|
-
|
|
561
|
-
`,
|
|
630
|
+
`
|
|
562
631
|
};
|
|
563
632
|
}
|
|
633
|
+
|
|
564
634
|
return null;
|
|
565
635
|
}
|
|
566
636
|
}
|
|
@@ -625,15 +695,17 @@
|
|
|
625
695
|
// Emissive-only materials should be self-lit and not affected by fog
|
|
626
696
|
if (emissiveOnly) {
|
|
627
697
|
material.fogEnabled = false;
|
|
698
|
+
} else if (fogEnabled) {
|
|
699
|
+
// IMPORTANT: Disable Babylon's built-in fog when using TextFogPlugin.
|
|
700
|
+
// Built-in fog only affects diffuse/ambient, not emissive.
|
|
701
|
+
// If we left fogEnabled=true, diffuse would be fogged twice (once by Babylon,
|
|
702
|
+
// once by the plugin), while emissive would only be fogged once by the plugin.
|
|
703
|
+
// By disabling built-in fog and handling ALL fog in the plugin, we get uniform
|
|
704
|
+
// fog application to the entire fragment (matching terrain behavior).
|
|
705
|
+
material.fogEnabled = false;
|
|
706
|
+
material._textFogPlugin = new TextFogPlugin(material);
|
|
628
707
|
} else {
|
|
629
|
-
material.fogEnabled =
|
|
630
|
-
// Attach fog plugin to properly blend emissive color with fog
|
|
631
|
-
// Babylon's standard fog only affects diffuse/ambient, not emissive.
|
|
632
|
-
// The plugin re-fogs the entire fragment output so emissive fades properly.
|
|
633
|
-
// (The slight double-fog on diffuse/ambient is negligible since text is primarily emissive)
|
|
634
|
-
if (fogEnabled) {
|
|
635
|
-
material._textFogPlugin = new TextFogPlugin(material);
|
|
636
|
-
}
|
|
708
|
+
material.fogEnabled = false;
|
|
637
709
|
}
|
|
638
710
|
|
|
639
711
|
return material;
|
|
@@ -659,7 +731,8 @@
|
|
|
659
731
|
material.disableLighting = true;
|
|
660
732
|
material.alpha = opac;
|
|
661
733
|
material.backFaceCulling = false;
|
|
662
|
-
|
|
734
|
+
// Disable Babylon's built-in fog - TextFogPlugin handles all fog uniformly
|
|
735
|
+
material.fogEnabled = false;
|
|
663
736
|
if (fogEnabled) {
|
|
664
737
|
material._textFogPlugin = new TextFogPlugin(material);
|
|
665
738
|
}
|