Codels
삼각형 108개2.00 × 1.00 × 0.32 m

코드에서 사용하기

에디터에서 리믹스
독립형 ES 모듈이에요 — three에만 의존해요. 팩토리 함수를 호출하고 그룹을 씬에 추가하세요.
/**
 * Modular Half Wall — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 108 · Size (W × H × D): 2.00 × 1.00 × 0.32 m
 *
 * Usage:
 *   import { createHalfWall } from './half-wall.js';
 *   
 *   const model = createHalfWall();
 *   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 createHalfWall() {
  const root = new THREE.Group();
  root.name = 'HalfWall';

  // 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 });

  // Parts
  const plinth = new THREE.Mesh(new THREE.BoxGeometry(2, 0.3, 0.31), plinthMat);
  plinth.name = 'plinth';
  plinth.position.set(0, 0.15, 0);
  root.add(plinth);
  const cap = new THREE.Mesh(new THREE.BoxGeometry(2, 0.2, 0.32), dressedMat);
  cap.name = 'cap';
  cap.position.set(0, 0.9, 0);
  root.add(cap);
  const core = new THREE.Mesh(new THREE.BoxGeometry(2, 0.5, 0.25), mortarMat);
  core.name = 'core';
  core.position.set(0, 0.55, 0);
  root.add(core);
  const stone = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.6509, 0.28, 0.27), 0.005, 850), stoneMat);
  stone.name = 'stone';
  stone.position.set(-0.6646, 0.45, 0);
  root.add(stone);
  const stone2 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4571, 0.28, 0.2843), 0.005, 851), stoneMat);
  stone2.name = 'stone';
  stone2.position.set(-0.0906, 0.45, 0);
  root.add(stone2);
  const stone3 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.8321, 0.28, 0.2791), 0.005, 852), stoneMat);
  stone3.name = 'stone';
  stone3.position.set(0.574, 0.45, 0);
  root.add(stone3);
  const stone4 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.6534, 0.18, 0.2717), 0.005, 853), stoneMat);
  stone4.name = 'stone';
  stone4.position.set(-0.6633, 0.7, 0);
  root.add(stone4);
  const stone5 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.6986, 0.18, 0.2811), 0.005, 854), stone3Mat);
  stone5.name = 'stone';
  stone5.position.set(0.0327, 0.7, 0);
  root.add(stone5);
  const stone6 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.588, 0.18, 0.273), 0.005, 855), stone2Mat);
  stone6.name = 'stone';
  stone6.position.set(0.696, 0.7, 0);
  root.add(stone6);

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

export default createHalfWall;

평점 및 댓글

—
아직 평점이 없어요 — 첫 평점을 남겨 보세요.
5
0
4
0
3
0
2
0
1
0

평점과 댓글을 남기려면 로그인하세요.

댓글 0개

아직 댓글이 없어요. 이 모델을 어떻게 사용했는지, 어떤 점이 더 나아질 수 있을지 공유해 주세요.

관련 모델

같은 카테고리 또는 비슷한 태그