@babylonjs/core 6.3.1 → 6.4.1

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.
Files changed (71) hide show
  1. package/Audio/audioSceneComponent.js +2 -2
  2. package/Audio/audioSceneComponent.js.map +1 -1
  3. package/Cameras/Inputs/arcRotateCameraMouseWheelInput.js +10 -1
  4. package/Cameras/Inputs/arcRotateCameraMouseWheelInput.js.map +1 -1
  5. package/Debug/physicsViewer.d.ts +17 -0
  6. package/Debug/physicsViewer.js +153 -2
  7. package/Debug/physicsViewer.js.map +1 -1
  8. package/Engines/WebGPU/webgpuCacheBindGroups.js +1 -1
  9. package/Engines/WebGPU/webgpuCacheBindGroups.js.map +1 -1
  10. package/Engines/WebGPU/webgpuCacheRenderPipeline.js +4 -3
  11. package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
  12. package/Engines/WebGPU/webgpuClearQuad.js +1 -1
  13. package/Engines/WebGPU/webgpuClearQuad.js.map +1 -1
  14. package/Engines/WebGPU/webgpuMaterialContext.d.ts +1 -0
  15. package/Engines/WebGPU/webgpuMaterialContext.js +1 -0
  16. package/Engines/WebGPU/webgpuMaterialContext.js.map +1 -1
  17. package/Engines/WebGPU/webgpuPipelineContext.d.ts +3 -1
  18. package/Engines/WebGPU/webgpuPipelineContext.js +2 -0
  19. package/Engines/WebGPU/webgpuPipelineContext.js.map +1 -1
  20. package/Engines/WebGPU/webgpuTextureHelper.d.ts +1 -1
  21. package/Engines/WebGPU/webgpuTextureHelper.js +28 -9
  22. package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
  23. package/Engines/engine.d.ts +5 -0
  24. package/Engines/engine.js +0 -1
  25. package/Engines/engine.js.map +1 -1
  26. package/Engines/thinEngine.js +2 -2
  27. package/Engines/thinEngine.js.map +1 -1
  28. package/Engines/webgpuEngine.js +2 -1
  29. package/Engines/webgpuEngine.js.map +1 -1
  30. package/Instrumentation/sceneInstrumentation.js +25 -1
  31. package/Instrumentation/sceneInstrumentation.js.map +1 -1
  32. package/Materials/material.js +0 -5
  33. package/Materials/material.js.map +1 -1
  34. package/Materials/materialPluginManager.js +7 -0
  35. package/Materials/materialPluginManager.js.map +1 -1
  36. package/Maths/math.path.d.ts +33 -0
  37. package/Maths/math.path.js +116 -0
  38. package/Maths/math.path.js.map +1 -1
  39. package/Meshes/Builders/decalBuilder.js +146 -114
  40. package/Meshes/Builders/decalBuilder.js.map +1 -1
  41. package/Meshes/Builders/index.d.ts +1 -0
  42. package/Meshes/Builders/index.js +1 -0
  43. package/Meshes/Builders/index.js.map +1 -1
  44. package/Meshes/Builders/textBuilder.d.ts +51 -0
  45. package/Meshes/Builders/textBuilder.js +210 -0
  46. package/Meshes/Builders/textBuilder.js.map +1 -0
  47. package/Meshes/mesh.d.ts +3 -0
  48. package/Meshes/mesh.js +3 -0
  49. package/Meshes/mesh.js.map +1 -1
  50. package/Meshes/meshBuilder.d.ts +2 -0
  51. package/Meshes/meshBuilder.js +2 -0
  52. package/Meshes/meshBuilder.js.map +1 -1
  53. package/Meshes/meshUVSpaceRenderer.js +6 -3
  54. package/Meshes/meshUVSpaceRenderer.js.map +1 -1
  55. package/Misc/perfCounter.d.ts +5 -0
  56. package/Misc/perfCounter.js +7 -0
  57. package/Misc/perfCounter.js.map +1 -1
  58. package/Morph/morphTargetManager.js +3 -0
  59. package/Morph/morphTargetManager.js.map +1 -1
  60. package/Physics/v2/Plugins/havokPlugin.js +12 -2
  61. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  62. package/Rendering/fluidRenderer/fluidRenderer.d.ts +1 -1
  63. package/Rendering/fluidRenderer/fluidRenderer.js.map +1 -1
  64. package/Sprites/spriteManager.js +5 -9
  65. package/Sprites/spriteManager.js.map +1 -1
  66. package/XR/webXRSessionManager.d.ts +6 -0
  67. package/XR/webXRSessionManager.js +9 -0
  68. package/XR/webXRSessionManager.js.map +1 -1
  69. package/package.json +1 -1
  70. package/scene.js +1 -0
  71. package/scene.js.map +1 -1
@@ -0,0 +1,51 @@
1
+ import type { Scene } from "../../scene";
2
+ import type { Nullable } from "../../types";
3
+ import { Mesh } from "../mesh";
4
+ /**
5
+ * Parser inspired by https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/FontLoader.js
6
+ */
7
+ /**
8
+ * Represents glyph data generated by http://gero3.github.io/facetype.js/
9
+ */
10
+ export interface IGlyphData {
11
+ /** Commands used to draw (line, move, curve, etc..) */
12
+ o: string;
13
+ /** Width */
14
+ ha: number;
15
+ }
16
+ /**
17
+ * Represents font data generated by http://gero3.github.io/facetype.js/
18
+ */
19
+ export interface IFontData {
20
+ /**
21
+ * Font resolution
22
+ */
23
+ resolution: number;
24
+ /** Underline tickness */
25
+ underlineThickness: number;
26
+ /** Bounding box */
27
+ boundingBox: {
28
+ yMax: number;
29
+ yMin: number;
30
+ };
31
+ /** List of supported glyphs */
32
+ glyphs: {
33
+ [key: string]: IGlyphData;
34
+ };
35
+ }
36
+ /**
37
+ * Create a text mesh
38
+ * @param name defines the name of the mesh
39
+ * @param text defines the text to use to build the mesh
40
+ * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)
41
+ * @param options defines options used to create the mesh
42
+ * @param scene defines the hosting scene
43
+ * @returns a new Mesh
44
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/text
45
+ */
46
+ export declare function CreateText(name: string, text: string, fontData: IFontData, options?: {
47
+ size?: number;
48
+ resolution?: number;
49
+ depth?: number;
50
+ sideOrientation?: number;
51
+ }, scene?: Nullable<Scene>): Nullable<Mesh>;
@@ -0,0 +1,210 @@
1
+ import { Path2 } from "../../Maths/math.path.js";
2
+ import { Vector3 } from "../../Maths/math.vector.js";
3
+ import { Mesh } from "../mesh.js";
4
+ import { ExtrudePolygon } from "./polygonBuilder.js";
5
+ // Shape functions
6
+ class ShapePath {
7
+ /** Create the ShapePath used to support glyphs */
8
+ constructor(resolution) {
9
+ this._paths = [];
10
+ this._tempPaths = [];
11
+ this._holes = [];
12
+ this._resolution = resolution;
13
+ }
14
+ /** Move the virtual cursor to a coordinate */
15
+ moveTo(x, y) {
16
+ this._currentPath = new Path2(x, y);
17
+ this._tempPaths.push(this._currentPath);
18
+ }
19
+ /** Draw a line from the virtual cursor to a given coordinate */
20
+ lineTo(x, y) {
21
+ this._currentPath.addLineTo(x, y);
22
+ }
23
+ /** Create a quadratic curve from the virtual cursor to a given coordinate */
24
+ quadraticCurveTo(cpx, cpy, x, y) {
25
+ this._currentPath.addQuadraticCurveTo(cpx, cpy, x, y, this._resolution);
26
+ }
27
+ /** Create a bezier curve from the virtual cursor to a given coordinate */
28
+ bezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y) {
29
+ this._currentPath.addBezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y, this._resolution);
30
+ }
31
+ /** Extract holes based on CW / CCW */
32
+ extractHoles() {
33
+ for (const path of this._tempPaths) {
34
+ if (path.area() > 0) {
35
+ this._holes.push(path);
36
+ }
37
+ else {
38
+ this._paths.push(path);
39
+ }
40
+ }
41
+ if (!this._paths.length && this._holes.length) {
42
+ const temp = this._holes;
43
+ this._holes = this._paths;
44
+ this._paths = temp;
45
+ }
46
+ this._tempPaths.length = 0;
47
+ }
48
+ /** Gets the list of paths */
49
+ get paths() {
50
+ return this._paths;
51
+ }
52
+ /** Gets the list of holes */
53
+ get holes() {
54
+ return this._holes;
55
+ }
56
+ }
57
+ // Utility functions
58
+ function CreateShapePath(char, scale, offsetX, offsetY, resolution, fontData) {
59
+ const glyph = fontData.glyphs[char] || fontData.glyphs["?"];
60
+ if (!glyph) {
61
+ // return if there is no glyph data
62
+ return null;
63
+ }
64
+ const shapePath = new ShapePath(resolution);
65
+ if (glyph.o) {
66
+ const outline = glyph.o.split(" ");
67
+ for (let i = 0, l = outline.length; i < l;) {
68
+ const action = outline[i++];
69
+ switch (action) {
70
+ case "m": {
71
+ // moveTo
72
+ const x = parseInt(outline[i++]) * scale + offsetX;
73
+ const y = parseInt(outline[i++]) * scale + offsetY;
74
+ shapePath.moveTo(x, y);
75
+ break;
76
+ }
77
+ case "l": {
78
+ // lineTo
79
+ const x = parseInt(outline[i++]) * scale + offsetX;
80
+ const y = parseInt(outline[i++]) * scale + offsetY;
81
+ shapePath.lineTo(x, y);
82
+ break;
83
+ }
84
+ case "q": {
85
+ // quadraticCurveTo
86
+ const cpx = parseInt(outline[i++]) * scale + offsetX;
87
+ const cpy = parseInt(outline[i++]) * scale + offsetY;
88
+ const cpx1 = parseInt(outline[i++]) * scale + offsetX;
89
+ const cpy1 = parseInt(outline[i++]) * scale + offsetY;
90
+ shapePath.quadraticCurveTo(cpx1, cpy1, cpx, cpy);
91
+ break;
92
+ }
93
+ case "b": {
94
+ // bezierCurveTo
95
+ const cpx = parseInt(outline[i++]) * scale + offsetX;
96
+ const cpy = parseInt(outline[i++]) * scale + offsetY;
97
+ const cpx1 = parseInt(outline[i++]) * scale + offsetX;
98
+ const cpy1 = parseInt(outline[i++]) * scale + offsetY;
99
+ const cpx2 = parseInt(outline[i++]) * scale + offsetX;
100
+ const cpy2 = parseInt(outline[i++]) * scale + offsetY;
101
+ shapePath.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);
102
+ break;
103
+ }
104
+ }
105
+ }
106
+ }
107
+ // Extract holes (based on clockwise data)
108
+ shapePath.extractHoles();
109
+ return { offsetX: glyph.ha * scale, shapePath: shapePath };
110
+ }
111
+ function CreateShapePaths(text, size, resolution, fontData) {
112
+ const chars = Array.from(text);
113
+ const scale = size / fontData.resolution;
114
+ const line_height = (fontData.boundingBox.yMax - fontData.boundingBox.yMin + fontData.underlineThickness) * scale;
115
+ const shapePaths = [];
116
+ let offsetX = 0, offsetY = 0;
117
+ for (let i = 0; i < chars.length; i++) {
118
+ const char = chars[i];
119
+ if (char === "\n") {
120
+ offsetX = 0;
121
+ offsetY -= line_height;
122
+ }
123
+ else {
124
+ const ret = CreateShapePath(char, scale, offsetX, offsetY, resolution, fontData);
125
+ if (ret) {
126
+ offsetX += ret.offsetX;
127
+ shapePaths.push(ret.shapePath);
128
+ }
129
+ }
130
+ }
131
+ return shapePaths;
132
+ }
133
+ /**
134
+ * Create a text mesh
135
+ * @param name defines the name of the mesh
136
+ * @param text defines the text to use to build the mesh
137
+ * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)
138
+ * @param options defines options used to create the mesh
139
+ * @param scene defines the hosting scene
140
+ * @returns a new Mesh
141
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/text
142
+ */
143
+ export function CreateText(name, text, fontData, options = {
144
+ size: 50,
145
+ resolution: 8,
146
+ depth: 1.0,
147
+ }, scene = null) {
148
+ // First we need to generate the paths
149
+ const shapePaths = CreateShapePaths(text, options.size || 50, options.resolution || 8, fontData);
150
+ // And extrude them
151
+ const meshes = [];
152
+ for (const shapePath of shapePaths) {
153
+ if (!shapePath.paths.length) {
154
+ continue;
155
+ }
156
+ const holes = shapePath.holes.slice(); // Copy it as we will update the copy
157
+ for (const path of shapePath.paths) {
158
+ const holeVectors = [];
159
+ const shapeVectors = [];
160
+ const points = path.getPoints();
161
+ for (const point of points) {
162
+ shapeVectors.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane
163
+ }
164
+ // Holes
165
+ const localHolesCopy = holes.slice();
166
+ for (const hole of localHolesCopy) {
167
+ const points = hole.getPoints();
168
+ let found = false;
169
+ for (const point of points) {
170
+ if (path.isPointInside(point)) {
171
+ found = true;
172
+ break;
173
+ }
174
+ }
175
+ if (!found) {
176
+ continue;
177
+ }
178
+ const holePoints = [];
179
+ for (const point of points) {
180
+ holePoints.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane
181
+ }
182
+ holeVectors.push(holePoints);
183
+ // Remove the hole as it was already used
184
+ holes.splice(holes.indexOf(hole), 1);
185
+ }
186
+ // Extrusion!
187
+ const mesh = ExtrudePolygon(name, {
188
+ shape: shapeVectors,
189
+ holes: holeVectors.length ? holeVectors : undefined,
190
+ depth: options.depth || 1.0,
191
+ sideOrientation: Mesh._GetDefaultSideOrientation(options.sideOrientation || Mesh.DOUBLESIDE),
192
+ }, scene);
193
+ meshes.push(mesh);
194
+ }
195
+ }
196
+ // Then we can merge everyone into one single mesh
197
+ const newMesh = Mesh.MergeMeshes(meshes, true, true);
198
+ if (newMesh) {
199
+ // Move pivot to center
200
+ const bbox = newMesh === null || newMesh === void 0 ? void 0 : newMesh.getBoundingInfo();
201
+ newMesh.position.x = -(bbox === null || bbox === void 0 ? void 0 : bbox.boundingBox.extendSizeWorld._x);
202
+ newMesh.position.y = -(bbox === null || bbox === void 0 ? void 0 : bbox.boundingBox.extendSizeWorld._y);
203
+ newMesh.position.z = -(bbox === null || bbox === void 0 ? void 0 : bbox.boundingBox.extendSizeWorld._z);
204
+ newMesh.name = name;
205
+ newMesh.rotation.x = -Math.PI / 2;
206
+ newMesh.bakeCurrentTransformIntoVertices();
207
+ }
208
+ return newMesh;
209
+ }
210
+ //# sourceMappingURL=textBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textBuilder.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Meshes/Builders/textBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAsClD,kBAAkB;AAClB,MAAM,SAAS;IAOX,kDAAkD;IAClD,YAAY,UAAkB;QAPtB,WAAM,GAAY,EAAE,CAAC;QACrB,eAAU,GAAY,EAAE,CAAC;QACzB,WAAM,GAAY,EAAE,CAAC;QAMzB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAClC,CAAC;IAED,8CAA8C;IAC9C,MAAM,CAAC,CAAS,EAAE,CAAS;QACvB,IAAI,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AC,OAAO,CAAC,eAAe,IAAI,IAAI,CAAC,UAAU,CAAC;aAC/F,EACD,KAAK,CACR,CAAC;YACF,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACrB;KACJ;IAED,kDAAkD;IAClD,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAErD,IAAI,OAAO,EAAE;QACT,uBAAuB;QACvB,MAAM,IAAI,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,EAAE,CAAC;QACxC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,eAAe,CAAC,EAAE,CAAA,CAAC;QAC3D,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,eAAe,CAAC,EAAE,CAAA,CAAC;QAC3D,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,CAAC,eAAe,CAAC,EAAE,CAAA,CAAC;QAC3D,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QAEpB,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QAElC,OAAO,CAAC,gCAAgC,EAAE,CAAC;KAC9C;IAED,OAAO,OAAO,CAAC;AACnB,CAAC","sourcesContent":["import { Path2 } from \"../../Maths/math.path\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { ExtrudePolygon } from \"./polygonBuilder\";\r\n\r\n/**\r\n * Parser inspired by https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/FontLoader.js\r\n */\r\n\r\n// Interfaces\r\n\r\n/**\r\n * Represents glyph data generated by http://gero3.github.io/facetype.js/\r\n */\r\nexport interface IGlyphData {\r\n /** Commands used to draw (line, move, curve, etc..) */\r\n o: string;\r\n\r\n /** Width */\r\n ha: number;\r\n}\r\n\r\n/**\r\n * Represents font data generated by http://gero3.github.io/facetype.js/\r\n */\r\nexport interface IFontData {\r\n /**\r\n * Font resolution\r\n */\r\n resolution: number;\r\n /** Underline tickness */\r\n underlineThickness: number;\r\n /** Bounding box */\r\n boundingBox: {\r\n yMax: number;\r\n yMin: number;\r\n };\r\n /** List of supported glyphs */\r\n glyphs: { [key: string]: IGlyphData };\r\n}\r\n\r\n// Shape functions\r\nclass ShapePath {\r\n private _paths: Path2[] = [];\r\n private _tempPaths: Path2[] = [];\r\n private _holes: Path2[] = [];\r\n private _currentPath: Path2;\r\n private _resolution: number;\r\n\r\n /** Create the ShapePath used to support glyphs */\r\n constructor(resolution: number) {\r\n this._resolution = resolution;\r\n }\r\n\r\n /** Move the virtual cursor to a coordinate */\r\n moveTo(x: number, y: number) {\r\n this._currentPath = new Path2(x, y);\r\n this._tempPaths.push(this._currentPath);\r\n }\r\n\r\n /** Draw a line from the virtual cursor to a given coordinate */\r\n lineTo(x: number, y: number) {\r\n this._currentPath.addLineTo(x, y);\r\n }\r\n\r\n /** Create a quadratic curve from the virtual cursor to a given coordinate */\r\n quadraticCurveTo(cpx: number, cpy: number, x: number, y: number) {\r\n this._currentPath.addQuadraticCurveTo(cpx, cpy, x, y, this._resolution);\r\n }\r\n\r\n /** Create a bezier curve from the virtual cursor to a given coordinate */\r\n bezierCurveTo(cpx1: number, cpy1: number, cpx2: number, cpy2: number, x: number, y: number) {\r\n this._currentPath.addBezierCurveTo(cpx1, cpy1, cpx2, cpy2, x, y, this._resolution);\r\n }\r\n\r\n /** Extract holes based on CW / CCW */\r\n extractHoles() {\r\n for (const path of this._tempPaths) {\r\n if (path.area() > 0) {\r\n this._holes.push(path);\r\n } else {\r\n this._paths.push(path);\r\n }\r\n }\r\n\r\n if (!this._paths.length && this._holes.length) {\r\n const temp = this._holes;\r\n this._holes = this._paths;\r\n this._paths = temp;\r\n }\r\n\r\n this._tempPaths.length = 0;\r\n }\r\n\r\n /** Gets the list of paths */\r\n get paths() {\r\n return this._paths;\r\n }\r\n\r\n /** Gets the list of holes */\r\n get holes() {\r\n return this._holes;\r\n }\r\n}\r\n\r\n// Utility functions\r\nfunction CreateShapePath(\r\n char: string,\r\n scale: number,\r\n offsetX: number,\r\n offsetY: number,\r\n resolution: number,\r\n fontData: IFontData\r\n): Nullable<{\r\n offsetX: number;\r\n shapePath: ShapePath;\r\n}> {\r\n const glyph = fontData.glyphs[char] || fontData.glyphs[\"?\"];\r\n\r\n if (!glyph) {\r\n // return if there is no glyph data\r\n return null;\r\n }\r\n\r\n const shapePath = new ShapePath(resolution);\r\n\r\n if (glyph.o) {\r\n const outline = glyph.o.split(\" \");\r\n\r\n for (let i = 0, l = outline.length; i < l; ) {\r\n const action = outline[i++];\r\n\r\n switch (action) {\r\n case \"m\": {\r\n // moveTo\r\n const x = parseInt(outline[i++]) * scale + offsetX;\r\n const y = parseInt(outline[i++]) * scale + offsetY;\r\n\r\n shapePath.moveTo(x, y);\r\n break;\r\n }\r\n case \"l\": {\r\n // lineTo\r\n const x = parseInt(outline[i++]) * scale + offsetX;\r\n const y = parseInt(outline[i++]) * scale + offsetY;\r\n\r\n shapePath.lineTo(x, y);\r\n break;\r\n }\r\n case \"q\": {\r\n // quadraticCurveTo\r\n const cpx = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy = parseInt(outline[i++]) * scale + offsetY;\r\n const cpx1 = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy1 = parseInt(outline[i++]) * scale + offsetY;\r\n\r\n shapePath.quadraticCurveTo(cpx1, cpy1, cpx, cpy);\r\n break;\r\n }\r\n case \"b\": {\r\n // bezierCurveTo\r\n const cpx = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy = parseInt(outline[i++]) * scale + offsetY;\r\n const cpx1 = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy1 = parseInt(outline[i++]) * scale + offsetY;\r\n const cpx2 = parseInt(outline[i++]) * scale + offsetX;\r\n const cpy2 = parseInt(outline[i++]) * scale + offsetY;\r\n\r\n shapePath.bezierCurveTo(cpx1, cpy1, cpx2, cpy2, cpx, cpy);\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Extract holes (based on clockwise data)\r\n shapePath.extractHoles();\r\n\r\n return { offsetX: glyph.ha * scale, shapePath: shapePath };\r\n}\r\n\r\nfunction CreateShapePaths(text: string, size: number, resolution: number, fontData: IFontData) {\r\n const chars = Array.from(text);\r\n const scale = size / fontData.resolution;\r\n const line_height = (fontData.boundingBox.yMax - fontData.boundingBox.yMin + fontData.underlineThickness) * scale;\r\n\r\n const shapePaths: ShapePath[] = [];\r\n\r\n let offsetX = 0,\r\n offsetY = 0;\r\n\r\n for (let i = 0; i < chars.length; i++) {\r\n const char = chars[i];\r\n\r\n if (char === \"\\n\") {\r\n offsetX = 0;\r\n offsetY -= line_height;\r\n } else {\r\n const ret = CreateShapePath(char, scale, offsetX, offsetY, resolution, fontData);\r\n\r\n if (ret) {\r\n offsetX += ret.offsetX;\r\n shapePaths.push(ret.shapePath);\r\n }\r\n }\r\n }\r\n\r\n return shapePaths;\r\n}\r\n\r\n/**\r\n * Create a text mesh\r\n * @param name defines the name of the mesh\r\n * @param text defines the text to use to build the mesh\r\n * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)\r\n * @param options defines options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns a new Mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/text\r\n */\r\nexport function CreateText(\r\n name: string,\r\n text: string,\r\n fontData: IFontData,\r\n options: {\r\n size?: number;\r\n resolution?: number;\r\n depth?: number;\r\n sideOrientation?: number;\r\n } = {\r\n size: 50,\r\n resolution: 8,\r\n depth: 1.0,\r\n },\r\n scene: Nullable<Scene> = null\r\n): Nullable<Mesh> {\r\n // First we need to generate the paths\r\n const shapePaths = CreateShapePaths(text, options.size || 50, options.resolution || 8, fontData);\r\n\r\n // And extrude them\r\n const meshes: Mesh[] = [];\r\n for (const shapePath of shapePaths) {\r\n if (!shapePath.paths.length) {\r\n continue;\r\n }\r\n\r\n const holes = shapePath.holes.slice(); // Copy it as we will update the copy\r\n for (const path of shapePath.paths) {\r\n const holeVectors: Vector3[][] = [];\r\n const shapeVectors: Vector3[] = [];\r\n const points = path.getPoints();\r\n for (const point of points) {\r\n shapeVectors.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane\r\n }\r\n\r\n // Holes\r\n const localHolesCopy = holes.slice();\r\n for (const hole of localHolesCopy) {\r\n const points = hole.getPoints();\r\n\r\n let found = false;\r\n for (const point of points) {\r\n if (path.isPointInside(point)) {\r\n found = true;\r\n break;\r\n }\r\n }\r\n\r\n if (!found) {\r\n continue;\r\n }\r\n\r\n const holePoints: Vector3[] = [];\r\n for (const point of points) {\r\n holePoints.push(new Vector3(point.x, 0, point.y)); // ExtrudePolygon expects data on the xz plane\r\n }\r\n holeVectors.push(holePoints);\r\n\r\n // Remove the hole as it was already used\r\n holes.splice(holes.indexOf(hole), 1);\r\n }\r\n\r\n // Extrusion!\r\n const mesh = ExtrudePolygon(\r\n name,\r\n {\r\n shape: shapeVectors,\r\n holes: holeVectors.length ? holeVectors : undefined,\r\n depth: options.depth || 1.0,\r\n sideOrientation: Mesh._GetDefaultSideOrientation(options.sideOrientation || Mesh.DOUBLESIDE),\r\n },\r\n scene\r\n );\r\n meshes.push(mesh);\r\n }\r\n }\r\n\r\n // Then we can merge everyone into one single mesh\r\n const newMesh = Mesh.MergeMeshes(meshes, true, true);\r\n\r\n if (newMesh) {\r\n // Move pivot to center\r\n const bbox = newMesh?.getBoundingInfo();\r\n newMesh.position.x = -bbox?.boundingBox.extendSizeWorld._x;\r\n newMesh.position.y = -bbox?.boundingBox.extendSizeWorld._y;\r\n newMesh.position.z = -bbox?.boundingBox.extendSizeWorld._z;\r\n newMesh.name = name;\r\n\r\n newMesh.rotation.x = -Math.PI / 2;\r\n\r\n newMesh.bakeCurrentTransformIntoVertices();\r\n }\r\n\r\n return newMesh;\r\n}\r\n"]}
package/Meshes/mesh.d.ts CHANGED
@@ -277,6 +277,9 @@ export declare class Mesh extends AbstractMesh implements IGetSetVerticesData {
277
277
  set overrideRenderingFillMode(fillMode: Nullable<number>);
278
278
  /**
279
279
  * Gets or sets a boolean indicating whether to render ignoring the active camera's max z setting. (false by default)
280
+ * You should not mix meshes that have this property set to true with meshes that have it set to false if they all write
281
+ * to the depth buffer, because the z-values are not comparable in the two cases and you will get rendering artifacts if you do.
282
+ * You can set the property to true for meshes that do not write to the depth buffer, or set the same value (either false or true) otherwise.
280
283
  * Note this will reduce performance when set to true.
281
284
  */
282
285
  ignoreCameraMaxZ: boolean;
package/Meshes/mesh.js CHANGED
@@ -310,6 +310,9 @@ export class Mesh extends AbstractMesh {
310
310
  this.overrideMaterialSideOrientation = null;
311
311
  /**
312
312
  * Gets or sets a boolean indicating whether to render ignoring the active camera's max z setting. (false by default)
313
+ * You should not mix meshes that have this property set to true with meshes that have it set to false if they all write
314
+ * to the depth buffer, because the z-values are not comparable in the two cases and you will get rendering artifacts if you do.
315
+ * You can set the property to true for meshes that do not write to the depth buffer, or set the same value (either false or true) otherwise.
313
316
  * Note this will reduce performance when set to true.
314
317
  */
315
318
  this.ignoreCameraMaxZ = false;