Skip to content

Commit d4754e1

Browse files
authored
Merge pull request #182 from remcoder/fix/stats-counter-position
Fix/stats counter position
2 parents 069f498 + 8baa2a0 commit d4754e1

5 files changed

Lines changed: 40 additions & 11 deletions

File tree

demo/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
<div class="dnd">☝️ Drop a gcode file here to view it</div>
2929
<div class="version-box">
30-
3130
<script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js" data-name="bmc-button" data-slug="remcoder" data-color="#303030" data-emoji="" data-font="Lato" data-text="Buy me a coffee" data-outline-color="#ffffff" data-font-color="#ffffff" data-coffee-color="#FFDD00" ></script>
32-
</div>
31+
</div>
3332
<div class="sidebar">
33+
<div class="scroll-container">
3434
<div>
3535
<h1>GCode Preview</h1>
3636
Presets:
@@ -214,6 +214,7 @@ <h1>GCode Preview</h1>
214214
</a>
215215
</section>
216216
</div>
217+
</div>
217218
</div>
218219

219220
<!-- <script src="js/canvas2image.js"></script> -->

demo/js/demo.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,14 @@ export function initDemo() {
160160
initialCameraPosition: [180, 150, 300],
161161
backgroundColor: initialBackgroundColor,
162162
lineHeight: 0.3,
163-
devMode: true
163+
devMode: {
164+
camera: true,
165+
renderer: true,
166+
parser: true,
167+
buildVolume: true,
168+
devHelpers: true,
169+
statsContainer: document.querySelector('.sidebar')
170+
}
164171
}));
165172

166173
backgroundColor.value = initialBackgroundColor;

demo/style.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,20 @@ body {
3333
left: 0;
3434
top: 0;
3535
bottom: 0;
36-
padding: 10px;
3736
line-height: 25px;
3837
transform: translateZ(0);
3938
display: flex;
4039
flex-direction: column;
4140
justify-content: space-between;
4241
transform: translateZ(0);
42+
}
43+
44+
.scroll-container {
45+
padding: 10px;
46+
4347
overflow-y: scroll;
4448
overflow-x: hidden;
49+
height: 100%;
4550
}
4651

4752
.description {
@@ -183,3 +188,9 @@ output {
183188
position: relative;
184189
bottom: 2px;
185190
}
191+
192+
.stats {
193+
position: absolute !important;
194+
right: -80px !important;
195+
left: unset !important;
196+
}

src/dev-gui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type DevModeOptions = {
66
parser?: boolean | false;
77
buildVolume?: boolean | false;
88
devHelpers?: boolean | false;
9+
statsContainer?: HTMLElement | undefined;
910
};
1011

1112
class DevGUI {
@@ -56,7 +57,6 @@ class DevGUI {
5657

5758
loadOpenFolders(): void {
5859
this.openFolders = JSON.parse(localStorage.getItem('dev-gui-open') || '{}').open || [];
59-
console.log(this.openFolders);
6060
}
6161

6262
saveOpenFolders(): void {

src/webgl-preview.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ export class WebGLPreview {
153153
private _toolColors: Record<number, Color> = {};
154154

155155
// debug
156-
private devMode?: boolean | DevModeOptions = true;
156+
private devMode?: boolean | DevModeOptions = false;
157157
private _lastRenderTime = 0;
158158
private _wireframe = false;
159-
private stats: Stats = new Stats();
159+
private stats?: Stats;
160+
private statsContainer?: HTMLElement;
160161
private devGui?: DevGUI;
161162

162163
constructor(opts: GCodePreviewOptions) {
@@ -181,6 +182,7 @@ export class WebGLPreview {
181182
this.renderTubes = opts.renderTubes ?? this.renderTubes;
182183
this.extrusionWidth = opts.extrusionWidth ?? this.extrusionWidth;
183184
this.devMode = opts.devMode ?? this.devMode;
185+
this.stats = this.devMode ? new Stats() : undefined;
184186

185187
if (opts.extrusionColor !== undefined) {
186188
this.extrusionColor = opts.extrusionColor;
@@ -245,10 +247,7 @@ export class WebGLPreview {
245247

246248
if (opts.allowDragNDrop) this._enableDropHandler();
247249

248-
if (this.devMode) {
249-
document.body.appendChild(this.stats.dom);
250-
this.initGui();
251-
}
250+
this.initStats();
252251
}
253252

254253
get extrusionColor(): Color | Color[] {
@@ -857,6 +856,17 @@ export class WebGLPreview {
857856
this.devGui = new DevGUI(this, this.devMode);
858857
}
859858
}
859+
860+
private initStats() {
861+
if (this.stats) {
862+
if (typeof this.devMode === 'object') {
863+
this.statsContainer = this.devMode.statsContainer;
864+
}
865+
(this.statsContainer ?? document.body).appendChild(this.stats.dom);
866+
this.stats.dom.classList.add('stats');
867+
this.initGui();
868+
}
869+
}
860870
}
861871

862872
function decode(uint8array: Uint8Array) {

0 commit comments

Comments
 (0)