@babylonjs/core 5.49.0 → 5.49.2
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/Engines/Native/nativeInterfaces.d.ts +1 -0
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/Native/nativePipelineContext.d.ts +6 -2
- package/Engines/Native/nativePipelineContext.js +12 -3
- package/Engines/Native/nativePipelineContext.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureHelper.js +2 -2
- package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
- package/Engines/WebGPU/webgpuTintWASM.js +1 -1
- package/Engines/WebGPU/webgpuTintWASM.js.map +1 -1
- package/Engines/engine.d.ts +53 -0
- package/Engines/nativeEngine.d.ts +2 -5
- package/Engines/nativeEngine.js +44 -12
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +1 -0
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/PBR/pbrMaterial.decalMap.d.ts +12 -0
- package/Materials/PBR/pbrMaterial.decalMap.js +18 -0
- package/Materials/PBR/pbrMaterial.decalMap.js.map +1 -0
- package/Materials/Textures/renderTargetTexture.js +2 -4
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/index.d.ts +2 -0
- package/Materials/index.js +2 -0
- package/Materials/index.js.map +1 -1
- package/Materials/material.decalMap.d.ts +3 -0
- package/Materials/material.decalMap.js +4 -0
- package/Materials/material.decalMap.js.map +1 -0
- package/Materials/material.decalMapConfiguration.d.ts +63 -0
- package/Materials/material.decalMapConfiguration.js +119 -0
- package/Materials/material.decalMapConfiguration.js.map +1 -0
- package/Materials/materialFlags.d.ts +6 -0
- package/Materials/materialFlags.js +14 -0
- package/Materials/materialFlags.js.map +1 -1
- package/Materials/standardMaterial.decalMap.d.ts +12 -0
- package/Materials/standardMaterial.decalMap.js +18 -0
- package/Materials/standardMaterial.decalMap.js.map +1 -0
- package/Materials/standardMaterial.js +1 -0
- package/Materials/standardMaterial.js.map +1 -1
- package/Maths/math.vector.d.ts +10 -0
- package/Maths/math.vector.js +14 -0
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/abstractMesh.decalMap.d.ts +12 -0
- package/Meshes/abstractMesh.decalMap.js +12 -0
- package/Meshes/abstractMesh.decalMap.js.map +1 -0
- package/Meshes/index.d.ts +2 -0
- package/Meshes/index.js +2 -0
- package/Meshes/index.js.map +1 -1
- package/Meshes/meshUVSpaceRenderer.d.ts +94 -0
- package/Meshes/meshUVSpaceRenderer.js +141 -0
- package/Meshes/meshUVSpaceRenderer.js.map +1 -0
- package/Particles/gpuParticleSystem.js +1 -1
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Physics/v2/physicsAggregate.d.ts +4 -0
- package/Physics/v2/physicsAggregate.js +4 -4
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +18 -2
- package/Physics/v2/physicsBody.js +66 -1
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Rendering/fluidRenderer/fluidRenderer.js +2 -1
- package/Rendering/fluidRenderer/fluidRenderer.js.map +1 -1
- package/Rendering/renderingManager.js +4 -2
- package/Rendering/renderingManager.js.map +1 -1
- package/Shaders/ShadersInclude/decalFragment.d.ts +5 -0
- package/Shaders/ShadersInclude/decalFragment.js +15 -0
- package/Shaders/ShadersInclude/decalFragment.js.map +1 -0
- package/Shaders/ShadersInclude/decalFragmentDeclaration.d.ts +5 -0
- package/Shaders/ShadersInclude/decalFragmentDeclaration.js +11 -0
- package/Shaders/ShadersInclude/decalFragmentDeclaration.js.map +1 -0
- package/Shaders/ShadersInclude/decalVertexDeclaration.d.ts +5 -0
- package/Shaders/ShadersInclude/decalVertexDeclaration.js +11 -0
- package/Shaders/ShadersInclude/decalVertexDeclaration.js.map +1 -0
- package/Shaders/ShadersInclude/defaultFragmentDeclaration.d.ts +1 -0
- package/Shaders/ShadersInclude/defaultFragmentDeclaration.js +2 -0
- package/Shaders/ShadersInclude/defaultFragmentDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/defaultVertexDeclaration.d.ts +1 -0
- package/Shaders/ShadersInclude/defaultVertexDeclaration.js +2 -0
- package/Shaders/ShadersInclude/defaultVertexDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockAlbedoOpacity.d.ts +1 -0
- package/Shaders/ShadersInclude/pbrBlockAlbedoOpacity.js +4 -0
- package/Shaders/ShadersInclude/pbrBlockAlbedoOpacity.js.map +1 -1
- package/Shaders/ShadersInclude/pbrFragmentDeclaration.d.ts +1 -0
- package/Shaders/ShadersInclude/pbrFragmentDeclaration.js +2 -0
- package/Shaders/ShadersInclude/pbrFragmentDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js +1 -0
- package/Shaders/ShadersInclude/pbrFragmentSamplersDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrVertexDeclaration.d.ts +1 -0
- package/Shaders/ShadersInclude/pbrVertexDeclaration.js +2 -0
- package/Shaders/ShadersInclude/pbrVertexDeclaration.js.map +1 -1
- package/Shaders/default.fragment.d.ts +1 -0
- package/Shaders/default.fragment.js +5 -0
- package/Shaders/default.fragment.js.map +1 -1
- package/Shaders/default.vertex.js +2 -0
- package/Shaders/default.vertex.js.map +1 -1
- package/Shaders/geometry.fragment.js +1 -1
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/meshUVSpaceRenderer.fragment.d.ts +5 -0
- package/Shaders/meshUVSpaceRenderer.fragment.js +9 -0
- package/Shaders/meshUVSpaceRenderer.fragment.js.map +1 -0
- package/Shaders/meshUVSpaceRenderer.vertex.d.ts +15 -0
- package/Shaders/meshUVSpaceRenderer.vertex.js +34 -0
- package/Shaders/meshUVSpaceRenderer.vertex.js.map +1 -0
- package/Shaders/pbr.fragment.js +4 -0
- package/Shaders/pbr.fragment.js.map +1 -1
- package/Shaders/pbr.vertex.js +2 -0
- package/Shaders/pbr.vertex.js.map +1 -1
- package/Shaders/screenSpaceReflection2.fragment.js +1 -1
- package/Shaders/screenSpaceReflection2.fragment.js.map +1 -1
- package/ShadersWGSL/gpuUpdateParticles.compute.js +1 -1
- package/ShadersWGSL/gpuUpdateParticles.compute.js.map +1 -1
- package/Sprites/spriteManager.js +5 -3
- package/Sprites/spriteManager.js.map +1 -1
- package/Sprites/spriteSceneComponent.d.ts +1 -1
- package/Sprites/spriteSceneComponent.js +7 -4
- package/Sprites/spriteSceneComponent.js.map +1 -1
- package/XR/features/WebXRDepthSensing.d.ts +118 -0
- package/XR/features/WebXRDepthSensing.js +268 -0
- package/XR/features/WebXRDepthSensing.js.map +1 -0
- package/XR/features/index.d.ts +1 -0
- package/XR/features/index.js +1 -0
- package/XR/features/index.js.map +1 -1
- package/XR/native/nativeXRFrame.d.ts +1 -0
- package/XR/native/nativeXRFrame.js +4 -0
- package/XR/native/nativeXRFrame.js.map +1 -1
- package/XR/webXRCamera.d.ts +1 -0
- package/XR/webXRCamera.js +4 -0
- package/XR/webXRCamera.js.map +1 -1
- package/XR/webXRFeaturesManager.d.ts +4 -0
- package/XR/webXRFeaturesManager.js +4 -0
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/assetContainer.js +13 -5
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Nullable } from "../types";
|
|
2
|
+
import type { MeshUVSpaceRenderer } from "./meshUVSpaceRenderer";
|
|
3
|
+
declare module "./abstractMesh" {
|
|
4
|
+
interface AbstractMesh {
|
|
5
|
+
/** @internal */
|
|
6
|
+
_decalMap: Nullable<MeshUVSpaceRenderer>;
|
|
7
|
+
/**
|
|
8
|
+
* Gets or sets the decal map for this mesh
|
|
9
|
+
*/
|
|
10
|
+
decalMap: Nullable<MeshUVSpaceRenderer>;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AbstractMesh } from "../Meshes/abstractMesh.js";
|
|
2
|
+
Object.defineProperty(AbstractMesh.prototype, "decalMap", {
|
|
3
|
+
get: function () {
|
|
4
|
+
return this._decalMap;
|
|
5
|
+
},
|
|
6
|
+
set: function (decalMap) {
|
|
7
|
+
this._decalMap = decalMap;
|
|
8
|
+
},
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=abstractMesh.decalMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstractMesh.decalMap.js","sourceRoot":"","sources":["../../../../lts/core/generated/Meshes/abstractMesh.decalMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAetD,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,SAAS,EAAE,UAAU,EAAE;IACtD,GAAG,EAAE;QACD,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IACD,GAAG,EAAE,UAA8B,QAAuC;QACtE,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IACD,UAAU,EAAE,IAAI;IAChB,YAAY,EAAE,IAAI;CACrB,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"../types\";\r\nimport { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport type { MeshUVSpaceRenderer } from \"./meshUVSpaceRenderer\";\r\n\r\ndeclare module \"./abstractMesh\" {\r\n export interface AbstractMesh {\r\n /** @internal */\r\n _decalMap: Nullable<MeshUVSpaceRenderer>;\r\n\r\n /**\r\n * Gets or sets the decal map for this mesh\r\n */\r\n decalMap: Nullable<MeshUVSpaceRenderer>;\r\n }\r\n}\r\n\r\nObject.defineProperty(AbstractMesh.prototype, \"decalMap\", {\r\n get: function (this: AbstractMesh) {\r\n return this._decalMap;\r\n },\r\n set: function (this: AbstractMesh, decalMap: Nullable<MeshUVSpaceRenderer>) {\r\n this._decalMap = decalMap;\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n"]}
|
package/Meshes/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./abstractMesh";
|
|
2
|
+
import "./abstractMesh.decalMap";
|
|
2
3
|
export * from "./Compression/index";
|
|
3
4
|
export * from "./csg";
|
|
5
|
+
export * from "./meshUVSpaceRenderer";
|
|
4
6
|
export * from "./geometry";
|
|
5
7
|
export * from "./groundMesh";
|
|
6
8
|
export * from "./goldbergMesh";
|
package/Meshes/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
2
|
/* eslint-disable import/no-internal-modules */
|
|
3
3
|
export * from "./abstractMesh.js";
|
|
4
|
+
import "./abstractMesh.decalMap.js";
|
|
4
5
|
export * from "./Compression/index.js";
|
|
5
6
|
export * from "./csg.js";
|
|
7
|
+
export * from "./meshUVSpaceRenderer.js";
|
|
6
8
|
export * from "./geometry.js";
|
|
7
9
|
export * from "./groundMesh.js";
|
|
8
10
|
export * from "./goldbergMesh.js";
|
package/Meshes/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lts/core/generated/Meshes/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+CAA+C;AAC/C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,OAAO,oBAAoB,CAAC;AAC5B,gDAAgD;AAChD,cAAc,oBAAoB,CAAC","sourcesContent":["/* eslint-disable import/export */\r\n/* eslint-disable import/no-internal-modules */\r\nexport * from \"./abstractMesh\";\r\nexport * from \"./Compression/index\";\r\nexport * from \"./csg\";\r\nexport * from \"./geometry\";\r\nexport * from \"./groundMesh\";\r\nexport * from \"./goldbergMesh\";\r\nexport * from \"./trailMesh\";\r\nexport * from \"./instancedMesh\";\r\nexport * from \"./linesMesh\";\r\nexport * from \"./mesh\";\r\nexport * from \"./mesh.vertexData\";\r\nexport * from \"./meshBuilder\";\r\nexport * from \"./meshSimplification\";\r\nexport * from \"./meshSimplificationSceneComponent\";\r\nexport * from \"./polygonMesh\";\r\nexport * from \"./geodesicMesh\";\r\nexport * from \"./subMesh\";\r\nexport * from \"./subMesh.project\";\r\nexport * from \"./meshLODLevel\";\r\nexport * from \"./transformNode\";\r\nexport * from \"./Builders/index\";\r\nexport * from \"./WebGL/webGLDataBuffer\";\r\nexport * from \"./WebGPU/webgpuDataBuffer\";\r\nimport \"./thinInstanceMesh\";\r\n// eslint-disable-next-line no-duplicate-imports\r\nexport * from \"./thinInstanceMesh\";\r\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lts/core/generated/Meshes/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+CAA+C;AAC/C,cAAc,gBAAgB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,OAAO,CAAC;AACtB,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,OAAO,oBAAoB,CAAC;AAC5B,gDAAgD;AAChD,cAAc,oBAAoB,CAAC","sourcesContent":["/* eslint-disable import/export */\r\n/* eslint-disable import/no-internal-modules */\r\nexport * from \"./abstractMesh\";\r\nimport \"./abstractMesh.decalMap\";\r\nexport * from \"./Compression/index\";\r\nexport * from \"./csg\";\r\nexport * from \"./meshUVSpaceRenderer\";\r\nexport * from \"./geometry\";\r\nexport * from \"./groundMesh\";\r\nexport * from \"./goldbergMesh\";\r\nexport * from \"./trailMesh\";\r\nexport * from \"./instancedMesh\";\r\nexport * from \"./linesMesh\";\r\nexport * from \"./mesh\";\r\nexport * from \"./mesh.vertexData\";\r\nexport * from \"./meshBuilder\";\r\nexport * from \"./meshSimplification\";\r\nexport * from \"./meshSimplificationSceneComponent\";\r\nexport * from \"./polygonMesh\";\r\nexport * from \"./geodesicMesh\";\r\nexport * from \"./subMesh\";\r\nexport * from \"./subMesh.project\";\r\nexport * from \"./meshLODLevel\";\r\nexport * from \"./transformNode\";\r\nexport * from \"./Builders/index\";\r\nexport * from \"./WebGL/webGLDataBuffer\";\r\nexport * from \"./WebGPU/webgpuDataBuffer\";\r\nimport \"./thinInstanceMesh\";\r\n// eslint-disable-next-line no-duplicate-imports\r\nexport * from \"./thinInstanceMesh\";\r\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Texture } from "../Materials/Textures/texture.js";
|
|
2
|
+
import type { Vector3 } from "../Maths/math.vector.js";
|
|
3
|
+
import type { Scene } from "../scene.js";
|
|
4
|
+
import type { AbstractMesh } from "./abstractMesh";
|
|
5
|
+
import type { BaseTexture } from "../Materials/Textures/baseTexture.js";
|
|
6
|
+
import { Color4 } from "../Maths/math.color.js";
|
|
7
|
+
import "../Shaders/meshUVSpaceRenderer.vertex";
|
|
8
|
+
import "../Shaders/meshUVSpaceRenderer.fragment";
|
|
9
|
+
/**
|
|
10
|
+
* Options for the MeshUVSpaceRenderer
|
|
11
|
+
* @since 5.49.1
|
|
12
|
+
*/
|
|
13
|
+
export interface IMeshUVSpaceRendererOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Width of the texture. Default: 1024
|
|
16
|
+
*/
|
|
17
|
+
width?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Height of the texture. Default: 1024
|
|
20
|
+
*/
|
|
21
|
+
height?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Type of the texture. Default: Constants.TEXTURETYPE_UNSIGNED_BYTE
|
|
24
|
+
*/
|
|
25
|
+
textureType?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Generate mip maps. Default: true
|
|
28
|
+
*/
|
|
29
|
+
generateMipMaps?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Optimize UV allocation. Default: true
|
|
32
|
+
* If you plan to use the texture as a decal map and rotate / offset the texture, you should set this to false
|
|
33
|
+
*/
|
|
34
|
+
optimizeUVAllocation?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Class used to render in the mesh UV space
|
|
38
|
+
* @since 5.49.1
|
|
39
|
+
*/
|
|
40
|
+
export declare class MeshUVSpaceRenderer {
|
|
41
|
+
private static _Shader;
|
|
42
|
+
private _mesh;
|
|
43
|
+
private _scene;
|
|
44
|
+
private _options;
|
|
45
|
+
private _textureCreatedInternally;
|
|
46
|
+
private static _GetShader;
|
|
47
|
+
private static _IsRenderTargetTexture;
|
|
48
|
+
/**
|
|
49
|
+
* Disposes of the global resources created by the MeshUVSpaceRenderer class
|
|
50
|
+
*/
|
|
51
|
+
static Dispose(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Clear color of the texture
|
|
54
|
+
*/
|
|
55
|
+
clearColor: Color4;
|
|
56
|
+
/**
|
|
57
|
+
* Target texture used for rendering
|
|
58
|
+
* If you don't set the property, a RenderTargetTexture will be created internally given the options provided to the constructor.
|
|
59
|
+
* If you provide a RenderTargetTexture, it will be used directly.
|
|
60
|
+
*/
|
|
61
|
+
texture: Texture;
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new MeshUVSpaceRenderer
|
|
64
|
+
* @param mesh The mesh used for the source UV space
|
|
65
|
+
* @param scene The scene the mesh belongs to
|
|
66
|
+
* @param options The options to use when creating the texture
|
|
67
|
+
*/
|
|
68
|
+
constructor(mesh: AbstractMesh, scene: Scene, options?: IMeshUVSpaceRendererOptions);
|
|
69
|
+
/**
|
|
70
|
+
* Checks if the texture is ready to be used
|
|
71
|
+
* @returns true if the texture is ready to be used
|
|
72
|
+
*/
|
|
73
|
+
isReady(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Projects and renders a texture in the mesh UV space
|
|
76
|
+
* @param texture The texture
|
|
77
|
+
* @param position The position of the center of projection (world space coordinates)
|
|
78
|
+
* @param normal The direction of the projection (world space coordinates)
|
|
79
|
+
* @param size The size of the projection
|
|
80
|
+
* @param angle The rotation angle around the direction of the projection
|
|
81
|
+
*/
|
|
82
|
+
renderTexture(texture: BaseTexture, position: Vector3, normal: Vector3, size: Vector3, angle?: number): void;
|
|
83
|
+
/**
|
|
84
|
+
* Clears the texture map
|
|
85
|
+
*/
|
|
86
|
+
clear(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Disposes of the ressources
|
|
89
|
+
*/
|
|
90
|
+
dispose(): void;
|
|
91
|
+
private _createDiffuseRTT;
|
|
92
|
+
private _createRenderTargetTexture;
|
|
93
|
+
private _createProjectionMatrix;
|
|
94
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Matrix } from "../Maths/math.vector.js";
|
|
2
|
+
|
|
3
|
+
import { ShaderMaterial } from "../Materials/shaderMaterial.js";
|
|
4
|
+
import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture.js";
|
|
5
|
+
import { Color4 } from "../Maths/math.color.js";
|
|
6
|
+
import "../Shaders/meshUVSpaceRenderer.vertex.js";
|
|
7
|
+
import "../Shaders/meshUVSpaceRenderer.fragment.js";
|
|
8
|
+
/**
|
|
9
|
+
* Class used to render in the mesh UV space
|
|
10
|
+
* @since 5.49.1
|
|
11
|
+
*/
|
|
12
|
+
export class MeshUVSpaceRenderer {
|
|
13
|
+
static _GetShader(scene) {
|
|
14
|
+
if (!MeshUVSpaceRenderer._Shader) {
|
|
15
|
+
const shader = new ShaderMaterial("meshUVSpaceRendererShader", scene, {
|
|
16
|
+
vertex: "meshUVSpaceRenderer",
|
|
17
|
+
fragment: "meshUVSpaceRenderer",
|
|
18
|
+
}, {
|
|
19
|
+
attributes: ["position", "normal", "uv"],
|
|
20
|
+
uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"],
|
|
21
|
+
needAlphaBlending: true,
|
|
22
|
+
});
|
|
23
|
+
shader.backFaceCulling = false;
|
|
24
|
+
shader.alphaMode = 2;
|
|
25
|
+
MeshUVSpaceRenderer._Shader = shader;
|
|
26
|
+
}
|
|
27
|
+
return MeshUVSpaceRenderer._Shader;
|
|
28
|
+
}
|
|
29
|
+
static _IsRenderTargetTexture(texture) {
|
|
30
|
+
return texture.renderList !== undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Disposes of the global resources created by the MeshUVSpaceRenderer class
|
|
34
|
+
*/
|
|
35
|
+
static Dispose() {
|
|
36
|
+
if (MeshUVSpaceRenderer._Shader) {
|
|
37
|
+
MeshUVSpaceRenderer._Shader.dispose();
|
|
38
|
+
MeshUVSpaceRenderer._Shader = null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new MeshUVSpaceRenderer
|
|
43
|
+
* @param mesh The mesh used for the source UV space
|
|
44
|
+
* @param scene The scene the mesh belongs to
|
|
45
|
+
* @param options The options to use when creating the texture
|
|
46
|
+
*/
|
|
47
|
+
constructor(mesh, scene, options) {
|
|
48
|
+
this._textureCreatedInternally = false;
|
|
49
|
+
/**
|
|
50
|
+
* Clear color of the texture
|
|
51
|
+
*/
|
|
52
|
+
this.clearColor = new Color4(0, 0, 0, 0);
|
|
53
|
+
this._mesh = mesh;
|
|
54
|
+
this._scene = scene;
|
|
55
|
+
this._options = {
|
|
56
|
+
width: 1024,
|
|
57
|
+
height: 1024,
|
|
58
|
+
textureType: 0,
|
|
59
|
+
generateMipMaps: true,
|
|
60
|
+
optimizeUVAllocation: true,
|
|
61
|
+
...options,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Checks if the texture is ready to be used
|
|
66
|
+
* @returns true if the texture is ready to be used
|
|
67
|
+
*/
|
|
68
|
+
isReady() {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
return MeshUVSpaceRenderer._GetShader(this._scene).isReady() && ((_b = (_a = this.texture) === null || _a === void 0 ? void 0 : _a.isReady()) !== null && _b !== void 0 ? _b : true);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Projects and renders a texture in the mesh UV space
|
|
74
|
+
* @param texture The texture
|
|
75
|
+
* @param position The position of the center of projection (world space coordinates)
|
|
76
|
+
* @param normal The direction of the projection (world space coordinates)
|
|
77
|
+
* @param size The size of the projection
|
|
78
|
+
* @param angle The rotation angle around the direction of the projection
|
|
79
|
+
*/
|
|
80
|
+
renderTexture(texture, position, normal, size, angle = 0) {
|
|
81
|
+
if (!this.texture) {
|
|
82
|
+
this._createDiffuseRTT();
|
|
83
|
+
}
|
|
84
|
+
if (MeshUVSpaceRenderer._IsRenderTargetTexture(this.texture)) {
|
|
85
|
+
const matrix = this._createProjectionMatrix(position, normal, size, angle);
|
|
86
|
+
const shader = MeshUVSpaceRenderer._GetShader(this._scene);
|
|
87
|
+
shader.setTexture("textureSampler", texture);
|
|
88
|
+
shader.setMatrix("projMatrix", matrix);
|
|
89
|
+
this.texture.render();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Clears the texture map
|
|
94
|
+
*/
|
|
95
|
+
clear() {
|
|
96
|
+
if (MeshUVSpaceRenderer._IsRenderTargetTexture(this.texture) && this.texture.renderTarget) {
|
|
97
|
+
const engine = this._scene.getEngine();
|
|
98
|
+
engine.bindFramebuffer(this.texture.renderTarget);
|
|
99
|
+
engine.clear(this.clearColor, true, true, true);
|
|
100
|
+
engine.unBindFramebuffer(this.texture.renderTarget);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Disposes of the ressources
|
|
105
|
+
*/
|
|
106
|
+
dispose() {
|
|
107
|
+
if (this._textureCreatedInternally) {
|
|
108
|
+
this.texture.dispose();
|
|
109
|
+
this._textureCreatedInternally = false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
_createDiffuseRTT() {
|
|
113
|
+
this._textureCreatedInternally = true;
|
|
114
|
+
const texture = this._createRenderTargetTexture(this._options.width, this._options.height);
|
|
115
|
+
texture.setMaterialForRendering(this._mesh, MeshUVSpaceRenderer._GetShader(this._scene));
|
|
116
|
+
this.texture = texture;
|
|
117
|
+
}
|
|
118
|
+
_createRenderTargetTexture(width, height) {
|
|
119
|
+
const rtt = new RenderTargetTexture(this._mesh.name + "_uvspaceTexture", { width, height }, this._scene, this._options.generateMipMaps, true, this._options.textureType, false, this._options.generateMipMaps ? 3 : 2, false, false, false, 5);
|
|
120
|
+
rtt.optimizeUVAllocation = !!this._options.optimizeUVAllocation;
|
|
121
|
+
rtt.onClearObservable.addOnce(() => {
|
|
122
|
+
this._scene.getEngine().clear(this.clearColor, true, true, true);
|
|
123
|
+
rtt.onClearObservable.add(() => { }); // this disables clearing the texture for the next frames
|
|
124
|
+
});
|
|
125
|
+
rtt.renderList = [this._mesh];
|
|
126
|
+
return rtt;
|
|
127
|
+
}
|
|
128
|
+
_createProjectionMatrix(position, normal, size, angle = 0) {
|
|
129
|
+
const yaw = -Math.atan2(normal.z, normal.x) - Math.PI / 2;
|
|
130
|
+
const len = Math.sqrt(normal.x * normal.x + normal.z * normal.z);
|
|
131
|
+
const pitch = Math.atan2(normal.y, len);
|
|
132
|
+
const p = position.add(normal.scale(size.z * 0.5));
|
|
133
|
+
const projWorldMatrix = Matrix.RotationYawPitchRoll(yaw, pitch, angle).multiply(Matrix.Translation(p.x, p.y, p.z));
|
|
134
|
+
const inverseProjWorldMatrix = Matrix.Invert(projWorldMatrix);
|
|
135
|
+
const projMatrix = Matrix.FromArray([2 / size.x, 0, 0, 0, 0, 2 / size.y, 0, 0, 0, 0, 1 / size.z, 0, 0, 0, 0, 1]);
|
|
136
|
+
const screenMatrix = Matrix.FromArray([0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1, 0, 0.5, 0.5, 0.0, 1]);
|
|
137
|
+
return inverseProjWorldMatrix.multiply(projMatrix).multiply(screenMatrix);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
MeshUVSpaceRenderer._Shader = null;
|
|
141
|
+
//# sourceMappingURL=meshUVSpaceRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meshUVSpaceRenderer.js","sourceRoot":"","sources":["../../../../lts/core/generated/Meshes/meshUVSpaceRenderer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,gCAA+B;AAChD,OAAO,EAAE,SAAS,EAAE,gCAA+B;AACnD,OAAO,EAAE,cAAc,EAA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IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QAEnD,MAAM,eAAe,GAAG,MAAM,CAAC,oBAAoB,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnH,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;QAE9D,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAEjH,MAAM,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAElG,OAAO,sBAAsB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC9E,CAAC;;AAxLc,2BAAO,GAA6B,IAAI,CAAC","sourcesContent":["import type { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Vector3 } from \"core/Maths/math.vector\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { AbstractMesh } from \"./abstractMesh\";\r\nimport type { ThinTexture } from \"core/Materials/Textures/thinTexture\";\r\nimport type { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { ShaderMaterial } from \"core/Materials/shaderMaterial\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport { Color4 } from \"core/Maths/math.color\";\r\n\r\nimport \"../Shaders/meshUVSpaceRenderer.vertex\";\r\nimport \"../Shaders/meshUVSpaceRenderer.fragment\";\r\n\r\n/**\r\n * Options for the MeshUVSpaceRenderer\r\n * @since 5.49.1\r\n */\r\nexport interface IMeshUVSpaceRendererOptions {\r\n /**\r\n * Width of the texture. Default: 1024\r\n */\r\n width?: number;\r\n /**\r\n * Height of the texture. Default: 1024\r\n */\r\n height?: number;\r\n /**\r\n * Type of the texture. Default: Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n */\r\n textureType?: number;\r\n /**\r\n * Generate mip maps. Default: true\r\n */\r\n generateMipMaps?: boolean;\r\n /**\r\n * Optimize UV allocation. Default: true\r\n * If you plan to use the texture as a decal map and rotate / offset the texture, you should set this to false\r\n */\r\n optimizeUVAllocation?: boolean;\r\n}\r\n\r\n/**\r\n * Class used to render in the mesh UV space\r\n * @since 5.49.1\r\n */\r\nexport class MeshUVSpaceRenderer {\r\n private static _Shader: Nullable<ShaderMaterial> = null;\r\n\r\n private _mesh: AbstractMesh;\r\n private _scene: Scene;\r\n private _options: Required<IMeshUVSpaceRendererOptions>;\r\n private _textureCreatedInternally = false;\r\n\r\n private static _GetShader(scene: Scene): ShaderMaterial {\r\n if (!MeshUVSpaceRenderer._Shader) {\r\n const shader = new ShaderMaterial(\r\n \"meshUVSpaceRendererShader\",\r\n scene,\r\n {\r\n vertex: \"meshUVSpaceRenderer\",\r\n fragment: \"meshUVSpaceRenderer\",\r\n },\r\n {\r\n attributes: [\"position\", \"normal\", \"uv\"],\r\n uniforms: [\"world\", \"worldView\", \"worldViewProjection\", \"view\", \"projection\"],\r\n needAlphaBlending: true,\r\n }\r\n );\r\n shader.backFaceCulling = false;\r\n shader.alphaMode = Constants.ALPHA_COMBINE;\r\n\r\n MeshUVSpaceRenderer._Shader = shader;\r\n }\r\n\r\n return MeshUVSpaceRenderer._Shader;\r\n }\r\n\r\n private static _IsRenderTargetTexture(texture: ThinTexture | RenderTargetTexture): texture is RenderTargetTexture {\r\n return (texture as RenderTargetTexture).renderList !== undefined;\r\n }\r\n\r\n /**\r\n * Disposes of the global resources created by the MeshUVSpaceRenderer class\r\n */\r\n public static Dispose(): void {\r\n if (MeshUVSpaceRenderer._Shader) {\r\n MeshUVSpaceRenderer._Shader.dispose();\r\n MeshUVSpaceRenderer._Shader = null;\r\n }\r\n }\r\n\r\n /**\r\n * Clear color of the texture\r\n */\r\n public clearColor = new Color4(0, 0, 0, 0);\r\n\r\n /**\r\n * Target texture used for rendering\r\n * If you don't set the property, a RenderTargetTexture will be created internally given the options provided to the constructor.\r\n * If you provide a RenderTargetTexture, it will be used directly.\r\n */\r\n public texture: Texture;\r\n\r\n /**\r\n * Creates a new MeshUVSpaceRenderer\r\n * @param mesh The mesh used for the source UV space\r\n * @param scene The scene the mesh belongs to\r\n * @param options The options to use when creating the texture\r\n */\r\n constructor(mesh: AbstractMesh, scene: Scene, options?: IMeshUVSpaceRendererOptions) {\r\n this._mesh = mesh;\r\n this._scene = scene;\r\n this._options = {\r\n width: 1024,\r\n height: 1024,\r\n textureType: Constants.TEXTURETYPE_UNSIGNED_BYTE,\r\n generateMipMaps: true,\r\n optimizeUVAllocation: true,\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Checks if the texture is ready to be used\r\n * @returns true if the texture is ready to be used\r\n */\r\n public isReady(): boolean {\r\n return MeshUVSpaceRenderer._GetShader(this._scene).isReady() && (this.texture?.isReady() ?? true);\r\n }\r\n\r\n /**\r\n * Projects and renders a texture in the mesh UV space\r\n * @param texture The texture\r\n * @param position The position of the center of projection (world space coordinates)\r\n * @param normal The direction of the projection (world space coordinates)\r\n * @param size The size of the projection\r\n * @param angle The rotation angle around the direction of the projection\r\n */\r\n public renderTexture(texture: BaseTexture, position: Vector3, normal: Vector3, size: Vector3, angle = 0): void {\r\n if (!this.texture) {\r\n this._createDiffuseRTT();\r\n }\r\n\r\n if (MeshUVSpaceRenderer._IsRenderTargetTexture(this.texture)) {\r\n const matrix = this._createProjectionMatrix(position, normal, size, angle);\r\n const shader = MeshUVSpaceRenderer._GetShader(this._scene);\r\n\r\n shader.setTexture(\"textureSampler\", texture);\r\n shader.setMatrix(\"projMatrix\", matrix);\r\n\r\n this.texture.render();\r\n }\r\n }\r\n\r\n /**\r\n * Clears the texture map\r\n */\r\n public clear(): void {\r\n if (MeshUVSpaceRenderer._IsRenderTargetTexture(this.texture) && this.texture.renderTarget) {\r\n const engine = this._scene.getEngine();\r\n\r\n engine.bindFramebuffer(this.texture.renderTarget);\r\n engine.clear(this.clearColor, true, true, true);\r\n engine.unBindFramebuffer(this.texture.renderTarget);\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the ressources\r\n */\r\n public dispose() {\r\n if (this._textureCreatedInternally) {\r\n this.texture.dispose();\r\n this._textureCreatedInternally = false;\r\n }\r\n }\r\n\r\n private _createDiffuseRTT(): void {\r\n this._textureCreatedInternally = true;\r\n\r\n const texture = this._createRenderTargetTexture(this._options.width, this._options.height);\r\n\r\n texture.setMaterialForRendering(this._mesh, MeshUVSpaceRenderer._GetShader(this._scene));\r\n\r\n this.texture = texture;\r\n }\r\n\r\n private _createRenderTargetTexture(width: number, height: number): RenderTargetTexture {\r\n const rtt = new RenderTargetTexture(\r\n this._mesh.name + \"_uvspaceTexture\",\r\n { width, height },\r\n this._scene,\r\n this._options.generateMipMaps,\r\n true,\r\n this._options.textureType,\r\n false,\r\n this._options.generateMipMaps ? Constants.TEXTURE_TRILINEAR_SAMPLINGMODE : Constants.TEXTURE_BILINEAR_SAMPLINGMODE,\r\n false,\r\n false,\r\n false,\r\n Constants.TEXTUREFORMAT_RGBA\r\n );\r\n\r\n rtt.optimizeUVAllocation = !!this._options.optimizeUVAllocation;\r\n\r\n rtt.onClearObservable.addOnce(() => {\r\n this._scene.getEngine().clear(this.clearColor, true, true, true);\r\n rtt.onClearObservable.add(() => {}); // this disables clearing the texture for the next frames\r\n });\r\n\r\n rtt.renderList = [this._mesh];\r\n\r\n return rtt;\r\n }\r\n\r\n private _createProjectionMatrix(position: Vector3, normal: Vector3, size: Vector3, angle = 0): Matrix {\r\n const yaw = -Math.atan2(normal.z, normal.x) - Math.PI / 2;\r\n const len = Math.sqrt(normal.x * normal.x + normal.z * normal.z);\r\n const pitch = Math.atan2(normal.y, len);\r\n\r\n const p = position.add(normal.scale(size.z * 0.5));\r\n\r\n const projWorldMatrix = Matrix.RotationYawPitchRoll(yaw, pitch, angle).multiply(Matrix.Translation(p.x, p.y, p.z));\r\n const inverseProjWorldMatrix = Matrix.Invert(projWorldMatrix);\r\n\r\n const projMatrix = Matrix.FromArray([2 / size.x, 0, 0, 0, 0, 2 / size.y, 0, 0, 0, 0, 1 / size.z, 0, 0, 0, 0, 1]);\r\n\r\n const screenMatrix = Matrix.FromArray([0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 1, 0, 0.5, 0.5, 0.0, 1]);\r\n\r\n return inverseProjWorldMatrix.multiply(projMatrix).multiply(screenMatrix);\r\n }\r\n}\r\n"]}
|
|
@@ -1205,7 +1205,7 @@ export class GPUParticleSystem extends BaseParticleSystem {
|
|
|
1205
1205
|
}
|
|
1206
1206
|
/** @internal */
|
|
1207
1207
|
_update(emitterWM) {
|
|
1208
|
-
if (!this.emitter) {
|
|
1208
|
+
if (!this.emitter || !this._targetBuffer) {
|
|
1209
1209
|
return;
|
|
1210
1210
|
}
|
|
1211
1211
|
if (!this._recreateUpdateEffect()) {
|