Codels
532 треуг.0,50 × 0,87 × 1,07 m

Использовать в коде

Ремикс в редакторе
Самодостаточный ES-модуль — зависит только от three. Вызовите фабрику и добавьте группу в сцену.
/**
 * Pig — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 532 · Size (W × H × D): 0.50 × 0.87 × 1.07 m
 *
 * Usage:
 *   import { createPig } from './pig.js';
 *   
 *   const model = createPig();
 *   model.position.set(0, 0, 0);
 *   scene.add(model);
 */
import * as THREE from 'three';

const deg = THREE.MathUtils.degToRad;

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

// Tube along a smooth curve through the given points.
function tube(path, radius, tubularSegments, radialSegments, closed = false) {
  const curve = new THREE.CatmullRomCurve3(path.map(([x, y, z]) => new THREE.Vector3(x, y, z)), closed);
  return new THREE.TubeGeometry(curve, tubularSegments, radius, radialSegments, closed);
}

export function createPig() {
  const root = new THREE.Group();
  root.name = 'Pig';

  // Materials
  const skinMat = new THREE.MeshStandardMaterial({ name: 'skin', color: 0xf2919f, roughness: 0.8, flatShading: true });
  const snoutMat = new THREE.MeshStandardMaterial({ name: 'snout', color: 0xd07d89, roughness: 0.7, flatShading: true });
  const darkMat = new THREE.MeshStandardMaterial({ name: 'dark', color: 0x5a3438, roughness: 0.6, flatShading: true });
  const eyeMat = new THREE.MeshStandardMaterial({ name: 'eye', color: 0x1f1a1b, roughness: 0.4, flatShading: true });
  const shineMat = new THREE.MeshStandardMaterial({ name: 'shine', color: 0xffffff, roughness: 0.4, flatShading: true });

  // Shared geometries
  const boxGeo = new THREE.BoxGeometry(0.12, 0.16, 0.12);
  const boxGeo2 = new THREE.BoxGeometry(0.125, 0.04, 0.125);
  const boxGeo3 = new THREE.BoxGeometry(0.045, 0.07, 0.02);
  const boxGeo4 = new THREE.BoxGeometry(0.06, 0.07, 0.06);
  const boxGeo5 = new THREE.BoxGeometry(0.022, 0.022, 0.01);
  const boxGeo6 = new THREE.BoxGeometry(0.07, 0.035, 0.01);
  const extrudeGeo = extrude([[-0.085, 0], [0.085, 0], [0.055, 0.1], [0, 0.17], [-0.055, 0.1]], 0.035);
  const extrudeGeo2 = extrude([[-0.05, 0.02], [0.05, 0.02], [0.03, 0.08], [0, 0.125], [-0.03, 0.08]], 0.01);

  // Parts
  const pig = new THREE.Group();
  pig.name = 'pig';
  root.add(pig);
  const legFL = new THREE.Group();
  legFL.name = 'legFL';
  legFL.position.set(0.15, 0.2, 0.17);
  pig.add(legFL);
  const legFLUpper = new THREE.Mesh(boxGeo, skinMat);
  legFLUpper.name = 'legFLUpper';
  legFLUpper.position.set(0, -0.08, 0);
  legFL.add(legFLUpper);
  const legFLHoof = new THREE.Mesh(boxGeo2, darkMat);
  legFLHoof.name = 'legFLHoof';
  legFLHoof.position.set(0, -0.18, 0);
  legFL.add(legFLHoof);
  const legFR = new THREE.Group();
  legFR.name = 'legFR';
  legFR.position.set(-0.15, 0.2, 0.17);
  pig.add(legFR);
  const legFRUpper = new THREE.Mesh(boxGeo, skinMat);
  legFRUpper.name = 'legFRUpper';
  legFRUpper.position.set(0, -0.08, 0);
  legFR.add(legFRUpper);
  const legFRHoof = new THREE.Mesh(boxGeo2, darkMat);
  legFRHoof.name = 'legFRHoof';
  legFRHoof.position.set(0, -0.18, 0);
  legFR.add(legFRHoof);
  const legBL = new THREE.Group();
  legBL.name = 'legBL';
  legBL.position.set(0.15, 0.2, -0.18);
  pig.add(legBL);
  const legBLUpper = new THREE.Mesh(boxGeo, skinMat);
  legBLUpper.name = 'legBLUpper';
  legBLUpper.position.set(0, -0.08, 0);
  legBL.add(legBLUpper);
  const legBLHoof = new THREE.Mesh(boxGeo2, darkMat);
  legBLHoof.name = 'legBLHoof';
  legBLHoof.position.set(0, -0.18, 0);
  legBL.add(legBLHoof);
  const legBR = new THREE.Group();
  legBR.name = 'legBR';
  legBR.position.set(-0.15, 0.2, -0.18);
  pig.add(legBR);
  const legBRUpper = new THREE.Mesh(boxGeo, skinMat);
  legBRUpper.name = 'legBRUpper';
  legBRUpper.position.set(0, -0.08, 0);
  legBR.add(legBRUpper);
  const legBRHoof = new THREE.Mesh(boxGeo2, darkMat);
  legBRHoof.name = 'legBRHoof';
  legBRHoof.position.set(0, -0.18, 0);
  legBR.add(legBRHoof);
  const body = new THREE.Group();
  body.name = 'body';
  pig.add(body);
  const torso = new THREE.Mesh(new THREE.BoxGeometry(0.5, 0.4, 0.6), skinMat);
  torso.name = 'torso';
  torso.position.set(0, 0.36, 0);
  body.add(torso);
  const tail = new THREE.Group();
  tail.name = 'tail';
  tail.position.set(0, 0.46, -0.3);
  pig.add(tail);
  const tailCurl = new THREE.Mesh(tube([[0, 0, -0.015], [0.0448, 0.0246, -0.022], [0.0463, 0.0729, -0.029], [0.0062, 0.0981, -0.036], [-0.0364, 0.0775, -0.043], [-0.0432, 0.0314, -0.05], [-0.0108, 0.0014, -0.057], [0.0284, 0.0113, -0.064], [0.0389, 0.047, -0.071], [0.0139, 0.0727, -0.078], [-0.021, 0.0647, -0.085]], 0.018, 24, 5), skinMat);
  tailCurl.name = 'tailCurl';
  tail.add(tailCurl);
  const head = new THREE.Group();
  head.name = 'head';
  head.position.set(0, 0.44, 0.24);
  pig.add(head);
  const skull = new THREE.Mesh(new THREE.BoxGeometry(0.5, 0.44, 0.38), skinMat);
  skull.name = 'skull';
  skull.position.set(0, 0.08, 0.14);
  head.add(skull);
  const snout = new THREE.Mesh(new THREE.BoxGeometry(0.24, 0.16, 0.09), snoutMat);
  snout.name = 'snout';
  snout.position.set(0, 0.01, 0.37);
  head.add(snout);
  const nostrilL = new THREE.Mesh(boxGeo3, darkMat);
  nostrilL.name = 'nostrilL';
  nostrilL.position.set(0.05, 0.01, 0.42);
  head.add(nostrilL);
  const nostrilR = new THREE.Mesh(boxGeo3, darkMat);
  nostrilR.name = 'nostrilR';
  nostrilR.position.set(-0.05, 0.01, 0.42);
  head.add(nostrilR);
  const eyeL = new THREE.Mesh(boxGeo4, eyeMat);
  eyeL.name = 'eyeL';
  eyeL.position.set(0.2, 0.15, 0.305);
  head.add(eyeL);
  const eyeShineL = new THREE.Mesh(boxGeo5, shineMat);
  eyeShineL.name = 'eyeShineL';
  eyeShineL.position.set(0.21, 0.165, 0.34);
  head.add(eyeShineL);
  const eyeR = new THREE.Mesh(boxGeo4, eyeMat);
  eyeR.name = 'eyeR';
  eyeR.position.set(-0.2, 0.15, 0.305);
  head.add(eyeR);
  const eyeShineR = new THREE.Mesh(boxGeo5, shineMat);
  eyeShineR.name = 'eyeShineR';
  eyeShineR.position.set(-0.21, 0.165, 0.34);
  head.add(eyeShineR);
  const cheekL = new THREE.Mesh(boxGeo6, snoutMat);
  cheekL.name = 'cheekL';
  cheekL.position.set(0.2, 0.06, 0.3355);
  head.add(cheekL);
  const cheekR = new THREE.Mesh(boxGeo6, snoutMat);
  cheekR.name = 'cheekR';
  cheekR.position.set(-0.2, 0.06, 0.3355);
  head.add(cheekR);
  const earL = new THREE.Group();
  earL.name = 'earL';
  earL.position.set(0.16, 0.28, 0.09);
  earL.rotation.set(deg(28), 0, deg(-18));
  head.add(earL);
  const earFlapL = new THREE.Mesh(extrudeGeo, skinMat);
  earFlapL.name = 'earFlapL';
  earL.add(earFlapL);
  const earInL = new THREE.Mesh(extrudeGeo2, snoutMat);
  earInL.name = 'earInL';
  earInL.position.set(0, 0, 0.02);
  earL.add(earInL);
  const earR = new THREE.Group();
  earR.name = 'earR';
  earR.position.set(-0.16, 0.28, 0.09);
  earR.rotation.set(deg(28), 0, deg(18));
  head.add(earR);
  const earFlapR = new THREE.Mesh(extrudeGeo, skinMat);
  earFlapR.name = 'earFlapR';
  earR.add(earFlapR);
  const earInR = new THREE.Mesh(extrudeGeo2, snoutMat);
  earInR.name = 'earInR';
  earInR.position.set(0, 0, 0.02);
  earR.add(earInR);

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

export default createPig;

Оценки и комментарии

—
Оценок пока нет — будьте первым.
5
0
4
0
3
0
2
0
1
0

Войдите, чтобы ставить оценки и оставлять комментарии.

0 комментариев

Комментариев пока нет. Расскажите, как вы использовали эту модель или что можно улучшить.

Похожие модели

Та же категория или похожие теги