Codels
156 Tris2,00 × 0,10 × 2,00 m

Im Code verwenden

Im Editor remixen
Eigenständiges ES-Modul — hängt nur von three ab. Ruf die Factory auf und füge die Gruppe deiner Szene hinzu.
/**
 * Modular Floor Tile — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 156 · Size (W × H × D): 2.00 × 0.10 × 2.00 m
 *
 * Usage:
 *   import { createFloorTile } from './floor-tile.js';
 *   
 *   const model = createFloorTile();
 *   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;
}

export function createFloorTile() {
  const root = new THREE.Group();
  root.name = 'FloorTile';

  // Materials
  const flagMat = new THREE.MeshStandardMaterial({ name: 'flag', color: 0x7c7871, roughness: 0.95, flatShading: true });
  const flag2Mat = new THREE.MeshStandardMaterial({ name: 'flag2', color: 0x67635c, roughness: 0.95, flatShading: true });
  const flag3Mat = new THREE.MeshStandardMaterial({ name: 'flag3', color: 0x8b867c, roughness: 0.95, flatShading: true });
  const mortarMat = new THREE.MeshStandardMaterial({ name: 'mortar', color: 0x3f3c38, roughness: 1, flatShading: true });

  // Parts
  const bed = new THREE.Mesh(new THREE.BoxGeometry(2, 0.07, 2), mortarMat);
  bed.name = 'bed';
  bed.position.set(0, 0.035, 0);
  root.add(bed);
  const flag = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.73, 0.0239, 0.48), 0.004, 1), flag2Mat);
  flag.name = 'flag';
  flag.position.set(-0.625, 0.082, -0.75);
  root.add(flag);
  const flag2 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.73, 0.0226, 0.48), 0.004, 2), flag2Mat);
  flag2.name = 'flag';
  flag2.position.set(0.125, 0.0813, -0.75);
  root.add(flag2);
  const flag3 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.48, 0.0239, 0.48), 0.004, 3), flag2Mat);
  flag3.name = 'flag';
  flag3.position.set(0.75, 0.082, -0.75);
  root.add(flag3);
  const flag4 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.58, 0.0241, 0.48), 0.004, 4), flag3Mat);
  flag4.name = 'flag';
  flag4.position.set(-0.7, 0.0821, -0.25);
  root.add(flag4);
  const flag5 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.58, 0.0233, 0.48), 0.004, 5), flag3Mat);
  flag5.name = 'flag';
  flag5.position.set(-0.1, 0.0817, -0.25);
  root.add(flag5);
  const flag6 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.78, 0.0253, 0.48), 0.004, 6), flagMat);
  flag6.name = 'flag';
  flag6.position.set(0.6, 0.0827, -0.25);
  root.add(flag6);
  const flag7 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.58, 0.0245, 0.48), 0.004, 7), flag2Mat);
  flag7.name = 'flag';
  flag7.position.set(-0.7, 0.0823, 0.25);
  root.add(flag7);
  const flag8 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.48, 0.0236, 0.48), 0.004, 8), flag2Mat);
  flag8.name = 'flag';
  flag8.position.set(-0.15, 0.0818, 0.25);
  root.add(flag8);
  const flag9 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.88, 0.0226, 0.48), 0.004, 9), flag3Mat);
  flag9.name = 'flag';
  flag9.position.set(0.55, 0.0813, 0.25);
  root.add(flag9);
  const flag10 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.88, 0.0247, 0.48), 0.004, 10), flag2Mat);
  flag10.name = 'flag';
  flag10.position.set(-0.55, 0.0824, 0.75);
  root.add(flag10);
  const flag11 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.58, 0.0258, 0.48), 0.004, 11), flag3Mat);
  flag11.name = 'flag';
  flag11.position.set(0.2, 0.0829, 0.75);
  root.add(flag11);
  const flag12 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.48, 0.0248, 0.48), 0.004, 12), flagMat);
  flag12.name = 'flag';
  flag12.position.set(0.75, 0.0824, 0.75);
  root.add(flag12);

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

export default createFloorTile;

Bewertungen & Kommentare

—
Noch keine Bewertungen — gib die erste ab.
5
0
4
0
3
0
2
0
1
0

Melde dich an, um zu bewerten und zu kommentieren.

0 Kommentare

Noch keine Kommentare. Erzähl, wie du dieses Modell genutzt hast oder was besser sein könnte.

Ähnliche Modelle

Gleiche Kategorie oder ähnliche Tags