From a65c796f93b152ad571968b10e1484098a51b0eb Mon Sep 17 00:00:00 2001 From: Roland Csibrei Date: Tue, 16 Apr 2024 15:07:39 +0200 Subject: [PATCH 1/2] Added GetPointsCount --- .../src/Meshes/Builders/greasedLineBuilder.ts | 25 ++++++++++++------- .../src/Meshes/GreasedLine/greasedLineMesh.ts | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/dev/core/src/Meshes/Builders/greasedLineBuilder.ts b/packages/dev/core/src/Meshes/Builders/greasedLineBuilder.ts index 267d55de766..a5479722c0c 100644 --- a/packages/dev/core/src/Meshes/Builders/greasedLineBuilder.ts +++ b/packages/dev/core/src/Meshes/Builders/greasedLineBuilder.ts @@ -167,17 +167,11 @@ export function CreateGreasedLine(name: string, options: GreasedLineMeshBuilderO materialOptions.colorDistribution = materialOptions?.colorDistribution ?? GreasedLineMeshColorDistribution.COLOR_DISTRIBUTION_START; materialOptions.materialType = materialOptions.materialType ?? GreasedLineMeshMaterialType.MATERIAL_TYPE_STANDARD; - let length = 0; - if (Array.isArray(allPoints[0])) { - allPoints.forEach((points) => { - length += points.length / 3; - }); - } - - const widths = CompleteGreasedLineWidthTable(length, options.widths ?? [], options.widthDistribution); + const pointsCount = GetPointsCount(allPoints); + const widths = CompleteGreasedLineWidthTable(pointsCount, options.widths ?? [], options.widthDistribution); const colors = materialOptions?.colors - ? CompleteGreasedLineColorTable(length, materialOptions.colors, materialOptions.colorDistribution, materialOptions.color ?? GreasedLineMaterialDefaults.DEFAULT_COLOR) + ? CompleteGreasedLineColorTable(pointsCount, materialOptions.colors, materialOptions.colorDistribution, materialOptions.color ?? GreasedLineMaterialDefaults.DEFAULT_COLOR) : undefined; // create new mesh if instance is not defined @@ -282,6 +276,19 @@ export function CreateGreasedLine(name: string, options: GreasedLineMeshBuilderO return instance; } +/** + * Counts the number of points + * @param allPoints Array of points [[x, y, z], [x, y, z], ...] or Array of points [x, y, z, x, y, z, ...] + * @returns total number of points + */ +export function GetPointsCount(allPoints: number[][]) { + let pointCount = 0; + for (const points of allPoints) { + pointCount += (points).length / 3; + } + return pointCount; +} + /** * Completes the width table/fills the missing entries. It means it creates a width entry for every point of the line mesh. * You can provide more points the widths when creating the mesh. This function will fill the empty entries. diff --git a/packages/dev/core/src/Meshes/GreasedLine/greasedLineMesh.ts b/packages/dev/core/src/Meshes/GreasedLine/greasedLineMesh.ts index 4cd640394db..1d640694c50 100644 --- a/packages/dev/core/src/Meshes/GreasedLine/greasedLineMesh.ts +++ b/packages/dev/core/src/Meshes/GreasedLine/greasedLineMesh.ts @@ -80,7 +80,7 @@ export class GreasedLineMesh extends GreasedLineBaseMesh { } protected _updateWidths(): void { - super._updateWidthsWithValue(0); + // intentionally left blank } protected _setPoints(points: number[][]) { From 884d0f09e5ebfa16758d9616cf864d31bb4471b5 Mon Sep 17 00:00:00 2001 From: Roland Csibrei Date: Tue, 2 Jul 2024 18:33:24 +0200 Subject: [PATCH 2/2] onStoppedObservable added for gpu particles --- packages/dev/core/src/Particles/gpuParticleSystem.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/dev/core/src/Particles/gpuParticleSystem.ts b/packages/dev/core/src/Particles/gpuParticleSystem.ts index 998be64f073..505c354f8d1 100644 --- a/packages/dev/core/src/Particles/gpuParticleSystem.ts +++ b/packages/dev/core/src/Particles/gpuParticleSystem.ts @@ -409,6 +409,9 @@ export class GPUParticleSystem extends BaseParticleSystem implements IDisposable if (this._stopped) { return; } + + this.onStoppedObservable.notifyObservers(this); + this._stopped = true; }