-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: Add Metrics Limits overlay #890
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd0c185
feat: Add Metrics Limits overlay
cyaiox 689aba9
fix: Parcels size and the counting of unique textures and materials
cyaiox 62821e2
fix: Refresh scene layout
cyaiox 0adf765
fix: Scene metrics
cyaiox c01aa73
refactor: Use const
cyaiox 04d5fd3
fix: Update metrics when remove entities
cyaiox 22d4d94
fix: IGNORE_MATERIALS
cyaiox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
packages/@dcl/inspector/src/components/Renderer/Metrics/Metrics.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
.Metrics { | ||
--metrics-bottom: 8px; | ||
--metrics-left: 8px; | ||
--metrics-button-height: 30px; | ||
--metrics-button-width: 30px; | ||
|
||
display: flex; | ||
align-items: center; | ||
position: absolute; | ||
bottom: var(--metrics-bottom); | ||
left: var(--metrics-left); | ||
z-index: 1; | ||
} | ||
|
||
.Metrics .Buttons { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 8px; | ||
} | ||
|
||
.Metrics .Buttons .Button { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: var(--metrics-button-height); | ||
width: var(--metrics-button-width); | ||
padding: 5px; | ||
border-radius: 4px; | ||
background-color: transparent; | ||
} | ||
|
||
.Metrics .Buttons .Button.Active svg { | ||
color: var(--base-06); | ||
} | ||
|
||
.Metrics .Buttons .Button svg { | ||
color: var(--base-02); | ||
} | ||
|
||
.Metrics > div.LimitExceeded { | ||
display: flex; | ||
align-items: center; | ||
text-transform: uppercase; | ||
cursor: default; | ||
} | ||
|
||
.Metrics > .Overlay { | ||
display: flex; | ||
flex-direction: column; | ||
width: 250px; | ||
position: absolute; | ||
overflow-y: auto; | ||
left: 0; | ||
bottom: calc(var(--metrics-bottom) + var(--metrics-button-height) + 8px); | ||
background-color: var(--base-19); | ||
padding: 13px 12px; | ||
border-radius: 4px; | ||
gap: 16px; | ||
} | ||
|
||
.Metrics > .Overlay h2.Header { | ||
display: flex; | ||
font-size: 14px; | ||
font-weight: 500; | ||
line-height: 17px; | ||
color: var(--base-01); | ||
margin-bottom: 0; | ||
gap: 4px; | ||
} | ||
|
||
.Metrics > .Overlay .Item .Title, | ||
.Metrics > .Overlay .Item .Description, | ||
.Metrics > .Overlay .Item .Description .Key { | ||
font-size: 11px; | ||
font-weight: 500; | ||
color: var(--base-01); | ||
margin-bottom: 0; | ||
} | ||
|
||
.Metrics > .Overlay .secondary { | ||
color: var(--base-09); | ||
} | ||
|
||
.Metrics > .Overlay .Items { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 8px; | ||
} | ||
|
||
.Metrics > .Overlay .Items .Item { | ||
display: flex; | ||
gap: 4px; | ||
padding: 8px 0; | ||
border-bottom: 1px solid var(--base-18); | ||
} | ||
|
||
.Metrics > .Overlay .Items .Item:last-of-type { | ||
border-bottom: none; | ||
} | ||
|
||
.Metrics > .Overlay .Item .Title { | ||
display: flex; | ||
flex: 1; | ||
align-items: center; | ||
} | ||
|
||
.Metrics > .Overlay .Item .Description { | ||
display: flex; | ||
flex: 1; | ||
align-items: center; | ||
gap: 4px; | ||
line-height: 14px; | ||
} | ||
|
||
.Metrics > .Overlay .Item .Description .Key { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 0 4px; | ||
height: 18px; | ||
border-radius: 4px; | ||
background-color: var(--base-13); | ||
} | ||
|
||
.Metrics .Buttons .Button.LimitExceeded svg, | ||
.Metrics > .Overlay .Item .Description.LimitExceeded, | ||
.Metrics > .Overlay .Item .Description.LimitExceeded .secondary { | ||
color: var(--error-dark); | ||
} | ||
|
||
.Metrics .Buttons .Button.Active.LimitExceeded svg { | ||
color: var(--error-main); | ||
} |
112 changes: 112 additions & 0 deletions
112
packages/@dcl/inspector/src/components/Renderer/Metrics/Metrics.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import React, { useCallback, useEffect, useMemo } from 'react' | ||
import cx from 'classnames' | ||
import { IoGridOutline as SquaresGridIcon, IoAlertCircleOutline as AlertIcon } from 'react-icons/io5' | ||
|
||
import { withSdk, WithSdkProps } from '../../../hoc/withSdk' | ||
import { useChange } from '../../../hooks/sdk/useChange' | ||
import { useOutsideClick } from '../../../hooks/useOutsideClick' | ||
import { Button } from '../../Button' | ||
import { getSceneLimits } from './utils' | ||
import type { Metrics } from './types' | ||
|
||
import './Metrics.css' | ||
|
||
const ICON_SIZE = 18 | ||
|
||
const Metrics = withSdk<WithSdkProps>(({ sdk }) => { | ||
const [showMetrics, setShowMetrics] = React.useState(false) | ||
const [metrics, setMetrics] = React.useState<Partial<Metrics>>({ | ||
triangles: 0, | ||
entities: 0, | ||
bodies: 0, | ||
materials: 0, | ||
textures: 0 | ||
}) | ||
|
||
const handleUpdateMetrics = useCallback(() => { | ||
const ROOT_ENGINE = sdk.engine.RootEntity | ||
const triangles = sdk.scene.meshes.reduce((acc, mesh) => acc + mesh.getTotalVertices(), 0) | ||
const entities = (sdk.components.Nodes.getOrNull(ROOT_ENGINE)?.value ?? [ROOT_ENGINE]).length - 1 | ||
setMetrics({ | ||
triangles: triangles, | ||
entities: entities, | ||
bodies: sdk.scene.meshes.length, | ||
materials: sdk.scene.materials.length, | ||
textures: sdk.scene.textures.length | ||
}) | ||
}, [sdk]) | ||
|
||
useEffect(handleUpdateMetrics, [handleUpdateMetrics]) | ||
|
||
useChange(handleUpdateMetrics, [handleUpdateMetrics]) | ||
|
||
const scene = useMemo(() => { | ||
return sdk.components.Scene.get(sdk.engine.RootEntity) | ||
}, [sdk]) | ||
|
||
const limits = useMemo<Metrics>(() => { | ||
const parcels = scene.layout.base.x * scene.layout.base.y | ||
return getSceneLimits(parcels) | ||
}, [scene]) | ||
|
||
const limitsExceeded = useMemo<Record<string, boolean>>(() => { | ||
return Object.fromEntries( | ||
Object.entries(metrics) | ||
.map(([key, value]) => [key, value > limits[key as keyof Metrics]]) | ||
.filter(([, value]) => value) | ||
) | ||
}, [metrics, limits]) | ||
|
||
const handleToggleMetricsOverlay = useCallback( | ||
(e: React.MouseEvent<HTMLButtonElement> | MouseEvent) => { | ||
e.preventDefault() | ||
e.stopPropagation() | ||
setShowMetrics((value) => !value) | ||
}, | ||
[showMetrics, setShowMetrics] | ||
) | ||
|
||
const overlayRef = useOutsideClick(handleToggleMetricsOverlay) | ||
|
||
return ( | ||
<div className="Metrics"> | ||
<div className="Buttons"> | ||
<Button | ||
className={cx({ Active: showMetrics, LimitExceeded: Object.values(limitsExceeded).length > 0 })} | ||
onClick={handleToggleMetricsOverlay} | ||
> | ||
<SquaresGridIcon size={ICON_SIZE} /> | ||
</Button> | ||
</div> | ||
{Object.values(limitsExceeded).length > 0 && ( | ||
<div className="LimitExceeded"> | ||
<AlertIcon /> | ||
Too many {Object.keys(limitsExceeded)[0].toUpperCase()} | ||
</div> | ||
)} | ||
{showMetrics && ( | ||
<div ref={overlayRef} className="Overlay"> | ||
<h2 className="Header"> | ||
{scene.layout.base.x}x{scene.layout.base.y} LAND | ||
<span className="secondary"> | ||
{scene.layout.base.x * 16}x{scene.layout.base.y * 16}m | ||
</span> | ||
</h2> | ||
<div className="Items"> | ||
{Object.entries(metrics).map(([key, value]) => ( | ||
<div className="Item" key={key}> | ||
<div className="Title">{key.toUpperCase()}</div> | ||
<div className={cx('Description', { LimitExceeded: limitsExceeded[key] })}> | ||
<span className="primary">{value}</span>/ | ||
<span className="secondary">{limits[key as keyof Metrics]}</span> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
}) | ||
|
||
export default React.memo(Metrics) |
2 changes: 2 additions & 0 deletions
2
packages/@dcl/inspector/src/components/Renderer/Metrics/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Metrics from './Metrics' | ||
export { Metrics } | ||
15 changes: 15 additions & 0 deletions
15
packages/@dcl/inspector/src/components/Renderer/Metrics/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export interface Metrics { | ||
triangles: number | ||
entities: number | ||
bodies: number | ||
materials: number | ||
textures: number | ||
} | ||
|
||
export enum Limits { | ||
triangles = 10000, | ||
entities = 200, | ||
bodies = 300, | ||
materials = 20, | ||
textures = 10 | ||
} | ||
11 changes: 11 additions & 0 deletions
11
packages/@dcl/inspector/src/components/Renderer/Metrics/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Limits, type Metrics } from './types' | ||
|
||
export function getSceneLimits(parcels: number): Metrics { | ||
return { | ||
triangles: parcels * Limits.triangles, | ||
entities: parcels * Limits.entities, | ||
bodies: parcels * Limits.bodies, | ||
materials: Math.floor(Math.log2(parcels + 1) * Limits.materials), | ||
textures: Math.floor(Math.log2(parcels + 1) * Limits.textures) | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the "COLSxROWS" layout only makes sense for the builder, but for scenes with irregular shapes it does not work. For example you could have a scene with the shape of an "S" and that is not translatable to a COLSxROWS format.
Also
layout.base
is not being used correctly in this context. The base is the corner of the scene where to originate the x,y,z coordinate system, but is not the number of columns or rows neither.Also for Worlds the LAND part is not relevant.
So I would say we simply remove the COLSxROWS label from the UI.