Codels
520 tris2,00 × 3,00 × 0,32 m

Utiliser dans le code

Remixer dans l’éditeur
Module ES autonome — ne dépend que de three. Appelez la fonction factory et ajoutez le groupe à votre scène.
/**
 * Modular Wall Doorway — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 520 · Size (W × H × D): 2.00 × 3.00 × 0.32 m
 *
 * Usage:
 *   import { createWallDoorway } from './wall-doorway.js';
 *   
 *   const model = createWallDoorway();
 *   model.position.set(0, 0, 0);
 *   scene.add(model);
 */
import * as THREE from 'three';

// Deterministic vertex displacement (organic low-poly look).
function jitter(geometry, amount, seed) {
  const pos = geometry.attributes.position;
  const h = (a, b, c, s) => {
    let x = Math.imul(a, 73856093) ^ Math.imul(b, 19349663) ^ Math.imul(c, 83492791) ^ Math.imul(s, 2654435761);
    x = Math.imul(x ^ (x >>> 16), 2246822507);
    x = Math.imul(x ^ (x >>> 13), 3266489909);
    return ((x ^ (x >>> 16)) >>> 0) / 4294967295 - 0.5;
  };
  for (let i = 0; i < pos.count; i++) {
    const x = pos.getX(i), y = pos.getY(i), z = pos.getZ(i);
    const qx = Math.round(x * 1000), qy = Math.round(y * 1000), qz = Math.round(z * 1000);
    pos.setXYZ(i, x + h(qx, qy, qz, seed) * 2 * amount, y + h(qx, qy, qz, seed + 1) * 2 * amount, z + h(qx, qy, qz, seed + 2) * 2 * amount);
  }
  pos.needsUpdate = true;
  geometry.computeVertexNormals();
  return geometry;
}

// Extrude a 2D outline along Z (centered). bevel = [thickness, size, segments].
function extrude(outline, depth, holes = [], bevel = null) {
  const shape = new THREE.Shape(outline.map(([x, y]) => new THREE.Vector2(x, y)));
  for (const hole of holes) shape.holes.push(new THREE.Path(hole.map(([x, y]) => new THREE.Vector2(x, y))));
  const options = bevel
    ? { depth, bevelEnabled: true, bevelThickness: bevel[0], bevelSize: bevel[1], bevelSegments: bevel[2] }
    : { depth, bevelEnabled: false };
  return new THREE.ExtrudeGeometry(shape, options).translate(0, 0, -depth / 2);
}

export function createWallDoorway() {
  const root = new THREE.Group();
  root.name = 'WallDoorway';

  // Materials
  const stoneMat = new THREE.MeshStandardMaterial({ name: 'stone', color: 0x7c7871, roughness: 0.95, flatShading: true });
  const stone2Mat = new THREE.MeshStandardMaterial({ name: 'stone2', color: 0x67635c, roughness: 0.95, flatShading: true });
  const stone3Mat = new THREE.MeshStandardMaterial({ name: 'stone3', color: 0x8b867c, roughness: 0.95, flatShading: true });
  const mortarMat = new THREE.MeshStandardMaterial({ name: 'mortar', color: 0x3f3c38, roughness: 1, flatShading: true });
  const plinthMat = new THREE.MeshStandardMaterial({ name: 'plinth', color: 0x57534d, roughness: 0.95, flatShading: true });
  const dressedMat = new THREE.MeshStandardMaterial({ name: 'dressed', color: 0x9a9488, roughness: 0.9, flatShading: true });

  // Shared geometries
  const boxGeo = new THREE.BoxGeometry(0.45, 0.3, 0.31);
  const boxGeo2 = new THREE.BoxGeometry(0.045, 1.94, 0.25);
  const boxGeo3 = new THREE.BoxGeometry(0.21, 0.28, 0.3);
  const boxGeo4 = new THREE.BoxGeometry(0.33, 0.28, 0.3);
  const boxGeo5 = new THREE.BoxGeometry(0.21, 0.255, 0.3);
  const boxGeo6 = new THREE.BoxGeometry(0.33, 0.255, 0.3);
  const boxGeo7 = new THREE.BoxGeometry(0.21, 0.18, 0.3);

  // Parts
  const plinth = new THREE.Mesh(boxGeo, plinthMat);
  plinth.name = 'plinth';
  plinth.position.set(-0.775, 0.15, 0);
  root.add(plinth);
  const plinth2 = new THREE.Mesh(boxGeo, plinthMat);
  plinth2.name = 'plinth';
  plinth2.position.set(0.775, 0.15, 0);
  root.add(plinth2);
  const threshold = new THREE.Mesh(new THREE.BoxGeometry(1.1, 0.12, 0.31), dressedMat);
  threshold.name = 'threshold';
  threshold.position.set(0, 0.06, 0);
  root.add(threshold);
  const cap = new THREE.Mesh(new THREE.BoxGeometry(2, 0.2, 0.32), dressedMat);
  cap.name = 'cap';
  cap.position.set(0, 2.9, 0);
  root.add(cap);
  const core = new THREE.Mesh(extrude([[-1, 0.3], [-0.59, 0.3], [-0.59, 2.24], [0.59, 2.24], [0.59, 0.3], [1, 0.3], [1, 2.8], [-1, 2.8]], 0.25), mortarMat);
  core.name = 'core';
  root.add(core);
  const revealLining = new THREE.Mesh(boxGeo2, mortarMat);
  revealLining.name = 'revealLining';
  revealLining.position.set(-0.5775, 1.27, 0);
  root.add(revealLining);
  const revealLining2 = new THREE.Mesh(boxGeo2, mortarMat);
  revealLining2.name = 'revealLining';
  revealLining2.position.set(0.5775, 1.27, 0);
  root.add(revealLining2);
  const jamb = new THREE.Mesh(boxGeo3, dressedMat);
  jamb.name = 'jamb';
  jamb.position.set(-0.655, 0.45, 0);
  root.add(jamb);
  const jamb2 = new THREE.Mesh(boxGeo3, dressedMat);
  jamb2.name = 'jamb';
  jamb2.position.set(0.655, 0.45, 0);
  root.add(jamb2);
  const jamb3 = new THREE.Mesh(boxGeo4, dressedMat);
  jamb3.name = 'jamb';
  jamb3.position.set(-0.715, 0.75, 0);
  root.add(jamb3);
  const jamb4 = new THREE.Mesh(boxGeo4, dressedMat);
  jamb4.name = 'jamb';
  jamb4.position.set(0.715, 0.75, 0);
  root.add(jamb4);
  const jamb5 = new THREE.Mesh(boxGeo5, dressedMat);
  jamb5.name = 'jamb';
  jamb5.position.set(-0.655, 1.0375, 0);
  root.add(jamb5);
  const jamb6 = new THREE.Mesh(boxGeo5, dressedMat);
  jamb6.name = 'jamb';
  jamb6.position.set(0.655, 1.0375, 0);
  root.add(jamb6);
  const jamb7 = new THREE.Mesh(boxGeo6, dressedMat);
  jamb7.name = 'jamb';
  jamb7.position.set(-0.715, 1.3125, 0);
  root.add(jamb7);
  const jamb8 = new THREE.Mesh(boxGeo6, dressedMat);
  jamb8.name = 'jamb';
  jamb8.position.set(0.715, 1.3125, 0);
  root.add(jamb8);
  const jamb9 = new THREE.Mesh(boxGeo5, dressedMat);
  jamb9.name = 'jamb';
  jamb9.position.set(-0.655, 1.5875, 0);
  root.add(jamb9);
  const jamb10 = new THREE.Mesh(boxGeo5, dressedMat);
  jamb10.name = 'jamb';
  jamb10.position.set(0.655, 1.5875, 0);
  root.add(jamb10);
  const jamb11 = new THREE.Mesh(boxGeo6, dressedMat);
  jamb11.name = 'jamb';
  jamb11.position.set(-0.715, 1.8625, 0);
  root.add(jamb11);
  const jamb12 = new THREE.Mesh(boxGeo6, dressedMat);
  jamb12.name = 'jamb';
  jamb12.position.set(0.715, 1.8625, 0);
  root.add(jamb12);
  const jamb13 = new THREE.Mesh(boxGeo7, dressedMat);
  jamb13.name = 'jamb';
  jamb13.position.set(-0.655, 2.1, 0);
  root.add(jamb13);
  const jamb14 = new THREE.Mesh(boxGeo7, dressedMat);
  jamb14.name = 'jamb';
  jamb14.position.set(0.655, 2.1, 0);
  root.add(jamb14);
  const lintel = new THREE.Mesh(new THREE.BoxGeometry(1.74, 0.29, 0.3), dressedMat);
  lintel.name = 'lintel';
  lintel.position.set(0, 2.345, 0);
  root.add(lintel);
  const stone = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.21, 0.28, 0.2787), 0.005, 550), stone2Mat);
  stone.name = 'stone';
  stone.position.set(-0.885, 0.45, 0);
  root.add(stone);
  const stone2 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.21, 0.28, 0.2864), 0.005, 551), stone2Mat);
  stone2.name = 'stone';
  stone2.position.set(0.885, 0.45, 0);
  root.add(stone2);
  const stone3 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.09, 0.28, 0.2787), 0.005, 552), stone2Mat);
  stone3.name = 'stone';
  stone3.position.set(-0.945, 0.75, 0);
  root.add(stone3);
  const stone4 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.09, 0.28, 0.2775), 0.005, 553), stone3Mat);
  stone4.name = 'stone';
  stone4.position.set(0.945, 0.75, 0);
  root.add(stone4);
  const stone5 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.21, 0.255, 0.2821), 0.005, 554), stone3Mat);
  stone5.name = 'stone';
  stone5.position.set(-0.885, 1.0375, 0);
  root.add(stone5);
  const stone6 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.21, 0.255, 0.2703), 0.005, 555), stoneMat);
  stone6.name = 'stone';
  stone6.position.set(0.885, 1.0375, 0);
  root.add(stone6);
  const stone7 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.09, 0.255, 0.275), 0.005, 556), stone2Mat);
  stone7.name = 'stone';
  stone7.position.set(-0.945, 1.3125, 0);
  root.add(stone7);
  const stone8 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.09, 0.255, 0.2803), 0.005, 557), stone2Mat);
  stone8.name = 'stone';
  stone8.position.set(0.945, 1.3125, 0);
  root.add(stone8);
  const stone9 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.21, 0.255, 0.2863), 0.005, 558), stone3Mat);
  stone9.name = 'stone';
  stone9.position.set(-0.885, 1.5875, 0);
  root.add(stone9);
  const stone10 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.21, 0.255, 0.2736), 0.005, 559), stone2Mat);
  stone10.name = 'stone';
  stone10.position.set(0.885, 1.5875, 0);
  root.add(stone10);
  const stone11 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.09, 0.255, 0.2673), 0.005, 560), stone3Mat);
  stone11.name = 'stone';
  stone11.position.set(-0.945, 1.8625, 0);
  root.add(stone11);
  const stone12 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.09, 0.255, 0.2731), 0.005, 561), stoneMat);
  stone12.name = 'stone';
  stone12.position.set(0.945, 1.8625, 0);
  root.add(stone12);
  const stone13 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.21, 0.18, 0.2743), 0.005, 562), stone2Mat);
  stone13.name = 'stone';
  stone13.position.set(-0.885, 2.1, 0);
  root.add(stone13);
  const stone14 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.21, 0.18, 0.2863), 0.005, 563), stoneMat);
  stone14.name = 'stone';
  stone14.position.set(0.885, 2.1, 0);
  root.add(stone14);
  const stone15 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.1, 0.28, 0.2857), 0.005, 564), stone2Mat);
  stone15.name = 'stone';
  stone15.position.set(-0.94, 2.35, 0);
  root.add(stone15);
  const stone16 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.1, 0.28, 0.2678), 0.005, 565), stone3Mat);
  stone16.name = 'stone';
  stone16.position.set(0.94, 2.35, 0);
  root.add(stone16);
  const stone17 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.5789, 0.28, 0.2836), 0.005, 566), stoneMat);
  stone17.name = 'stone';
  stone17.position.set(-0.7005, 2.65, 0);
  root.add(stone17);
  const stone18 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.5904, 0.28, 0.2815), 0.005, 567), stoneMat);
  stone18.name = 'stone';
  stone18.position.set(-0.0959, 2.65, 0);
  root.add(stone18);
  const stone19 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4882, 0.28, 0.2767), 0.005, 568), stone2Mat);
  stone19.name = 'stone';
  stone19.position.set(0.4634, 2.65, 0);
  root.add(stone19);
  const stone20 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.2625, 0.28, 0.2896), 0.005, 569), stone2Mat);
  stone20.name = 'stone';
  stone20.position.set(0.8588, 2.65, 0);
  root.add(stone20);

  root.traverse((o) => {
    if (o.isMesh) {
      o.castShadow = true;
      o.receiveShadow = true;
    }
  });
  return root;
}

export default createWallDoorway;

Notes et commentaires

—
Aucune note pour l’instant — soyez le premier.
5
0
4
0
3
0
2
0
1
0

Connectez-vous pour noter et commenter.

0 commentaire

Aucun commentaire pour l’instant. Dites comment vous avez utilisé ce modèle ou ce qui pourrait être amélioré.

Modèles similaires

Même catégorie ou étiquettes proches