1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-06-05 11:44:08 +02:00
This commit is contained in:
syuilo
2026-04-02 14:15:52 +09:00
parent a01bbf828d
commit ea8df304c9
22 changed files with 193 additions and 147 deletions

View File

@@ -146,6 +146,97 @@ type GetOptionsSchemaValues<T extends OptionsSchema> = {
never; never;
}; };
class ModelManager {
public root: BABYLON.Mesh;
public updatedCallback: (() => void) | null = null;
private bakedMeshes: BABYLON.Mesh[] = [];
constructor(root: BABYLON.Mesh, updatedCallback: (() => void) | null = null) {
this.root = root;
this.updatedCallback = updatedCallback;
}
public findMesh(keyword: string) {
const mesh = this.root.getChildMeshes().find(m => m.name.includes(keyword));
if (mesh == null) {
throw new Error(`Mesh with keyword "${keyword}" not found for object ${this.root.metadata?.objectType}`);
}
return mesh as BABYLON.Mesh;
}
public findMeshes(keyword: string) {
const meshes = this.root.getChildMeshes().filter(m => m.name.includes(keyword));
return meshes as BABYLON.Mesh[];
}
public findMaterial(keyword: string) {
return findMaterial(this.root, keyword);
}
public findTransformNode(keyword: string) {
const node = this.root.getChildTransformNodes().find(n => n.name.includes(keyword));
if (node == null) {
throw new Error(`TransformNode with keyword "${keyword}" not found for object ${this.root.metadata?.objectType}`);
}
return node;
}
public updated() {
this.bakeMesh();
this.updatedCallback?.(this.bakedMeshes.length > 0 ? this.bakedMeshes : this.root.getChildMeshes());
}
public bakeMesh() {
try {
for (const m of this.bakedMeshes) {
m.dispose();
}
this.bakedMeshes = [];
const childMeshes = this.root.getChildMeshes().filter(m => !m.name.includes('__TOP__') && !m.name.includes('__SIDE__') && !m.name.includes('__COLLISION__'));
if (childMeshes.length <= 1) {
return;
}
const toMerge = [] as BABYLON.Mesh[];
for (const mesh of childMeshes) {
let fixedMesh = mesh;
if (mesh instanceof BABYLON.InstancedMesh) {
const sourceMesh = mesh.sourceMesh;
const newMesh = sourceMesh.clone(mesh.name + '_baked');
newMesh.position = mesh.position.clone();
if (mesh.rotationQuaternion) {
newMesh.rotationQuaternion = mesh.rotationQuaternion.clone();
} else {
newMesh.rotation = mesh.rotation.clone();
}
newMesh.scaling = mesh.scaling.clone();
newMesh.parent = mesh.parent;
mesh.dispose();
fixedMesh = newMesh;
}
fixedMesh.isVisible = false;
toMerge.push(fixedMesh);
}
const merged = BABYLON.Mesh.MergeMeshes(toMerge, false, true, undefined, false, true);
merged.setParent(this.root);
this.bakedMeshes = [merged];
} catch (err) {
console.error('Failed to bake mesh for object', this.root.metadata?.objectType, err);
}
}
}
type ObjectDef<OpSc extends OptionsSchema = OptionsSchema> = { type ObjectDef<OpSc extends OptionsSchema = OptionsSchema> = {
id: string; id: string;
name: string; name: string;
@@ -162,12 +253,7 @@ type ObjectDef<OpSc extends OptionsSchema = OptionsSchema> = {
scene: BABYLON.Scene; scene: BABYLON.Scene;
root: BABYLON.Mesh; root: BABYLON.Mesh;
options: Readonly<GetOptionsSchemaValues<OpSc>>; options: Readonly<GetOptionsSchemaValues<OpSc>>;
loaderResult: BABYLON.ISceneLoaderAsyncResult; model: ModelManager;
meshUpdated: () => void;
findMesh: (keyword: string) => BABYLON.Mesh;
findMeshes: (keyword: string) => BABYLON.Mesh[];
findMaterial: (keyword: string) => BABYLON.PBRMaterial;
findTransformNode: (keyword: string) => BABYLON.TransformNode;
}) => RoomObjectInstance<GetOptionsSchemaValues<OpSc>>; }) => RoomObjectInstance<GetOptionsSchemaValues<OpSc>>;
}; };
@@ -952,40 +1038,22 @@ export class RoomEngine {
meshUpdated(loaderResult.meshes); meshUpdated(loaderResult.meshes);
const model = new ModelManager(subRoot, (meshes) => {
meshUpdated(meshes);
});
const objectInstance = def.createInstance({ const objectInstance = def.createInstance({
room: this, room: this,
scene: this.scene, scene: this.scene,
root, root,
options: args.options, options: args.options,
loaderResult: loaderResult, model,
meshUpdated: () => {
meshUpdated(root.getChildMeshes());
},
findMesh: (keyword) => {
const mesh = root.getChildMeshes().find(m => m.name.includes(keyword));
if (mesh == null) {
throw new Error(`Mesh with keyword "${keyword}" not found for object ${args.type}`);
}
return mesh as BABYLON.Mesh;
},
findMeshes: (keyword) => {
const meshes = root.getChildMeshes().filter(m => m.name.includes(keyword));
return meshes as BABYLON.Mesh[];
},
findMaterial: (keyword) => {
return findMaterial(root, keyword);
},
findTransformNode: (keyword) => {
const node = root.getChildTransformNodes().find(n => n.name.includes(keyword));
if (node == null) {
throw new Error(`TransformNode with keyword "${keyword}" not found for object ${args.type}`);
}
return node;
},
}); });
objectInstance.onInited?.(); objectInstance.onInited?.();
model.updated();
this.objectInstances.set(args.id, objectInstance); this.objectInstances.set(args.id, objectInstance);
this.objectMeshs.set(args.id, root); this.objectMeshs.set(args.id, root);
@@ -1558,31 +1626,9 @@ export class RoomObjectPreviewEngine {
scene: this.scene, scene: this.scene,
root, root,
options: args.options, options: args.options,
loaderResult: loaderResult, model: new ModelManager(subRoot, (meshes) => {
meshUpdated: () => { meshUpdated(meshes);
meshUpdated(root.getChildMeshes()); }),
},
findMesh: (keyword) => {
const mesh = root.getChildMeshes().find(m => m.name.includes(keyword));
if (mesh == null) {
throw new Error(`Mesh with keyword "${keyword}" not found for object ${args.type}`);
}
return mesh as BABYLON.Mesh;
},
findMeshes: (keyword) => {
const meshes = root.getChildMeshes().filter(m => m.name.includes(keyword));
return meshes as BABYLON.Mesh[];
},
findMaterial: (keyword) => {
return findMaterial(root, keyword);
},
findTransformNode: (keyword) => {
const node = root.getChildTransformNodes().find(n => n.name.includes(keyword));
if (node == null) {
throw new Error(`TransformNode with keyword "${keyword}" not found for object ${args.type}`);
}
return node;
},
}); });
objectInstance.onInited?.(); objectInstance.onInited?.();

View File

@@ -21,8 +21,8 @@ export const a4Case = defineObject({
}, },
}, },
placement: 'top', placement: 'top',
createInstance: ({ options, findMesh }) => { createInstance: ({ options, model }) => {
const bodyMesh = findMesh('__X_BODY__'); const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial; const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;
const applyColor = () => { const applyColor = () => {

View File

@@ -46,12 +46,12 @@ export const allInOnePc = defineObject({
}, },
}, },
placement: 'top', placement: 'top',
createInstance: ({ scene, options, findMesh, findMaterial }) => { createInstance: ({ scene, options, model }) => {
const screenMesh = findMesh('__X_SCREEN__'); const screenMesh = model.findMesh('__X_SCREEN__');
const bodyMaterial = findMaterial('__X_BODY__'); const bodyMaterial = model.findMaterial('__X_BODY__');
const bezelMaterial = findMaterial('__X_BEZEL__'); const bezelMaterial = model.findMaterial('__X_BEZEL__');
const screenMaterial = findMaterial('__X_SCREEN__'); const screenMaterial = model.findMaterial('__X_SCREEN__');
screenMaterial.ambientColor = new BABYLON.Color3(0, 0, 0); screenMaterial.ambientColor = new BABYLON.Color3(0, 0, 0);
screenMaterial.albedoColor = new BABYLON.Color3(0, 0, 0); screenMaterial.albedoColor = new BABYLON.Color3(0, 0, 0);

View File

@@ -26,11 +26,11 @@ export const aromaReedDiffuser = defineObject({
}, },
}, },
placement: 'top', placement: 'top',
createInstance: ({ options, findMesh }) => { createInstance: ({ options, model }) => {
const bottleMesh = findMesh('__X_BOTTLE__'); const bottleMesh = model.findMesh('__X_BOTTLE__');
const bottleMaterial = bottleMesh.material as BABYLON.PBRMaterial; const bottleMaterial = bottleMesh.material as BABYLON.PBRMaterial;
const oilMesh = findMesh('__X_OIL__'); const oilMesh = model.findMesh('__X_OIL__');
const oilMaterial = oilMesh.material as BABYLON.PBRMaterial; const oilMaterial = oilMesh.material as BABYLON.PBRMaterial;
const applyBottleColor = () => { const applyBottleColor = () => {

View File

@@ -21,8 +21,8 @@ export const bed = defineObject({
}, },
}, },
placement: 'floor', placement: 'floor',
createInstance: ({ options, findMesh }) => { createInstance: ({ options, model }) => {
const bodyMesh = findMesh('__X_BODY__'); const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial; const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;
const applyColor = () => { const applyColor = () => {

View File

@@ -40,13 +40,13 @@ export const blind = defineObject({
}, },
}, },
placement: 'bottom', placement: 'bottom',
createInstance: ({ options, loaderResult, meshUpdated }) => { createInstance: ({ options, model }) => {
const temp = createOverridedStates({ const temp = createOverridedStates({
angle: () => options.angle, angle: () => options.angle,
open: () => options.open, open: () => options.open,
}); });
const blade = loaderResult.meshes[0].getChildMeshes().find(m => m.name === 'Blade') as BABYLON.Mesh; const blade = model.root.getChildMeshes().find(m => m.name === 'Blade') as BABYLON.Mesh;
blade.rotation = new BABYLON.Vector3(options.angle, 0, 0); blade.rotation = new BABYLON.Vector3(options.angle, 0, 0);
let blades = [] as BABYLON.Mesh[]; let blades = [] as BABYLON.Mesh[];
@@ -67,7 +67,7 @@ export const blind = defineObject({
blades.push(b); blades.push(b);
} }
meshUpdated(); model.updated();
}; };
const applyAngle = () => { const applyAngle = () => {

View File

@@ -23,8 +23,8 @@ export const books = defineObject({
}, },
placement: 'top', placement: 'top',
mergeMeshes: ['__X_BOOK_1__', '__X_BOOK_2__', '__X_BOOK_3__', '__X_BOOK_4__', '__X_BOOK_5__', '__X_BOOK_6__', '__X_BOOK_7__', '__X_BOOK_8__', '__X_BOOK_9__', '__X_BOOK_10__'], mergeMeshes: ['__X_BOOK_1__', '__X_BOOK_2__', '__X_BOOK_3__', '__X_BOOK_4__', '__X_BOOK_5__', '__X_BOOK_6__', '__X_BOOK_7__', '__X_BOOK_8__', '__X_BOOK_9__', '__X_BOOK_10__'],
createInstance: ({ scene, options, findMesh, findMaterial }) => { createInstance: ({ scene, options, model }) => {
const coverMaterial = findMaterial('__X_COVER__'); const coverMaterial = model.findMaterial('__X_COVER__');
const applyVariation = () => { const applyVariation = () => {
const coverTexture = const coverTexture =
@@ -39,16 +39,16 @@ export const books = defineObject({
applyVariation(); applyVariation();
const bookMeshes = [ const bookMeshes = [
findMesh('__X_BOOK_1__'), model.findMesh('__X_BOOK_1__'),
findMesh('__X_BOOK_2__'), model.findMesh('__X_BOOK_2__'),
findMesh('__X_BOOK_3__'), model.findMesh('__X_BOOK_3__'),
findMesh('__X_BOOK_4__'), model.findMesh('__X_BOOK_4__'),
findMesh('__X_BOOK_5__'), model.findMesh('__X_BOOK_5__'),
findMesh('__X_BOOK_6__'), model.findMesh('__X_BOOK_6__'),
findMesh('__X_BOOK_7__'), model.findMesh('__X_BOOK_7__'),
findMesh('__X_BOOK_8__'), model.findMesh('__X_BOOK_8__'),
findMesh('__X_BOOK_9__'), model.findMesh('__X_BOOK_9__'),
findMesh('__X_BOOK_10__'), model.findMesh('__X_BOOK_10__'),
]; ];
for (const mesh of bookMeshes) { for (const mesh of bookMeshes) {

View File

@@ -21,8 +21,8 @@ export const cactusS = defineObject({
}, },
}, },
placement: 'top', placement: 'top',
createInstance: ({ options, findMesh }) => { createInstance: ({ options, model }) => {
const potMesh = findMesh('__X_POT__'); const potMesh = model.findMesh('__X_POT__');
const potMaterial = potMesh.material as BABYLON.PBRMaterial; const potMaterial = potMesh.material as BABYLON.PBRMaterial;
const applyPotColor = () => { const applyPotColor = () => {

View File

@@ -27,11 +27,11 @@ export const chair = defineObject({
}, },
placement: 'floor', placement: 'floor',
isChair: true, isChair: true,
createInstance: ({ findMesh, options }) => { createInstance: ({ model, options }) => {
const primaryMesh = findMesh('__X_PRIMARY__'); const primaryMesh = model.findMesh('__X_PRIMARY__');
const primaryMaterial = primaryMesh.material as BABYLON.PBRMaterial; const primaryMaterial = primaryMesh.material as BABYLON.PBRMaterial;
const secondaryMesh = findMesh('__X_SECONDARY__'); const secondaryMesh = model.findMesh('__X_SECONDARY__');
const secondaryMaterial = secondaryMesh.material as BABYLON.PBRMaterial; const secondaryMaterial = secondaryMesh.material as BABYLON.PBRMaterial;
const applyPrimaryColor = () => { const applyPrimaryColor = () => {

View File

@@ -21,8 +21,8 @@ export const colorBox = defineObject({
}, },
}, },
placement: 'floor', placement: 'floor',
createInstance: ({ options, findMesh }) => { createInstance: ({ options, model }) => {
const bodyMesh = findMesh('__X_BODY__'); const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial; const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;
const applyColor = () => { const applyColor = () => {

View File

@@ -21,8 +21,8 @@ export const desk = defineObject({
}, },
}, },
placement: 'floor', placement: 'floor',
createInstance: ({ options, findMaterial }) => { createInstance: ({ options, model }) => {
const topMaterial = findMaterial('__X_BODY__'); const topMaterial = model.findMaterial('__X_BODY__');
const applyTopColor = () => { const applyTopColor = () => {
const [r, g, b] = options.topColor; const [r, g, b] = options.topColor;

View File

@@ -54,13 +54,13 @@ export const laptopPc = defineObject({
}, },
}, },
placement: 'top', placement: 'top',
createInstance: ({ scene, options, findMesh, findMaterial, findTransformNode }) => { createInstance: ({ scene, options, model }) => {
const screenMesh = findMesh('__X_SCREEN__'); const screenMesh = model.findMesh('__X_SCREEN__');
const hutaNode = findTransformNode('__X_HUTA__'); const hutaNode = model.findTransformNode('__X_HUTA__');
const bodyMaterial = findMaterial('__X_BODY__'); const bodyMaterial = model.findMaterial('__X_BODY__');
const bezelMaterial = findMaterial('__X_BEZEL__'); const bezelMaterial = model.findMaterial('__X_BEZEL__');
const screenMaterial = findMaterial('__X_SCREEN__'); const screenMaterial = model.findMaterial('__X_SCREEN__');
screenMaterial.ambientColor = new BABYLON.Color3(0, 0, 0); screenMaterial.ambientColor = new BABYLON.Color3(0, 0, 0);
screenMaterial.albedoColor = new BABYLON.Color3(0, 0, 0); screenMaterial.albedoColor = new BABYLON.Color3(0, 0, 0);

View File

@@ -21,8 +21,8 @@ export const monitorSpeaker = defineObject({
}, },
}, },
placement: 'top', placement: 'top',
createInstance: ({ options, findMesh }) => { createInstance: ({ options, model }) => {
const bodyMesh = findMesh('__X_BODY__'); const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial; const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;
const applyColor = () => { const applyColor = () => {

View File

@@ -26,9 +26,9 @@ export const petBottle = defineObject({
}, },
}, },
placement: 'top', placement: 'top',
createInstance: ({ findMesh, options }) => { createInstance: ({ model, options }) => {
const capMesh = findMesh('__X_CAP__'); const capMesh = model.findMesh('__X_CAP__');
const liquidMesh = findMesh('__X_LIQUID__'); const liquidMesh = model.findMesh('__X_LIQUID__');
const applyWithCap = () => { const applyWithCap = () => {
capMesh.setEnabled(options.withCap); capMesh.setEnabled(options.withCap);

View File

@@ -83,17 +83,17 @@ export const pictureFrame = defineObject({
}, },
}, },
placement: 'side', placement: 'side',
createInstance: ({ scene, options, findMaterial, findMesh, meshUpdated }) => { createInstance: ({ scene, options, model }) => {
const frameMesh = findMesh('__X_FRAME__'); const frameMesh = model.findMesh('__X_FRAME__');
frameMesh.rotationQuaternion = null; frameMesh.rotationQuaternion = null;
const matMesh = findMesh('__X_MAT__'); const matMesh = model.findMesh('__X_MAT__');
matMesh.rotationQuaternion = null; matMesh.rotationQuaternion = null;
const coverMesh = findMesh('__X_COVER__'); const coverMesh = model.findMesh('__X_COVER__');
coverMesh.rotationQuaternion = null; coverMesh.rotationQuaternion = null;
const pictureMesh = findMesh('__X_PICTURE__'); const pictureMesh = model.findMesh('__X_PICTURE__');
pictureMesh.rotationQuaternion = null; pictureMesh.rotationQuaternion = null;
const pictureMaterial = findMaterial('__X_PICTURE__'); const pictureMaterial = model.findMaterial('__X_PICTURE__');
const updateUv = createPlaneUvMapper(pictureMesh); const updateUv = createPlaneUvMapper(pictureMesh);
@@ -115,7 +115,7 @@ export const pictureFrame = defineObject({
const applyFrameThickness = () => { const applyFrameThickness = () => {
frameMesh.morphTargetManager!.getTargetByName('Thickness')!.influence = options.frameThickness; frameMesh.morphTargetManager!.getTargetByName('Thickness')!.influence = options.frameThickness;
meshUpdated(); model.updated();
}; };
applyFrameThickness(); applyFrameThickness();
@@ -126,7 +126,7 @@ export const pictureFrame = defineObject({
pictureMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width * (1 - options.matHThickness); pictureMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width * (1 - options.matHThickness);
pictureMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height * (1 - options.matVThickness); pictureMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height * (1 - options.matVThickness);
matMesh.isVisible = options.matHThickness > 0 || options.matVThickness > 0; matMesh.isVisible = options.matHThickness > 0 || options.matVThickness > 0;
meshUpdated(); model.updated();
applyFit(); applyFit();
}; };
@@ -140,7 +140,7 @@ export const pictureFrame = defineObject({
matMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height; matMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height;
coverMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width; coverMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width;
coverMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height; coverMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height;
meshUpdated(); model.updated();
applyMatThickness(); applyMatThickness();
}; };
@@ -151,7 +151,7 @@ export const pictureFrame = defineObject({
frameMesh.morphTargetManager!.getTargetByName('Depth')!.influence = options.depth; frameMesh.morphTargetManager!.getTargetByName('Depth')!.influence = options.depth;
//coverMesh.morphTargetManager!.getTargetByName('Depth')!.influence = options.depth; //coverMesh.morphTargetManager!.getTargetByName('Depth')!.influence = options.depth;
coverMesh.morphTargetManager!.getTargetByName('Depth')!.influence = 0; coverMesh.morphTargetManager!.getTargetByName('Depth')!.influence = 0;
meshUpdated(); model.updated();
}; };
applyDepth(); applyDepth();
@@ -178,7 +178,7 @@ export const pictureFrame = defineObject({
applyCustomPicture(); applyCustomPicture();
const frameMaterial = findMaterial('__X_FRAME__'); const frameMaterial = model.findMaterial('__X_FRAME__');
const applyFrameColor = () => { const applyFrameColor = () => {
const [r, g, b] = options.frameColor; const [r, g, b] = options.frameColor;

View File

@@ -44,13 +44,13 @@ export const poster = defineObject({
}, },
}, },
placement: 'side', placement: 'side',
createInstance: ({ scene, options, findMaterial, findMesh, findMeshes, meshUpdated }) => { createInstance: ({ scene, options, model }) => {
const pictureMesh = findMesh('__X_PICTURE__'); const pictureMesh = model.findMesh('__X_PICTURE__');
pictureMesh.rotationQuaternion = null; pictureMesh.rotationQuaternion = null;
const pictureMaterial = findMaterial('__X_PICTURE__'); const pictureMaterial = model.findMaterial('__X_PICTURE__');
const pinMeshes = findMeshes('__X_PIN__'); const pinMeshes = model.findMeshes('__X_PIN__');
const updateUv = createPlaneUvMapper(pictureMesh); const updateUv = createPlaneUvMapper(pictureMesh);
@@ -77,7 +77,7 @@ export const poster = defineObject({
pinMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width; pinMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width;
pinMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height; pinMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height;
} }
meshUpdated(); model.updated();
applyFit(); applyFit();
}; };

View File

@@ -26,11 +26,11 @@ export const speaker = defineObject({
}, },
}, },
placement: 'top', placement: 'top',
createInstance: ({ options, findMesh }) => { createInstance: ({ options, model }) => {
const outerMesh = findMesh('__X_COVER__'); const outerMesh = model.findMesh('__X_COVER__');
const outerMaterial = outerMesh.material as BABYLON.PBRMaterial; const outerMaterial = outerMesh.material as BABYLON.PBRMaterial;
const innerMesh = findMesh('__X_BODY__'); const innerMesh = model.findMesh('__X_BODY__');
const innerMaterial = innerMesh.material as BABYLON.PBRMaterial; const innerMaterial = innerMesh.material as BABYLON.PBRMaterial;
const applyOuterColor = () => { const applyOuterColor = () => {

View File

@@ -83,17 +83,17 @@ export const tabletopPictureFrame = defineObject({
}, },
}, },
placement: 'top', placement: 'top',
createInstance: ({ scene, options, findMaterial, findMesh, meshUpdated }) => { createInstance: ({ scene, options, model }) => {
const frameMesh = findMesh('__X_FRAME__'); const frameMesh = model.findMesh('__X_FRAME__');
frameMesh.rotationQuaternion = null; frameMesh.rotationQuaternion = null;
const matMesh = findMesh('__X_MAT__'); const matMesh = model.findMesh('__X_MAT__');
matMesh.rotationQuaternion = null; matMesh.rotationQuaternion = null;
const coverMesh = findMesh('__X_COVER__'); const coverMesh = model.findMesh('__X_COVER__');
coverMesh.rotationQuaternion = null; coverMesh.rotationQuaternion = null;
const pictureMesh = findMesh('__X_PICTURE__'); const pictureMesh = model.findMesh('__X_PICTURE__');
pictureMesh.rotationQuaternion = null; pictureMesh.rotationQuaternion = null;
const pictureMaterial = findMaterial('__X_PICTURE__'); const pictureMaterial = model.findMaterial('__X_PICTURE__');
const updateUv = createPlaneUvMapper(pictureMesh); const updateUv = createPlaneUvMapper(pictureMesh);
@@ -118,7 +118,7 @@ export const tabletopPictureFrame = defineObject({
coverMesh.morphTargetManager!.getTargetByName('FrameThickness')!.influence = options.frameThickness; coverMesh.morphTargetManager!.getTargetByName('FrameThickness')!.influence = options.frameThickness;
matMesh.morphTargetManager!.getTargetByName('FrameThickness')!.influence = options.frameThickness; matMesh.morphTargetManager!.getTargetByName('FrameThickness')!.influence = options.frameThickness;
pictureMesh.morphTargetManager!.getTargetByName('FrameThickness')!.influence = options.frameThickness; pictureMesh.morphTargetManager!.getTargetByName('FrameThickness')!.influence = options.frameThickness;
meshUpdated(); model.updated();
}; };
applyFrameThickness(); applyFrameThickness();
@@ -131,7 +131,7 @@ export const tabletopPictureFrame = defineObject({
pictureMesh.morphTargetManager!.getTargetByName('MatH')!.influence = options.matHThickness * options.width; pictureMesh.morphTargetManager!.getTargetByName('MatH')!.influence = options.matHThickness * options.width;
pictureMesh.morphTargetManager!.getTargetByName('MatV')!.influence = options.matVThickness * options.height; pictureMesh.morphTargetManager!.getTargetByName('MatV')!.influence = options.matVThickness * options.height;
matMesh.isVisible = options.matHThickness > 0 || options.matVThickness > 0; matMesh.isVisible = options.matHThickness > 0 || options.matVThickness > 0;
meshUpdated(); model.updated();
applyFit(); applyFit();
}; };
@@ -145,7 +145,7 @@ export const tabletopPictureFrame = defineObject({
matMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height; matMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height;
coverMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width; coverMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width;
coverMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height; coverMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height;
meshUpdated(); model.updated();
applyMatThickness(); applyMatThickness();
}; };
@@ -156,7 +156,7 @@ export const tabletopPictureFrame = defineObject({
frameMesh.morphTargetManager!.getTargetByName('Depth')!.influence = options.depth; frameMesh.morphTargetManager!.getTargetByName('Depth')!.influence = options.depth;
//coverMesh.morphTargetManager!.getTargetByName('Depth')!.influence = options.depth; //coverMesh.morphTargetManager!.getTargetByName('Depth')!.influence = options.depth;
coverMesh.morphTargetManager!.getTargetByName('Depth')!.influence = 0; coverMesh.morphTargetManager!.getTargetByName('Depth')!.influence = 0;
meshUpdated(); model.updated();
}; };
applyDepth(); applyDepth();
@@ -183,7 +183,7 @@ export const tabletopPictureFrame = defineObject({
applyCustomPicture(); applyCustomPicture();
const frameMaterial = findMaterial('__X_FRAME__'); const frameMaterial = model.findMaterial('__X_FRAME__');
const applyFrameColor = () => { const applyFrameColor = () => {
const [r, g, b] = options.frameColor; const [r, g, b] = options.frameColor;

View File

@@ -44,15 +44,15 @@ export const tapestry = defineObject({
}, },
}, },
placement: 'side', placement: 'side',
createInstance: ({ scene, options, findMaterial, findMesh, findMeshes, meshUpdated }) => { createInstance: ({ scene, options, model }) => {
const pictureMesh = findMesh('__X_PICTURE__'); const pictureMesh = model.findMesh('__X_PICTURE__');
pictureMesh.rotationQuaternion = null; pictureMesh.rotationQuaternion = null;
const pipeTopMesh = findMesh('__X_PIPE_TOP__'); const pipeTopMesh = model.findMesh('__X_PIPE_TOP__');
const pipeBottomMesh = findMesh('__X_PIPE_BOTTOM__'); const pipeBottomMesh = model.findMesh('__X_PIPE_BOTTOM__');
const ropeMesh = findMesh('__X_ROPE__'); const ropeMesh = model.findMesh('__X_ROPE__');
const pictureMaterial = findMaterial('__X_PICTURE__'); const pictureMaterial = model.findMaterial('__X_PICTURE__');
const updateUv = createPlaneUvMapper(pictureMesh); const updateUv = createPlaneUvMapper(pictureMesh);
@@ -81,7 +81,7 @@ export const tapestry = defineObject({
pipeBottomMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height; pipeBottomMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height;
ropeMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width; ropeMesh.morphTargetManager!.getTargetByName('Width')!.influence = options.width;
ropeMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height; ropeMesh.morphTargetManager!.getTargetByName('Height')!.influence = options.height;
meshUpdated(); model.updated();
applyFit(); applyFit();
}; };

View File

@@ -21,8 +21,8 @@ export const wallClock = defineObject({
}, },
}, },
placement: 'side', placement: 'side',
createInstance: ({ room, root, options, findMaterial }) => { createInstance: ({ room, root, options, model }) => {
const frameMaterial = findMaterial('__X_FRAME__'); const frameMaterial = model.findMaterial('__X_FRAME__');
const applyFrameColor = () => { const applyFrameColor = () => {
const [r, g, b] = options.frameColor; const [r, g, b] = options.frameColor;

View File

@@ -33,7 +33,7 @@ export const wallShelf = defineObject({
}, },
}, },
placement: 'side', placement: 'side',
createInstance: ({ findMesh, options, root }) => { createInstance: ({ model, options, root }) => {
const applyStyle = () => { const applyStyle = () => {
const aMeshes = root.getChildMeshes().filter(m => m.name.includes('__X_VARIATION_A__')); const aMeshes = root.getChildMeshes().filter(m => m.name.includes('__X_VARIATION_A__'));
const bMeshes = root.getChildMeshes().filter(m => m.name.includes('__X_VARIATION_B__')); const bMeshes = root.getChildMeshes().filter(m => m.name.includes('__X_VARIATION_B__'));
@@ -56,7 +56,7 @@ export const wallShelf = defineObject({
applyStyle(); applyStyle();
const bodyMesh = findMesh('__X_BODY__'); const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial; const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;
const bodyTexture = bodyMaterial.albedoTexture as BABYLON.Texture; const bodyTexture = bodyMaterial.albedoTexture as BABYLON.Texture;

View File

@@ -26,8 +26,8 @@ export const woodRingFloorLamp = defineObject({
}, },
}, },
placement: 'floor', placement: 'floor',
createInstance: ({ options, findMaterial }) => { createInstance: ({ options, model }) => {
const shadeMaterial = findMaterial('__X_SHADE__'); const shadeMaterial = model.findMaterial('__X_SHADE__');
const applyShadeColor = () => { const applyShadeColor = () => {
const [r, g, b] = options.shadeColor; const [r, g, b] = options.shadeColor;
@@ -36,7 +36,7 @@ export const woodRingFloorLamp = defineObject({
applyShadeColor(); applyShadeColor();
const bodyMaterial = findMaterial('__X_BODY__'); const bodyMaterial = model.findMaterial('__X_BODY__');
const applyBodyColor = () => { const applyBodyColor = () => {
const [r, g, b] = options.bodyColor; const [r, g, b] = options.bodyColor;