fix: hide gallery export planes
🔍 Lint / 🪄 Check lint (pull_request) Has been cancelled
🔍 Lint / 🎨 Check format (pull_request) Has been cancelled
🔍 Lint / 🔎 Typecheck (pull_request) Has been cancelled
📊 Quality / 🔒 Security Audit (pull_request) Has been cancelled
📊 Quality / 📋 Dependency Freshness (pull_request) Has been cancelled
📊 Quality / 📦 Bundle Size (pull_request) Has been cancelled
🔍 Lint / 🏗 Build (pull_request) Has been cancelled

This commit is contained in:
Tom Boullay
2026-05-25 19:13:02 +02:00
parent cf71148935
commit 054cb975da
+47 -1
View File
@@ -72,6 +72,12 @@ interface TextureDiagnostic {
summary: string; summary: string;
} }
interface GalleryModelScene extends THREE.Object3D {
userData: THREE.Object3D["userData"] & {
hiddenExportPlaneCount?: number;
};
}
interface GalleryViewerErrorBoundaryProps { interface GalleryViewerErrorBoundaryProps {
children: ReactNode; children: ReactNode;
resetKey: string; resetKey: string;
@@ -180,19 +186,49 @@ function GalleryModelPreview({
} }
function createGalleryModelScene(scene: THREE.Object3D): THREE.Object3D { function createGalleryModelScene(scene: THREE.Object3D): THREE.Object3D {
const modelScene = scene.clone(true); const modelScene = scene.clone(true) as GalleryModelScene;
const exportPlaneMeshes: THREE.Mesh[] = [];
modelScene.traverse((object) => { modelScene.traverse((object) => {
if (!(object instanceof THREE.Mesh)) return; if (!(object instanceof THREE.Mesh)) return;
if (isExportPlaneMesh(object)) {
exportPlaneMeshes.push(object);
return;
}
object.material = Array.isArray(object.material) object.material = Array.isArray(object.material)
? object.material.map(createGalleryMaterial) ? object.material.map(createGalleryMaterial)
: createGalleryMaterial(object.material); : createGalleryMaterial(object.material);
}); });
for (const mesh of exportPlaneMeshes) {
mesh.parent?.remove(mesh);
}
modelScene.userData.hiddenExportPlaneCount = exportPlaneMeshes.length;
return modelScene; return modelScene;
} }
function isExportPlaneMesh(mesh: THREE.Mesh): boolean {
const name = mesh.name.toLowerCase();
if (name !== "plan" && name !== "plane") return false;
mesh.geometry.computeBoundingBox();
const boundingBox = mesh.geometry.boundingBox;
if (!boundingBox) return false;
const size = new THREE.Vector3();
boundingBox.getSize(size);
const dimensions = [size.x, size.y, size.z];
const flatDimensions = dimensions.filter((dimension) => dimension <= 0.001);
const largestDimension = Math.max(...dimensions);
return flatDimensions.length > 0 && largestDimension > 1;
}
function createGalleryMaterial(material: THREE.Material): THREE.Material { function createGalleryMaterial(material: THREE.Material): THREE.Material {
const galleryMaterial = material.clone(); const galleryMaterial = material.clone();
const materialWithNormalMap = galleryMaterial as THREE.Material & { const materialWithNormalMap = galleryMaterial as THREE.Material & {
@@ -360,6 +396,8 @@ function getTextureDiagnostic(
): TextureDiagnostic { ): TextureDiagnostic {
let textureCount = 0; let textureCount = 0;
let missingTextureImageCount = 0; let missingTextureImageCount = 0;
const hiddenExportPlaneCount =
(modelScene as GalleryModelScene).userData.hiddenExportPlaneCount ?? 0;
modelScene.traverse((object) => { modelScene.traverse((object) => {
if (!(object instanceof THREE.Mesh)) return; if (!(object instanceof THREE.Mesh)) return;
@@ -392,6 +430,14 @@ function getTextureDiagnostic(
}; };
} }
if (hiddenExportPlaneCount > 0) {
return {
modelId,
status: "warning",
summary: `${hiddenExportPlaneCount} plan(s) d'export masqué(s)`,
};
}
if (textureCount === 0) { if (textureCount === 0) {
return { return {
modelId, modelId,