Skip to content

Commit

Permalink
fixes issues with texture loading, see #231
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwoert committed Jan 30, 2024
1 parent 0b43cc4 commit ab983cf
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class MagicCircle {
}
});

// Receive default values by hydrating (one reload for example)
// Receive default values by hydrating (on reload for example)
const hydration = await this.ipc.invoke<Record<string, any>>('hydrate');
(this.plugins || []).forEach((p) => {
if (p.hydrate && hydration) {
Expand Down
5 changes: 5 additions & 0 deletions core/client/src/controls/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ export default class ImageControl extends Control<string | ImageBitmap> {
this.label('Image');
}
}

// disable watching on images...
watch() {
return this;
}
}
4 changes: 4 additions & 0 deletions core/editor/src/app/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ const config: Config = {
plugins,
controls,
settings: {
layers: {
hydrate: true,
},
screenshots: {
directoryBasedOnFrameUrl: false,
gitInfo: true,
share: true,
},
playControls: {
fullscreen: false,
Expand Down
7 changes: 7 additions & 0 deletions core/gltf/magic.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export default {
directoryBasedOnFrameUrl: true,
screenshots: {
gitInfo: false,
share: false,
},
layers: {
hydrate: false,
},
playControls: {
fullScreen: true,
},
},
};
4 changes: 4 additions & 0 deletions core/schema/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,13 @@ export interface Config {
settings: {
pageTitle?: string;
iframeAllow?: string;
layers?: {
hydrate?: boolean;
};
screenshots?: {
directoryBasedOnFrameUrl?: boolean;
gitInfo?: boolean;
share?: boolean;
};
playControls?: {
fullscreen?: boolean;
Expand Down
14 changes: 9 additions & 5 deletions plugins/layers/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ export default class Layers extends Plugin {

hydrate() {
const hydrate: Record<string, any> = {};
this.lookup.export((key, value) => {
if ('value' in value && !value.blockHydrate) {
hydrate[key] = value.value;
}
});

if (this.app.getSetting('layers.hydrate', true)) {
this.lookup.export((key, value) => {
if ('value' in value && !value.blockHydrate) {
hydrate[key] = value.value;
}
});
}

return hydrate;
}

Expand Down
1 change: 1 addition & 0 deletions plugins/screenshots/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default class Screenshots extends Plugin {
label: 'copy',
icon: 'Share',
tooltip: 'Share current settings',
hide: this.app.getSetting('screenshots.share') === false,
wrap: (inside) => (
<MenuPortal
showOnClick
Expand Down
20 changes: 14 additions & 6 deletions plugins/three/src/TextureFolder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
import {
BooleanControl,
Control,
Expand All @@ -15,7 +16,7 @@ type TextureFolderSettings = {
export class TextureFolder extends Folder {
constructor(
label: string,
reference: Control<any>['reference'],
reference: { needsUpdate: boolean } & Control<any>['reference'],
key: string,
settings: TextureFolderSettings = {}
) {
Expand All @@ -34,11 +35,10 @@ export class TextureFolder extends Folder {
.label('Use texture')
.on('update', (newVal) => {
if (newVal) {
// eslint-disable-next-line
reference[key] = new Texture();
} else {
// eslint-disable-next-line
reference[key] = undefined;
reference.needsUpdate = true;
}

if (settings.onChange) settings.onChange();
Expand All @@ -48,9 +48,17 @@ export class TextureFolder extends Folder {

if (obj.on) {
controls.push(
new NumberControl(value, 'wrapS'),
new NumberControl(value, 'wrapT'),
new ImageControl(value.source, 'data').label('Image')
new NumberControl(value.repeat, 'x').label('repeat x'),
new NumberControl(value.repeat, 'y').label('repeat y'),
new NumberControl(value.offset, 'x').range(-1, 1).label('offset x'),
new NumberControl(value.offset, 'y').range(-1, 1).label('offset y'),
new ImageControl(value.source, 'data')
.label('Image')
.on('update', (newVal) => {
value.source.data = newVal;
value.needsUpdate = true;
reference.needsUpdate = true;
})
);
}

Expand Down

0 comments on commit ab983cf

Please sign in to comment.