Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added GetPointsCount #14988

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 16 additions & 9 deletions packages/dev/core/src/Meshes/Builders/greasedLineBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 += (<number[]>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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class GreasedLineMesh extends GreasedLineBaseMesh {
}

protected _updateWidths(): void {
super._updateWidthsWithValue(0);
// intentionally left blank
}

protected _setPoints(points: number[][]) {
Expand Down