Codels
268 Tris1,33 × 0,85 × 1,42 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.
/**
 * Boulder — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 268 · Size (W × H × D): 1.33 × 0.85 × 1.42 m
 *
 * Usage:
 *   import { createBoulder } from './boulder.js';
 *   
 *   const model = createBoulder();
 *   model.position.set(0, 0, 0);
 *   scene.add(model);
 */
import * as THREE from 'three';

const deg = THREE.MathUtils.degToRad;

// 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 createBoulder() {
  const root = new THREE.Group();
  root.name = 'Boulder';

  // Materials
  const stoneMat = new THREE.MeshStandardMaterial({ name: 'stone', color: 0x676b72, roughness: 0.92, flatShading: true });
  const pebbleMat = new THREE.MeshStandardMaterial({ name: 'pebble', color: 0x595c62, roughness: 0.95, flatShading: true });
  const mossMat = new THREE.MeshStandardMaterial({ name: 'moss', color: 0x52733a, roughness: 1, flatShading: true });

  // Shared geometries
  const icosahedronGeo = jitter(new THREE.IcosahedronGeometry(1, 1), 0.14, 4);

  // Parts
  const rock = new THREE.Mesh(icosahedronGeo, stoneMat);
  rock.name = 'rock';
  rock.position.set(0, 0.4594, 0);
  rock.rotation.set(deg(5.9306), deg(338.5505), 0);
  rock.scale.set(0.6871, 0.4027, 0.5469);
  root.add(rock);
  const moss = new THREE.Mesh(icosahedronGeo, mossMat);
  moss.name = 'moss';
  moss.position.set(0, 0.4876, 0);
  moss.rotation.set(deg(5.9306), deg(338.5505), 0);
  moss.scale.set(0.6184, 0.4027, 0.4922);
  root.add(moss);
  const pebble1 = new THREE.Mesh(jitter(new THREE.DodecahedronGeometry(0.1162, 0), 0.0174, 28), pebbleMat);
  pebble1.name = 'pebble1';
  pebble1.position.set(0.3287, 0.0592, -0.7388);
  pebble1.rotation.set(deg(3.1291), deg(262.3212), 0);
  pebble1.scale.set(1, 0.6, 1);
  root.add(pebble1);
  const pebble2 = new THREE.Mesh(jitter(new THREE.DodecahedronGeometry(0.1235, 0), 0.0185, 29), pebbleMat);
  pebble2.name = 'pebble2';
  pebble2.position.set(0.4849, 0.1215, -0.5006);
  pebble2.rotation.set(deg(76.0278), deg(84.1818), 0);
  pebble2.scale.set(1, 0.6, 1);
  root.add(pebble2);
  const pebble3 = new THREE.Mesh(jitter(new THREE.DodecahedronGeometry(0.082, 0), 0.0123, 30), pebbleMat);
  pebble3.name = 'pebble3';
  pebble3.position.set(0.4246, 0.054, -0.6306);
  pebble3.rotation.set(deg(31.3078), deg(352.5002), 0);
  pebble3.scale.set(1, 0.6, 1);
  root.add(pebble3);

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

export default createBoulder;

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