diff --git a/packages/frontend/src/utility/room/objects/pictureFrame.ts b/packages/frontend/src/utility/room/objects/pictureFrame.ts index b21d2da2f2..0e885ddc1f 100644 --- a/packages/frontend/src/utility/room/objects/pictureFrame.ts +++ b/packages/frontend/src/utility/room/objects/pictureFrame.ts @@ -15,11 +15,6 @@ export const pictureFrame = defineObject({ type: 'color', label: 'Frame color', }, - direction: { - type: 'enum', - label: 'Direction', - enum: ['vertical', 'horizontal'], - }, width: { type: 'range', label: 'Width', @@ -67,7 +62,6 @@ export const pictureFrame = defineObject({ }, default: { frameColor: [0.71, 0.58, 0.39], - direction: 'vertical', width: 0.5, height: 0.5, frameThickness: 0.5, @@ -91,6 +85,8 @@ export const pictureFrame = defineObject({ pictureMesh.rotationQuaternion = null; pictureMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UVKind, true); + const pictureMaterial = findMaterial('__X_PICTURE__'); + const uvs = pictureMesh.getVerticesData(BABYLON.VertexBuffer.UVKind); const ax = uvs[6]; const ay = uvs[7]; @@ -101,45 +97,12 @@ export const pictureFrame = defineObject({ const dx = uvs[0]; const dy = uvs[1]; - const applyDirection = () => { - if (options.direction === 'vertical') { - frameMesh.rotation.z = 0; - matMesh.rotation.z = 0; - coverMesh.rotation.z = 0; - pictureMesh.rotation.z = 0; - - uvs[6] = ax; - uvs[7] = ay; - uvs[2] = bx; - uvs[3] = by; - uvs[4] = cx; - uvs[5] = cy; - uvs[0] = dx; - uvs[1] = dy; - } else if (options.direction === 'horizontal') { - frameMesh.rotation.z = -Math.PI / 2; - matMesh.rotation.z = -Math.PI / 2; - coverMesh.rotation.z = -Math.PI / 2; - pictureMesh.rotation.z = -Math.PI / 2; - - uvs[6] = cy; - uvs[7] = cx; - uvs[2] = dy; - uvs[3] = dx; - uvs[4] = ay; - uvs[5] = ax; - uvs[0] = by; - uvs[1] = bx; - } - - pictureMesh.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs); - }; - - //applyDirection(); - const applyFit = () => { - const srcWidth = 1920; - const srcHeight = 1200; + const tex = pictureMaterial.albedoTexture; + if (tex == null) return; + + const srcWidth = tex.getSize().width; + const srcHeight = tex.getSize().height; const targetWidth = options.width * (1 - (options.matHThickness * MAT_THICKNESS_FACTOR)); const targetHeight = options.height * (1 - (options.matVThickness * MAT_THICKNESS_FACTOR)); @@ -238,8 +201,6 @@ export const pictureFrame = defineObject({ applySize(); - const pictureMaterial = findMaterial('__X_PICTURE__'); - const applyCustomPicture = () => { if (options.customPicture != null) { const tex = new BABYLON.Texture(options.customPicture, room.scene, false, false); @@ -248,6 +209,12 @@ export const pictureFrame = defineObject({ pictureMaterial.albedoColor = new BABYLON.Color3(1, 1, 1); pictureMaterial.albedoTexture = tex; + + applyFit(); + + tex.onLoadObservable.addOnce(() => { + applyFit(); + }); } else { pictureMaterial.albedoColor = new BABYLON.Color3(0.5, 0.5, 0.5); pictureMaterial.albedoTexture = null; @@ -296,3 +263,41 @@ export const pictureFrame = defineObject({ }; }, }); + +/* + +const applyDirection = () => { + if (options.direction === 'vertical') { + frameMesh.rotation.z = 0; + matMesh.rotation.z = 0; + coverMesh.rotation.z = 0; + pictureMesh.rotation.z = 0; + + uvs[6] = ax; + uvs[7] = ay; + uvs[2] = bx; + uvs[3] = by; + uvs[4] = cx; + uvs[5] = cy; + uvs[0] = dx; + uvs[1] = dy; + } else if (options.direction === 'horizontal') { + frameMesh.rotation.z = -Math.PI / 2; + matMesh.rotation.z = -Math.PI / 2; + coverMesh.rotation.z = -Math.PI / 2; + pictureMesh.rotation.z = -Math.PI / 2; + + uvs[6] = cy; + uvs[7] = cx; + uvs[2] = dy; + uvs[3] = dx; + uvs[4] = ay; + uvs[5] = ax; + uvs[0] = by; + uvs[1] = bx; + } + + pictureMesh.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs); +}; + +*/