Spaces:
Running on Zero
Running on Zero
Download examples/example_2.html from hugging-apps/inkling-2-mini-3d-coder: direct link, hf CLI and curl.
- Browser
- Download file 23.3 kB
-
https://huggingface.co/spaces/hugging-apps/inkling-2-mini-3d-coder/resolve/main/examples/example_2.html
- Command line
-
hf download hf://spaces/hugging-apps/inkling-2-mini-3d-coder/examples/example_2.html
-
curl -L -o example_2.html https://huggingface.co/spaces/hugging-apps/inkling-2-mini-3d-coder/resolve/main/examples/example_2.html
23.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Family Home Cutaway</title> | |
| <style> | |
| :root { | |
| color-scheme: light; | |
| font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, | |
| "Segoe UI", sans-serif; | |
| } | |
| * { box-sizing: border-box; } | |
| html, body { | |
| width: 100%; | |
| height: 100%; | |
| margin: 0; | |
| overflow: hidden; | |
| background: #dfeaf2; | |
| } | |
| #scene { | |
| position: fixed; | |
| inset: 0; | |
| } | |
| .panel { | |
| position: fixed; | |
| z-index: 10; | |
| top: 18px; | |
| left: 18px; | |
| width: min(330px, calc(100vw - 36px)); | |
| padding: 18px; | |
| border: 1px solid rgba(255,255,255,.72); | |
| border-radius: 18px; | |
| background: rgba(255,255,255,.86); | |
| box-shadow: 0 14px 42px rgba(43,75,96,.18); | |
| backdrop-filter: blur(14px); | |
| -webkit-backdrop-filter: blur(14px); | |
| } | |
| h1 { | |
| margin: 0 0 5px; | |
| color: #17384b; | |
| font-size: 22px; | |
| letter-spacing: -.03em; | |
| } | |
| .subtitle { | |
| margin: 0 0 16px; | |
| color: #587184; | |
| font-size: 13px; | |
| line-height: 1.45; | |
| } | |
| .buttons { | |
| display: flex; | |
| flex-wrap: wrap; | |
| gap: 8px; | |
| } | |
| button { | |
| appearance: none; | |
| border: 1px solid #c6d5df; | |
| border-radius: 10px; | |
| padding: 9px 12px; | |
| color: #244a5e; | |
| background: #f7fbfd; | |
| font: inherit; | |
| font-size: 12px; | |
| font-weight: 700; | |
| cursor: pointer; | |
| transition: transform .15s ease, background .15s ease, border-color .15s ease; | |
| } | |
| button:hover { | |
| transform: translateY(-1px); | |
| background: #fff; | |
| border-color: #8fb2c5; | |
| } | |
| button:active { transform: translateY(0); } | |
| button[aria-pressed="false"] { | |
| color: #718795; | |
| background: #e9f0f4; | |
| } | |
| .hint { | |
| margin: 14px 0 0; | |
| color: #6b8292; | |
| font-size: 11px; | |
| line-height: 1.5; | |
| } | |
| .hint strong { color: #35596c; } | |
| .legend { | |
| position: fixed; | |
| z-index: 10; | |
| right: 18px; | |
| bottom: 18px; | |
| display: flex; | |
| gap: 7px; | |
| align-items: center; | |
| padding: 8px 11px; | |
| border-radius: 999px; | |
| color: #456575; | |
| background: rgba(255,255,255,.78); | |
| box-shadow: 0 8px 24px rgba(43,75,96,.12); | |
| backdrop-filter: blur(10px); | |
| font-size: 11px; | |
| } | |
| @media (max-width: 600px) { | |
| .panel { top: 10px; left: 10px; padding: 14px; } | |
| .legend { right: 10px; bottom: 10px; } | |
| .hint { display: none; } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="scene"></div> | |
| <section class="panel"> | |
| <h1>Family Home</h1> | |
| <p class="subtitle">Interactive two-storey cutaway with central staircase.</p> | |
| <div class="buttons"> | |
| <button id="roofToggle" aria-pressed="true">Hide roof</button> | |
| <button id="floorToggle" aria-pressed="true">Hide upper floor</button> | |
| <button id="resetView">Reset view</button> | |
| </div> | |
| <p class="hint"> | |
| <strong>Drag</strong> to rotate · <strong>Scroll / pinch</strong> to zoom · | |
| <strong>Double-click</strong> to reset | |
| </p> | |
| </section> | |
| <div class="legend">Cut-away family residence</div> | |
| <script type="module"> | |
| import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"; | |
| const mount = document.getElementById("scene"); | |
| const scene = new THREE.Scene(); | |
| scene.background = new THREE.Color(0xdfeaf2); | |
| scene.fog = new THREE.Fog(0xdfeaf2, 24, 48); | |
| const camera = new THREE.PerspectiveCamera( | |
| 42, | |
| innerWidth / innerHeight, | |
| 0.1, | |
| 100 | |
| ); | |
| const renderer = new THREE.WebGLRenderer({ antialias: true }); | |
| renderer.setSize(innerWidth, innerHeight); | |
| renderer.setPixelRatio(Math.min(devicePixelRatio, 2)); | |
| renderer.shadowMap.enabled = true; | |
| renderer.shadowMap.type = THREE.PCFSoftShadowMap; | |
| renderer.outputColorSpace = THREE.SRGBColorSpace; | |
| renderer.toneMapping = THREE.ACESFilmicToneMapping; | |
| renderer.toneMappingExposure = 1.12; | |
| mount.appendChild(renderer.domElement); | |
| const hemi = new THREE.HemisphereLight(0xeaf7ff, 0x8c8879, 2.0); | |
| scene.add(hemi); | |
| const sun = new THREE.DirectionalLight(0xfff4dc, 3.2); | |
| sun.position.set(-8, 13, 9); | |
| sun.castShadow = true; | |
| sun.shadow.mapSize.set(2048, 2048); | |
| sun.shadow.camera.left = -14; | |
| sun.shadow.camera.right = 14; | |
| sun.shadow.camera.top = 14; | |
| sun.shadow.camera.bottom = -14; | |
| sun.shadow.camera.near = 1; | |
| sun.shadow.camera.far = 35; | |
| scene.add(sun); | |
| const fill = new THREE.DirectionalLight(0xb8d8ff, 1.0); | |
| fill.position.set(9, 6, -7); | |
| scene.add(fill); | |
| const mats = { | |
| foundation: new THREE.MeshStandardMaterial({ color: 0x8d9293, roughness: .95 }), | |
| floor: new THREE.MeshStandardMaterial({ color: 0xc89b6c, roughness: .75 }), | |
| upperFloor: new THREE.MeshStandardMaterial({ color: 0xd7b58a, roughness: .75 }), | |
| wall: new THREE.MeshStandardMaterial({ color: 0xf0e8da, roughness: .92 }), | |
| wallInside: new THREE.MeshStandardMaterial({ color: 0xe3d8c8, roughness: .94 }), | |
| trim: new THREE.MeshStandardMaterial({ color: 0x526b76, roughness: .7 }), | |
| wood: new THREE.MeshStandardMaterial({ color: 0x8b5f3d, roughness: .8 }), | |
| darkWood: new THREE.MeshStandardMaterial({ color: 0x604533, roughness: .8 }), | |
| steel: new THREE.MeshStandardMaterial({ color: 0x7b929c, metalness: .55, roughness: .35 }), | |
| glass: new THREE.MeshStandardMaterial({ | |
| color: 0x8fc6d3, | |
| metalness: .15, | |
| roughness: .15, | |
| transparent: true, | |
| opacity: .65 | |
| }), | |
| white: new THREE.MeshStandardMaterial({ color: 0xf8f5ec, roughness: .72 }), | |
| fabric: new THREE.MeshStandardMaterial({ color: 0xe4b4a3, roughness: 1 }), | |
| fabricBlue: new THREE.MeshStandardMaterial({ color: 0x7ca6b6, roughness: 1 }), | |
| fabricGreen: new THREE.MeshStandardMaterial({ color: 0x91a98b, roughness: 1 }), | |
| foliage: new THREE.MeshStandardMaterial({ color: 0x55784f, roughness: 1 }), | |
| black: new THREE.MeshStandardMaterial({ color: 0x26343c, roughness: .55 }), | |
| rug: new THREE.MeshStandardMaterial({ color: 0xb6c5a4, roughness: 1 }), | |
| kitchen: new THREE.MeshStandardMaterial({ color: 0x567b83, roughness: .55 }), | |
| roof: new THREE.MeshStandardMaterial({ color: 0x586b74, roughness: .85 }), | |
| roofEnd: new THREE.MeshStandardMaterial({ color: 0xe7dfd1, roughness: .9 }) | |
| }; | |
| function box(parent, size, position, material, cast = true) { | |
| const mesh = new THREE.Mesh( | |
| new THREE.BoxGeometry(size[0], size[1], size[2]), | |
| material | |
| ); | |
| mesh.position.set(position[0], position[1], position[2]); | |
| mesh.castShadow = cast; | |
| mesh.receiveShadow = true; | |
| parent.add(mesh); | |
| return mesh; | |
| } | |
| function cylinder(parent, radius, height, position, material, segments = 20) { | |
| const mesh = new THREE.Mesh( | |
| new THREE.CylinderGeometry(radius, radius, height, segments), | |
| material | |
| ); | |
| mesh.position.set(position[0], position[1], position[2]); | |
| mesh.castShadow = true; | |
| mesh.receiveShadow = true; | |
| parent.add(mesh); | |
| return mesh; | |
| } | |
| function sofa(parent, position, material, rotation = 0) { | |
| const group = new THREE.Group(); | |
| group.position.set(...position); | |
| group.rotation.y = rotation; | |
| box(group, [2.15, .38, .85], [0, .42, 0], material); | |
| box(group, [2.15, .72, .2], [0, .72, -.36], material); | |
| box(group, [.2, .65, .9], [-1.02, .64, 0], material); | |
| box(group, [.2, .65, .9], [1.02, .64, 0], material); | |
| box(group, [.82, .13, .63], [-.48, .67, .08], mats.white); | |
| box(group, [.82, .13, .63], [.48, .67, .08], mats.white); | |
| cylinder(group, .08, .15, [-.75, .14, .27], mats.darkWood, 10); | |
| cylinder(group, .08, .15, [.75, .14, .27], mats.darkWood, 10); | |
| parent.add(group); | |
| return group; | |
| } | |
| function chair(parent, position, material, rotation = 0) { | |
| const group = new THREE.Group(); | |
| group.position.set(...position); | |
| group.rotation.y = rotation; | |
| box(group, [.52, .12, .52], [0, .65, 0], material); | |
| box(group, [.52, .72, .11], [0, 1.0, -.22], material); | |
| for (const x of [-.2, .2]) { | |
| for (const z of [-.2, .2]) { | |
| box(group, [.07, .65, .07], [x, .32, z], mats.darkWood); | |
| } | |
| } | |
| parent.add(group); | |
| return group; | |
| } | |
| function bed(parent, position, width = 1.75) { | |
| const group = new THREE.Group(); | |
| group.position.set(...position); | |
| box(group, [width + .2, .3, 2.25], [0, .28, 0], mats.wood); | |
| box(group, [width, .22, 2.0], [0, .52, 0], mats.fabricBlue); | |
| box(group, [width * .85, .16, .78], [0, .69, -.42], mats.white); | |
| box(group, [width, .72, .15], [0, .72, -1.02], mats.darkWood); | |
| box(group, [.62, .3, .72], [-width * .25, .7, .48], mats.fabric); | |
| box(group, [.62, .3, .72], [width * .25, .7, .48], mats.fabric); | |
| parent.add(group); | |
| return group; | |
| } | |
| function labelSprite(text, color = "#315d70") { | |
| const canvas = document.createElement("canvas"); | |
| canvas.width = 512; | |
| canvas.height = 128; | |
| const ctx = canvas.getContext("2d"); | |
| ctx.clearRect(0, 0, canvas.width, canvas.height); | |
| ctx.fillStyle = "rgba(255,255,255,.92)"; | |
| ctx.strokeStyle = color; | |
| ctx.lineWidth = 7; | |
| ctx.beginPath(); | |
| ctx.roundRect(8, 12, 496, 104, 30); | |
| ctx.fill(); | |
| ctx.stroke(); | |
| ctx.fillStyle = color; | |
| ctx.font = "700 40px system-ui, sans-serif"; | |
| ctx.textAlign = "center"; | |
| ctx.textBaseline = "middle"; | |
| ctx.fillText(text, 256, 65); | |
| const texture = new THREE.CanvasTexture(canvas); | |
| texture.colorSpace = THREE.SRGBColorSpace; | |
| const material = new THREE.SpriteMaterial({ | |
| map: texture, | |
| transparent: true, | |
| depthTest: false, | |
| depthWrite: false | |
| }); | |
| const sprite = new THREE.Sprite(material); | |
| sprite.scale.set(2.5, .625, 1); | |
| sprite.renderOrder = 30; | |
| return sprite; | |
| } | |
| const home = new THREE.Group(); | |
| scene.add(home); | |
| // Ground outside plane. | |
| const ground = new THREE.Mesh( | |
| new THREE.PlaneGeometry(100, 100), | |
| new THREE.MeshStandardMaterial({ color: 0xb7c9b7, roughness: 1 }) | |
| ); | |
| ground.rotation.x = -Math.PI / 2; | |
| ground.position.y = -.18; | |
| ground.receiveShadow = true; | |
| scene.add(ground); | |
| // Foundation and ground floor. | |
| box(home, [10.5, .35, 9], [0, -.05, 0], mats.foundation); | |
| box(home, [10, .14, 8.8], [0, .2, 0], mats.floor); | |
| box(home, [.26, 3.2, 8.8], [-5, 1.85, 0], mats.wall); | |
| box(home, [10, 3.2, .26], [0, 1.85, -4.4], mats.wall); | |
| // Ground-floor partitions, leaving a stairwell open. | |
| box(home, [.18, 3.2, 4.35], [-.65, 1.85, -2.2], mats.wallInside); | |
| box(home, [.18, 3.2, 3.15], [-.65, 1.85, 2.85], mats.wallInside); | |
| box(home, [5.35, 3.2, .16], [2.65, 1.85, -.05], mats.wallInside); | |
| box(home, [.16, 3.2, 1.35], [.2, 1.85, 1.3], mats.wallInside); | |
| // Front-facing fascia to emphasize the cutaway. | |
| box(home, [10.5, .23, .22], [0, 3.43, 4.4], mats.trim); | |
| box(home, [10.5, .16, .22], [0, 3.55, -4.4], mats.trim); | |
| // Living room. | |
| box(home, [3.6, .025, 2.6], [-2.9, .3, .35], mats.rug, false); | |
| sofa(home, [-2.85, .3, .55], mats.fabricBlue, 0); | |
| box(home, [1.4, .5, .65], [-2.8, .56, 1.75], mats.darkWood); | |
| cylinder(home, .12, .55, [-3.75, .58, 1.75], mats.wood, 12); | |
| box(home, [2.4, 1.45, .18], [-2.85, 1.25, -3.97], mats.black); | |
| box(home, [1.8, .28, .4], [-2.85, .45, -3.75], mats.darkWood); | |
| cylinder(home, .3, .9, [-4.15, .75, 2.8], mats.foliage); | |
| cylinder(home, .13, .7, [-4.15, .35, 2.8], mats.wood, 12); | |
| // Kitchen. | |
| box(home, [4.15, .12, 1.05], [2.55, .38, -3.82], mats.white); | |
| box(home, [.28, 2.5, .9], [3.45, 1.58, -3.84], mats.white); | |
| box(home, [3.5, .86, 1.05], [1.95, .82, -3.82], mats.kitchen); | |
| box(home, [3.6, .08, 1.12], [1.95, 1.28, -3.82], mats.white); | |
| box(home, [1.5, .08, .7], [2.35, 1.34, -3.82], mats.steel); | |
| box(home, [1.25, .1, .9], [.35, 1.33, -3.82], mats.black); | |
| cylinder(home, .035, .65, [-.95, 1.6, -3.82], mats.steel, 10); | |
| box(home, [.85, 1.7, .8], [4.35, 1.18, -2.1], mats.white); | |
| box(home, [.04, 1.48, .04], [3.91, 1.2, -1.69], mats.steel); | |
| // Dining area. | |
| box(home, [2.8, .12, 1.45], [2.6, .91, 1.7], mats.wood); | |
| for (const x of [1.55, 3.65]) { | |
| for (const z of [1.12, 2.28]) { | |
| box(home, [.15, .86, .15], [x, .5, z], mats.darkWood); | |
| } | |
| } | |
| box(home, [2.4, .04, 1.2], [2.6, 1.0, 1.7], mats.white, false); | |
| chair(home, [1.35, .3, 1.7], mats.fabricGreen, Math.PI / 2); | |
| chair(home, [3.85, .3, 1.7], mats.fabricGreen, -Math.PI / 2); | |
| chair(home, [2.6, .3, .75], mats.fabricGreen, 0); | |
| chair(home, [2.6, .3, 2.65], mats.fabricGreen, Math.PI); | |
| box(home, [.75, .75, .75], [4.25, .67, 2.85], mats.white); | |
| // Central staircase: 13 rising steps from the open cutaway. | |
| const stairGroup = new THREE.Group(); | |
| home.add(stairGroup); | |
| const steps = 13; | |
| const rise = 3.0 / steps; | |
| const run = 3.7 / steps; | |
| for (let i = 0; i < steps; i++) { | |
| const y = .27 + i * rise; | |
| const z = -1.85 + i * run; | |
| box(stairGroup, [1.75, .16, run + .03], [0, y, z], mats.wood); | |
| if (i % 2 === 0) { | |
| box(stairGroup, [1.72, .035, .045], [0, y + .095, z - run * .48], mats.white, false); | |
| } | |
| } | |
| box(stairGroup, [.12, 1.05, 3.8], [-.93, 1.95, 0], mats.trim); | |
| box(stairGroup, [.12, 1.05, 3.8], [.93, 1.95, 0], mats.trim); | |
| for (let i = 0; i <= 5; i++) { | |
| const z = -1.75 + i * .87; | |
| const y = .45 + i * .5; | |
| box(stairGroup, [.09, 1.0, .09], [-.93, y, z], mats.steel); | |
| box(stairGroup, [.09, 1.0, .09], [.93, y, z], mats.steel); | |
| } | |
| // Ground-floor labels. | |
| const groundLabels = new THREE.Group(); | |
| home.add(groundLabels); | |
| const livingLabel = labelSprite("LIVING ROOM", "#3b7186"); | |
| livingLabel.position.set(-2.8, 2.25, .35); | |
| groundLabels.add(livingLabel); | |
| const kitchenLabel = labelSprite("KITCHEN", "#4d7b62"); | |
| kitchenLabel.position.set(2.6, 2.15, -2.15); | |
| groundLabels.add(kitchenLabel); | |
| const diningLabel = labelSprite("DINING ROOM", "#9a6545"); | |
| diningLabel.position.set(2.55, 2.05, 1.65); | |
| groundLabels.add(diningLabel); | |
| // Upper floor group. | |
| const upperGroup = new THREE.Group(); | |
| home.add(upperGroup); | |
| // Segmented upper slab leaves a clear stairwell opening. | |
| box(upperGroup, [10.5, .26, .25], [0, 3.28, -4.28], mats.upperFloor); | |
| box(upperGroup, [10.5, .26, 2.45], [0, 3.28, 3.15], mats.upperFloor); | |
| box(upperGroup, [4.0, .26, 3.6], [-3.0, 3.28, -.05], mats.upperFloor); | |
| box(upperGroup, [4.0, .26, 3.6], [3.0, .26, -.05], mats.upperFloor); | |
| box(upperGroup, [.26, 2.8, 8.8], [-5, 4.9, 0], mats.wall); | |
| box(upperGroup, [10, 2.8, .26], [0, 4.9, -4.4], mats.wall); | |
| box(upperGroup, [.2, 2.8, 8.8], [-.65, 4.9, 0], mats.wallInside); | |
| box(upperGroup, [5.35, 2.8, .16], [2.65, 4.9, -.25], mats.wallInside); | |
| box(upperGroup, [.16, 2.8, 2.55], [2.98, 4.9, 2.15], mats.wallInside); | |
| // Upper windows and frames. | |
| for (const x of [-3.25, 2.35]) { | |
| box(upperGroup, [1.55, 1.35, .12], [x, 5.05, -4.25], mats.glass, false); | |
| box(upperGroup, [1.72, .08, .16], [x, 5.78, -4.16], mats.trim); | |
| box(upperGroup, [1.72, .08, .16], [x, 4.32, -4.16], mats.trim); | |
| box(upperGroup, [.08, 1.48, .16], [x, 5.05, -4.16], mats.trim); | |
| } | |
| box(upperGroup, [.12, 1.55, 1.4], [-4.85, 5.0, 1.25], mats.glass, false); | |
| box(upperGroup, [.17, 1.72, .08], [-4.73, 5.0, 1.25], mats.trim); | |
| // Master bedroom. | |
| bed(upperGroup, [-3.25, 3.43, -2.2], 1.85); | |
| box(upperGroup, [.75, .7, .6], [-4.35, 3.85, -2.25], mats.wood); | |
| box(upperGroup, [.75, .7, .6], [-2.15, 3.85, -2.25], mats.wood); | |
| box(upperGroup, [1.7, .65, .72], [-2.75, 3.85, 1.25], mats.darkWood); | |
| box(upperGroup, [1.4, .12, .55], [-2.75, 4.25, 1.25], mats.trim); | |
| // Upper living / landing area. | |
| sofa(upperGroup, [1.35, 3.43, .45], mats.fabricGreen, Math.PI / 2); | |
| box(upperGroup, [1.25, .4, .65], [2.65, 3.82, .55], mats.darkWood); | |
| box(upperGroup, [.55, .9, .55], [4.25, 3.95, 1.15], mats.white); | |
| // Upper bedroom. | |
| bed(upperGroup, [3.55, 3.43, -2.25], 1.45); | |
| box(upperGroup, [.6, .55, .5], [2.35, 3.75, -2.2], mats.wood); | |
| box(upperGroup, [.65, .6, .55], [4.65, 3.8, -2.2], mats.wood); | |
| box(upperGroup, [1.5, .75, .65], [3.4, 3.83, 2.3], mats.wood); | |
| box(upperGroup, [1.35, .08, .55], [3.4, 4.25, 2.3], mats.trim); | |
| // Upper labels. | |
| const masterLabel = labelSprite("MASTER BEDROOM", "#6d5b8c"); | |
| masterLabel.position.set(-3.25, 5.65, -.8); | |
| upperGroup.add(masterLabel); | |
| const upperLivingLabel = labelSprite("UPPER ROOM", "#537b73"); | |
| upperLivingLabel.position.set(1.4, 5.45, .1); | |
| upperGroup.add(upperLivingLabel); | |
| const roomLabel = labelSprite("BEDROOM", "#8a644e"); | |
| roomLabel.position.set(3.45, 5.55, -.8); | |
| upperGroup.add(roomLabel); | |
| // Stairwell guardrail on the upper level. | |
| box(upperGroup, [.12, 1.0, 3.65], [-.93, 3.98, 0], mats.trim); | |
| for (const z of [-1.55, -.65, .25, 1.15, 1.85]) { | |
| box(upperGroup, [.09, 1.0, .09], [-.93, 4.05, z], mats.steel); | |
| } | |
| // Roof group: gable roof with sloping panels and triangular end walls. | |
| const roofGroup = new THREE.Group(); | |
| home.add(roofGroup); | |
| const roofAngle = Math.atan2(1.7, 4.4); | |
| const roofLength = Math.sqrt(4.4 * 4.4 + 1.7 * 1.7); | |
| const nearRoof = box(roofGroup, [10.8, .16, roofLength], [0, 7.25, 2.2], mats.roof); | |
| nearRoof.rotation.x = roofAngle; | |
| const farRoof = box(roofGroup, [10.8, .16, roofLength], [0, 7.25, -2.2], mats.roof); | |
| farRoof.rotation.x = -roofAngle; | |
| function gable(x) { | |
| const shape = new THREE.Shape(); | |
| shape.moveTo(-4.4, 0); | |
| shape.lineTo(4.4, 0); | |
| shape.lineTo(0, 1.7); | |
| shape.closePath(); | |
| const geometry = new THREE.ExtrudeGeometry(shape, { | |
| depth: .18, | |
| bevelEnabled: false | |
| }); | |
| const mesh = new THREE.Mesh(geometry, mats.roofEnd); | |
| mesh.rotation.y = Math.PI / 2; | |
| mesh.position.set(x, 6.35, 0); | |
| mesh.castShadow = true; | |
| mesh.receiveShadow = true; | |
| roofGroup.add(mesh); | |
| } | |
| gable(-5.18); | |
| gable(5.0); | |
| // Chimney. | |
| box(roofGroup, [.8, 2.2, .8], [-3.65, 7.25, -1.45], mats.wall); | |
| box(roofGroup, [1.05, .2, 1.05], [-3.65, 8.4, -1.45], mats.trim); | |
| // Trees provide scale without distracting the cutaway. | |
| function tree(x, z, scale = 1) { | |
| const group = new THREE.Group(); | |
| group.position.set(x, 0, z); | |
| group.scale.setScalar(scale); | |
| cylinder(group, .18, 1.7, [0, .75, 0], mats.wood, 12); | |
| const crown = new THREE.Mesh( | |
| new THREE.IcosahedronGeometry(1.05, 1), | |
| mats.foliage | |
| ); | |
| crown.position.y = 2.15; | |
| crown.scale.y = 1.15; | |
| crown.castShadow = true; | |
| group.add(crown); | |
| scene.add(group); | |
| } | |
| tree(-7.2, -3.6, 1.0); | |
| tree(7.1, -2.7, .82); | |
| tree(6.7, 3.8, .7); | |
| // Direct camera controls, implemented without addons. | |
| const target = new THREE.Vector3(0, 2.45, 0); | |
| const initial = { | |
| yaw: .68, | |
| pitch: .47, | |
| radius: 18.5 | |
| }; | |
| let yaw = initial.yaw; | |
| let pitch = initial.pitch; | |
| let radius = initial.radius; | |
| let dragging = false; | |
| let lastX = 0; | |
| let lastY = 0; | |
| const pointers = new Map(); | |
| let pinchDistance = 0; | |
| function updateCamera() { | |
| const cp = Math.cos(pitch); | |
| camera.position.set( | |
| target.x + radius * Math.sin(yaw) * cp, | |
| target.y + radius * Math.sin(pitch), | |
| target.z + radius * Math.cos(yaw) * cp | |
| ); | |
| camera.lookAt(target); | |
| } | |
| updateCamera(); | |
| const canvas = renderer.domElement; | |
| canvas.style.touchAction = "none"; | |
| canvas.style.cursor = "grab"; | |
| canvas.addEventListener("pointerdown", event => { | |
| pointers.set(event.pointerId, { x: event.clientX, y: event.clientY }); | |
| if (pointers.size === 1) { | |
| dragging = true; | |
| lastX = event.clientX; | |
| lastY = event.clientY; | |
| canvas.setPointerCapture(event.pointerId); | |
| canvas.style.cursor = "grabbing"; | |
| } else if (pointers.size === 2) { | |
| const [a, b] = [...pointers.values()]; | |
| pinchDistance = Math.hypot(a.x - b.x, a.y - b.y); | |
| } | |
| }); | |
| canvas.addEventListener("pointermove", event => { | |
| if (!pointers.has(event.pointerId)) return; | |
| pointers.set(event.pointerId, { x: event.clientX, y: event.clientY }); | |
| if (pointers.size === 2) { | |
| const [a, b] = [...pointers.values()]; | |
| const distance = Math.hypot(a.x - b.x, a.y - b.y); | |
| radius = THREE.MathUtils.clamp(radius * (pinchDistance / distance), 9, 30); | |
| pinchDistance = distance; | |
| } else if (dragging) { | |
| const dx = event.clientX - lastX; | |
| const dy = event.clientY - lastY; | |
| yaw -= dx * .006; | |
| pitch = THREE.MathUtils.clamp(pitch + dy * .0045, .13, 1.25); | |
| lastX = event.clientX; | |
| lastY = event.clientY; | |
| } | |
| updateCamera(); | |
| }); | |
| function endPointer(event) { | |
| pointers.delete(event.pointerId); | |
| if (pointers.size < 2) dragging = false; | |
| canvas.style.cursor = pointers.size ? "grabbing" : "grab"; | |
| } | |
| canvas.addEventListener("pointerup", endPointer); | |
| canvas.addEventListener("pointercancel", endPointer); | |
| canvas.addEventListener("pointerleave", endPointer); | |
| canvas.addEventListener("wheel", event => { | |
| event.preventDefault(); | |
| radius = THREE.MathUtils.clamp(radius + event.deltaY * .012, 9, 30); | |
| updateCamera(); | |
| }, { passive: false }); | |
| canvas.addEventListener("dblclick", resetView); | |
| const roofButton = document.getElementById("roofToggle"); | |
| const floorButton = document.getElementById("floorToggle"); | |
| const resetButton = document.getElementById("resetView"); | |
| roofButton.addEventListener("click", () => { | |
| roofGroup.visible = !roofGroup.visible; | |
| roofButton.setAttribute("aria-pressed", String(roofGroup.visible)); | |
| roofButton.textContent = roofGroup.visible ? "Hide roof" : "Show roof"; | |
| }); | |
| floorButton.addEventListener("click", () => { | |
| upperGroup.visible = !upperGroup.visible; | |
| floorButton.setAttribute("aria-pressed", String(upperGroup.visible)); | |
| floorButton.textContent = upperGroup.visible ? "Hide upper floor" : "Show upper floor"; | |
| }); | |
| function resetView() { | |
| yaw = initial.yaw; | |
| pitch = initial.pitch; | |
| radius = initial.radius; | |
| updateCamera(); | |
| } | |
| resetButton.addEventListener("click", resetView); | |
| addEventListener("resize", () => { | |
| camera.aspect = innerWidth / innerHeight; | |
| camera.updateProjectionMatrix(); | |
| renderer.setSize(innerWidth, innerHeight); | |
| renderer.setPixelRatio(Math.min(devicePixelRatio, 2)); | |
| }); | |
| function animate() { | |
| requestAnimationFrame(animate); | |
| renderer.render(scene, camera); | |
| } | |
| animate(); | |
| </script> | |
| </body> | |
| </html> |