-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathPerformanceCheckDialog.js
181 lines (164 loc) · 5.62 KB
/
PerformanceCheckDialog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import React, { useContext } from "react";
import PropTypes from "prop-types";
import styled, { ThemeContext } from "styled-components";
import Dialog from "./Dialog";
import { bytesToSize } from "../utils";
const ColoredText = styled.span`
color: ${props => props.color};
`;
const PerformanceItemContainer = styled.li`
display: flex;
min-height: 100px;
background-color: ${props => props.theme.toolbar};
border: 1px solid ${props => props.theme.panel};
border-radius: 4px;
margin: 4px;
color: white;
max-width: 560px;
& > :first-child {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100px;
}
& > :last-child {
display: flex;
flex-direction: column;
flex: 1;
padding: 12px;
border-left: 1px solid ${props => props.theme.panel2};
}
h5 {
font-size: 20px;
}
h6 {
font-size: 16px;
}
a {
white-space: nowrap;
color: ${props => props.theme.blue};
}
p {
margin: 0;
}
`;
function PerformanceCheckItem({ score, scoreColor, title, description, learnMoreUrl, children }) {
return (
<PerformanceItemContainer>
<div>
<ColoredText as="h5" color={scoreColor}>
{score}
</ColoredText>
</div>
<div>
<h6>
{title}: {children}
</h6>
<p>
{description}{" "}
<a rel="noopener noreferrer" target="_blank" href={learnMoreUrl}>
Learn More
</a>
</p>
</div>
</PerformanceItemContainer>
);
}
PerformanceCheckItem.propTypes = {
score: PropTypes.string.isRequired,
scoreColor: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
children: PropTypes.node,
description: PropTypes.string.isRequired,
learnMoreUrl: PropTypes.string.isRequired
};
const scoreToValue = {
Low: 0,
Medium: 1,
High: 2
};
export default function PerformanceCheckDialog({ scores, ...rest }) {
const theme = useContext(ThemeContext);
const scoreToColor = {
Low: theme.green,
Medium: theme.yellow,
High: theme.red
};
const texturesScore =
scoreToValue[scores.textures.largeTexturesScore] > scoreToValue[scores.textures.score]
? scores.textures.largeTexturesScore
: scores.textures.score;
return (
<Dialog {...rest}>
<ul>
<PerformanceCheckItem
title="Polygon Count"
description="We recommend your scene use no more than 50,000 triangles for mobile devices."
learnMoreUrl="https://docs.hubsfoundation.org/spoke-optimization.html"
score={scores.polygons.score}
scoreColor={scoreToColor[scores.polygons.score]}
>
<ColoredText color={scoreToColor[scores.polygons.score]}>
{scores.polygons.value.toLocaleString()} Triangles
</ColoredText>
</PerformanceCheckItem>
<PerformanceCheckItem
title="Materials"
description="We recommend using no more than 25 unique materials in your scene to reduce draw calls on mobile devices."
learnMoreUrl="https://docs.hubsfoundation.org/spoke-optimization.html"
score={scores.materials.score}
scoreColor={scoreToColor[scores.materials.score]}
>
<ColoredText color={scoreToColor[scores.materials.score]}>
{scores.materials.value} Unique Materials
</ColoredText>
</PerformanceCheckItem>
<PerformanceCheckItem
title="Textures"
description="We recommend your textures use no more than 256MB of video RAM for mobile devices. We also recommend against using textures larger than 2048 x 2048."
learnMoreUrl="https://docs.hubsfoundation.org/spoke-optimization.html"
score={texturesScore}
scoreColor={scoreToColor[texturesScore]}
>
<ColoredText color={scoreToColor[scores.textures.score]}>
~{bytesToSize(scores.textures.value)} Video RAM
</ColoredText>
,{" "}
<ColoredText color={scoreToColor[scores.textures.largeTexturesScore]}>
{scores.textures.largeTexturesValue} Large Textures
</ColoredText>
</PerformanceCheckItem>
<PerformanceCheckItem
title="Lights"
description="While dynamic lights are not enabled on mobile devices, we recommend using no more than 3 lights in your scene (excluding ambient and hemisphere lights) for your scene to run on low end PCs."
learnMoreUrl="https://docs.hubsfoundation.org/spoke-optimization.html"
score={scores.lights.score}
scoreColor={scoreToColor[scores.lights.score]}
>
<ColoredText color={scoreToColor[scores.lights.score]}>{scores.lights.value} Lights</ColoredText>
</PerformanceCheckItem>
<PerformanceCheckItem
title="File Size"
description="We recommend a final file size of no more than 16MB for low bandwidth connections. Reducing the file size will reduce the time it takes to download your scene."
learnMoreUrl="https://docs.hubsfoundation.org/spoke-optimization.html"
score={scores.fileSize.score}
scoreColor={scoreToColor[scores.fileSize.score]}
>
<ColoredText color={scoreToColor[scores.fileSize.score]}>{bytesToSize(scores.fileSize.value)}</ColoredText>
</PerformanceCheckItem>
</ul>
</Dialog>
);
}
PerformanceCheckDialog.propTypes = {
scores: PropTypes.object.isRequired,
tag: PropTypes.string.isRequired,
onConfirm: PropTypes.func.isRequired,
confirmLabel: PropTypes.string.isRequired
};
PerformanceCheckDialog.defaultProps = {
tag: "div",
title: "Performance Check",
confirmLabel: "Publish Scene"
};