|
1 |
| -import {TextureStore} from '@spearwolf/twopoint5d'; |
2 |
| -import {Stage2DElement} from '@spearwolf/twopoint5d-elements'; |
| 1 | +import {Stage2DElement, TextureStoreElement} from '@spearwolf/twopoint5d-elements'; |
3 | 2 | import '@spearwolf/twopoint5d-elements/two5-display.js';
|
4 | 3 | import '@spearwolf/twopoint5d-elements/two5-stage2d.js';
|
| 4 | +import '@spearwolf/twopoint5d-elements/two5-texture-store.js'; |
5 | 5 | import {Color, Scene, Sprite, SpriteMaterial} from 'three';
|
6 | 6 | import './display.css';
|
7 | 7 | import './style.css';
|
8 | 8 |
|
9 |
| -console.log('hej ho!'); |
| 9 | +const initialize = async (action: (stageEl: Stage2DElement, storeEl: TextureStoreElement) => void) => { |
| 10 | + const [stageEl, storeEl] = await Promise.all([ |
| 11 | + Stage2DElement.whenDefined(document.getElementById('stage2d')), |
| 12 | + TextureStoreElement.whenDefined(document.getElementById('texstore')), |
| 13 | + ]); |
| 14 | + action(stageEl, storeEl); |
| 15 | +}; |
10 | 16 |
|
11 |
| -const textures = new TextureStore().load('/assets/textures.json'); |
12 |
| - |
13 |
| -Stage2DElement.whenDefined(document.getElementById('stage2d')).then((el) => { |
14 |
| - // let renderFrameLogCount = 0; |
15 |
| - |
16 |
| - // el.addEventListener(StageResize, (e: StageResizeEvent) => { |
17 |
| - // renderFrameLogCount = 0; |
18 |
| - // console.debug(StageResize, e.detail); |
19 |
| - // }); |
20 |
| - |
21 |
| - el.sceneReady().then((scene: Scene) => { |
| 17 | +initialize((stageEl, {store}) => { |
| 18 | + stageEl.sceneReady().then((scene: Scene) => { |
22 | 19 | scene.background = new Color(0x212121);
|
23 |
| - }); |
24 |
| - |
25 |
| - el.firstFrame().then(({renderer, scene}) => { |
26 |
| - textures.renderer = renderer; |
27 | 20 |
|
28 | 21 | const sprite = new Sprite();
|
29 | 22 | sprite.scale.set(197, 205, 1);
|
30 | 23 | scene.add(sprite);
|
31 | 24 |
|
32 |
| - textures.get('ballPatternRot', ['texture', 'imageCoords'], ([texture, imageCoords]) => { |
| 25 | + store.get('ballPatternRot', ['texture', 'imageCoords'], ([texture, imageCoords]) => { |
33 | 26 | console.log('texture', {texture, imageCoords});
|
34 | 27 |
|
35 | 28 | sprite.material?.dispose();
|
36 | 29 | sprite.material = new SpriteMaterial({map: texture});
|
37 | 30 | });
|
38 | 31 | });
|
39 |
| - |
40 |
| - // el.on(StageRenderFrame, (props: StageRenderFrameProps) => { |
41 |
| - // if (renderFrameLogCount++ < 3) { |
42 |
| - // console.debug(StageRenderFrame, props.frameNo, props); |
43 |
| - // } |
44 |
| - // }); |
45 | 32 | });
|
0 commit comments