@onerjs/core 8.35.8 → 8.36.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.
- package/Cameras/geospatialCamera.d.ts +2 -0
- package/Cameras/geospatialCamera.js +10 -3
- package/Cameras/geospatialCamera.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js +6 -3
- package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js.map +1 -1
- package/Maths/math.path.js +9 -3
- package/Maths/math.path.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +3 -0
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Particles/Node/Blocks/particleSourceTextureBlock.d.ts +4 -0
- package/Particles/Node/Blocks/particleSourceTextureBlock.js +9 -3
- package/Particles/Node/Blocks/particleSourceTextureBlock.js.map +1 -1
- package/ShadersWGSL/iblVoxelGrid.vertex.js +2 -2
- package/ShadersWGSL/iblVoxelGrid.vertex.js.map +1 -1
- package/XR/features/WebXRHandTracking.d.ts +2 -1
- package/XR/features/WebXRHandTracking.js +59 -35
- package/XR/features/WebXRHandTracking.js.map +1 -1
- package/package.json +1 -1
|
@@ -23,6 +23,10 @@ export declare class ParticleTextureSourceBlock extends NodeParticleBlock {
|
|
|
23
23
|
private _sourceTexture;
|
|
24
24
|
private _cachedData;
|
|
25
25
|
private _clonedTextures;
|
|
26
|
+
/**
|
|
27
|
+
* Gets or sets the strenght of the flow map effect
|
|
28
|
+
*/
|
|
29
|
+
invertY: boolean;
|
|
26
30
|
/**
|
|
27
31
|
* Indicates if the texture data should be serialized as a base64 string.
|
|
28
32
|
*/
|
|
@@ -62,6 +62,10 @@ export class ParticleTextureSourceBlock extends NodeParticleBlock {
|
|
|
62
62
|
this._sourceTexture = null;
|
|
63
63
|
this._cachedData = null;
|
|
64
64
|
this._clonedTextures = [];
|
|
65
|
+
/**
|
|
66
|
+
* Gets or sets the strenght of the flow map effect
|
|
67
|
+
*/
|
|
68
|
+
this.invertY = true;
|
|
65
69
|
/**
|
|
66
70
|
* Indicates if the texture data should be serialized as a base64 string.
|
|
67
71
|
*/
|
|
@@ -157,7 +161,7 @@ export class ParticleTextureSourceBlock extends NodeParticleBlock {
|
|
|
157
161
|
// Cross-engine: recreate texture from URL if available, preserving invertY
|
|
158
162
|
const url = this._sourceTexture.url || this._url;
|
|
159
163
|
if (url) {
|
|
160
|
-
const invertY = this._sourceTexture.invertY ??
|
|
164
|
+
const invertY = this._sourceTexture.invertY ?? this.invertY;
|
|
161
165
|
const tex = new Texture(url, state.scene, undefined, invertY);
|
|
162
166
|
this._copyTextureProperties(this._sourceTexture, tex);
|
|
163
167
|
this._clonedTextures.push(tex);
|
|
@@ -185,12 +189,12 @@ export class ParticleTextureSourceBlock extends NodeParticleBlock {
|
|
|
185
189
|
return;
|
|
186
190
|
}
|
|
187
191
|
if (this._textureDataUrl) {
|
|
188
|
-
const tex = new Texture(this._textureDataUrl, state.scene);
|
|
192
|
+
const tex = new Texture(this._textureDataUrl, state.scene, undefined, this.invertY);
|
|
189
193
|
this._clonedTextures.push(tex);
|
|
190
194
|
this.texture._storedValue = tex;
|
|
191
195
|
return;
|
|
192
196
|
}
|
|
193
|
-
const tex = new Texture(this._url, state.scene);
|
|
197
|
+
const tex = new Texture(this._url, state.scene, undefined, this.invertY);
|
|
194
198
|
this._clonedTextures.push(tex);
|
|
195
199
|
this.texture._storedValue = tex;
|
|
196
200
|
}
|
|
@@ -202,6 +206,7 @@ export class ParticleTextureSourceBlock extends NodeParticleBlock {
|
|
|
202
206
|
const serializationObject = super.serialize();
|
|
203
207
|
serializationObject.url = this.url;
|
|
204
208
|
serializationObject.serializedCachedData = this.serializedCachedData;
|
|
209
|
+
serializationObject.invertY = this.invertY;
|
|
205
210
|
if (this.serializedCachedData) {
|
|
206
211
|
serializationObject.textureDataUrl = this.textureDataUrl;
|
|
207
212
|
}
|
|
@@ -215,6 +220,7 @@ export class ParticleTextureSourceBlock extends NodeParticleBlock {
|
|
|
215
220
|
super._deserialize(serializationObject);
|
|
216
221
|
this.url = serializationObject.url;
|
|
217
222
|
this.serializedCachedData = !!serializationObject.serializedCachedData;
|
|
223
|
+
this.invertY = !!serializationObject.invertY;
|
|
218
224
|
if (serializationObject.textureDataUrl) {
|
|
219
225
|
this.textureDataUrl = serializationObject.textureDataUrl;
|
|
220
226
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"particleSourceTextureBlock.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Particles/Node/Blocks/particleSourceTextureBlock.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,+CAAwC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,qCAAqC,EAAE,MAAM,gDAAgD,CAAC;AACvG,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,sCAA+B;AActD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,iBAAiB;IAY7D;;OAEG;IACH,IAAW,GAAG;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,IAAW,GAAG,CAAC,KAAa;QACxB,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACtB,OAAO;QACX,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED,IAAW,cAAc,CAAC,KAAa;QACnC,IAAI,IAAI,CAAC,eAAe,KAAK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AAM,CAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAClD,MAAM,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAChD,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC5B,MAAM,CAAC,yBAAyB,GAAG,MAAM,CAAC,yBAAyB,CAAC;QAEpE,8DAA8D;QAC9D,MAAM,aAAa,GAAG,MAAiB,CAAC;QACxC,MAAM,aAAa,GAAG,MAAiB,CAAC;QACxC,IAAI,aAAa,CAAC,OAAO,KAAK,SAAS,IAAI,aAAa,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAC7E,aAAa,CAAC,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC;YAC9C,aAAa,CAAC,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC;YAC9C,aAAa,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;YAC5C,aAAa,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;YAC5C,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;YACxC,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;YACxC,aAAa,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;QAC5C,CAAC;IACL,CAAC;CACJ;AAED,aAAa,CAAC,oCAAoC,EAAE,0BAA0B,CAAC,CAAC","sourcesContent":["import type { NodeParticleConnectionPoint } from \"../nodeParticleBlockConnectionPoint\";\r\nimport type { NodeParticleBuildState } from \"../nodeParticleBuildState\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { BaseTexture } from \"../../../Materials/Textures/baseTexture\";\r\nimport type { ProceduralTexture } from \"../../../Materials\";\r\n\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { NodeParticleBlockConnectionPointTypes } from \"../Enums/nodeParticleBlockConnectionPointTypes\";\r\nimport { NodeParticleBlock } from \"../nodeParticleBlock\";\r\nimport { TextureTools } from \"core/Misc/textureTools\";\r\n\r\n/**\r\n * Interface used to define texture data\r\n */\r\nexport interface INodeParticleTextureData {\r\n /** Width of the texture in pixels */\r\n width: number;\r\n /** Height of the texture in pixels */\r\n height: number;\r\n /** RGBA pixel data */\r\n data: Uint8ClampedArray;\r\n}\r\n\r\n/**\r\n * Block used to provide a texture for particles in a particle system\r\n */\r\nexport class ParticleTextureSourceBlock extends NodeParticleBlock {\r\n private _url: string = \"\";\r\n private _textureDataUrl: string = \"\";\r\n private _sourceTexture: Nullable<BaseTexture> = null;\r\n private _cachedData: Nullable<INodeParticleTextureData> = null;\r\n private _clonedTextures: BaseTexture[] = [];\r\n\r\n /**\r\n * Indicates if the texture data should be serialized as a base64 string.\r\n */\r\n public serializedCachedData: boolean = false;\r\n\r\n /**\r\n * Gets or sets the URL of the texture to be used by this block.\r\n */\r\n public get url(): string {\r\n return this._url;\r\n }\r\n\r\n public set url(value: string) {\r\n if (this._url === value) {\r\n return;\r\n }\r\n this._cachedData = null;\r\n this._url = value;\r\n this._textureDataUrl = \"\";\r\n this._sourceTexture = null;\r\n }\r\n\r\n /**\r\n * Gets or sets the data URL of the texture to be used by this block.\r\n * This is a base64 encoded string representing the texture data.\r\n */\r\n public get textureDataUrl(): string {\r\n return this._textureDataUrl;\r\n }\r\n\r\n public set textureDataUrl(value: string) {\r\n if (this._textureDataUrl === value) {\r\n return;\r\n }\r\n\r\n this._cachedData = null;\r\n this._textureDataUrl = value;\r\n this._url = \"\";\r\n this._sourceTexture = null;\r\n }\r\n\r\n /**\r\n * Directly sets the texture to be used by this block.\r\n * This value will not be serialized.\r\n */\r\n public set sourceTexture(value: Nullable<BaseTexture>) {\r\n if (this._sourceTexture === value) {\r\n return;\r\n }\r\n this._cachedData = null;\r\n this._sourceTexture = value;\r\n this._url = (value as Texture).url || \"\";\r\n this._textureDataUrl = \"\";\r\n }\r\n\r\n /**\r\n * Create a new ParticleTextureSourceBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerOutput(\"texture\", NodeParticleBlockConnectionPointTypes.Texture);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public override getClassName() {\r\n return \"ParticleTextureSourceBlock\";\r\n }\r\n\r\n /**\r\n * Gets the texture output component\r\n */\r\n public get texture(): NodeParticleConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the texture content as a promise\r\n * @returns a promise that resolves to the texture content, including width, height, and pixel data\r\n */\r\n async extractTextureContentAsync() {\r\n if (!this.texture._storedValue && !this._sourceTexture) {\r\n return null;\r\n }\r\n\r\n if (this._cachedData) {\r\n return this._cachedData;\r\n }\r\n\r\n const texture = this.texture._storedValue || this._sourceTexture;\r\n return await new Promise<\r\n Nullable<{\r\n width: number;\r\n height: number;\r\n data: Uint8ClampedArray;\r\n }>\r\n >((resolve, reject) => {\r\n if (!texture.isReady()) {\r\n texture.onLoadObservable.addOnce(async () => {\r\n try {\r\n this._cachedData = await this.extractTextureContentAsync();\r\n resolve(this._cachedData);\r\n } catch (e) {\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(e);\r\n }\r\n });\r\n return;\r\n }\r\n const size = texture.getSize();\r\n if (texture.getContent) {\r\n const proceduralTexture = texture as ProceduralTexture;\r\n proceduralTexture\r\n .getContent()\r\n // eslint-disable-next-line github/no-then\r\n ?.then((data) => {\r\n this._cachedData = {\r\n width: size.width,\r\n height: size.height,\r\n data: data as Uint8ClampedArray,\r\n };\r\n resolve(this._cachedData);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch(reject);\r\n } else {\r\n TextureTools.GetTextureDataAsync(texture, size.width, size.height)\r\n // eslint-disable-next-line github/no-then\r\n .then((data) => {\r\n this._cachedData = {\r\n width: size.width,\r\n height: size.height,\r\n data: new Uint8ClampedArray(data),\r\n };\r\n texture.dispose();\r\n resolve(this._cachedData);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch(reject);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Builds the block\r\n * @param state defines the current build state\r\n */\r\n public override _build(state: NodeParticleBuildState) {\r\n if (this._sourceTexture) {\r\n // The same NodeParticleSystemSet can be built into multiple scenes/engines\r\n // (original system scene, editor preview scene).\r\n // Textures are engine-specific, so we need to handle cross-engine cases.\r\n const sourceScene = this._sourceTexture.getScene?.();\r\n const sourceEngine = sourceScene?.getEngine?.();\r\n const targetEngine = state.scene.getEngine();\r\n\r\n if (sourceEngine && sourceEngine !== targetEngine) {\r\n // Cross-engine: recreate texture from URL if available, preserving invertY\r\n const url = (this._sourceTexture as Texture).url || this._url;\r\n if (url) {\r\n const invertY = (this._sourceTexture as Texture).invertY ?? true;\r\n const tex = new Texture(url, state.scene, undefined, invertY);\r\n this._copyTextureProperties(this._sourceTexture, tex);\r\n this._clonedTextures.push(tex);\r\n this.texture._storedValue = tex;\r\n return;\r\n }\r\n // No URL available - use the source texture directly as fallback\r\n // This may not render correctly but avoids breaking completely\r\n this.texture._storedValue = this._sourceTexture;\r\n return;\r\n }\r\n\r\n // Same engine: clone works correctly and preserves all properties\r\n const cloned = this._sourceTexture.clone();\r\n if (cloned) {\r\n this._clonedTextures.push(cloned);\r\n this.texture._storedValue = cloned;\r\n } else {\r\n this.texture._storedValue = this._sourceTexture;\r\n }\r\n return;\r\n }\r\n\r\n if (!this._textureDataUrl && !this._url) {\r\n this.texture._storedValue = null;\r\n return;\r\n }\r\n\r\n if (this._textureDataUrl) {\r\n const tex = new Texture(this._textureDataUrl, state.scene);\r\n this._clonedTextures.push(tex);\r\n this.texture._storedValue = tex;\r\n return;\r\n }\r\n\r\n const tex = new Texture(this._url, state.scene);\r\n this._clonedTextures.push(tex);\r\n this.texture._storedValue = tex;\r\n }\r\n\r\n /**\r\n * Serializes this block\r\n * @returns the serialization object\r\n */\r\n public override serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.url = this.url;\r\n serializationObject.serializedCachedData = this.serializedCachedData;\r\n\r\n if (this.serializedCachedData) {\r\n serializationObject.textureDataUrl = this.textureDataUrl;\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Deserializes this block from a serialization object\r\n * @param serializationObject the serialization object\r\n */\r\n public override _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.url = serializationObject.url;\r\n this.serializedCachedData = !!serializationObject.serializedCachedData;\r\n\r\n if (serializationObject.textureDataUrl) {\r\n this.textureDataUrl = serializationObject.textureDataUrl;\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the block and its associated resources\r\n */\r\n public override dispose(): void {\r\n // Dispose all cloned textures we created\r\n for (const tex of this._clonedTextures) {\r\n tex.dispose();\r\n }\r\n this._clonedTextures = [];\r\n this.texture._storedValue = null;\r\n // Never dispose _sourceTexture - it's owned by the caller\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Copies texture properties from source to target texture\r\n * @param source - The source texture to copy properties from\r\n * @param target - The target texture to copy properties to\r\n */\r\n private _copyTextureProperties(source: BaseTexture, target: BaseTexture): void {\r\n // BaseTexture properties\r\n target.hasAlpha = source.hasAlpha;\r\n target.level = source.level;\r\n target.coordinatesIndex = source.coordinatesIndex;\r\n target.coordinatesMode = source.coordinatesMode;\r\n target.wrapU = source.wrapU;\r\n target.wrapV = source.wrapV;\r\n target.wrapR = source.wrapR;\r\n target.anisotropicFilteringLevel = source.anisotropicFilteringLevel;\r\n\r\n // Texture-specific properties (if both are Texture instances)\r\n const sourceTexture = source as Texture;\r\n const targetTexture = target as Texture;\r\n if (sourceTexture.uOffset !== undefined && targetTexture.uOffset !== undefined) {\r\n targetTexture.uOffset = sourceTexture.uOffset;\r\n targetTexture.vOffset = sourceTexture.vOffset;\r\n targetTexture.uScale = sourceTexture.uScale;\r\n targetTexture.vScale = sourceTexture.vScale;\r\n targetTexture.uAng = sourceTexture.uAng;\r\n targetTexture.vAng = sourceTexture.vAng;\r\n targetTexture.wAng = sourceTexture.wAng;\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ParticleTextureSourceBlock\", ParticleTextureSourceBlock);\r\n"]}
|
|
1
|
+
{"version":3,"file":"particleSourceTextureBlock.js","sourceRoot":"","sources":["../../../../../../dev/core/src/Particles/Node/Blocks/particleSourceTextureBlock.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,+CAAwC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,qCAAqC,EAAE,MAAM,gDAAgD,CAAC;AACvG,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,sCAA+B;AActD;;GAEG;AACH,MAAM,OAAO,0BAA2B,SAAQ,iBAAiB;IAiB7D;;OAEG;IACH,IAAW,GAAG;QACV,OAAO,IAAI,CAAC,IAAI,CAAC;IACrB,CAAC;IAED,IAAW,GAAG,CAAC,KAAa;QACxB,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACtB,OAAO;QACX,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED,IAAW,cAAc,CAAC,KAAa;QACnC,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;YACjC,OAAO;QACX,CAAC;QAED,IAAI,CAA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Point } from \"../nodeParticleBlockConnectionPoint\";\r\nimport type { NodeParticleBuildState } from \"../nodeParticleBuildState\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { BaseTexture } from \"../../../Materials/Textures/baseTexture\";\r\nimport type { ProceduralTexture } from \"../../../Materials/Textures/Procedurals/proceduralTexture\";\r\n\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { RegisterClass } from \"../../../Misc/typeStore\";\r\nimport { NodeParticleBlockConnectionPointTypes } from \"../Enums/nodeParticleBlockConnectionPointTypes\";\r\nimport { NodeParticleBlock } from \"../nodeParticleBlock\";\r\nimport { TextureTools } from \"core/Misc/textureTools\";\r\n\r\n/**\r\n * Interface used to define texture data\r\n */\r\nexport interface INodeParticleTextureData {\r\n /** Width of the texture in pixels */\r\n width: number;\r\n /** Height of the texture in pixels */\r\n height: number;\r\n /** RGBA pixel data */\r\n data: Uint8ClampedArray;\r\n}\r\n\r\n/**\r\n * Block used to provide a texture for particles in a particle system\r\n */\r\nexport class ParticleTextureSourceBlock extends NodeParticleBlock {\r\n private _url: string = \"\";\r\n private _textureDataUrl: string = \"\";\r\n private _sourceTexture: Nullable<BaseTexture> = null;\r\n private _cachedData: Nullable<INodeParticleTextureData> = null;\r\n private _clonedTextures: BaseTexture[] = [];\r\n\r\n /**\r\n * Gets or sets the strenght of the flow map effect\r\n */\r\n public invertY = true;\r\n\r\n /**\r\n * Indicates if the texture data should be serialized as a base64 string.\r\n */\r\n public serializedCachedData: boolean = false;\r\n\r\n /**\r\n * Gets or sets the URL of the texture to be used by this block.\r\n */\r\n public get url(): string {\r\n return this._url;\r\n }\r\n\r\n public set url(value: string) {\r\n if (this._url === value) {\r\n return;\r\n }\r\n this._cachedData = null;\r\n this._url = value;\r\n this._textureDataUrl = \"\";\r\n this._sourceTexture = null;\r\n }\r\n\r\n /**\r\n * Gets or sets the data URL of the texture to be used by this block.\r\n * This is a base64 encoded string representing the texture data.\r\n */\r\n public get textureDataUrl(): string {\r\n return this._textureDataUrl;\r\n }\r\n\r\n public set textureDataUrl(value: string) {\r\n if (this._textureDataUrl === value) {\r\n return;\r\n }\r\n\r\n this._cachedData = null;\r\n this._textureDataUrl = value;\r\n this._url = \"\";\r\n this._sourceTexture = null;\r\n }\r\n\r\n /**\r\n * Directly sets the texture to be used by this block.\r\n * This value will not be serialized.\r\n */\r\n public set sourceTexture(value: Nullable<BaseTexture>) {\r\n if (this._sourceTexture === value) {\r\n return;\r\n }\r\n this._cachedData = null;\r\n this._sourceTexture = value;\r\n this._url = (value as Texture).url || \"\";\r\n this._textureDataUrl = \"\";\r\n }\r\n\r\n /**\r\n * Create a new ParticleTextureSourceBlock\r\n * @param name defines the block name\r\n */\r\n public constructor(name: string) {\r\n super(name);\r\n\r\n this.registerOutput(\"texture\", NodeParticleBlockConnectionPointTypes.Texture);\r\n }\r\n\r\n /**\r\n * Gets the current class name\r\n * @returns the class name\r\n */\r\n public override getClassName() {\r\n return \"ParticleTextureSourceBlock\";\r\n }\r\n\r\n /**\r\n * Gets the texture output component\r\n */\r\n public get texture(): NodeParticleConnectionPoint {\r\n return this._outputs[0];\r\n }\r\n\r\n /**\r\n * Gets the texture content as a promise\r\n * @returns a promise that resolves to the texture content, including width, height, and pixel data\r\n */\r\n async extractTextureContentAsync() {\r\n if (!this.texture._storedValue && !this._sourceTexture) {\r\n return null;\r\n }\r\n\r\n if (this._cachedData) {\r\n return this._cachedData;\r\n }\r\n\r\n const texture = this.texture._storedValue || this._sourceTexture;\r\n return await new Promise<\r\n Nullable<{\r\n width: number;\r\n height: number;\r\n data: Uint8ClampedArray;\r\n }>\r\n >((resolve, reject) => {\r\n if (!texture.isReady()) {\r\n texture.onLoadObservable.addOnce(async () => {\r\n try {\r\n this._cachedData = await this.extractTextureContentAsync();\r\n resolve(this._cachedData);\r\n } catch (e) {\r\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\r\n reject(e);\r\n }\r\n });\r\n return;\r\n }\r\n const size = texture.getSize();\r\n if (texture.getContent) {\r\n const proceduralTexture = texture as ProceduralTexture;\r\n proceduralTexture\r\n .getContent()\r\n // eslint-disable-next-line github/no-then\r\n ?.then((data) => {\r\n this._cachedData = {\r\n width: size.width,\r\n height: size.height,\r\n data: data as Uint8ClampedArray,\r\n };\r\n resolve(this._cachedData);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch(reject);\r\n } else {\r\n TextureTools.GetTextureDataAsync(texture, size.width, size.height)\r\n // eslint-disable-next-line github/no-then\r\n .then((data) => {\r\n this._cachedData = {\r\n width: size.width,\r\n height: size.height,\r\n data: new Uint8ClampedArray(data),\r\n };\r\n texture.dispose();\r\n resolve(this._cachedData);\r\n })\r\n // eslint-disable-next-line github/no-then\r\n .catch(reject);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Builds the block\r\n * @param state defines the current build state\r\n */\r\n public override _build(state: NodeParticleBuildState) {\r\n if (this._sourceTexture) {\r\n // The same NodeParticleSystemSet can be built into multiple scenes/engines\r\n // (original system scene, editor preview scene).\r\n // Textures are engine-specific, so we need to handle cross-engine cases.\r\n const sourceScene = this._sourceTexture.getScene?.();\r\n const sourceEngine = sourceScene?.getEngine?.();\r\n const targetEngine = state.scene.getEngine();\r\n\r\n if (sourceEngine && sourceEngine !== targetEngine) {\r\n // Cross-engine: recreate texture from URL if available, preserving invertY\r\n const url = (this._sourceTexture as Texture).url || this._url;\r\n if (url) {\r\n const invertY = (this._sourceTexture as Texture).invertY ?? this.invertY;\r\n const tex = new Texture(url, state.scene, undefined, invertY);\r\n this._copyTextureProperties(this._sourceTexture, tex);\r\n this._clonedTextures.push(tex);\r\n this.texture._storedValue = tex;\r\n return;\r\n }\r\n // No URL available - use the source texture directly as fallback\r\n // This may not render correctly but avoids breaking completely\r\n this.texture._storedValue = this._sourceTexture;\r\n return;\r\n }\r\n\r\n // Same engine: clone works correctly and preserves all properties\r\n const cloned = this._sourceTexture.clone();\r\n if (cloned) {\r\n this._clonedTextures.push(cloned);\r\n this.texture._storedValue = cloned;\r\n } else {\r\n this.texture._storedValue = this._sourceTexture;\r\n }\r\n return;\r\n }\r\n\r\n if (!this._textureDataUrl && !this._url) {\r\n this.texture._storedValue = null;\r\n return;\r\n }\r\n\r\n if (this._textureDataUrl) {\r\n const tex = new Texture(this._textureDataUrl, state.scene, undefined, this.invertY);\r\n this._clonedTextures.push(tex);\r\n this.texture._storedValue = tex;\r\n return;\r\n }\r\n\r\n const tex = new Texture(this._url, state.scene, undefined, this.invertY);\r\n this._clonedTextures.push(tex);\r\n this.texture._storedValue = tex;\r\n }\r\n\r\n /**\r\n * Serializes this block\r\n * @returns the serialization object\r\n */\r\n public override serialize(): any {\r\n const serializationObject = super.serialize();\r\n\r\n serializationObject.url = this.url;\r\n serializationObject.serializedCachedData = this.serializedCachedData;\r\n serializationObject.invertY = this.invertY;\r\n\r\n if (this.serializedCachedData) {\r\n serializationObject.textureDataUrl = this.textureDataUrl;\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Deserializes this block from a serialization object\r\n * @param serializationObject the serialization object\r\n */\r\n public override _deserialize(serializationObject: any) {\r\n super._deserialize(serializationObject);\r\n\r\n this.url = serializationObject.url;\r\n this.serializedCachedData = !!serializationObject.serializedCachedData;\r\n this.invertY = !!serializationObject.invertY;\r\n\r\n if (serializationObject.textureDataUrl) {\r\n this.textureDataUrl = serializationObject.textureDataUrl;\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the block and its associated resources\r\n */\r\n public override dispose(): void {\r\n // Dispose all cloned textures we created\r\n for (const tex of this._clonedTextures) {\r\n tex.dispose();\r\n }\r\n this._clonedTextures = [];\r\n this.texture._storedValue = null;\r\n // Never dispose _sourceTexture - it's owned by the caller\r\n super.dispose();\r\n }\r\n\r\n /**\r\n * Copies texture properties from source to target texture\r\n * @param source - The source texture to copy properties from\r\n * @param target - The target texture to copy properties to\r\n */\r\n private _copyTextureProperties(source: BaseTexture, target: BaseTexture): void {\r\n // BaseTexture properties\r\n target.hasAlpha = source.hasAlpha;\r\n target.level = source.level;\r\n target.coordinatesIndex = source.coordinatesIndex;\r\n target.coordinatesMode = source.coordinatesMode;\r\n target.wrapU = source.wrapU;\r\n target.wrapV = source.wrapV;\r\n target.wrapR = source.wrapR;\r\n target.anisotropicFilteringLevel = source.anisotropicFilteringLevel;\r\n\r\n // Texture-specific properties (if both are Texture instances)\r\n const sourceTexture = source as Texture;\r\n const targetTexture = target as Texture;\r\n if (sourceTexture.uOffset !== undefined && targetTexture.uOffset !== undefined) {\r\n targetTexture.uOffset = sourceTexture.uOffset;\r\n targetTexture.vOffset = sourceTexture.vOffset;\r\n targetTexture.uScale = sourceTexture.uScale;\r\n targetTexture.vScale = sourceTexture.vScale;\r\n targetTexture.uAng = sourceTexture.uAng;\r\n targetTexture.vAng = sourceTexture.vAng;\r\n targetTexture.wAng = sourceTexture.wAng;\r\n }\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ParticleTextureSourceBlock\", ParticleTextureSourceBlock);\r\n"]}
|
|
@@ -57,7 +57,7 @@ readMatrixWeightValue(offset+componentSize*2u,dataType),
|
|
|
57
57
|
readMatrixWeightValue(offset+componentSize*3u,dataType)
|
|
58
58
|
);}
|
|
59
59
|
#if NUM_BONE_INFLUENCERS>4
|
|
60
|
-
fn readMatrixIndexExtraValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=
|
|
60
|
+
fn readMatrixIndexExtraValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word : u32=matricesIndicesExtra[wordOffset];return convertToFloat(word,byteInWord,dataType);}
|
|
61
61
|
fn readMatrixIndicesExtra(info: vec3f,vertexIndex : u32)->vec4f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec4f(
|
|
62
62
|
readMatrixIndexExtraValue(offset,dataType),
|
|
63
63
|
readMatrixIndexExtraValue(offset+componentSize,dataType),
|
|
@@ -65,7 +65,7 @@ readMatrixIndexExtraValue(offset+componentSize*2u,dataType),
|
|
|
65
65
|
readMatrixIndexExtraValue(offset+componentSize*3u,dataType)
|
|
66
66
|
);}
|
|
67
67
|
fn readMatrixWeightExtraValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=bitcast<u32>(matricesWeightsExtra[wordOffset]);return convertToFloat(word,byteInWord,dataType);}
|
|
68
|
-
fn
|
|
68
|
+
fn readMatrixWeightsExtra(info : vec3f,vertexIndex : u32)->vec4f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec4f(
|
|
69
69
|
readMatrixWeightExtraValue(offset,dataType),
|
|
70
70
|
readMatrixWeightExtraValue(offset+componentSize,dataType),
|
|
71
71
|
readMatrixWeightExtraValue(offset+componentSize*2u,dataType),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iblVoxelGrid.vertex.js","sourceRoot":"","sources":["../../../../dev/core/src/ShadersWGSL/iblVoxelGrid.vertex.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,sDAAsD,CAAC;AAC9D,OAAO,gDAAgD,CAAC;AACxD,OAAO,8BAA8B,CAAC;AACtC,OAAO,uCAAuC,CAAC;AAE/C,MAAM,IAAI,GAAG,0BAA0B,CAAC;AACxC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyGd,CAAC;AACF,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;IACtC,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/morphTargetsVertexGlobalDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexDeclaration\";\nimport \"./ShadersInclude/bonesVertex\";\nimport \"./ShadersInclude/bakedVertexAnimation\";\n\nconst name = \"iblVoxelGridVertexShader\";\nconst shader = `#include <bakedVertexAnimationDeclaration>\n#include <bonesDeclaration>(attribute matricesIndices : vec4f;,,attribute matricesWeights : vec4f;,,attribute matricesIndicesExtra : vec4f;,,attribute matricesWeightsExtra : vec4f;,)\n#include <helperFunctions>\n#include <instancesDeclaration>\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef VERTEX_PULLING_USE_INDEX_BUFFER\nvar<storage,read> indices : array<u32>;\n#endif\nvar<storage,read> position : array<f32>;\n#if NUM_BONE_INFLUENCERS>0\nvar<storage,read> matricesIndices : array<u32>;var<storage,read> matricesWeights : array<f32>;uniform vp_matricesIndices_info: vec3f;uniform vp_matricesWeights_info: vec3f;\n#if NUM_BONE_INFLUENCERS>4\nvar<storage,read> matricesIndicesExtra : array<u32>;var<storage,read> matricesWeightsExtra : array<f32>;uniform vp_matricesIndicesExtra_info: vec3f;uniform vp_matricesWeightsExtra_info: vec3f;\n#endif\n#endif\nuniform world : mat4x4f;uniform invWorldScale: mat4x4f;varying vNormalizedPosition : vec3f;flat varying f_swizzle: i32;uniform vp_position_info: vec3f; \nfn convertToFloat(word: u32,byteInWord: u32,dataType: u32)->f32 {switch (dataType) {case 5120u: { \nlet shift=byteInWord*8u;let value=(word>>shift) & 0xFFu;return f32(i32(value<<24u)>>24u)/127.0; }\ncase 5121u: { \nlet shift=byteInWord*8u;let value=(word>>shift) & 0xFFu;return f32(value)/255.0;}\ncase 5122u: { \nlet shift=(byteInWord & 0xFFFFFFFEu)*8u; \nlet value=(word>>shift) & 0xFFFFu;return f32(i32(value<<16u)>>16u);}\ncase 5123u: { \nlet shift=(byteInWord & 0xFFFFFFFEu)*8u; \nlet value=(word>>shift) & 0xFFFFu;return f32(value);}\ncase 5126u: { \nreturn bitcast<f32>(word);}\ndefault: {return 0.0;}}}\nfn readPositionValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=bitcast<u32>(position[wordOffset]);return convertToFloat(word,byteInWord,dataType);}\nfn readVertexPosition(info: vec3f,vertexIndex: u32)->vec3f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec3f(\nreadPositionValue(offset,dataType),\nreadPositionValue(offset+componentSize,dataType),\nreadPositionValue(offset+componentSize*2u,dataType)\n);}\n#if NUM_BONE_INFLUENCERS>0\nfn readMatrixIndexValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=matricesIndices[wordOffset];return convertToFloat(word,byteInWord,dataType);}\nfn readMatrixIndices(info: vec3f,vertexIndex : u32)->vec4f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec4f(\nreadMatrixIndexValue(offset,dataType),\nreadMatrixIndexValue(offset+componentSize,dataType),\nreadMatrixIndexValue(offset+componentSize*2u,dataType),\nreadMatrixIndexValue(offset+componentSize*3u,dataType)\n);}\nfn readMatrixWeightValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=bitcast<u32>(matricesWeights[wordOffset]);return convertToFloat(word,byteInWord,dataType);}\nfn readMatrixWeights(info: vec3f,vertexIndex : u32)->vec4f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec4f(\nreadMatrixWeightValue(offset,dataType),\nreadMatrixWeightValue(offset+componentSize,dataType),\nreadMatrixWeightValue(offset+componentSize*2u,dataType),\nreadMatrixWeightValue(offset+componentSize*3u,dataType)\n);}\n#if NUM_BONE_INFLUENCERS>4\nfn readMatrixIndexExtraValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=
|
|
1
|
+
{"version":3,"file":"iblVoxelGrid.vertex.js","sourceRoot":"","sources":["../../../../dev/core/src/ShadersWGSL/iblVoxelGrid.vertex.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,sDAAsD,CAAC;AAC9D,OAAO,gDAAgD,CAAC;AACxD,OAAO,8BAA8B,CAAC;AACtC,OAAO,uCAAuC,CAAC;AAE/C,MAAM,IAAI,GAAG,0BAA0B,CAAC;AACxC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyGd,CAAC;AACF,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;IACtC,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAChD,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/morphTargetsVertexGlobalDeclaration\";\nimport \"./ShadersInclude/morphTargetsVertexDeclaration\";\nimport \"./ShadersInclude/bonesVertex\";\nimport \"./ShadersInclude/bakedVertexAnimation\";\n\nconst name = \"iblVoxelGridVertexShader\";\nconst shader = `#include <bakedVertexAnimationDeclaration>\n#include <bonesDeclaration>(attribute matricesIndices : vec4f;,,attribute matricesWeights : vec4f;,,attribute matricesIndicesExtra : vec4f;,,attribute matricesWeightsExtra : vec4f;,)\n#include <helperFunctions>\n#include <instancesDeclaration>\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef VERTEX_PULLING_USE_INDEX_BUFFER\nvar<storage,read> indices : array<u32>;\n#endif\nvar<storage,read> position : array<f32>;\n#if NUM_BONE_INFLUENCERS>0\nvar<storage,read> matricesIndices : array<u32>;var<storage,read> matricesWeights : array<f32>;uniform vp_matricesIndices_info: vec3f;uniform vp_matricesWeights_info: vec3f;\n#if NUM_BONE_INFLUENCERS>4\nvar<storage,read> matricesIndicesExtra : array<u32>;var<storage,read> matricesWeightsExtra : array<f32>;uniform vp_matricesIndicesExtra_info: vec3f;uniform vp_matricesWeightsExtra_info: vec3f;\n#endif\n#endif\nuniform world : mat4x4f;uniform invWorldScale: mat4x4f;varying vNormalizedPosition : vec3f;flat varying f_swizzle: i32;uniform vp_position_info: vec3f; \nfn convertToFloat(word: u32,byteInWord: u32,dataType: u32)->f32 {switch (dataType) {case 5120u: { \nlet shift=byteInWord*8u;let value=(word>>shift) & 0xFFu;return f32(i32(value<<24u)>>24u)/127.0; }\ncase 5121u: { \nlet shift=byteInWord*8u;let value=(word>>shift) & 0xFFu;return f32(value)/255.0;}\ncase 5122u: { \nlet shift=(byteInWord & 0xFFFFFFFEu)*8u; \nlet value=(word>>shift) & 0xFFFFu;return f32(i32(value<<16u)>>16u);}\ncase 5123u: { \nlet shift=(byteInWord & 0xFFFFFFFEu)*8u; \nlet value=(word>>shift) & 0xFFFFu;return f32(value);}\ncase 5126u: { \nreturn bitcast<f32>(word);}\ndefault: {return 0.0;}}}\nfn readPositionValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=bitcast<u32>(position[wordOffset]);return convertToFloat(word,byteInWord,dataType);}\nfn readVertexPosition(info: vec3f,vertexIndex: u32)->vec3f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec3f(\nreadPositionValue(offset,dataType),\nreadPositionValue(offset+componentSize,dataType),\nreadPositionValue(offset+componentSize*2u,dataType)\n);}\n#if NUM_BONE_INFLUENCERS>0\nfn readMatrixIndexValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=matricesIndices[wordOffset];return convertToFloat(word,byteInWord,dataType);}\nfn readMatrixIndices(info: vec3f,vertexIndex : u32)->vec4f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec4f(\nreadMatrixIndexValue(offset,dataType),\nreadMatrixIndexValue(offset+componentSize,dataType),\nreadMatrixIndexValue(offset+componentSize*2u,dataType),\nreadMatrixIndexValue(offset+componentSize*3u,dataType)\n);}\nfn readMatrixWeightValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=bitcast<u32>(matricesWeights[wordOffset]);return convertToFloat(word,byteInWord,dataType);}\nfn readMatrixWeights(info: vec3f,vertexIndex : u32)->vec4f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec4f(\nreadMatrixWeightValue(offset,dataType),\nreadMatrixWeightValue(offset+componentSize,dataType),\nreadMatrixWeightValue(offset+componentSize*2u,dataType),\nreadMatrixWeightValue(offset+componentSize*3u,dataType)\n);}\n#if NUM_BONE_INFLUENCERS>4\nfn readMatrixIndexExtraValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word : u32=matricesIndicesExtra[wordOffset];return convertToFloat(word,byteInWord,dataType);}\nfn readMatrixIndicesExtra(info: vec3f,vertexIndex : u32)->vec4f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec4f(\nreadMatrixIndexExtraValue(offset,dataType),\nreadMatrixIndexExtraValue(offset+componentSize,dataType),\nreadMatrixIndexExtraValue(offset+componentSize*2u,dataType),\nreadMatrixIndexExtraValue(offset+componentSize*3u,dataType)\n);}\nfn readMatrixWeightExtraValue(byteOffset: u32,dataType: u32)->f32 {let wordOffset=byteOffset/4u;let byteInWord=byteOffset % 4u;let word: u32=bitcast<u32>(matricesWeightsExtra[wordOffset]);return convertToFloat(word,byteInWord,dataType);}\nfn readMatrixWeightsExtra(info : vec3f,vertexIndex : u32)->vec4f {let baseOffset=u32(info.x);let stride=u32(info.y);let dataType=u32(info.z);let offset=baseOffset+vertexIndex*stride;let componentSize=select(select(2u,1u,dataType==5120u || dataType==5121u),4u,dataType==5126u);return vec4f(\nreadMatrixWeightExtraValue(offset,dataType),\nreadMatrixWeightExtraValue(offset+componentSize,dataType),\nreadMatrixWeightExtraValue(offset+componentSize*2u,dataType),\nreadMatrixWeightExtraValue(offset+componentSize*3u,dataType)\n);}\n#endif\n#endif\nfn readVertexIndex(index : u32)->u32 {\n#ifndef VERTEX_PULLING_USE_INDEX_BUFFER\nreturn index;\n#else\n#ifdef VERTEX_PULLING_INDEX_BUFFER_32BITS\nreturn indices[index];\n#else\nlet u32_index=index/2u;let bit_offset=(index & 1u)*16u;return (indices[u32_index]>>bit_offset) & 0xFFFFu;\n#endif\n#endif\n}\nfn calculateTriangleNormal(v0\n: vec3<f32>,v1\n: vec3<f32>,v2\n: vec3<f32>)\n->vec3<f32> {let edge1=v1-v0;let edge2=v2-v0;let triangleNormal=cross(edge1,edge2);let normalizedTriangleNormal=normalize(triangleNormal);return normalizedTriangleNormal;}\n@vertex\nfn main(input : VertexInputs)->FragmentInputs {\n#include <morphTargetsVertexGlobal>\nvar triPositions: array<vec3f,3>;var thisTriIndex : u32=input.vertexIndex; \nfor (var i: u32=0u; i<3u; i=i+1u) {var provokingVertNum : u32=input.vertexIndex/3*3;let vertIdx=readVertexIndex(provokingVertNum+i);if (provokingVertNum+i==input.vertexIndex) {thisTriIndex=i;}\nvar positionUpdated=readVertexPosition(uniforms.vp_position_info,vertIdx);\n#include <instancesVertex>\nlet inputPosition: vec3f=positionUpdated;\n#include <morphTargetsVertex>(vertexInputs.position\\\\),inputPosition),vertexInputs.vertexIndex,vertIdx)[0..maxSimultaneousMorphTargets]\n#if NUM_BONE_INFLUENCERS>0\nlet matrixIndex=readMatrixIndices(uniforms.vp_matricesIndices_info,vertIdx);let matrixWeight=readMatrixWeights(uniforms.vp_matricesWeights_info,vertIdx);\n#if NUM_BONE_INFLUENCERS>4\nlet matrixIndexExtra=readMatrixIndicesExtra(uniforms.vp_matricesIndicesExtra_info,vertIdx);let matrixWeightExtra=readMatrixWeightsExtra(uniforms.vp_matricesWeightsExtra_info,vertIdx);\n#endif\n#endif\n#include<bonesVertex>(vertexInputs.matricesIndices,matrixIndex,vertexInputs.matricesWeights,matrixWeight,vertexInputs.matricesIndicesExtra,matrixIndexExtra,vertexInputs.matricesWeightsExtra,matrixWeightExtra)\n#include<bakedVertexAnimation>(vertexInputs.matricesIndices,matrixIndex,vertexInputs.matricesWeights,matrixWeight,vertexInputs.matricesIndicesExtra,matrixIndexExtra,vertexInputs.matricesWeightsExtra,matrixWeightExtra)\ntriPositions[i]=(finalWorld*vec4(positionUpdated,1.0)).xyz;}\nvar N : vec3<f32>=calculateTriangleNormal(triPositions[0],triPositions[1],triPositions[2]);let worldPos=triPositions[thisTriIndex];vertexOutputs.position=uniforms.invWorldScale*vec4(worldPos,1.0);N=abs(N);if (N.x>N.y && N.x>N.z) {vertexOutputs.f_swizzle=0;vertexOutputs.position=vec4f(vertexOutputs.position.yzx,1.0);} else if (N.y>N.z) {vertexOutputs.f_swizzle=1;vertexOutputs.position=vec4f(vertexOutputs.position.zxy,1.0);} else {vertexOutputs.f_swizzle=2;vertexOutputs.position=vec4f(vertexOutputs.position.xyz,1.0);}\nvertexOutputs.vNormalizedPosition=vertexOutputs.position.xyz*0.5+0.5;vertexOutputs.position.z =\nvertexOutputs.vNormalizedPosition.z; }\n`;\n// Sideeffect\nif (!ShaderStore.ShadersStoreWGSL[name]) {\n ShaderStore.ShadersStoreWGSL[name] = shader;\n}\n/** @internal */\nexport const iblVoxelGridVertexShaderWGSL = { name, shader };\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WebXRAbstractFeature } from "./WebXRAbstractFeature.js";
|
|
2
2
|
import type { WebXRSessionManager } from "../webXRSessionManager.js";
|
|
3
3
|
import type { AbstractMesh } from "../../Meshes/abstractMesh.js";
|
|
4
|
-
import
|
|
4
|
+
import { Mesh } from "../../Meshes/mesh.js";
|
|
5
5
|
import type { WebXRInput } from "../webXRInput.js";
|
|
6
6
|
import type { WebXRInputSource } from "../webXRInputSource.js";
|
|
7
7
|
import type { Nullable } from "../../types.js";
|
|
@@ -225,6 +225,7 @@ export declare class WebXRHand implements IDisposable {
|
|
|
225
225
|
* The float array that will directly receive the transform matrix data from WebXR.
|
|
226
226
|
*/
|
|
227
227
|
private _jointTransformMatrices;
|
|
228
|
+
private _jointSpaces;
|
|
228
229
|
private _tempJointMatrix;
|
|
229
230
|
/**
|
|
230
231
|
* The float array that will directly receive the joint radii from WebXR.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WebXRAbstractFeature } from "./WebXRAbstractFeature.js";
|
|
2
2
|
import { WebXRFeatureName, WebXRFeaturesManager } from "../webXRFeaturesManager.js";
|
|
3
|
+
import { Mesh } from "../../Meshes/mesh.js";
|
|
3
4
|
import { Matrix, Quaternion } from "../../Maths/math.vector.js";
|
|
4
5
|
import { PhysicsImpostor } from "../../Physics/v1/physicsImpostor.js";
|
|
5
6
|
import { PhysicsAggregate } from "../../Physics/v2/physicsAggregate.js";
|
|
@@ -225,6 +226,7 @@ export class WebXRHand {
|
|
|
225
226
|
* The float array that will directly receive the transform matrix data from WebXR.
|
|
226
227
|
*/
|
|
227
228
|
this._jointTransformMatrices = new Float32Array(HandJointReferenceArray.length * 16);
|
|
229
|
+
this._jointSpaces = new Array(HandJointReferenceArray.length);
|
|
228
230
|
this._tempJointMatrix = new Matrix();
|
|
229
231
|
/**
|
|
230
232
|
* The float array that will directly receive the joint radii from WebXR.
|
|
@@ -305,16 +307,18 @@ export class WebXRHand {
|
|
|
305
307
|
}
|
|
306
308
|
// TODO: Modify webxr.d.ts to better match WebXR IDL so we don't need this any cast.
|
|
307
309
|
const anyHand = hand;
|
|
308
|
-
|
|
310
|
+
for (let i = 0; i < HandJointReferenceArray.length; ++i) {
|
|
311
|
+
this._jointSpaces[i] = anyHand[HandJointReferenceArray[i]] || hand.get(HandJointReferenceArray[i]);
|
|
312
|
+
}
|
|
309
313
|
let trackingSuccessful = false;
|
|
310
314
|
if (xrFrame.fillPoses && xrFrame.fillJointRadii) {
|
|
311
|
-
trackingSuccessful = xrFrame.fillPoses(
|
|
315
|
+
trackingSuccessful = xrFrame.fillPoses(this._jointSpaces, referenceSpace, this._jointTransformMatrices) && xrFrame.fillJointRadii(this._jointSpaces, this._jointRadii);
|
|
312
316
|
}
|
|
313
317
|
else if (xrFrame.getJointPose) {
|
|
314
318
|
trackingSuccessful = true;
|
|
315
319
|
// Warning: This codepath is slow by comparison, only here for compat.
|
|
316
|
-
for (let jointIdx = 0; jointIdx <
|
|
317
|
-
const jointPose = xrFrame.getJointPose(
|
|
320
|
+
for (let jointIdx = 0; jointIdx < this._jointSpaces.length; jointIdx++) {
|
|
321
|
+
const jointPose = xrFrame.getJointPose(this._jointSpaces[jointIdx], referenceSpace);
|
|
318
322
|
if (jointPose) {
|
|
319
323
|
this._jointTransformMatrices.set(jointPose.transform.matrix, jointIdx * 16);
|
|
320
324
|
this._jointRadii[jointIdx] = jointPose.radius || 0.008;
|
|
@@ -328,6 +332,18 @@ export class WebXRHand {
|
|
|
328
332
|
if (!trackingSuccessful) {
|
|
329
333
|
return;
|
|
330
334
|
}
|
|
335
|
+
// L1 Cache Optimization: Invert to LHS in valid Babylon systems IN PLACE
|
|
336
|
+
// This linear loop is much faster than doing it per-object and avoids cache thrashing
|
|
337
|
+
if (!this._scene.useRightHandedSystem) {
|
|
338
|
+
for (let i = 0; i < HandJointReferenceArray.length; ++i) {
|
|
339
|
+
const offset = i * 16;
|
|
340
|
+
this._jointTransformMatrices[offset + 2] *= -1;
|
|
341
|
+
this._jointTransformMatrices[offset + 6] *= -1;
|
|
342
|
+
this._jointTransformMatrices[offset + 8] *= -1;
|
|
343
|
+
this._jointTransformMatrices[offset + 9] *= -1;
|
|
344
|
+
this._jointTransformMatrices[offset + 14] *= -1;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
331
347
|
for (let jointIdx = 0; jointIdx < HandJointReferenceArray.length; jointIdx++) {
|
|
332
348
|
const jointTransform = this._jointTransforms[jointIdx];
|
|
333
349
|
Matrix.FromArrayToRef(this._jointTransformMatrices, jointIdx * 16, this._tempJointMatrix);
|
|
@@ -340,16 +356,12 @@ export class WebXRHand {
|
|
|
340
356
|
jointMesh.rotationQuaternion.copyFrom(jointTransform.rotationQuaternion);
|
|
341
357
|
jointMesh.scaling.setAll(scaledJointRadius);
|
|
342
358
|
jointMesh.parent = xrCamera.parent;
|
|
343
|
-
//
|
|
344
|
-
if
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
jointTransform.position.z *= -1;
|
|
350
|
-
jointTransform.rotationQuaternion.z *= -1;
|
|
351
|
-
jointTransform.rotationQuaternion.w *= -1;
|
|
352
|
-
}
|
|
359
|
+
// Restore correct transform for meshes that are NOT left-handed (e.g. default GLTF)
|
|
360
|
+
// The buffer is now LHS, so if the mesh expects RHS, we must un-flip.
|
|
361
|
+
if (!this._leftHandedMeshes && !this._scene.useRightHandedSystem && this._handMesh) {
|
|
362
|
+
jointTransform.position.z *= -1;
|
|
363
|
+
jointTransform.rotationQuaternion.z *= -1;
|
|
364
|
+
jointTransform.rotationQuaternion.w *= -1;
|
|
353
365
|
}
|
|
354
366
|
}
|
|
355
367
|
if (this._handMesh) {
|
|
@@ -385,15 +397,21 @@ export class WebXRHand {
|
|
|
385
397
|
* WebXR Hand Joint tracking feature, available for selected browsers and devices
|
|
386
398
|
*/
|
|
387
399
|
export class WebXRHandTracking extends WebXRAbstractFeature {
|
|
388
|
-
static _GenerateTrackedJointMeshes(
|
|
389
|
-
const meshes = {};
|
|
390
|
-
["left", "right"]
|
|
400
|
+
static _GenerateTrackedJointMeshes(options, originalMesh) {
|
|
401
|
+
const meshes = { left: [], right: [] };
|
|
402
|
+
for (const handedness of ["left", "right"]) {
|
|
403
|
+
const h = handedness;
|
|
391
404
|
const trackedMeshes = [];
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
405
|
+
for (let i = 0; i < HandJointReferenceArray.length; i++) {
|
|
406
|
+
let newInstance;
|
|
407
|
+
if (originalMesh instanceof Mesh) {
|
|
408
|
+
newInstance = originalMesh.createInstance(`${handedness}-handJoint-${i}`);
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
newInstance = originalMesh.clone(`${handedness}-handJoint-${i}`, null);
|
|
412
|
+
}
|
|
413
|
+
if (options.jointMeshes?.onHandJointMeshGenerated) {
|
|
414
|
+
const returnedMesh = options.jointMeshes.onHandJointMeshGenerated(newInstance, i, h);
|
|
397
415
|
if (returnedMesh) {
|
|
398
416
|
if (returnedMesh !== newInstance) {
|
|
399
417
|
newInstance.dispose();
|
|
@@ -402,8 +420,8 @@ export class WebXRHandTracking extends WebXRAbstractFeature {
|
|
|
402
420
|
}
|
|
403
421
|
}
|
|
404
422
|
newInstance.isPickable = false;
|
|
405
|
-
if (
|
|
406
|
-
const props =
|
|
423
|
+
if (options.jointMeshes?.enablePhysics) {
|
|
424
|
+
const props = options.jointMeshes?.physicsProps;
|
|
407
425
|
// downscale the instances so that physics will be initialized correctly
|
|
408
426
|
newInstance.scaling.setAll(0.02);
|
|
409
427
|
// Detect physics version
|
|
@@ -412,7 +430,7 @@ export class WebXRHandTracking extends WebXRAbstractFeature {
|
|
|
412
430
|
const physicsVersion = physicsEngine?.getPluginVersion() || 1;
|
|
413
431
|
if (physicsVersion === 2) {
|
|
414
432
|
// V2 physics
|
|
415
|
-
const impostorType = props
|
|
433
|
+
const impostorType = props?.impostorType !== undefined ? props.impostorType : PhysicsImpostor.SphereImpostor;
|
|
416
434
|
let shapeType = 0 /* PhysicsShapeType.SPHERE */;
|
|
417
435
|
// Map v1 impostor types to v2 shape types
|
|
418
436
|
switch (impostorType) {
|
|
@@ -430,28 +448,30 @@ export class WebXRHandTracking extends WebXRAbstractFeature {
|
|
|
430
448
|
}
|
|
431
449
|
const aggregate = new PhysicsAggregate(newInstance, shapeType, {
|
|
432
450
|
mass: 0,
|
|
433
|
-
friction: props
|
|
434
|
-
restitution: props
|
|
451
|
+
friction: props?.friction ?? 0.2,
|
|
452
|
+
restitution: props?.restitution ?? 0.2,
|
|
435
453
|
}, scene);
|
|
436
454
|
aggregate.body.setMotionType(1 /* PhysicsMotionType.ANIMATED */);
|
|
437
455
|
aggregate.body.disableSync = true;
|
|
438
456
|
}
|
|
439
457
|
else {
|
|
440
458
|
// V1 physics
|
|
441
|
-
const type = props
|
|
442
|
-
newInstance.physicsImpostor = new PhysicsImpostor(newInstance, type, { mass: 0, ...props });
|
|
459
|
+
const type = props?.impostorType !== undefined ? props.impostorType : PhysicsImpostor.SphereImpostor;
|
|
460
|
+
newInstance.physicsImpostor = new PhysicsImpostor(newInstance, type, props ? { mass: 0, ...props } : { mass: 0 });
|
|
443
461
|
}
|
|
444
462
|
}
|
|
463
|
+
if (options.jointMeshes?.invisible) {
|
|
464
|
+
newInstance.isVisible = false;
|
|
465
|
+
}
|
|
445
466
|
newInstance.rotationQuaternion = new Quaternion();
|
|
446
|
-
newInstance.isVisible = false;
|
|
447
467
|
trackedMeshes.push(newInstance);
|
|
448
468
|
}
|
|
449
|
-
meshes[
|
|
450
|
-
}
|
|
451
|
-
return
|
|
469
|
+
meshes[h] = trackedMeshes;
|
|
470
|
+
}
|
|
471
|
+
return meshes;
|
|
452
472
|
}
|
|
453
473
|
static async _GenerateDefaultHandMeshesAsync(scene, xrSessionManager, options) {
|
|
454
|
-
// eslint-disable-next-line no-async-promise-executor
|
|
474
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
455
475
|
return await new Promise(async (resolve) => {
|
|
456
476
|
const riggedMeshes = {};
|
|
457
477
|
// check the cache, defensive
|
|
@@ -508,9 +528,13 @@ export class WebXRHandTracking extends WebXRAbstractFeature {
|
|
|
508
528
|
}
|
|
509
529
|
const handMesh = handGLB.meshes[1];
|
|
510
530
|
handMesh._internalAbstractMeshDataInfo._computeBonesUsingShaders = true;
|
|
531
|
+
if (handMesh.skeleton) {
|
|
532
|
+
handMesh.skeleton.useTextureToStoreBoneMatrices = false;
|
|
533
|
+
}
|
|
511
534
|
// if in multiview do not use the material
|
|
512
535
|
if (!isMultiview && !options?.handMeshes?.disableHandShader) {
|
|
513
536
|
handMesh.material = handShader.clone(`${handedness}HandShaderClone`, true);
|
|
537
|
+
handMesh.material.freeze();
|
|
514
538
|
}
|
|
515
539
|
handMesh.isVisible = false;
|
|
516
540
|
riggedMeshes[handedness] = handMesh;
|
|
@@ -612,7 +636,7 @@ export class WebXRHandTracking extends WebXRAbstractFeature {
|
|
|
612
636
|
return;
|
|
613
637
|
}
|
|
614
638
|
const handedness = xrController.inputSource.handedness;
|
|
615
|
-
const webxrHand = new WebXRHand(xrController, this._handResources.jointMeshes[handedness], this._handResources.handMeshes && this._handResources.handMeshes[handedness], this._handResources.rigMappings && this._handResources.rigMappings[handedness], this.options.handMeshes?.meshesUseLeftHandedCoordinates, this.options.jointMeshes?.invisible, this.options.jointMeshes?.scaleFactor);
|
|
639
|
+
const webxrHand = new WebXRHand(xrController, this._handResources.jointMeshes && this._handResources.jointMeshes[handedness], this._handResources.handMeshes && this._handResources.handMeshes[handedness], this._handResources.rigMappings && this._handResources.rigMappings[handedness], this.options.handMeshes?.meshesUseLeftHandedCoordinates, this.options.jointMeshes?.invisible, this.options.jointMeshes?.scaleFactor);
|
|
616
640
|
this._attachedHands[xrController.uniqueId] = webxrHand;
|
|
617
641
|
this._trackingHands[handedness] = webxrHand;
|
|
618
642
|
this.onHandAddedObservable.notifyObservers(webxrHand);
|