This commit is contained in:
syuilo 2026-04-02 21:30:37 +09:00
commit b91409f5c6
7 changed files with 39 additions and 39 deletions

View file

@ -271,7 +271,7 @@ type ObjectDef<OpSc extends OptionsSchema = OptionsSchema> = {
root: BABYLON.Mesh;
options: Readonly<GetOptionsSchemaValues<OpSc>>;
model: ModelManager;
}) => RoomObjectInstance<GetOptionsSchemaValues<OpSc>>;
}) => RoomObjectInstance<GetOptionsSchemaValues<OpSc>> | Promise<RoomObjectInstance<GetOptionsSchemaValues<OpSc>>>; // TODO: createInstanceをasyncにするのではなく、別にreadyみたいなものを返させる
};
export function defineObject<const OpSc extends OptionsSchema>(def: ObjectDef<OpSc>): ObjectDef<OpSc> {
@ -1061,7 +1061,7 @@ export class RoomEngine {
meshUpdated(meshes);
});
const objectInstance = def.createInstance({
const objectInstance = await def.createInstance({
room: this,
scene: this.scene,
root,
@ -1640,7 +1640,7 @@ export class RoomObjectPreviewEngine {
meshUpdated(loaderResult.meshes);
const objectInstance = def.createInstance({
const objectInstance = await def.createInstance({
room: null,
scene: this.scene,
root,

View file

@ -46,7 +46,7 @@ export const allInOnePc = defineObject({
},
},
placement: 'top',
createInstance: ({ scene, options, model }) => {
createInstance: async ({ scene, options, model }) => {
const screenMesh = model.findMesh('__X_SCREEN__');
const bodyMaterial = model.findMaterial('__X_BODY__');
@ -70,7 +70,7 @@ export const allInOnePc = defineObject({
applyFit();
const applyCustomPicture = () => {
const applyCustomPicture = () => new Promise<void>((resolve) => {
if (options.customPicture != null) {
const tex = new BABYLON.Texture(options.customPicture, scene, false, false);
tex.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
@ -79,17 +79,17 @@ export const allInOnePc = defineObject({
screenMaterial.emissiveTexture = tex;
applyFit();
tex.onLoadObservable.addOnce(() => {
applyFit();
resolve();
});
} else {
screenMaterial.emissiveTexture = null;
resolve();
}
};
});
applyCustomPicture();
await applyCustomPicture();
const applyScreenBrightness = () => {
const b = options.screenBrightness;

View file

@ -54,7 +54,7 @@ export const laptopPc = defineObject({
},
},
placement: 'top',
createInstance: ({ scene, options, model }) => {
createInstance: async ({ scene, options, model }) => {
const screenMesh = model.findMesh('__X_SCREEN__');
const hutaNode = model.findTransformNode('__X_HUTA__');
@ -79,7 +79,7 @@ export const laptopPc = defineObject({
applyFit();
const applyCustomPicture = () => {
const applyCustomPicture = () => new Promise<void>((resolve) => {
if (options.customPicture != null) {
const tex = new BABYLON.Texture(options.customPicture, scene, false, false);
tex.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
@ -88,17 +88,17 @@ export const laptopPc = defineObject({
screenMaterial.emissiveTexture = tex;
applyFit();
tex.onLoadObservable.addOnce(() => {
applyFit();
resolve();
});
} else {
screenMaterial.emissiveTexture = null;
resolve();
}
};
});
applyCustomPicture();
await applyCustomPicture();
const applyScreenBrightness = () => {
const b = options.screenBrightness;

View file

@ -83,7 +83,7 @@ export const pictureFrame = defineObject({
},
},
placement: 'side',
createInstance: ({ scene, options, model }) => {
createInstance: async ({ scene, options, model }) => {
const frameMesh = model.findMesh('__X_FRAME__');
frameMesh.rotationQuaternion = null;
const matMesh = model.findMesh('__X_MAT__');
@ -156,7 +156,7 @@ export const pictureFrame = defineObject({
applyDepth();
const applyCustomPicture = () => {
const applyCustomPicture = () => new Promise<void>((resolve) => {
if (options.customPicture != null) {
const tex = new BABYLON.Texture(options.customPicture, scene, false, false);
tex.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
@ -165,18 +165,18 @@ export const pictureFrame = defineObject({
pictureMaterial.albedoColor = new BABYLON.Color3(1, 1, 1);
pictureMaterial.albedoTexture = tex;
applyFit();
tex.onLoadObservable.addOnce(() => {
applyFit();
resolve();
});
} else {
pictureMaterial.albedoColor = new BABYLON.Color3(0.5, 0.5, 0.5);
pictureMaterial.albedoTexture = null;
resolve();
}
};
});
applyCustomPicture();
await applyCustomPicture();
const frameMaterial = model.findMaterial('__X_FRAME__');

View file

@ -44,7 +44,7 @@ export const poster = defineObject({
},
},
placement: 'side',
createInstance: ({ scene, options, model }) => {
createInstance: async ({ scene, options, model }) => {
const pictureMesh = model.findMesh('__X_PICTURE__');
pictureMesh.rotationQuaternion = null;
@ -84,7 +84,7 @@ export const poster = defineObject({
applySize();
const applyCustomPicture = () => {
const applyCustomPicture = () => new Promise<void>((resolve) => {
if (options.customPicture != null) {
const tex = new BABYLON.Texture(options.customPicture, scene, false, false);
tex.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
@ -93,18 +93,18 @@ export const poster = defineObject({
pictureMaterial.albedoColor = new BABYLON.Color3(1, 1, 1);
pictureMaterial.albedoTexture = tex;
applyFit();
tex.onLoadObservable.addOnce(() => {
applyFit();
resolve();
});
} else {
pictureMaterial.albedoColor = new BABYLON.Color3(0.5, 0.5, 0.5);
pictureMaterial.albedoTexture = null;
resolve();
}
};
});
applyCustomPicture();
await applyCustomPicture();
return {
onInited: () => {

View file

@ -83,7 +83,7 @@ export const tabletopPictureFrame = defineObject({
},
},
placement: 'top',
createInstance: ({ scene, options, model }) => {
createInstance: async ({ scene, options, model }) => {
const frameMesh = model.findMesh('__X_FRAME__');
frameMesh.rotationQuaternion = null;
const matMesh = model.findMesh('__X_MAT__');
@ -161,7 +161,7 @@ export const tabletopPictureFrame = defineObject({
applyDepth();
const applyCustomPicture = () => {
const applyCustomPicture = () => new Promise<void>((resolve) => {
if (options.customPicture != null) {
const tex = new BABYLON.Texture(options.customPicture, scene, false, false);
tex.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
@ -170,18 +170,18 @@ export const tabletopPictureFrame = defineObject({
pictureMaterial.albedoColor = new BABYLON.Color3(1, 1, 1);
pictureMaterial.albedoTexture = tex;
applyFit();
tex.onLoadObservable.addOnce(() => {
applyFit();
resolve();
});
} else {
pictureMaterial.albedoColor = new BABYLON.Color3(0.5, 0.5, 0.5);
pictureMaterial.albedoTexture = null;
resolve();
}
};
});
applyCustomPicture();
await applyCustomPicture();
const frameMaterial = model.findMaterial('__X_FRAME__');

View file

@ -44,7 +44,7 @@ export const tapestry = defineObject({
},
},
placement: 'side',
createInstance: ({ scene, options, model }) => {
createInstance: async ({ scene, options, model }) => {
const pictureMesh = model.findMesh('__X_PICTURE__');
pictureMesh.rotationQuaternion = null;
@ -88,7 +88,7 @@ export const tapestry = defineObject({
applySize();
const applyCustomPicture = () => {
const applyCustomPicture = () => new Promise<void>((resolve) => {
if (options.customPicture != null) {
const tex = new BABYLON.Texture(options.customPicture, scene, false, false);
tex.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
@ -97,18 +97,18 @@ export const tapestry = defineObject({
pictureMaterial.albedoColor = new BABYLON.Color3(1, 1, 1);
pictureMaterial.albedoTexture = tex;
applyFit();
tex.onLoadObservable.addOnce(() => {
applyFit();
resolve();
});
} else {
pictureMaterial.albedoColor = new BABYLON.Color3(0.5, 0.5, 0.5);
pictureMaterial.albedoTexture = null;
resolve();
}
};
});
applyCustomPicture();
await applyCustomPicture();
return {
onInited: () => {