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

Various improvement #105

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion app/modifiers/three-renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Modifier, { ArgsFor } from 'ember-modifier';
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import { OrbitControls } from 'text2stl/utils/OrbitControls';
import { tracked } from '@glimmer/tracking';
import config from 'text2stl/config/environment';
import { registerDestructor } from '@ember/destroyable';
Expand Down
3 changes: 2 additions & 1 deletion app/routes/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default class AppRoute extends Route {

async model({ locale }: { locale: string }) {
this.intl.locale = locale === 'en-us' ? locale : [locale, 'en-us'];
await this.fontManager.loadFontList();
// No await here, let's the loading happen & await for it in generator route
this.fontManager.loadFontList();
}

updateMeta(transition: Transition) {
Expand Down
7 changes: 6 additions & 1 deletion app/routes/app/generator.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import type FontManagerService from 'text2stl/services/font-manager';
import TextMakerSettings from 'text2stl/models/text-maker-settings';
import config from 'text2stl/config/environment';

const {
APP: { textMakerDefault },
} = config;

export default class ApplicationRoute extends Route {
export default class GeneratorRoute extends Route {
@service declare fontManager: FontManagerService;

queryParams = {
modelSettings: {
replace: true, // No history for model changes
},
};

async model(params: { modelSettings: string }) {
await this.fontManager.loadFontList();
// Create a default settings for first rendering
const model = new TextMakerSettings({
...textMakerDefault,
Expand Down
23 changes: 0 additions & 23 deletions app/routes/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
import Route from '@ember/routing/route';
import * as THREE from 'three';

let loader: THREE.ObjectLoader | undefined = undefined;

function loadJSONMesh(path: string): Promise<THREE.Object3D> {
if (!loader) {
loader = new THREE.ObjectLoader();
}

return new Promise(function (resolve, reject) {
loader?.load(path, resolve, () => {}, reject);
});
}

export default class AppIndex extends Route {
async model() {
return [
await loadJSONMesh('/mesh/1.json'),
await loadJSONMesh('/mesh/2.json'),
await loadJSONMesh('/mesh/3.json'),
await loadJSONMesh('/mesh/4.json'),
await loadJSONMesh('/mesh/5.json'),
];
}

afterModel() {
document.querySelector('#app-loader')?.remove();
}
Expand Down
9 changes: 9 additions & 0 deletions app/services/font-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ export default class FontManagerService extends Service {
return fetch(input, init);
}

loadFontListPromise: undefined | Promise<void> = undefined;
async loadFontList() {
if (!this.loadFontListPromise) {
this.loadFontListPromise = this._loadFontList();
}

await this.loadFontListPromise;
}

async _loadFontList() {
for (const category of this.availableFontCategories) {
const fontManager = new FontManager(googleFontApiKey, FONT_FAMILY_DEFAULT, {
...OPTIONS_DEFAULTS,
Expand Down
2 changes: 1 addition & 1 deletion app/services/stl-exporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Service from '@ember/service';
import { STLExporter } from 'three/examples/jsm/exporters/STLExporter';
import { STLExporter } from 'text2stl/utils/STLExporter';

import type { Mesh } from 'three';

Expand Down
2 changes: 1 addition & 1 deletion app/services/text-maker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Service from '@ember/service';
import * as opentype from 'opentype.js';
import * as THREE from 'three';
import { mergeBufferGeometries } from 'three/examples/jsm/utils/BufferGeometryUtils';
import { mergeBufferGeometries } from 'text2stl/utils/BufferGeometryUtils';
import config from 'text2stl/config/environment';
import { generateSupportShape } from 'text2stl/misc/support-shape-generation';

Expand Down
22 changes: 1 addition & 21 deletions app/templates/app/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,11 @@
<dd>{{t "index_page.list.stl.dd"}}</dd>
</dl>
</div>
<div class="uk-card-media-bottom">
<div uk-slideshow="animation: fade; autoplay: true; autoplay-interval: 3000; ratio: 7:3; max-height: 250; draggable: false">
<ul class="uk-slideshow-items">
{{#each this.model as |mesh idx|}}
<ThreePreview @mesh={{mesh}} as |preview|>
<li>
<preview.renderer @parentSize={{true}} @nearCamera={{true}} />
<div class="uk-position-bottom uk-position-small uk-text-center">
<h4 class="uk-margin-remove uk-text-primary">
{{t (concat "text_type." (plus idx))}}
</h4>
</div>
</li>
</ThreePreview>
{{/each}}
</ul>
<ul class="uk-slideshow-nav uk-dotnav uk-flex-center uk-margin"></ul>
</div>
</div>
<div class="uk-card-footer">
<LinkTo @route="app.generator" class="uk-button uk-button-primary uk-align-center">
{{t "index_page.button"}}
</LinkTo>
</div>
</div>
</div>
</div>

</div>
Loading