Jump to content

GUI Performance


Ericky14
 Share

Recommended Posts

Hello,

I am trying to use the GUI TextBlock and Image components to display an icon and a text underneath it (number count) on top of a hexagon.

In the scene, there can be hundreds of hexagons at once. Without instantiating the GUI components, the scene runs with no much problem at all, 200~ hexagons at 60fps... With it, the fps drops considerably.

Is there any GUI optimization advice you guys can give me? I would appreciate it. :)

constructor(parentHex, text, sizeScale, icon) {
if (global.Image) {
const GUI = require('babylonjs-gui');
 
const materialType = MATERIAL_TYPES.DYNAMIC_LABEL;
const name = `hex_label_plane_${sizeScale}`;
let plane = Main.scene.getMeshByName(name);
 
if (!plane) {
plane = BABYLON.MeshBuilder.CreatePlane(name, { size: 1.1 * sizeScale }, Main.scene);
Util.setMaterial(plane, materialType);
Util.setScalingToZero(plane);
}
 
plane = plane.clone('clone');
plane.position = Util.getNewVector(parentHex.position);
plane.position.y += (parentHex.extents.y * Config.HEX_Y_SCALE) + 0.01;
plane.rotation.x = Math.PI / 2;
 
Util.setScalingToOne(plane);
plane.setParent(parentHex);
plane.originalScaling = Util.getNewVector(plane.scaling);
 
plane.setVisibility = (visible) => {
visible ? Util.setScalingToZero(plane) : Util.resetScaling(plane);
};
 
const panel = new GUI.StackPanel();
panel.verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_CENTER;
this._panel = panel;
 
if (icon) {
const image = new GUI.Image('hexLabelIcon', icon);
image.height = `${Config.HEX_LABEL_ICON_HEIGHT / sizeScale}px`;
image.paddingBottom = `${Config.HEX_LABEL_ICON_PADDING_BOTTOM / sizeScale}px`;
image.verticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_BOTTOM;
image.stretch = GUI.Image.STRETCH_UNIFORM;
panel.addControl(image);
}
 
const textBlock = new GUI.TextBlock(`hex_label_${text}`, text);
textBlock.height = `${Config.HEX_LABEL_FONT_SIZE / sizeScale}px`;
textBlock.color = 'black';
textBlock.fontSize = `${Config.HEX_LABEL_FONT_SIZE / sizeScale}px`;
textBlock.textVerticalAlignment = GUI.Control.VERTICAL_ALIGNMENT_TOP;
panel.addControl(textBlock);
 
this.advancedTexture = GUI.AdvancedDynamicTexture.CreateForMesh(plane);
this.advancedTexture.addControl(panel);
 
return plane;
}
}

Screen Shot 2017-12-21 at 11.01.14 PM.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...