Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,21 @@ export interface CadGeometryState {
status: CadGeometryStatus
message: string
progress: number | null
stats: CadModelStats | null
}

export interface CadModelStats {
format: string
meshCount: number
vertexCount: number
triangleCount: number
bounds: {
x: number
y: number
z: number
}
fileSizeBytes: number | null
downloadMs: number | null
parseMs: number
totalMs: number
}
91 changes: 91 additions & 0 deletions src/components/app/CadComponentWorkbench.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,50 @@ import type { UseCadComponentEditorResult } from "../../hooks/useCadComponentEdi
import type { UseCadViewerResult } from "../../hooks/useCadViewer"
import type { Alignment, AxisDirection } from "../../types"

function formatCount(value: number | null | undefined) {
if (value === null || value === undefined) {
return "-"
}

return new Intl.NumberFormat("en-US").format(value)
}

function formatBytes(value: number | null | undefined) {
if (!value) {
return "-"
}

const units = ["B", "KB", "MB", "GB"]
let size = value
let unitIndex = 0
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024
unitIndex += 1
}

return `${size >= 10 || unitIndex === 0 ? size.toFixed(0) : size.toFixed(1)} ${units[unitIndex]}`
}

function formatMs(value: number | null | undefined) {
if (value === null || value === undefined) {
return "-"
}

if (value >= 1000) {
return `${(value / 1000).toFixed(2)} s`
}

return `${Math.round(value)} ms`
}

function formatBounds(stats: UseCadViewerResult["modelStats"]) {
if (!stats) {
return "-"
}

return `${stats.bounds.x.toFixed(2)} x ${stats.bounds.y.toFixed(2)} x ${stats.bounds.z.toFixed(2)} mm`
}

interface CadComponentWorkbenchProps {
editor: UseCadComponentEditorResult
viewer: UseCadViewerResult
Expand Down Expand Up @@ -71,6 +115,53 @@ export function CadComponentWorkbench({
</article>
</div>

<details className="model-stats-panel">
<summary className="model-stats-header">
<span className="summary-label">Model Stats</span>
<strong>{viewer.modelStats?.format ?? "No model"}</strong>
</summary>
<div className="model-stats-grid">
<div>
<span>Meshes</span>
<strong>{formatCount(viewer.modelStats?.meshCount)}</strong>
</div>
<div>
<span>Vertices</span>
<strong>
{formatCount(viewer.modelStats?.vertexCount)}
</strong>
</div>
<div>
<span>Triangles</span>
<strong>
{formatCount(viewer.modelStats?.triangleCount)}
</strong>
</div>
<div>
<span>Bounds</span>
<strong>{formatBounds(viewer.modelStats)}</strong>
</div>
<div>
<span>File Size</span>
<strong>
{formatBytes(viewer.modelStats?.fileSizeBytes)}
</strong>
</div>
<div>
<span>Download</span>
<strong>{formatMs(viewer.modelStats?.downloadMs)}</strong>
</div>
<div>
<span>Parse</span>
<strong>{formatMs(viewer.modelStats?.parseMs)}</strong>
</div>
<div>
<span>Total</span>
<strong>{formatMs(viewer.modelStats?.totalMs)}</strong>
</div>
</div>
</details>

<div className="actions hero-actions">
<button
type="button"
Expand Down
Loading
Loading