An AI agent skill that turns any subject into a 3D film or app
Add ground layer heights and a coplanar surface check
Nguyen Xuan Anbc499fb0ab8a
diff --git a/plugins/visualize-in-3d/skills/visualize-in-3d/references/brief.md b/plugins/visualize-in-3d/skills/visualize-in-3d/references/brief.mdindex 15328d3..26a59e0 100644--- a/plugins/visualize-in-3d/skills/visualize-in-3d/references/brief.md+++ b/plugins/visualize-in-3d/skills/visualize-in-3d/references/brief.md@@ -85,7 +85,10 @@ GLBs with instancing for repeats, drive every moving part and clip from the simukeeps the previous and current pose of everything that moves and renders the pose interpolated by the leftovertime, so motion and the follow camera change every frame (no stutter). No two surfaces share a plane and no twomodules overlap: lay repeats end to end, build curves (track, viaduct deck) as continuous swept geometry, lift-stacked floors a few centimetres apart, and set the camera near plane to about 0.5 m. Layered transparent surfaces+stacked floors a few centimetres apart, and set the camera near plane to about 0.5 m. Ground layers each get+their own height: grass -0.2 m, pads -0.06, road and floor modules 0, paint and decals +0.04. Where a pad or plaza+replaces a road, leave the road modules out there instead of laying both. Run {{SKILL_DIR}}/scripts/coplanar-check.js+on the built scene and fix every pair it lists before any screenshot. Layered transparent surfaces(glass over glass) read as a smear; keep one glass layer and make the rest opaque. Clicking an object selects itand opens its card; clicking a list row flies the camera to it (and follows it if it moves); switching sites changesthe world. Soft shadows, ambient occlusion, gentle bloom on lights, smooth camera moves. 60 fps at 1920x1080 on adiff --git a/plugins/visualize-in-3d/skills/visualize-in-3d/scripts/coplanar-check.js b/plugins/visualize-in-3d/skills/visualize-in-3d/scripts/coplanar-check.jsnew file mode 100644index 0000000..aee347c--- /dev/null+++ b/plugins/visualize-in-3d/skills/visualize-in-3d/scripts/coplanar-check.js@@ -0,0 +1,48 @@+// Finds flat surfaces that fight for the same depth (z-fighting): two meshes whose footprints overlap+// and whose top faces lie within `tolerance` metres of each other. Run it in the page once the world is built:+// import { findCoplanarPairs } from './coplanar-check.js';+// console.table(findCoplanarPairs(scene));+// Fix every pair it reports: remove the hidden surface, or move the layers at least 3 cm apart.+import * as THREE from 'three';++const FLAT_RATIO = 0.05;++function flatFootprint(mesh) {+ const box = new THREE.Box3().setFromObject(mesh);+ const height = box.max.y - box.min.y;+ const width = box.max.x - box.min.x;+ const depth = box.max.z - box.min.z;+ if (width <= 0 || depth <= 0) return null;+ if (height > FLAT_RATIO * Math.max(width, depth) && height > 0.3) return null;+ return { box, top: box.max.y };+}++function overlapArea(first, second) {+ const overlapX = Math.min(first.max.x, second.max.x) - Math.max(first.min.x, second.min.x);+ const overlapZ = Math.min(first.max.z, second.max.z) - Math.max(first.min.z, second.min.z);+ if (overlapX <= 0 || overlapZ <= 0) return 0;+ return overlapX * overlapZ;+}++export function findCoplanarPairs(scene, { tolerance = 0.03, minimumArea = 0.25 } = {}) {+ scene.updateMatrixWorld(true);+ const flats = [];+ scene.traverse((object) => {+ if (!object.isMesh || !object.visible || object.isInstancedMesh) return;+ const material = Array.isArray(object.material) ? object.material[0] : object.material;+ if (material && material.transparent && material.opacity < 0.5) return;+ const footprint = flatFootprint(object);+ if (footprint) flats.push({ name: object.name || object.parent?.name || '(unnamed)', ...footprint });+ });+ const pairs = [];+ for (let first = 0; first < flats.length; first++) {+ for (let second = first + 1; second < flats.length; second++) {+ const gap = Math.abs(flats[first].top - flats[second].top);+ if (gap >= tolerance) continue;+ const area = overlapArea(flats[first].box, flats[second].box);+ if (area < minimumArea) continue;+ pairs.push({ first: flats[first].name, second: flats[second].name, gapCm: +(gap * 100).toFixed(1), overlapM2: +area.toFixed(1) });+ }+ }+ return pairs.sort((left, right) => right.overlapM2 - left.overlapM2);+}