@babylonjs/post-processes 9.14.0 → 9.16.0
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/asciiArt/asciiArtPostProcess.js +141 -124
- package/asciiArt/asciiArtPostProcess.js.map +1 -1
- package/digitalRain/digitalRainPostProcess.js +140 -123
- package/digitalRain/digitalRainPostProcess.js.map +1 -1
- package/edgeDetection/edgeDetectionPostProcess.js +135 -116
- package/edgeDetection/edgeDetectionPostProcess.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __esDecorate, __runInitializers } from "@babylonjs/core/tslib.es6.js";
|
|
2
2
|
import { serialize } from "@babylonjs/core/Misc/decorators.js";
|
|
3
3
|
import { SerializationHelper } from "@babylonjs/core/Misc/decorators.serialization.js";
|
|
4
4
|
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
@@ -12,133 +12,150 @@ import "./asciiart.fragment.js";
|
|
|
12
12
|
* It basically takes care rendering the font front the given font size to a texture.
|
|
13
13
|
* This is used later on in the postprocess.
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const textureWidth = Math.ceil(this._charSize * text.length);
|
|
47
|
-
const textureHeight = this._charSize;
|
|
48
|
-
// Create the texture that will store the font characters.
|
|
49
|
-
this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
|
|
50
|
-
//scene.getEngine().setclamp
|
|
51
|
-
const textureSize = this.getSize();
|
|
52
|
-
// Create a canvas with the final size: the one matching the texture.
|
|
53
|
-
const canvas = document.createElement("canvas");
|
|
54
|
-
canvas.width = textureSize.width;
|
|
55
|
-
canvas.height = textureSize.height;
|
|
56
|
-
const context = canvas.getContext("2d");
|
|
57
|
-
context.textBaseline = "top";
|
|
58
|
-
context.font = font;
|
|
59
|
-
context.fillStyle = "white";
|
|
60
|
-
context.imageSmoothingEnabled = false;
|
|
61
|
-
// Sets the text in the texture.
|
|
62
|
-
for (let i = 0; i < text.length; i++) {
|
|
63
|
-
context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);
|
|
64
|
-
}
|
|
65
|
-
// Flush the text in the dynamic texture.
|
|
66
|
-
scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Gets the max char width of a font.
|
|
70
|
-
* @param font the font to use, use the W3C CSS notation
|
|
71
|
-
* @returns the max char width
|
|
72
|
-
*/
|
|
73
|
-
_getFontWidth(font) {
|
|
74
|
-
const fontDraw = document.createElement("canvas");
|
|
75
|
-
const ctx = fontDraw.getContext("2d");
|
|
76
|
-
ctx.fillStyle = "white";
|
|
77
|
-
ctx.font = font;
|
|
78
|
-
return ctx.measureText("W").width;
|
|
79
|
-
}
|
|
80
|
-
// More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
|
|
81
|
-
/**
|
|
82
|
-
* Gets the max char height of a font.
|
|
83
|
-
* @param font the font to use, use the W3C CSS notation
|
|
84
|
-
* @returns the max char height
|
|
85
|
-
*/
|
|
86
|
-
_getFontHeight(font) {
|
|
87
|
-
const fontDraw = document.createElement("canvas");
|
|
88
|
-
const ctx = fontDraw.getContext("2d");
|
|
89
|
-
ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
|
|
90
|
-
ctx.textBaseline = "top";
|
|
91
|
-
ctx.fillStyle = "white";
|
|
92
|
-
ctx.font = font;
|
|
93
|
-
ctx.fillText("jH|", 0, 0);
|
|
94
|
-
const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
|
|
95
|
-
let start = -1;
|
|
96
|
-
let end = -1;
|
|
97
|
-
for (let row = 0; row < fontDraw.height; row++) {
|
|
98
|
-
for (let column = 0; column < fontDraw.width; column++) {
|
|
99
|
-
const index = (row * fontDraw.width + column) * 4;
|
|
100
|
-
if (pixels[index] === 0) {
|
|
101
|
-
if (column === fontDraw.width - 1 && start !== -1) {
|
|
102
|
-
end = row;
|
|
103
|
-
row = fontDraw.height;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
continue;
|
|
15
|
+
let AsciiArtFontTexture = (() => {
|
|
16
|
+
var _a;
|
|
17
|
+
let _classSuper = BaseTexture;
|
|
18
|
+
let __font_decorators;
|
|
19
|
+
let __font_initializers = [];
|
|
20
|
+
let __font_extraInitializers = [];
|
|
21
|
+
let __text_decorators;
|
|
22
|
+
let __text_initializers = [];
|
|
23
|
+
let __text_extraInitializers = [];
|
|
24
|
+
return _a = class AsciiArtFontTexture extends _classSuper {
|
|
25
|
+
/**
|
|
26
|
+
* Gets the size of one char in the texture (each char fits in size * size space in the texture).
|
|
27
|
+
*/
|
|
28
|
+
get charSize() {
|
|
29
|
+
return this._charSize;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a new instance of the Ascii Art FontTexture class
|
|
33
|
+
* @param name the name of the texture
|
|
34
|
+
* @param font the font to use, use the W3C CSS notation
|
|
35
|
+
* @param text the caracter set to use in the rendering.
|
|
36
|
+
* @param scene the scene that owns the texture
|
|
37
|
+
*/
|
|
38
|
+
constructor(name, font, text, scene = null) {
|
|
39
|
+
super(scene);
|
|
40
|
+
this._font = __runInitializers(this, __font_initializers, void 0);
|
|
41
|
+
this._text = (__runInitializers(this, __font_extraInitializers), __runInitializers(this, __text_initializers, void 0));
|
|
42
|
+
this._charSize = __runInitializers(this, __text_extraInitializers);
|
|
43
|
+
scene = this.getScene();
|
|
44
|
+
if (!scene) {
|
|
45
|
+
return;
|
|
107
46
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
47
|
+
this.name = name;
|
|
48
|
+
this._text == text;
|
|
49
|
+
this._font == font;
|
|
50
|
+
this.wrapU = Texture.CLAMP_ADDRESSMODE;
|
|
51
|
+
this.wrapV = Texture.CLAMP_ADDRESSMODE;
|
|
52
|
+
//this.anisotropicFilteringLevel = 1;
|
|
53
|
+
// Get the font specific info.
|
|
54
|
+
const maxCharHeight = this._getFontHeight(font);
|
|
55
|
+
const maxCharWidth = this._getFontWidth(font);
|
|
56
|
+
this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
|
|
57
|
+
// This is an approximate size, but should always be able to fit at least the maxCharCount.
|
|
58
|
+
const textureWidth = Math.ceil(this._charSize * text.length);
|
|
59
|
+
const textureHeight = this._charSize;
|
|
60
|
+
// Create the texture that will store the font characters.
|
|
61
|
+
this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
|
|
62
|
+
//scene.getEngine().setclamp
|
|
63
|
+
const textureSize = this.getSize();
|
|
64
|
+
// Create a canvas with the final size: the one matching the texture.
|
|
65
|
+
const canvas = document.createElement("canvas");
|
|
66
|
+
canvas.width = textureSize.width;
|
|
67
|
+
canvas.height = textureSize.height;
|
|
68
|
+
const context = canvas.getContext("2d");
|
|
69
|
+
context.textBaseline = "top";
|
|
70
|
+
context.font = font;
|
|
71
|
+
context.fillStyle = "white";
|
|
72
|
+
context.imageSmoothingEnabled = false;
|
|
73
|
+
// Sets the text in the texture.
|
|
74
|
+
for (let i = 0; i < text.length; i++) {
|
|
75
|
+
context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);
|
|
76
|
+
}
|
|
77
|
+
// Flush the text in the dynamic texture.
|
|
78
|
+
scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets the max char width of a font.
|
|
82
|
+
* @param font the font to use, use the W3C CSS notation
|
|
83
|
+
* @returns the max char width
|
|
84
|
+
*/
|
|
85
|
+
_getFontWidth(font) {
|
|
86
|
+
const fontDraw = document.createElement("canvas");
|
|
87
|
+
const ctx = fontDraw.getContext("2d");
|
|
88
|
+
ctx.fillStyle = "white";
|
|
89
|
+
ctx.font = font;
|
|
90
|
+
return ctx.measureText("W").width;
|
|
91
|
+
}
|
|
92
|
+
// More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
|
|
93
|
+
/**
|
|
94
|
+
* Gets the max char height of a font.
|
|
95
|
+
* @param font the font to use, use the W3C CSS notation
|
|
96
|
+
* @returns the max char height
|
|
97
|
+
*/
|
|
98
|
+
_getFontHeight(font) {
|
|
99
|
+
const fontDraw = document.createElement("canvas");
|
|
100
|
+
const ctx = fontDraw.getContext("2d");
|
|
101
|
+
ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
|
|
102
|
+
ctx.textBaseline = "top";
|
|
103
|
+
ctx.fillStyle = "white";
|
|
104
|
+
ctx.font = font;
|
|
105
|
+
ctx.fillText("jH|", 0, 0);
|
|
106
|
+
const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
|
|
107
|
+
let start = -1;
|
|
108
|
+
let end = -1;
|
|
109
|
+
for (let row = 0; row < fontDraw.height; row++) {
|
|
110
|
+
for (let column = 0; column < fontDraw.width; column++) {
|
|
111
|
+
const index = (row * fontDraw.width + column) * 4;
|
|
112
|
+
if (pixels[index] === 0) {
|
|
113
|
+
if (column === fontDraw.width - 1 && start !== -1) {
|
|
114
|
+
end = row;
|
|
115
|
+
row = fontDraw.height;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
if (start === -1) {
|
|
122
|
+
start = row;
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
111
126
|
}
|
|
112
|
-
break;
|
|
113
127
|
}
|
|
128
|
+
return { height: end - start + 1, offset: start - 1 };
|
|
114
129
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Clones the current AsciiArtTexture.
|
|
132
|
+
* @returns the clone of the texture.
|
|
133
|
+
*/
|
|
134
|
+
clone() {
|
|
135
|
+
return new _a(this.name, this._font, this._text, this.getScene());
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Parses a json object representing the texture and returns an instance of it.
|
|
139
|
+
* @param source the source JSON representation
|
|
140
|
+
* @param scene the scene to create the texture for
|
|
141
|
+
* @returns the parsed texture
|
|
142
|
+
*/
|
|
143
|
+
static Parse(source, scene) {
|
|
144
|
+
const texture = SerializationHelper.Parse(() => new _a(source.name, source.font, source.text, scene), source, scene, null);
|
|
145
|
+
return texture;
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
(() => {
|
|
149
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
150
|
+
__font_decorators = [serialize("font")];
|
|
151
|
+
__text_decorators = [serialize("text")];
|
|
152
|
+
__esDecorate(null, null, __font_decorators, { kind: "field", name: "_font", static: false, private: false, access: { has: obj => "_font" in obj, get: obj => obj._font, set: (obj, value) => { obj._font = value; } }, metadata: _metadata }, __font_initializers, __font_extraInitializers);
|
|
153
|
+
__esDecorate(null, null, __text_decorators, { kind: "field", name: "_text", static: false, private: false, access: { has: obj => "_text" in obj, get: obj => obj._text, set: (obj, value) => { obj._text = value; } }, metadata: _metadata }, __text_initializers, __text_extraInitializers);
|
|
154
|
+
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
155
|
+
})(),
|
|
156
|
+
_a;
|
|
157
|
+
})();
|
|
158
|
+
export { AsciiArtFontTexture };
|
|
142
159
|
/**
|
|
143
160
|
* AsciiArtPostProcess helps rendering everithing in Ascii Art.
|
|
144
161
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asciiArtPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/asciiArt/asciiArtPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D,OAAO,+CAA+C,CAAC;AACvD,OAAO,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAShD;;OAEG;IACH,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED;;;;;;OAMG;IACH,YAAY,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,QAAyB,IAAI;QAC/E,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAExB,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,OAAO;QACX,CAAC;QAED,IAAI,CAAC,IAA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AAI,CAAC;gBAC5B,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,YAAY,CAAC;gBACpD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;gBACrD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC;YAC/D,CAAC;QACL,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC;QAChD,IAAI,CAAC,oBAAoB,GAAG,IAAI,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACrF,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC;QAExD,IAAI,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YAC9B,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAE7D,MAAM,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAEtI,MAAM,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACnG,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import { type Nullable } from \"core/types\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport { type Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { type Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport { type Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./asciiart.fragment\";\r\n\r\n/**\r\n * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class AsciiArtFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Ascii Art FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n //this.anisotropicFilteringLevel = 1;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = Math.ceil(this._charSize * text.length);\r\n const textureHeight = this._charSize;\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @returns the max char width\r\n */\r\n private _getFontWidth(font: string): number {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n\r\n return ctx.measureText(\"W\").width;\r\n }\r\n\r\n // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/\r\n /**\r\n * Gets the max char height of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @returns the max char height\r\n */\r\n private _getFontHeight(font: string): { height: number; offset: number } {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);\r\n ctx.textBaseline = \"top\";\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n ctx.fillText(\"jH|\", 0, 0);\r\n const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n let start = -1;\r\n let end = -1;\r\n for (let row = 0; row < fontDraw.height; row++) {\r\n for (let column = 0; column < fontDraw.width; column++) {\r\n const index = (row * fontDraw.width + column) * 4;\r\n if (pixels[index] === 0) {\r\n if (column === fontDraw.width - 1 && start !== -1) {\r\n end = row;\r\n row = fontDraw.height;\r\n break;\r\n }\r\n continue;\r\n } else {\r\n if (start === -1) {\r\n start = row;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n return { height: end - start + 1, offset: start - 1 };\r\n }\r\n\r\n /**\r\n * Clones the current AsciiArtTexture.\r\n * @returns the clone of the texture.\r\n */\r\n public override clone(): AsciiArtFontTexture {\r\n return new AsciiArtFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @returns the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): AsciiArtFontTexture {\r\n const texture = SerializationHelper.Parse(() => new AsciiArtFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Ascii Art Post Process.\r\n */\r\nexport interface IAsciiArtPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * The character set to use in the postprocess.\r\n */\r\n characterSet?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * AsciiArtPostProcess helps rendering everithing in Ascii Art.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new AsciiArtPostProcess(\"myAscii\", \"20px Monospace\", camera);\r\n */\r\nexport class AsciiArtPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _asciiArtFontTexture: AsciiArtFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Instantiates a new Ascii Art Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Nullable<Camera>, options?: string | IAsciiArtPostProcessOptions) {\r\n super(name, \"asciiart\", [\"asciiArtFontInfos\", \"asciiArtOptions\"], [\"asciiArtFont\"], 1, camera, Texture.TRILINEAR_SAMPLINGMODE, undefined, true);\r\n\r\n // Default values.\r\n let font = \"40px Monospace\";\r\n let characterSet = \" `-.'_:,\\\"=^;<+!*?/cL\\\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof options === \"string\") {\r\n font = options;\r\n } else {\r\n font = options.font || font;\r\n characterSet = options.characterSet || characterSet;\r\n this.mixToTile = options.mixToTile || this.mixToTile;\r\n this.mixToNormal = options.mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n const scene = camera?.getScene() || this._scene;\r\n this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, scene);\r\n const textureSize = this._asciiArtFontTexture.getSize();\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"asciiArtFont\", this._asciiArtFontTexture);\r\n\r\n effect.setFloat4(\"asciiArtFontInfos\", this._asciiArtFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);\r\n\r\n effect.setFloat4(\"asciiArtOptions\", this.width, this.height, this.mixToNormal, this.mixToTile);\r\n };\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"asciiArtPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/asciiArt/asciiArtPostProcess.ts"],"names":[],"mappings":";AAC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I,IAAI,CAAC,MAAM,CAAC;QAChD,IAAI,CAAC,oBAAoB,GAAG,IAAI,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACrF,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC;QAExD,IAAI,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YAC9B,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAE7D,MAAM,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAEtI,MAAM,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACnG,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import { type Nullable } from \"core/types\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport { type Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { type Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport { type Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./asciiart.fragment\";\r\n\r\n/**\r\n * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class AsciiArtFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Ascii Art FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n //this.anisotropicFilteringLevel = 1;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = Math.ceil(this._charSize * text.length);\r\n const textureHeight = this._charSize;\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @returns the max char width\r\n */\r\n private _getFontWidth(font: string): number {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n\r\n return ctx.measureText(\"W\").width;\r\n }\r\n\r\n // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/\r\n /**\r\n * Gets the max char height of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @returns the max char height\r\n */\r\n private _getFontHeight(font: string): { height: number; offset: number } {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);\r\n ctx.textBaseline = \"top\";\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n ctx.fillText(\"jH|\", 0, 0);\r\n const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n let start = -1;\r\n let end = -1;\r\n for (let row = 0; row < fontDraw.height; row++) {\r\n for (let column = 0; column < fontDraw.width; column++) {\r\n const index = (row * fontDraw.width + column) * 4;\r\n if (pixels[index] === 0) {\r\n if (column === fontDraw.width - 1 && start !== -1) {\r\n end = row;\r\n row = fontDraw.height;\r\n break;\r\n }\r\n continue;\r\n } else {\r\n if (start === -1) {\r\n start = row;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n return { height: end - start + 1, offset: start - 1 };\r\n }\r\n\r\n /**\r\n * Clones the current AsciiArtTexture.\r\n * @returns the clone of the texture.\r\n */\r\n public override clone(): AsciiArtFontTexture {\r\n return new AsciiArtFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @returns the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): AsciiArtFontTexture {\r\n const texture = SerializationHelper.Parse(() => new AsciiArtFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Ascii Art Post Process.\r\n */\r\nexport interface IAsciiArtPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * The character set to use in the postprocess.\r\n */\r\n characterSet?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * AsciiArtPostProcess helps rendering everithing in Ascii Art.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new AsciiArtPostProcess(\"myAscii\", \"20px Monospace\", camera);\r\n */\r\nexport class AsciiArtPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _asciiArtFontTexture: AsciiArtFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Instantiates a new Ascii Art Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Nullable<Camera>, options?: string | IAsciiArtPostProcessOptions) {\r\n super(name, \"asciiart\", [\"asciiArtFontInfos\", \"asciiArtOptions\"], [\"asciiArtFont\"], 1, camera, Texture.TRILINEAR_SAMPLINGMODE, undefined, true);\r\n\r\n // Default values.\r\n let font = \"40px Monospace\";\r\n let characterSet = \" `-.'_:,\\\"=^;<+!*?/cL\\\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof options === \"string\") {\r\n font = options;\r\n } else {\r\n font = options.font || font;\r\n characterSet = options.characterSet || characterSet;\r\n this.mixToTile = options.mixToTile || this.mixToTile;\r\n this.mixToNormal = options.mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n const scene = camera?.getScene() || this._scene;\r\n this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, scene);\r\n const textureSize = this._asciiArtFontTexture.getSize();\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"asciiArtFont\", this._asciiArtFontTexture);\r\n\r\n effect.setFloat4(\"asciiArtFontInfos\", this._asciiArtFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);\r\n\r\n effect.setFloat4(\"asciiArtOptions\", this.width, this.height, this.mixToNormal, this.mixToTile);\r\n };\r\n }\r\n}\r\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __esDecorate, __runInitializers } from "@babylonjs/core/tslib.es6.js";
|
|
2
2
|
import { serialize } from "@babylonjs/core/Misc/decorators.js";
|
|
3
3
|
import { SerializationHelper } from "@babylonjs/core/Misc/decorators.serialization.js";
|
|
4
4
|
import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
|
@@ -13,132 +13,149 @@ import "./digitalrain.fragment.js";
|
|
|
13
13
|
* It basically takes care rendering the font front the given font size to a texture.
|
|
14
14
|
* This is used later on in the postprocess.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const textureHeight = Math.ceil(this._charSize * text.length);
|
|
48
|
-
// Create the texture that will store the font characters.
|
|
49
|
-
this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
|
|
50
|
-
//scene.getEngine().setclamp
|
|
51
|
-
const textureSize = this.getSize();
|
|
52
|
-
// Create a canvas with the final size: the one matching the texture.
|
|
53
|
-
const canvas = document.createElement("canvas");
|
|
54
|
-
canvas.width = textureSize.width;
|
|
55
|
-
canvas.height = textureSize.height;
|
|
56
|
-
const context = canvas.getContext("2d");
|
|
57
|
-
context.textBaseline = "top";
|
|
58
|
-
context.font = font;
|
|
59
|
-
context.fillStyle = "white";
|
|
60
|
-
context.imageSmoothingEnabled = false;
|
|
61
|
-
// Sets the text in the texture.
|
|
62
|
-
for (let i = 0; i < text.length; i++) {
|
|
63
|
-
context.fillText(text[i], 0, i * this._charSize - maxCharHeight.offset);
|
|
64
|
-
}
|
|
65
|
-
// Flush the text in the dynamic texture.
|
|
66
|
-
scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Gets the max char width of a font.
|
|
70
|
-
* @param font the font to use, use the W3C CSS notation
|
|
71
|
-
* @returns the max char width
|
|
72
|
-
*/
|
|
73
|
-
_getFontWidth(font) {
|
|
74
|
-
const fontDraw = document.createElement("canvas");
|
|
75
|
-
const ctx = fontDraw.getContext("2d");
|
|
76
|
-
ctx.fillStyle = "white";
|
|
77
|
-
ctx.font = font;
|
|
78
|
-
return ctx.measureText("W").width;
|
|
79
|
-
}
|
|
80
|
-
// More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
|
|
81
|
-
/**
|
|
82
|
-
* Gets the max char height of a font.
|
|
83
|
-
* @param font the font to use, use the W3C CSS notation
|
|
84
|
-
* @returns the max char height
|
|
85
|
-
*/
|
|
86
|
-
_getFontHeight(font) {
|
|
87
|
-
const fontDraw = document.createElement("canvas");
|
|
88
|
-
const ctx = fontDraw.getContext("2d");
|
|
89
|
-
ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
|
|
90
|
-
ctx.textBaseline = "top";
|
|
91
|
-
ctx.fillStyle = "white";
|
|
92
|
-
ctx.font = font;
|
|
93
|
-
ctx.fillText("jH|", 0, 0);
|
|
94
|
-
const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
|
|
95
|
-
let start = -1;
|
|
96
|
-
let end = -1;
|
|
97
|
-
for (let row = 0; row < fontDraw.height; row++) {
|
|
98
|
-
for (let column = 0; column < fontDraw.width; column++) {
|
|
99
|
-
const index = (row * fontDraw.width + column) * 4;
|
|
100
|
-
if (pixels[index] === 0) {
|
|
101
|
-
if (column === fontDraw.width - 1 && start !== -1) {
|
|
102
|
-
end = row;
|
|
103
|
-
row = fontDraw.height;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
continue;
|
|
16
|
+
let DigitalRainFontTexture = (() => {
|
|
17
|
+
var _a;
|
|
18
|
+
let _classSuper = BaseTexture;
|
|
19
|
+
let __font_decorators;
|
|
20
|
+
let __font_initializers = [];
|
|
21
|
+
let __font_extraInitializers = [];
|
|
22
|
+
let __text_decorators;
|
|
23
|
+
let __text_initializers = [];
|
|
24
|
+
let __text_extraInitializers = [];
|
|
25
|
+
return _a = class DigitalRainFontTexture extends _classSuper {
|
|
26
|
+
/**
|
|
27
|
+
* Gets the size of one char in the texture (each char fits in size * size space in the texture).
|
|
28
|
+
*/
|
|
29
|
+
get charSize() {
|
|
30
|
+
return this._charSize;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a new instance of the Digital Rain FontTexture class
|
|
34
|
+
* @param name the name of the texture
|
|
35
|
+
* @param font the font to use, use the W3C CSS notation
|
|
36
|
+
* @param text the caracter set to use in the rendering.
|
|
37
|
+
* @param scene the scene that owns the texture
|
|
38
|
+
*/
|
|
39
|
+
constructor(name, font, text, scene = null) {
|
|
40
|
+
super(scene);
|
|
41
|
+
this._font = __runInitializers(this, __font_initializers, void 0);
|
|
42
|
+
this._text = (__runInitializers(this, __font_extraInitializers), __runInitializers(this, __text_initializers, void 0));
|
|
43
|
+
this._charSize = __runInitializers(this, __text_extraInitializers);
|
|
44
|
+
scene = this.getScene();
|
|
45
|
+
if (!scene) {
|
|
46
|
+
return;
|
|
107
47
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
48
|
+
this.name = name;
|
|
49
|
+
this._text == text;
|
|
50
|
+
this._font == font;
|
|
51
|
+
this.wrapU = Texture.CLAMP_ADDRESSMODE;
|
|
52
|
+
this.wrapV = Texture.CLAMP_ADDRESSMODE;
|
|
53
|
+
// Get the font specific info.
|
|
54
|
+
const maxCharHeight = this._getFontHeight(font);
|
|
55
|
+
const maxCharWidth = this._getFontWidth(font);
|
|
56
|
+
this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
|
|
57
|
+
// This is an approximate size, but should always be able to fit at least the maxCharCount.
|
|
58
|
+
const textureWidth = this._charSize;
|
|
59
|
+
const textureHeight = Math.ceil(this._charSize * text.length);
|
|
60
|
+
// Create the texture that will store the font characters.
|
|
61
|
+
this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
|
|
62
|
+
//scene.getEngine().setclamp
|
|
63
|
+
const textureSize = this.getSize();
|
|
64
|
+
// Create a canvas with the final size: the one matching the texture.
|
|
65
|
+
const canvas = document.createElement("canvas");
|
|
66
|
+
canvas.width = textureSize.width;
|
|
67
|
+
canvas.height = textureSize.height;
|
|
68
|
+
const context = canvas.getContext("2d");
|
|
69
|
+
context.textBaseline = "top";
|
|
70
|
+
context.font = font;
|
|
71
|
+
context.fillStyle = "white";
|
|
72
|
+
context.imageSmoothingEnabled = false;
|
|
73
|
+
// Sets the text in the texture.
|
|
74
|
+
for (let i = 0; i < text.length; i++) {
|
|
75
|
+
context.fillText(text[i], 0, i * this._charSize - maxCharHeight.offset);
|
|
76
|
+
}
|
|
77
|
+
// Flush the text in the dynamic texture.
|
|
78
|
+
scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets the max char width of a font.
|
|
82
|
+
* @param font the font to use, use the W3C CSS notation
|
|
83
|
+
* @returns the max char width
|
|
84
|
+
*/
|
|
85
|
+
_getFontWidth(font) {
|
|
86
|
+
const fontDraw = document.createElement("canvas");
|
|
87
|
+
const ctx = fontDraw.getContext("2d");
|
|
88
|
+
ctx.fillStyle = "white";
|
|
89
|
+
ctx.font = font;
|
|
90
|
+
return ctx.measureText("W").width;
|
|
91
|
+
}
|
|
92
|
+
// More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
|
|
93
|
+
/**
|
|
94
|
+
* Gets the max char height of a font.
|
|
95
|
+
* @param font the font to use, use the W3C CSS notation
|
|
96
|
+
* @returns the max char height
|
|
97
|
+
*/
|
|
98
|
+
_getFontHeight(font) {
|
|
99
|
+
const fontDraw = document.createElement("canvas");
|
|
100
|
+
const ctx = fontDraw.getContext("2d");
|
|
101
|
+
ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
|
|
102
|
+
ctx.textBaseline = "top";
|
|
103
|
+
ctx.fillStyle = "white";
|
|
104
|
+
ctx.font = font;
|
|
105
|
+
ctx.fillText("jH|", 0, 0);
|
|
106
|
+
const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
|
|
107
|
+
let start = -1;
|
|
108
|
+
let end = -1;
|
|
109
|
+
for (let row = 0; row < fontDraw.height; row++) {
|
|
110
|
+
for (let column = 0; column < fontDraw.width; column++) {
|
|
111
|
+
const index = (row * fontDraw.width + column) * 4;
|
|
112
|
+
if (pixels[index] === 0) {
|
|
113
|
+
if (column === fontDraw.width - 1 && start !== -1) {
|
|
114
|
+
end = row;
|
|
115
|
+
row = fontDraw.height;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
if (start === -1) {
|
|
122
|
+
start = row;
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
111
126
|
}
|
|
112
|
-
break;
|
|
113
127
|
}
|
|
128
|
+
return { height: end - start + 1, offset: start - 1 };
|
|
114
129
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Clones the current DigitalRainFontTexture.
|
|
132
|
+
* @returns the clone of the texture.
|
|
133
|
+
*/
|
|
134
|
+
clone() {
|
|
135
|
+
return new _a(this.name, this._font, this._text, this.getScene());
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Parses a json object representing the texture and returns an instance of it.
|
|
139
|
+
* @param source the source JSON representation
|
|
140
|
+
* @param scene the scene to create the texture for
|
|
141
|
+
* @returns the parsed texture
|
|
142
|
+
*/
|
|
143
|
+
static Parse(source, scene) {
|
|
144
|
+
const texture = SerializationHelper.Parse(() => new _a(source.name, source.font, source.text, scene), source, scene, null);
|
|
145
|
+
return texture;
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
(() => {
|
|
149
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
150
|
+
__font_decorators = [serialize("font")];
|
|
151
|
+
__text_decorators = [serialize("text")];
|
|
152
|
+
__esDecorate(null, null, __font_decorators, { kind: "field", name: "_font", static: false, private: false, access: { has: obj => "_font" in obj, get: obj => obj._font, set: (obj, value) => { obj._font = value; } }, metadata: _metadata }, __font_initializers, __font_extraInitializers);
|
|
153
|
+
__esDecorate(null, null, __text_decorators, { kind: "field", name: "_text", static: false, private: false, access: { has: obj => "_text" in obj, get: obj => obj._text, set: (obj, value) => { obj._text = value; } }, metadata: _metadata }, __text_initializers, __text_extraInitializers);
|
|
154
|
+
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
155
|
+
})(),
|
|
156
|
+
_a;
|
|
157
|
+
})();
|
|
158
|
+
export { DigitalRainFontTexture };
|
|
142
159
|
/**
|
|
143
160
|
* DigitalRainPostProcess helps rendering everithing in digital rain.
|
|
144
161
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digitalRainPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/digitalRain/digitalRainPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAE1D,OAAO,EAAE,W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,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,CAChB,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YAC9B,MAAM,CAAC,UAAU,CAAC,iBAAiB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;YAEnE,MAAM,CAAC,SAAS,CAAC,sBAAsB,EAAE,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAE5I,MAAM,CAAC,SAAS,CAAC,oBAAoB,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAElG,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;YAExC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;YACpB,cAAc,GAAG,KAAK,CAAC;YACvB,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import { type Nullable } from \"core/types\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport { type Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { type Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport { type Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./digitalrain.fragment\";\r\n\r\n/**\r\n * DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class DigitalRainFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Digital Rain FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = this._charSize;\r\n const textureHeight = Math.ceil(this._charSize * text.length);\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], 0, i * this._charSize - maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @returns the max char width\r\n */\r\n private _getFontWidth(font: string): number {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n\r\n return ctx.measureText(\"W\").width;\r\n }\r\n\r\n // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/\r\n /**\r\n * Gets the max char height of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @returns the max char height\r\n */\r\n private _getFontHeight(font: string): { height: number; offset: number } {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);\r\n ctx.textBaseline = \"top\";\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n ctx.fillText(\"jH|\", 0, 0);\r\n const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n let start = -1;\r\n let end = -1;\r\n for (let row = 0; row < fontDraw.height; row++) {\r\n for (let column = 0; column < fontDraw.width; column++) {\r\n const index = (row * fontDraw.width + column) * 4;\r\n if (pixels[index] === 0) {\r\n if (column === fontDraw.width - 1 && start !== -1) {\r\n end = row;\r\n row = fontDraw.height;\r\n break;\r\n }\r\n continue;\r\n } else {\r\n if (start === -1) {\r\n start = row;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n return { height: end - start + 1, offset: start - 1 };\r\n }\r\n\r\n /**\r\n * Clones the current DigitalRainFontTexture.\r\n * @returns the clone of the texture.\r\n */\r\n public override clone(): DigitalRainFontTexture {\r\n return new DigitalRainFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @returns the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): DigitalRainFontTexture {\r\n const texture = SerializationHelper.Parse(() => new DigitalRainFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Digital Rain Post Process.\r\n */\r\nexport interface IDigitalRainPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * DigitalRainPostProcess helps rendering everithing in digital rain.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new DigitalRainPostProcess(\"digitalRain\", \"20px Monospace\", camera);\r\n */\r\nexport class DigitalRainPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _digitalRainFontTexture: DigitalRainFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Speed of the effect\r\n */\r\n public speed: number = 0.003;\r\n\r\n /**\r\n * Instantiates a new Digital Rain Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IDigitalRainPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Nullable<Camera>, options?: string | IDigitalRainPostProcessOptions) {\r\n super(\r\n name,\r\n \"digitalrain\",\r\n [\"digitalRainFontInfos\", \"digitalRainOptions\", \"cosTimeZeroOne\", \"matrixSpeed\"],\r\n [\"digitalRainFont\"],\r\n 1.0,\r\n camera,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n undefined,\r\n true\r\n );\r\n\r\n // Default values.\r\n let font = \"15px Monospace\";\r\n const characterSet =\r\n \"古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof options === \"string\") {\r\n font = options;\r\n } else {\r\n font = options.font || font;\r\n this.mixToTile = options.mixToTile || this.mixToTile;\r\n this.mixToNormal = options.mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n const scene = camera?.getScene() || null;\r\n this._digitalRainFontTexture = new DigitalRainFontTexture(name, font, characterSet, scene);\r\n const textureSize = this._digitalRainFontTexture.getSize();\r\n\r\n let alpha = 0.0;\r\n let cosTimeZeroOne = 0.0;\r\n const matrix = Matrix.FromValues(\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random()\r\n );\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"digitalRainFont\", this._digitalRainFontTexture);\r\n\r\n effect.setFloat4(\"digitalRainFontInfos\", this._digitalRainFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);\r\n\r\n effect.setFloat4(\"digitalRainOptions\", this.width, this.height, this.mixToNormal, this.mixToTile);\r\n\r\n effect.setMatrix(\"matrixSpeed\", matrix);\r\n\r\n alpha += this.speed;\r\n cosTimeZeroOne = alpha;\r\n effect.setFloat(\"cosTimeZeroOne\", cosTimeZeroOne);\r\n };\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"digitalRainPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/digitalRain/digitalRainPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D,OAAO,+CAA+C,CAAC;AACvD,OAAO,wBAAwB,CAAC;AAEhC;;;;;GAKG;IACU,sBAAsB;;sBAAS,WAAW;;;;;;;sBAA1C,sBAAuB,SAAQ,WAAW;YASnD;;eAEG;YACH,IAAW,QAAQ;gBACf,OAAO,IAAI,CAAC,SAAS,CAAC;YAC1B,CAAC;YAED;;;;;;eAMG;YACH,YAAY,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,QAAyB,IAAI;gBAC/E,KAAK,CAAC,KAAK,CAAC,CAAC;gBAtBT,UAAK,wDAAS;gBAGd,UAAK,6GAAS;gBAEd,cAAS,qDAAS;gBAmBtB,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;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,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,CAChB,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YAC9B,MAAM,CAAC,UAAU,CAAC,iBAAiB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;YAEnE,MAAM,CAAC,SAAS,CAAC,sBAAsB,EAAE,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAE5I,MAAM,CAAC,SAAS,CAAC,oBAAoB,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAElG,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;YAExC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;YACpB,cAAc,GAAG,KAAK,CAAC;YACvB,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import { type Nullable } from \"core/types\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport { type Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { type Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport { type Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./digitalrain.fragment\";\r\n\r\n/**\r\n * DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class DigitalRainFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Digital Rain FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = this._charSize;\r\n const textureHeight = Math.ceil(this._charSize * text.length);\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], 0, i * this._charSize - maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @returns the max char width\r\n */\r\n private _getFontWidth(font: string): number {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n\r\n return ctx.measureText(\"W\").width;\r\n }\r\n\r\n // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/\r\n /**\r\n * Gets the max char height of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @returns the max char height\r\n */\r\n private _getFontHeight(font: string): { height: number; offset: number } {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);\r\n ctx.textBaseline = \"top\";\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n ctx.fillText(\"jH|\", 0, 0);\r\n const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n let start = -1;\r\n let end = -1;\r\n for (let row = 0; row < fontDraw.height; row++) {\r\n for (let column = 0; column < fontDraw.width; column++) {\r\n const index = (row * fontDraw.width + column) * 4;\r\n if (pixels[index] === 0) {\r\n if (column === fontDraw.width - 1 && start !== -1) {\r\n end = row;\r\n row = fontDraw.height;\r\n break;\r\n }\r\n continue;\r\n } else {\r\n if (start === -1) {\r\n start = row;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n return { height: end - start + 1, offset: start - 1 };\r\n }\r\n\r\n /**\r\n * Clones the current DigitalRainFontTexture.\r\n * @returns the clone of the texture.\r\n */\r\n public override clone(): DigitalRainFontTexture {\r\n return new DigitalRainFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @returns the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): DigitalRainFontTexture {\r\n const texture = SerializationHelper.Parse(() => new DigitalRainFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Digital Rain Post Process.\r\n */\r\nexport interface IDigitalRainPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * DigitalRainPostProcess helps rendering everithing in digital rain.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new DigitalRainPostProcess(\"digitalRain\", \"20px Monospace\", camera);\r\n */\r\nexport class DigitalRainPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _digitalRainFontTexture: DigitalRainFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Speed of the effect\r\n */\r\n public speed: number = 0.003;\r\n\r\n /**\r\n * Instantiates a new Digital Rain Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IDigitalRainPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Nullable<Camera>, options?: string | IDigitalRainPostProcessOptions) {\r\n super(\r\n name,\r\n \"digitalrain\",\r\n [\"digitalRainFontInfos\", \"digitalRainOptions\", \"cosTimeZeroOne\", \"matrixSpeed\"],\r\n [\"digitalRainFont\"],\r\n 1.0,\r\n camera,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n undefined,\r\n true\r\n );\r\n\r\n // Default values.\r\n let font = \"15px Monospace\";\r\n const characterSet =\r\n \"古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof options === \"string\") {\r\n font = options;\r\n } else {\r\n font = options.font || font;\r\n this.mixToTile = options.mixToTile || this.mixToTile;\r\n this.mixToNormal = options.mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n const scene = camera?.getScene() || null;\r\n this._digitalRainFontTexture = new DigitalRainFontTexture(name, font, characterSet, scene);\r\n const textureSize = this._digitalRainFontTexture.getSize();\r\n\r\n let alpha = 0.0;\r\n let cosTimeZeroOne = 0.0;\r\n const matrix = Matrix.FromValues(\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random()\r\n );\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"digitalRainFont\", this._digitalRainFontTexture);\r\n\r\n effect.setFloat4(\"digitalRainFontInfos\", this._digitalRainFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);\r\n\r\n effect.setFloat4(\"digitalRainOptions\", this.width, this.height, this.mixToNormal, this.mixToTile);\r\n\r\n effect.setMatrix(\"matrixSpeed\", matrix);\r\n\r\n alpha += this.speed;\r\n cosTimeZeroOne = alpha;\r\n effect.setFloat(\"cosTimeZeroOne\", cosTimeZeroOne);\r\n };\r\n }\r\n}\r\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __esDecorate, __runInitializers } from "@babylonjs/core/tslib.es6.js";
|
|
2
2
|
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
3
3
|
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
|
4
4
|
import { Constants } from "@babylonjs/core/Engines/constants.js";
|
|
@@ -14,121 +14,140 @@ import "./edgeDetection.fragment.js";
|
|
|
14
14
|
* The Edge Detection effect highlights the edges of objects in the scene like a toon.
|
|
15
15
|
* This can be used for stylized rendering, outlining, or visual effects that require edge enhancement.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
effect.setFloat("edgeWidth", this.edgeWidth);
|
|
80
|
-
effect.setColor3("edgeColor", this.edgeColor);
|
|
81
|
-
const normalTexture = this._geometryBufferRenderer.getGBuffer().textures[1];
|
|
82
|
-
const depthTexture = this._geometryBufferRenderer.getGBuffer().textures[0];
|
|
83
|
-
effect.setTexture("normalSampler", normalTexture);
|
|
84
|
-
effect.setTexture("depthSampler", depthTexture);
|
|
85
|
-
switch (this.renderMode) {
|
|
86
|
-
case 0:
|
|
87
|
-
break;
|
|
88
|
-
case 1:
|
|
89
|
-
effect.setTexture("textureSampler", this._geometryBufferRenderer.getGBuffer().textures[1]);
|
|
90
|
-
effect.setFloat("edgeWidth", 0);
|
|
91
|
-
break;
|
|
92
|
-
case 2:
|
|
93
|
-
effect.setTexture("textureSampler", this._geometryBufferRenderer.getGBuffer().textures[0]);
|
|
94
|
-
effect.setFloat("edgeWidth", 0);
|
|
95
|
-
break;
|
|
96
|
-
case 3:
|
|
97
|
-
effect.setTexture("textureSampler", h1);
|
|
98
|
-
break;
|
|
17
|
+
let EdgeDetectionPostProcess = (() => {
|
|
18
|
+
var _a;
|
|
19
|
+
let _classSuper = PostProcess;
|
|
20
|
+
let _edgeColor_decorators;
|
|
21
|
+
let _edgeColor_initializers = [];
|
|
22
|
+
let _edgeColor_extraInitializers = [];
|
|
23
|
+
let _edgeIntensity_decorators;
|
|
24
|
+
let _edgeIntensity_initializers = [];
|
|
25
|
+
let _edgeIntensity_extraInitializers = [];
|
|
26
|
+
let _edgeWidth_decorators;
|
|
27
|
+
let _edgeWidth_initializers = [];
|
|
28
|
+
let _edgeWidth_extraInitializers = [];
|
|
29
|
+
let _renderMode_decorators;
|
|
30
|
+
let _renderMode_initializers = [];
|
|
31
|
+
let _renderMode_extraInitializers = [];
|
|
32
|
+
return _a = class EdgeDetectionPostProcess extends _classSuper {
|
|
33
|
+
/**
|
|
34
|
+
* Get the current class name of the current effect
|
|
35
|
+
* @returns "EdgeDetectionPostProcess"
|
|
36
|
+
*/
|
|
37
|
+
getClassName() {
|
|
38
|
+
return "EdgeDetectionPostProcess";
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new instance of EdgeDetectionPostProcess.
|
|
42
|
+
* @param name The name of the effect.
|
|
43
|
+
* @param scene The scene where the edge detection post-process will be applied.
|
|
44
|
+
* @param options The required width/height ratio or specific options for the post-process.
|
|
45
|
+
* @param camera The camera to apply the post-process to.
|
|
46
|
+
* @param samplingMode The sampling mode to be used when computing the pass. (default: TEXTURE_NEAREST_NEAREST)
|
|
47
|
+
* @param reusable If the post-process can be reused on the same frame. (default: false)
|
|
48
|
+
* @param textureType The type of textures used when performing the post-process. (default: TEXTURETYPE_HALF_FLOAT)
|
|
49
|
+
*/
|
|
50
|
+
constructor(name, scene, options, camera, samplingMode, reusable, textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE) {
|
|
51
|
+
super(name, "edgeDetection", ["width", "height", "edgeColor", "edgeIntensity", "edgeWidth", "renderMode"], ["normalSampler", "depthSampler"], options, camera, samplingMode, scene.getEngine(), reusable, null, textureType);
|
|
52
|
+
/**
|
|
53
|
+
* Defines the color of the detected edges.
|
|
54
|
+
*/
|
|
55
|
+
this.edgeColor = __runInitializers(this, _edgeColor_initializers, new Color3(0, 0, 0));
|
|
56
|
+
/**
|
|
57
|
+
* Defines the intensity of the detected edges.
|
|
58
|
+
* Higher values result in more pronounced edges.
|
|
59
|
+
* default: 0.2 (min:0, max:1)
|
|
60
|
+
*/
|
|
61
|
+
this.edgeIntensity = (__runInitializers(this, _edgeColor_extraInitializers), __runInitializers(this, _edgeIntensity_initializers, 0.2));
|
|
62
|
+
/**
|
|
63
|
+
* Defines the width of the detected edges.
|
|
64
|
+
* Higher values result in thicker edges.
|
|
65
|
+
* default: 0.2 (min:0.125, max:1)
|
|
66
|
+
*/
|
|
67
|
+
this.edgeWidth = (__runInitializers(this, _edgeIntensity_extraInitializers), __runInitializers(this, _edgeWidth_initializers, 0.2));
|
|
68
|
+
/**
|
|
69
|
+
* Defines the render mode.
|
|
70
|
+
* default: 0
|
|
71
|
+
* 0: general, 1: normal, 2: depth, 3: outline only
|
|
72
|
+
*/
|
|
73
|
+
this.renderMode = (__runInitializers(this, _edgeWidth_extraInitializers), __runInitializers(this, _renderMode_initializers, 0));
|
|
74
|
+
this._geometryBufferRenderer = __runInitializers(this, _renderMode_extraInitializers);
|
|
75
|
+
this._geometryBufferRenderer = scene.enableGeometryBufferRenderer();
|
|
76
|
+
if (!this._geometryBufferRenderer) {
|
|
77
|
+
// Geometry buffer renderer is not supported. So, work as a passthrough.
|
|
78
|
+
Logger.Error("Geometry Buffer Renderer support is required for this post-process.");
|
|
99
79
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
80
|
+
else {
|
|
81
|
+
// h1 is a blank texture used as a black background for renderMode 3 (outline only).
|
|
82
|
+
// It is never rendered into, so a 1x1 size is sufficient. We cannot use this.width/this.height
|
|
83
|
+
// here because they are still -1 at construction time (set later during activate()).
|
|
84
|
+
const h1 = new RenderTargetTexture("h1", { width: 1, height: 1 }, scene, {
|
|
85
|
+
samplingMode: Constants.TEXTURE_NEAREST_NEAREST,
|
|
86
|
+
generateMipMaps: false,
|
|
87
|
+
generateDepthBuffer: false,
|
|
88
|
+
type: Constants.TEXTURETYPE_HALF_FLOAT,
|
|
89
|
+
});
|
|
90
|
+
// Geometry buffer renderer is supported.
|
|
91
|
+
this.onApply = (effect) => {
|
|
92
|
+
effect.setFloat("width", this.width);
|
|
93
|
+
effect.setFloat("height", this.height);
|
|
94
|
+
effect.setFloat("edgeIntensity", this.edgeIntensity);
|
|
95
|
+
effect.setFloat("edgeWidth", this.edgeWidth);
|
|
96
|
+
effect.setColor3("edgeColor", this.edgeColor);
|
|
97
|
+
const normalTexture = this._geometryBufferRenderer.getGBuffer().textures[1];
|
|
98
|
+
const depthTexture = this._geometryBufferRenderer.getGBuffer().textures[0];
|
|
99
|
+
effect.setTexture("normalSampler", normalTexture);
|
|
100
|
+
effect.setTexture("depthSampler", depthTexture);
|
|
101
|
+
switch (this.renderMode) {
|
|
102
|
+
case 0:
|
|
103
|
+
break;
|
|
104
|
+
case 1:
|
|
105
|
+
effect.setTexture("textureSampler", this._geometryBufferRenderer.getGBuffer().textures[1]);
|
|
106
|
+
effect.setFloat("edgeWidth", 0);
|
|
107
|
+
break;
|
|
108
|
+
case 2:
|
|
109
|
+
effect.setTexture("textureSampler", this._geometryBufferRenderer.getGBuffer().textures[0]);
|
|
110
|
+
effect.setFloat("edgeWidth", 0);
|
|
111
|
+
break;
|
|
112
|
+
case 3:
|
|
113
|
+
effect.setTexture("textureSampler", h1);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
effect.setInt("renderMode", this.renderMode);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Support test.
|
|
122
|
+
*/
|
|
123
|
+
static get IsSupported() {
|
|
124
|
+
const engine = EngineStore.LastCreatedEngine;
|
|
125
|
+
if (!engine) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
return engine.getCaps().drawBuffersExtension;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
static _Parse(parsedPostProcess, targetCamera, scene, rootUrl) {
|
|
134
|
+
return SerializationHelper.Parse(() => new _a(parsedPostProcess.name, scene, parsedPostProcess.options, targetCamera, parsedPostProcess.renderTargetSamplingMode, parsedPostProcess.textureType, parsedPostProcess.reusable), parsedPostProcess, scene, rootUrl);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
(() => {
|
|
138
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
139
|
+
_edgeColor_decorators = [serialize()];
|
|
140
|
+
_edgeIntensity_decorators = [serialize()];
|
|
141
|
+
_edgeWidth_decorators = [serialize()];
|
|
142
|
+
_renderMode_decorators = [serialize()];
|
|
143
|
+
__esDecorate(null, null, _edgeColor_decorators, { kind: "field", name: "edgeColor", static: false, private: false, access: { has: obj => "edgeColor" in obj, get: obj => obj.edgeColor, set: (obj, value) => { obj.edgeColor = value; } }, metadata: _metadata }, _edgeColor_initializers, _edgeColor_extraInitializers);
|
|
144
|
+
__esDecorate(null, null, _edgeIntensity_decorators, { kind: "field", name: "edgeIntensity", static: false, private: false, access: { has: obj => "edgeIntensity" in obj, get: obj => obj.edgeIntensity, set: (obj, value) => { obj.edgeIntensity = value; } }, metadata: _metadata }, _edgeIntensity_initializers, _edgeIntensity_extraInitializers);
|
|
145
|
+
__esDecorate(null, null, _edgeWidth_decorators, { kind: "field", name: "edgeWidth", static: false, private: false, access: { has: obj => "edgeWidth" in obj, get: obj => obj.edgeWidth, set: (obj, value) => { obj.edgeWidth = value; } }, metadata: _metadata }, _edgeWidth_initializers, _edgeWidth_extraInitializers);
|
|
146
|
+
__esDecorate(null, null, _renderMode_decorators, { kind: "field", name: "renderMode", static: false, private: false, access: { has: obj => "renderMode" in obj, get: obj => obj.renderMode, set: (obj, value) => { obj.renderMode = value; } }, metadata: _metadata }, _renderMode_initializers, _renderMode_extraInitializers);
|
|
147
|
+
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
148
|
+
})(),
|
|
149
|
+
_a;
|
|
150
|
+
})();
|
|
151
|
+
export { EdgeDetectionPostProcess };
|
|
133
152
|
RegisterClass("BABYLON.EdgeDetectionPostProcess", EdgeDetectionPostProcess);
|
|
134
153
|
//# sourceMappingURL=edgeDetectionPostProcess.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edgeDetectionPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/edgeDetection/edgeDetectionPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAA2B,WAAW,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,qDAAqD,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAElF,OAAO,0BAA0B,CAAC;AAElC;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,WAAW;IAiCrD;;;OAGG;IACa,YAAY;QACxB,OAAO,0BAA0B,CAAC;IACtC,CAAC;IAED;;;;;;;;;OASG;IACH,YACI,IAAY,EACZ,KAAY,EACZ,OAAoC,EACpC,MAAwB,EACxB,YAAqB,EACrB,QAAkB,EAClB,cAAsB,SAAS,CAAC,yBAAyB;QAEzD,KAAK,CACD,IAAI,EACJ,eAAe,EACf,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,CAAC,EAC5E,CAAC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AM,GAAG,WAAW,CAAC,iBAAiB,CAAC;QAC7C,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,oBAAoB,CAAC;IACjD,CAAC;IAED;;OAEG;IACI,MAAM,CAAU,MAAM,CAAC,iBAAsB,EAAE,YAAoB,EAAE,KAAY,EAAE,OAAe;QACrG,OAAO,mBAAmB,CAAC,KAAK,CAC5B,GAAG,EAAE,CACD,IAAI,wBAAwB,CACxB,iBAAiB,CAAC,IAAI,EACtB,KAAK,EACL,iBAAiB,CAAC,OAAO,EACzB,YAAY,EACZ,iBAAiB,CAAC,wBAAwB,EAC1C,iBAAiB,CAAC,WAAW,EAC7B,iBAAiB,CAAC,QAAQ,CAC7B,EACL,iBAAiB,EACjB,KAAK,EACL,OAAO,CACV,CAAC;IACN,CAAC;CACJ;AAvJU;IADN,SAAS,EAAE;2DACmC;AAQxC;IADN,SAAS,EAAE;+DACuB;AAQ5B;IADN,SAAS,EAAE;2DACmB;AAQxB;IADN,SAAS,EAAE;4DACkB;AAiIlC,aAAa,CAAC,kCAAkC,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import { type Nullable } from \"core/types\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { type Camera } from \"core/Cameras/camera\";\r\nimport { type Effect } from \"core/Materials/effect\";\r\nimport { type PostProcessOptions, PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport \"core/Rendering/geometryBufferRendererSceneComponent\";\r\nimport { type GeometryBufferRenderer } from \"core/Rendering/geometryBufferRenderer\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { EngineStore } from \"core/Engines/engineStore\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport { type Scene } from \"core/scene\";\r\nimport \"./edgeDetection.fragment\";\r\n\r\n/**\r\n * The Edge Detection effect highlights the edges of objects in the scene like a toon.\r\n * This can be used for stylized rendering, outlining, or visual effects that require edge enhancement.\r\n */\r\nexport class EdgeDetectionPostProcess extends PostProcess {\r\n /**\r\n * Defines the color of the detected edges.\r\n */\r\n @serialize()\r\n public edgeColor: Color3 = new Color3(0, 0, 0);\r\n\r\n /**\r\n * Defines the intensity of the detected edges.\r\n * Higher values result in more pronounced edges.\r\n * default: 0.2 (min:0, max:1)\r\n */\r\n @serialize()\r\n public edgeIntensity: number = 0.2;\r\n\r\n /**\r\n * Defines the width of the detected edges.\r\n * Higher values result in thicker edges.\r\n * default: 0.2 (min:0.125, max:1)\r\n */\r\n @serialize()\r\n public edgeWidth: number = 0.2;\r\n\r\n /**\r\n * Defines the render mode.\r\n * default: 0\r\n * 0: general, 1: normal, 2: depth, 3: outline only\r\n */\r\n @serialize()\r\n public renderMode: number = 0;\r\n\r\n private _geometryBufferRenderer: Nullable<GeometryBufferRenderer>;\r\n\r\n /**\r\n * Get the current class name of the current effect\r\n * @returns \"EdgeDetectionPostProcess\"\r\n */\r\n public override getClassName(): string {\r\n return \"EdgeDetectionPostProcess\";\r\n }\r\n\r\n /**\r\n * Creates a new instance of EdgeDetectionPostProcess.\r\n * @param name The name of the effect.\r\n * @param scene The scene where the edge detection post-process will be applied.\r\n * @param options The required width/height ratio or specific options for the post-process.\r\n * @param camera The camera to apply the post-process to.\r\n * @param samplingMode The sampling mode to be used when computing the pass. (default: TEXTURE_NEAREST_NEAREST)\r\n * @param reusable If the post-process can be reused on the same frame. (default: false)\r\n * @param textureType The type of textures used when performing the post-process. (default: TEXTURETYPE_HALF_FLOAT)\r\n */\r\n constructor(\r\n name: string,\r\n scene: Scene,\r\n options: number | PostProcessOptions,\r\n camera: Nullable<Camera>,\r\n samplingMode?: number,\r\n reusable?: boolean,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n ) {\r\n super(\r\n name,\r\n \"edgeDetection\",\r\n [\"width\", \"height\", \"edgeColor\", \"edgeIntensity\", \"edgeWidth\", \"renderMode\"],\r\n [\"normalSampler\", \"depthSampler\"],\r\n options,\r\n camera,\r\n samplingMode,\r\n scene.getEngine(),\r\n reusable,\r\n null,\r\n textureType\r\n );\r\n\r\n this._geometryBufferRenderer = scene.enableGeometryBufferRenderer();\r\n\r\n if (!this._geometryBufferRenderer) {\r\n // Geometry buffer renderer is not supported. So, work as a passthrough.\r\n Logger.Error(\"Geometry Buffer Renderer support is required for this post-process.\");\r\n } else {\r\n // h1 is a blank texture used as a black background for renderMode 3 (outline only).\r\n // It is never rendered into, so a 1x1 size is sufficient. We cannot use this.width/this.height\r\n // here because they are still -1 at construction time (set later during activate()).\r\n const h1 = new RenderTargetTexture(\"h1\", { width: 1, height: 1 }, scene, {\r\n samplingMode: Constants.TEXTURE_NEAREST_NEAREST,\r\n generateMipMaps: false,\r\n generateDepthBuffer: false,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n });\r\n\r\n // Geometry buffer renderer is supported.\r\n this.onApply = (effect: Effect) => {\r\n effect.setFloat(\"width\", this.width);\r\n effect.setFloat(\"height\", this.height);\r\n effect.setFloat(\"edgeIntensity\", this.edgeIntensity);\r\n effect.setFloat(\"edgeWidth\", this.edgeWidth);\r\n effect.setColor3(\"edgeColor\", this.edgeColor);\r\n\r\n const normalTexture = this._geometryBufferRenderer!.getGBuffer().textures[1];\r\n const depthTexture = this._geometryBufferRenderer!.getGBuffer().textures[0];\r\n\r\n effect.setTexture(\"normalSampler\", normalTexture);\r\n effect.setTexture(\"depthSampler\", depthTexture);\r\n\r\n switch (this.renderMode) {\r\n case 0:\r\n break;\r\n case 1:\r\n effect.setTexture(\"textureSampler\", this._geometryBufferRenderer!.getGBuffer().textures[1]);\r\n effect.setFloat(\"edgeWidth\", 0);\r\n break;\r\n case 2:\r\n effect.setTexture(\"textureSampler\", this._geometryBufferRenderer!.getGBuffer().textures[0]);\r\n effect.setFloat(\"edgeWidth\", 0);\r\n break;\r\n case 3:\r\n effect.setTexture(\"textureSampler\", h1);\r\n break;\r\n }\r\n effect.setInt(\"renderMode\", this.renderMode);\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Support test.\r\n */\r\n public static get IsSupported(): boolean {\r\n const engine = EngineStore.LastCreatedEngine;\r\n if (!engine) {\r\n return false;\r\n }\r\n\r\n return engine.getCaps().drawBuffersExtension;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static override _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {\r\n return SerializationHelper.Parse(\r\n () =>\r\n new EdgeDetectionPostProcess(\r\n parsedPostProcess.name,\r\n scene,\r\n parsedPostProcess.options,\r\n targetCamera,\r\n parsedPostProcess.renderTargetSamplingMode,\r\n parsedPostProcess.textureType,\r\n parsedPostProcess.reusable\r\n ),\r\n parsedPostProcess,\r\n scene,\r\n rootUrl\r\n );\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.EdgeDetectionPostProcess\", EdgeDetectionPostProcess);\r\n"]}
|
|
1
|
+
{"version":3,"file":"edgeDetectionPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/edgeDetection/edgeDetectionPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAA2B,WAAW,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,qDAAqD,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO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CAQX,SAAS,EAAE;YAvBZ,6KAAO,SAAS,6BAAT,SAAS,6FAA+B;YAQ/C,yLAAO,aAAa,6BAAb,aAAa,qGAAe;YAQnC,6KAAO,SAAS,6BAAT,SAAS,6FAAe;YAQ/B,gLAAO,UAAU,6BAAV,UAAU,+FAAa;;;;;SA7BrB,wBAAwB;AA8JrC,aAAa,CAAC,kCAAkC,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import { type Nullable } from \"core/types\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { type Camera } from \"core/Cameras/camera\";\r\nimport { type Effect } from \"core/Materials/effect\";\r\nimport { type PostProcessOptions, PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport \"core/Rendering/geometryBufferRendererSceneComponent\";\r\nimport { type GeometryBufferRenderer } from \"core/Rendering/geometryBufferRenderer\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { EngineStore } from \"core/Engines/engineStore\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport { type Scene } from \"core/scene\";\r\nimport \"./edgeDetection.fragment\";\r\n\r\n/**\r\n * The Edge Detection effect highlights the edges of objects in the scene like a toon.\r\n * This can be used for stylized rendering, outlining, or visual effects that require edge enhancement.\r\n */\r\nexport class EdgeDetectionPostProcess extends PostProcess {\r\n /**\r\n * Defines the color of the detected edges.\r\n */\r\n @serialize()\r\n public edgeColor: Color3 = new Color3(0, 0, 0);\r\n\r\n /**\r\n * Defines the intensity of the detected edges.\r\n * Higher values result in more pronounced edges.\r\n * default: 0.2 (min:0, max:1)\r\n */\r\n @serialize()\r\n public edgeIntensity: number = 0.2;\r\n\r\n /**\r\n * Defines the width of the detected edges.\r\n * Higher values result in thicker edges.\r\n * default: 0.2 (min:0.125, max:1)\r\n */\r\n @serialize()\r\n public edgeWidth: number = 0.2;\r\n\r\n /**\r\n * Defines the render mode.\r\n * default: 0\r\n * 0: general, 1: normal, 2: depth, 3: outline only\r\n */\r\n @serialize()\r\n public renderMode: number = 0;\r\n\r\n private _geometryBufferRenderer: Nullable<GeometryBufferRenderer>;\r\n\r\n /**\r\n * Get the current class name of the current effect\r\n * @returns \"EdgeDetectionPostProcess\"\r\n */\r\n public override getClassName(): string {\r\n return \"EdgeDetectionPostProcess\";\r\n }\r\n\r\n /**\r\n * Creates a new instance of EdgeDetectionPostProcess.\r\n * @param name The name of the effect.\r\n * @param scene The scene where the edge detection post-process will be applied.\r\n * @param options The required width/height ratio or specific options for the post-process.\r\n * @param camera The camera to apply the post-process to.\r\n * @param samplingMode The sampling mode to be used when computing the pass. (default: TEXTURE_NEAREST_NEAREST)\r\n * @param reusable If the post-process can be reused on the same frame. (default: false)\r\n * @param textureType The type of textures used when performing the post-process. (default: TEXTURETYPE_HALF_FLOAT)\r\n */\r\n constructor(\r\n name: string,\r\n scene: Scene,\r\n options: number | PostProcessOptions,\r\n camera: Nullable<Camera>,\r\n samplingMode?: number,\r\n reusable?: boolean,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n ) {\r\n super(\r\n name,\r\n \"edgeDetection\",\r\n [\"width\", \"height\", \"edgeColor\", \"edgeIntensity\", \"edgeWidth\", \"renderMode\"],\r\n [\"normalSampler\", \"depthSampler\"],\r\n options,\r\n camera,\r\n samplingMode,\r\n scene.getEngine(),\r\n reusable,\r\n null,\r\n textureType\r\n );\r\n\r\n this._geometryBufferRenderer = scene.enableGeometryBufferRenderer();\r\n\r\n if (!this._geometryBufferRenderer) {\r\n // Geometry buffer renderer is not supported. So, work as a passthrough.\r\n Logger.Error(\"Geometry Buffer Renderer support is required for this post-process.\");\r\n } else {\r\n // h1 is a blank texture used as a black background for renderMode 3 (outline only).\r\n // It is never rendered into, so a 1x1 size is sufficient. We cannot use this.width/this.height\r\n // here because they are still -1 at construction time (set later during activate()).\r\n const h1 = new RenderTargetTexture(\"h1\", { width: 1, height: 1 }, scene, {\r\n samplingMode: Constants.TEXTURE_NEAREST_NEAREST,\r\n generateMipMaps: false,\r\n generateDepthBuffer: false,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n });\r\n\r\n // Geometry buffer renderer is supported.\r\n this.onApply = (effect: Effect) => {\r\n effect.setFloat(\"width\", this.width);\r\n effect.setFloat(\"height\", this.height);\r\n effect.setFloat(\"edgeIntensity\", this.edgeIntensity);\r\n effect.setFloat(\"edgeWidth\", this.edgeWidth);\r\n effect.setColor3(\"edgeColor\", this.edgeColor);\r\n\r\n const normalTexture = this._geometryBufferRenderer!.getGBuffer().textures[1];\r\n const depthTexture = this._geometryBufferRenderer!.getGBuffer().textures[0];\r\n\r\n effect.setTexture(\"normalSampler\", normalTexture);\r\n effect.setTexture(\"depthSampler\", depthTexture);\r\n\r\n switch (this.renderMode) {\r\n case 0:\r\n break;\r\n case 1:\r\n effect.setTexture(\"textureSampler\", this._geometryBufferRenderer!.getGBuffer().textures[1]);\r\n effect.setFloat(\"edgeWidth\", 0);\r\n break;\r\n case 2:\r\n effect.setTexture(\"textureSampler\", this._geometryBufferRenderer!.getGBuffer().textures[0]);\r\n effect.setFloat(\"edgeWidth\", 0);\r\n break;\r\n case 3:\r\n effect.setTexture(\"textureSampler\", h1);\r\n break;\r\n }\r\n effect.setInt(\"renderMode\", this.renderMode);\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Support test.\r\n */\r\n public static get IsSupported(): boolean {\r\n const engine = EngineStore.LastCreatedEngine;\r\n if (!engine) {\r\n return false;\r\n }\r\n\r\n return engine.getCaps().drawBuffersExtension;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static override _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {\r\n return SerializationHelper.Parse(\r\n () =>\r\n new EdgeDetectionPostProcess(\r\n parsedPostProcess.name,\r\n scene,\r\n parsedPostProcess.options,\r\n targetCamera,\r\n parsedPostProcess.renderTargetSamplingMode,\r\n parsedPostProcess.textureType,\r\n parsedPostProcess.reusable\r\n ),\r\n parsedPostProcess,\r\n scene,\r\n rootUrl\r\n );\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.EdgeDetectionPostProcess\", EdgeDetectionPostProcess);\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babylonjs/post-processes",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.16.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"postcompile": "build-tools -c add-js-to-es6"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@babylonjs/core": "9.
|
|
21
|
+
"@babylonjs/core": "9.16.0",
|
|
22
22
|
"@dev/build-tools": "^1.0.0",
|
|
23
23
|
"@dev/post-processes": "^1.0.0"
|
|
24
24
|
},
|