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

Button3D: Allow setting the dimensions at creation time #13637

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/dev/gui/src/3D/controls/button3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ export class Button3D extends AbstractButton3D {
/** @internal */
protected _currentMaterial: Material;

protected _width: number;
protected _height: number;
protected _depth: number;

/**
* Creates a new button
* @param name defines the control name
*/
constructor(name?: string) {
constructor(name?: string, width = 1, height = 1, depth = 0.08) {
RaananW marked this conversation as resolved.
Show resolved Hide resolved
super(name);

this._width = width;
this._height = height;
this._depth = depth;

// Default animations

this.pointerEnterAnimation = () => {
Expand Down Expand Up @@ -83,15 +91,18 @@ export class Button3D extends AbstractButton3D {
const mesh = CreateBox(
this.name + "_rootMesh",
{
width: 1.0,
height: 1.0,
depth: 0.08,
width: this._width,
height: this._height,
depth: this._depth,
faceUV: faceUV,
wrap: true,
},
scene
);

this._contentScaleRatioY = (this._contentScaleRatio * this._width) / this._height;
this._setFacadeTextureScaling();

return mesh;
}

Expand Down
11 changes: 9 additions & 2 deletions packages/dev/gui/src/3D/controls/contentDisplay3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class ContentDisplay3D extends Control3D {
private _facadeTexture: Nullable<AdvancedDynamicTexture>;
protected _contentResolution = 512;
protected _contentScaleRatio = 2;
protected _contentScaleRatioY: number | undefined;
RaananW marked this conversation as resolved.
Show resolved Hide resolved

/**
* Gets or sets the GUI 2D content used to display the button's facade
Expand All @@ -36,8 +37,7 @@ export class ContentDisplay3D extends Control3D {
true,
Texture.TRILINEAR_SAMPLINGMODE
);
this._facadeTexture.rootContainer.scaleX = this._contentScaleRatio;
this._facadeTexture.rootContainer.scaleY = this._contentScaleRatio;
this._setFacadeTextureScaling();
this._facadeTexture.premulAlpha = true;
} else {
this._facadeTexture.rootContainer.clearControls();
Expand All @@ -48,6 +48,13 @@ export class ContentDisplay3D extends Control3D {
this._applyFacade(this._facadeTexture);
}

protected _setFacadeTextureScaling() {
if (this._facadeTexture) {
this._facadeTexture.rootContainer.scaleX = this._contentScaleRatio;
this._facadeTexture.rootContainer.scaleY = this._contentScaleRatioY ?? this._contentScaleRatio;
}
}

/**
* Gets or sets the texture resolution used to render content (512 by default)
*/
Expand Down