Codels
삼각형 144개0.46 × 3.00 × 0.46 m

코드에서 사용하기

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

  // 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(0.46, 0.35, 0.46), plinthMat);
  plinth.name = 'plinth';
  plinth.position.set(0, 0.175, 0);
  root.add(plinth);
  const cap = new THREE.Mesh(new THREE.BoxGeometry(0.46, 0.25, 0.46), dressedMat);
  cap.name = 'cap';
  cap.position.set(0, 2.875, 0);
  root.add(cap);
  const core = new THREE.Mesh(new THREE.BoxGeometry(0.37, 2.4, 0.37), mortarMat);
  core.name = 'core';
  core.position.set(0, 1.55, 0);
  root.add(core);
  const block = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.23, 0.412), 0.004, 40), stone3Mat);
  block.name = 'block';
  block.position.set(0, 0.475, 0);
  root.add(block);
  const block2 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.412, 0.28, 0.4), 0.004, 41), stone3Mat);
  block2.name = 'block';
  block2.position.set(0, 0.75, 0);
  root.add(block2);
  const block3 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.255, 0.412), 0.004, 42), stone3Mat);
  block3.name = 'block';
  block3.position.set(0, 1.0375, 0);
  root.add(block3);
  const block4 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.412, 0.255, 0.4), 0.004, 43), stoneMat);
  block4.name = 'block';
  block4.position.set(0, 1.3125, 0);
  root.add(block4);
  const block5 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.255, 0.412), 0.004, 44), stone2Mat);
  block5.name = 'block';
  block5.position.set(0, 1.5875, 0);
  root.add(block5);
  const block6 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.412, 0.255, 0.4), 0.004, 45), stone2Mat);
  block6.name = 'block';
  block6.position.set(0, 1.8625, 0);
  root.add(block6);
  const block7 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.18, 0.412), 0.004, 46), stoneMat);
  block7.name = 'block';
  block7.position.set(0, 2.1, 0);
  root.add(block7);
  const block8 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.412, 0.28, 0.4), 0.004, 47), stone3Mat);
  block8.name = 'block';
  block8.position.set(0, 2.35, 0);
  root.add(block8);
  const block9 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.23, 0.412), 0.004, 48), stone3Mat);
  block9.name = 'block';
  block9.position.set(0, 2.625, 0);
  root.add(block9);

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

export default createGridPillar;

평점 및 댓글

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

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

댓글 0개

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

관련 모델

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