Codels
삼각형 872개4.00 × 0.17 × 4.00 m

코드에서 사용하기

에디터에서 리믹스
독립형 ES 모듈이에요 — three에만 의존해요. 팩토리 함수를 호출하고 그룹을 씬에 추가하세요.
/**
 * Road Corner — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 872 · Size (W × H × D): 4.00 × 0.17 × 4.00 m
 *
 * Usage:
 *   import { createRoadCorner } from './road-corner.js';
 *   
 *   const model = createRoadCorner();
 *   model.position.set(0, 0, 0);
 *   scene.add(model);
 */
import * as THREE from 'three';

const deg = THREE.MathUtils.degToRad;

// Revolve a 2D profile [[radius, y], ...] around the Y axis.
function lathe(points, segments, phiStart = 0, phiLength = Math.PI * 2) {
  return new THREE.LatheGeometry(points.map(([x, y]) => new THREE.Vector2(x, y)), segments, phiStart, phiLength);
}

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

  // Materials
  const asphaltMat = new THREE.MeshStandardMaterial({ name: 'asphalt', color: 0x41454b, roughness: 0.95, flatShading: true });
  const whiteMat = new THREE.MeshStandardMaterial({ name: 'white', color: 0xecebe4, roughness: 0.7, flatShading: true });
  const yellowMat = new THREE.MeshStandardMaterial({ name: 'yellow', color: 0xe9b72c, roughness: 0.7, flatShading: true });
  const curbMat = new THREE.MeshStandardMaterial({ name: 'curb', color: 0xb4b2ab, roughness: 0.9, flatShading: true });
  const paverMat = new THREE.MeshStandardMaterial({ name: 'paver', color: 0x92918b, roughness: 0.95, flatShading: true });
  const baseMat = new THREE.MeshStandardMaterial({ name: 'base', color: 0x64635f, roughness: 1, flatShading: true });
  const grateMat = new THREE.MeshStandardMaterial({ name: 'grate', color: 0x26292c, roughness: 0.6, metalness: 0.5, flatShading: true });

  // Shared geometries
  const boxGeo = new THREE.BoxGeometry(0.24, 0.006, 0.035);

  // Parts
  const asphalt = new THREE.Mesh(extrude([[-1.35, 2], [-1.3339, 1.6716], [-1.2856, 1.3464], [-1.2058, 1.0275], [-1.095, 0.718], [-0.9544, 0.4208], [-0.7854, 0.1388], [-0.5896, -0.1252], [-0.3688, -0.3688], [-0.1252, -0.5896], [0.1388, -0.7854], [0.4208, -0.9544], [0.718, -1.095], [1.0275, -1.2058], [1.3464, -1.2856], [1.6716, -1.3339], [2, -1.35], [2, 1.35], [1.9363, 1.3531], [1.8732, 1.3625], [1.8113, 1.378], [1.7513, 1.3995], [1.6936, 1.4268], [1.6389, 1.4595], [1.5876, 1.4975], [1.5404, 1.5404], [1.4975, 1.5876], [1.4595, 1.6389], [1.4268, 1.6936], [1.3995, 1.7513], [1.378, 1.8113], [1.3625, 1.8732], [1.3531, 1.9363], [1.35, 2]], 0.02), asphaltMat);
  asphalt.name = 'asphalt';
  asphalt.position.set(0, 0.01, 0);
  asphalt.rotation.set(deg(90), 0, 0);
  root.add(asphalt);
  const edgeLine = new THREE.Mesh(lathe([[1.12, 0], [1.02, 0]], 16, -Math.PI, Math.PI / 2), whiteMat);
  edgeLine.name = 'edgeLine';
  edgeLine.position.set(2, 0.025, 2);
  root.add(edgeLine);
  const edgeLine2 = new THREE.Mesh(lathe([[2.98, 0], [2.88, 0]], 16, -Math.PI, Math.PI / 2), whiteMat);
  edgeLine2.name = 'edgeLine';
  edgeLine2.position.set(2, 0.025, 2);
  root.add(edgeLine2);
  const centerDash = new THREE.Mesh(lathe([[2.055, 0], [1.945, 0]], 3, -2.1598, 0.3927), yellowMat);
  centerDash.name = 'centerDash';
  centerDash.position.set(2, 0.025, 2);
  root.add(centerDash);
  const centerDash2 = new THREE.Mesh(lathe([[2.055, 0], [1.945, 0]], 3, -2.9452, 0.3927), yellowMat);
  centerDash2.name = 'centerDash';
  centerDash2.position.set(2, 0.025, 2);
  root.add(centerDash2);
  const curb = new THREE.Mesh(extrude([[1.35, 2], [1.3625, 1.8732], [1.3995, 1.7513], [1.4595, 1.6389], [1.5404, 1.5404], [1.6389, 1.4595], [1.7513, 1.3995], [1.8732, 1.3625], [2, 1.35], [2, 1.49], [1.9005, 1.4998], [1.8048, 1.5288], [1.7167, 1.576], [1.6394, 1.6394], [1.576, 1.7167], [1.5288, 1.8048], [1.4998, 1.9005], [1.49, 2]], 0.165), curbMat);
  curb.name = 'curb';
  curb.position.set(0, 0.0825, 0);
  curb.rotation.set(deg(90), 0, 0);
  root.add(curb);
  const sidewalkBase = new THREE.Mesh(extrude([[1.49, 2], [1.4998, 1.9005], [1.5288, 1.8048], [1.576, 1.7167], [1.6394, 1.6394], [1.7167, 1.576], [1.8048, 1.5288], [1.9005, 1.4998], [2, 1.49], [2, 2]], 0.13), baseMat);
  sidewalkBase.name = 'sidewalkBase';
  sidewalkBase.position.set(0, 0.065, 0);
  sidewalkBase.rotation.set(deg(90), 0, 0);
  root.add(sidewalkBase);
  const paver = new THREE.Mesh(extrude([[1.4966, 1.994], [1.5057, 1.9017], [1.5344, 1.8071], [1.5809, 1.72], [1.6436, 1.6436], [1.72, 1.5809], [1.8071, 1.5344], [1.9017, 1.5057], [1.994, 1.4966], [1.994, 1.994]], 0.02), paverMat);
  paver.name = 'paver';
  paver.position.set(0, 0.14, 0);
  paver.rotation.set(deg(90), 0, 0);
  root.add(paver);
  const curb2 = new THREE.Mesh(extrude([[2, -1.35], [1.6716, -1.3339], [1.3464, -1.2856], [1.0275, -1.2058], [0.718, -1.095], [0.4208, -0.9544], [0.1388, -0.7854], [-0.1252, -0.5896], [-0.3688, -0.3688], [-0.5896, -0.1252], [-0.7854, 0.1388], [-0.9544, 0.4208], [-1.095, 0.718], [-1.2058, 1.0275], [-1.2856, 1.3464], [-1.3339, 1.6716], [-1.35, 2], [-1.49, 2], [-1.4732, 1.6579], [-1.4229, 1.3191], [-1.3397, 0.9869], [-1.2243, 0.6644], [-1.0779, 0.3548], [-0.9018, 0.0611], [-0.6978, -0.214], [-0.4678, -0.4678], [-0.214, -0.6978], [0.0611, -0.9018], [0.3548, -1.0779], [0.6644, -1.2243], [0.9869, -1.3397], [1.3191, -1.4229], [1.6579, -1.4732], [2, -1.49]], 0.165), curbMat);
  curb2.name = 'curb';
  curb2.position.set(0, 0.0825, 0);
  curb2.rotation.set(deg(90), 0, 0);
  root.add(curb2);
  const sidewalkBase2 = new THREE.Mesh(extrude([[2, -1.49], [1.6579, -1.4732], [1.3191, -1.4229], [0.9869, -1.3397], [0.6644, -1.2243], [0.3548, -1.0779], [0.0611, -0.9018], [-0.214, -0.6978], [-0.4678, -0.4678], [-0.6978, -0.214], [-0.9018, 0.0611], [-1.0779, 0.3548], [-1.2243, 0.6644], [-1.3397, 0.9869], [-1.4229, 1.3191], [-1.4732, 1.6579], [-1.49, 2], [-2, 2], [-2, -2], [2, -2]], 0.13), baseMat);
  sidewalkBase2.name = 'sidewalkBase';
  sidewalkBase2.position.set(0, 0.065, 0);
  sidewalkBase2.rotation.set(deg(90), 0, 0);
  root.add(sidewalkBase2);
  const paver2 = new THREE.Mesh(extrude([[-1.496, 1.994], [-1.4825, 1.6933], [-1.4432, 1.3949], [-1.3784, 1.101], [-1.8595, 0.9721], [-1.9337, 1.3084], [-1.9786, 1.6499], [-1.994, 1.994], [-1.8695, 1.994]], 0.02), paverMat);
  paver2.name = 'paver';
  paver2.position.set(0, 0.14, 0);
  paver2.rotation.set(deg(90), 0, 0);
  root.add(paver2);
  const paver3 = new THREE.Mesh(extrude([[-1.3753, 1.0894], [-1.2845, 0.8024], [-1.1693, 0.5243], [-1.0306, 0.2572], [-1.4619, 0.0082], [-1.6206, 0.3139], [-1.7524, 0.6321], [-1.8564, 0.9605]], 0.02), paverMat);
  paver3.name = 'paver';
  paver3.position.set(0, 0.14, 0);
  paver3.rotation.set(deg(90), 0, 0);
  root.add(paver3);
  const paver4 = new THREE.Mesh(extrude([[-1.0246, 0.2468], [-0.8626, -0.0069], [-0.6794, -0.2457], [-0.4763, -0.4678], [-0.8284, -0.8199], [-1.0609, -0.5658], [-1.2705, -0.2925], [-1.4559, -0.0022]], 0.02), paverMat);
  paver4.name = 'paver';
  paver4.position.set(0, 0.14, 0);
  paver4.rotation.set(deg(90), 0, 0);
  root.add(paver4);
  const paver5 = new THREE.Mesh(extrude([[-0.4678, -0.4763], [-0.2457, -0.6794], [-0.0069, -0.8626], [0.2468, -1.0246], [-0.0022, -1.4559], [-0.2925, -1.2705], [-0.5658, -1.0609], [-0.8199, -0.8284]], 0.02), paverMat);
  paver5.name = 'paver';
  paver5.position.set(0, 0.14, 0);
  paver5.rotation.set(deg(90), 0, 0);
  root.add(paver5);
  const paver6 = new THREE.Mesh(extrude([[0.2572, -1.0306], [0.5243, -1.1693], [0.8024, -1.2845], [1.0894, -1.3753], [0.9605, -1.8564], [0.6321, -1.7524], [0.3139, -1.6206], [0.0082, -1.4619]], 0.02), paverMat);
  paver6.name = 'paver';
  paver6.position.set(0, 0.14, 0);
  paver6.rotation.set(deg(90), 0, 0);
  root.add(paver6);
  const paver7 = new THREE.Mesh(extrude([[1.101, -1.3784], [1.3949, -1.4432], [1.6933, -1.4825], [1.994, -1.496], [1.994, -1.8072], [1.994, -1.994], [1.6499, -1.9786], [1.3084, -1.9337], [0.9721, -1.8595]], 0.02), paverMat);
  paver7.name = 'paver';
  paver7.position.set(0, 0.14, 0);
  paver7.rotation.set(deg(90), 0, 0);
  root.add(paver7);
  const paver8 = new THREE.Mesh(extrude([[-1.994, 1.8141], [-1.9713, 1.4741], [-1.8695, 0.9632], [-1.7022, 0.4697], [-1.4723, 0.0022], [-1.994, -0.299]], 0.02), paverMat);
  paver8.name = 'paver';
  paver8.position.set(0, 0.14, 0);
  paver8.rotation.set(deg(90), 0, 0);
  root.add(paver8);
  const paver9 = new THREE.Mesh(extrude([[-1.4663, -0.0082], [-1.1763, -0.4411], [-0.8327, -0.8327], [-0.4411, -1.1763], [-0.0082, -1.4663], [-0.3129, -1.994], [-1.994, -1.994], [-1.994, -0.3129]], 0.02), paverMat);
  paver9.name = 'paver';
  paver9.position.set(0, 0.14, 0);
  paver9.rotation.set(deg(90), 0, 0);
  root.add(paver9);
  const paver10 = new THREE.Mesh(extrude([[0.0022, -1.4723], [0.4697, -1.7022], [0.9632, -1.8695], [1.4741, -1.9713], [1.8141, -1.994], [-0.299, -1.994]], 0.02), paverMat);
  paver10.name = 'paver';
  paver10.position.set(0, 0.14, 0);
  paver10.rotation.set(deg(90), 0, 0);
  root.add(paver10);
  const drain = new THREE.Group();
  drain.name = 'drain';
  drain.position.set(-0.2415, 0, -0.2415);
  drain.rotation.set(0, deg(-45), 0);
  root.add(drain);
  const drainGrate = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.012, 0.6), grateMat);
  drainGrate.name = 'drainGrate';
  drainGrate.position.set(0, 0.022, 0);
  drain.add(drainGrate);
  const grateBar = new THREE.Mesh(boxGeo, baseMat);
  grateBar.name = 'grateBar';
  grateBar.position.set(0, 0.028, -0.22);
  drain.add(grateBar);
  const grateBar2 = new THREE.Mesh(boxGeo, baseMat);
  grateBar2.name = 'grateBar';
  grateBar2.position.set(0, 0.028, -0.11);
  drain.add(grateBar2);
  const grateBar3 = new THREE.Mesh(boxGeo, baseMat);
  grateBar3.name = 'grateBar';
  grateBar3.position.set(0, 0.028, 0);
  drain.add(grateBar3);
  const grateBar4 = new THREE.Mesh(boxGeo, baseMat);
  grateBar4.name = 'grateBar';
  grateBar4.position.set(0, 0.028, 0.11);
  drain.add(grateBar4);
  const grateBar5 = new THREE.Mesh(boxGeo, baseMat);
  grateBar5.name = 'grateBar';
  grateBar5.position.set(0, 0.028, 0.22);
  drain.add(grateBar5);

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

export default createRoadCorner;

평점 및 댓글

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

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

댓글 0개

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

관련 모델

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