Skip to content

Commit

Permalink
Added option to disable bevels and regain 15-20 fps
Browse files Browse the repository at this point in the history
-created "const enableBevels" Bool and set default to "false" for the time being.
  • Loading branch information
Aitolda committed Oct 14, 2024
1 parent c023121 commit 985c80c
Showing 1 changed file with 62 additions and 48 deletions.
110 changes: 62 additions & 48 deletions src/modules/entity/entities/LabelEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ export class LabelEntity {
const tagBackgroundColorString = tagBackgroundColor.toHexString();
const memoName = `${name}${icon ? "-i" : ""}-${tagBackgroundColorString}`;

// Add this line at the beginning of the method:
const enableBevels = false; // Set to false to disable bevels

// Declare corners and edges outside the conditional block
const corners: Mesh[] = []
const edges: Mesh[] = []

// Attempt to reuse a memoized mesh, if one exists.
let mesh = meshMemo.get(memoName)?.clone("Label", object, false, false);

Expand Down Expand Up @@ -266,52 +273,52 @@ export class LabelEntity {
);
plane.material = foregroundMaterial;

// Rounded corners.
const corners = new Array<Mesh>();
const cornerPositions = [
new Vector3(-tagWidth / 2, tagHeight / 2 - tagCornerRadius, 0),
new Vector3(tagWidth / 2, tagHeight / 2 - tagCornerRadius, 0),
new Vector3(tagWidth / 2, -tagHeight / 2 + tagCornerRadius, 0),
new Vector3(-tagWidth / 2, -tagHeight / 2 + tagCornerRadius, 0),
];
const sector = createSector(
"LabelCorner",
Vector3.Up(),
Vector3.Left(),
tagCornerRadius,
scene
);
corners.push(sector);
corners.push(sector.clone("LabelCorner"));
corners.push(sector.clone("LabelCorner"));
corners.push(sector.clone("LabelCorner"));
let index = 0;
for (const cornerMesh of corners) {
cornerMesh.material = backgroundMaterial;
cornerMesh.position = cornerPositions[index];
cornerMesh.rotate(new Vector3(0, 0, 1), -index * (Math.PI / 2));
index += 1;
}

// Left and right edges.
const edges = new Array<Mesh>();
const edgeOptions = {
width: tagCornerRadius,
height: tagHeight - tagCornerRadius * 2,
sideOrientation: Mesh.FRONTSIDE,
updatable: false,
};
const edgePositions = [
new Vector3(-tagWidth / 2 - tagCornerRadius / 2, 0, 0),
new Vector3(tagWidth / 2 + tagCornerRadius / 2, 0, 0),
];
edges.push(MeshBuilder.CreatePlane("LabelLeftEdge", edgeOptions, scene));
edges.push(MeshBuilder.CreatePlane("LabelRightEdge", edgeOptions, scene));
index = 0;
for (const edgeMesh of edges) {
edgeMesh.material = backgroundMaterial;
edgeMesh.position = edgePositions[index];
index += 1;
if (enableBevels) {
// Rounded corners.
const cornerPositions = [
new Vector3(-tagWidth / 2, tagHeight / 2 - tagCornerRadius, 0),
new Vector3(tagWidth / 2, tagHeight / 2 - tagCornerRadius, 0),
new Vector3(tagWidth / 2, -tagHeight / 2 + tagCornerRadius, 0),
new Vector3(-tagWidth / 2, -tagHeight / 2 + tagCornerRadius, 0),
];
const sector = createSector(
"LabelCorner",
Vector3.Up(),
Vector3.Left(),
tagCornerRadius,
scene
);
corners.push(sector);
corners.push(sector.clone("LabelCorner"));
corners.push(sector.clone("LabelCorner"));
corners.push(sector.clone("LabelCorner"));
let index = 0;
for (const cornerMesh of corners) {
cornerMesh.material = backgroundMaterial;
cornerMesh.position = cornerPositions[index];
cornerMesh.rotate(new Vector3(0, 0, 1), -index * (Math.PI / 2));
index += 1;
}

// Left and right edges.
const edgeOptions = {
width: tagCornerRadius,
height: tagHeight - tagCornerRadius * 2,
sideOrientation: Mesh.FRONTSIDE,
updatable: false,
};
const edgePositions = [
new Vector3(-tagWidth / 2 - tagCornerRadius / 2, 0, 0),
new Vector3(tagWidth / 2 + tagCornerRadius / 2, 0, 0),
];
edges.push(MeshBuilder.CreatePlane("LabelLeftEdge", edgeOptions, scene));
edges.push(MeshBuilder.CreatePlane("LabelRightEdge", edgeOptions, scene));
index = 0;
for (const edgeMesh of edges) {
edgeMesh.material = backgroundMaterial;
edgeMesh.position = edgePositions[index];
index += 1;
}
}

// Arrow mesh.
Expand All @@ -330,9 +337,16 @@ export class LabelEntity {
arrow.rotation.z = -Math.PI / 2;
arrow.scaling.x = 0.5;

// Modify the mesh merging section:
const meshesToMerge = [plane];
if (enableBevels) {
meshesToMerge.push(...corners, ...edges);
}
meshesToMerge.push(arrow);

// Merge the label meshes.
const mergedMesh = Mesh.MergeMeshes(
[plane, ...corners, ...edges, arrow],
meshesToMerge,
true,
true,
undefined,
Expand Down Expand Up @@ -444,4 +458,4 @@ export class LabelEntity {
const labelMeshes = object.getChildMeshes(false, (node) => (/^Label/iu).test(node.name));
labelMeshes.forEach((labelMesh) => labelMesh.dispose(false, false));
}
}
}

0 comments on commit 985c80c

Please sign in to comment.