Codels
2628 三角面2.12 × 2.12 × 5.47 m

在代码中使用

在编辑器中改编
自包含的 ES 模块,仅依赖 three。调用工厂函数,然后把返回的 group 添加到场景中。
/**
 * Pickup Truck — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 2,628 · Size (W × H × D): 2.12 × 2.12 × 5.47 m
 *
 * Usage:
 *   import { createPickupTruck } from './pickup-truck.js';
 *   
 *   const model = createPickupTruck();
 *   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 createPickupTruck() {
  const root = new THREE.Group();
  root.name = 'PickupTruck';

  // Materials
  const paintMat = new THREE.MeshStandardMaterial({ name: 'paint', color: 0xe0812f, roughness: 0.5, metalness: 0.1, flatShading: true });
  const glassMat = new THREE.MeshStandardMaterial({ name: 'glass', color: 0x2a3542, roughness: 0.2, metalness: 0.3, flatShading: true });
  const trimMat = new THREE.MeshStandardMaterial({ name: 'trim', color: 0x2a2b2f, roughness: 0.85, flatShading: true });
  const chromeMat = new THREE.MeshStandardMaterial({ name: 'chrome', color: 0xcdd1d6, roughness: 0.3, metalness: 0.65, flatShading: true });
  const headlightMat = new THREE.MeshStandardMaterial({ name: 'headlight', color: 0xfff6dc, roughness: 0.3, emissive: 0xffe6a6, emissiveIntensity: 0.9, flatShading: true });
  const taillightMat = new THREE.MeshStandardMaterial({ name: 'taillight', color: 0xd81f26, roughness: 0.3, emissive: 0xff2424, emissiveIntensity: 0.7, flatShading: true });
  const woodMat = new THREE.MeshStandardMaterial({ name: 'wood', color: 0xa46c39, roughness: 0.9, flatShading: true });

  // Shared geometries
  const extrudeGeo = extrude([[0.9283, 1.33], [0.645, 1.75], [-0.4, 1.75], [-0.4, 1.33]], 0.02);
  const boxGeo = new THREE.BoxGeometry(0.08, 0.3, 0.06);
  const boxGeo2 = new THREE.BoxGeometry(0.14, 0.32, 0.06);
  const boxGeo3 = new THREE.BoxGeometry(0.12, 0.1, 0.14);
  const boxGeo4 = new THREE.BoxGeometry(0.03, 0.035, 0.16);
  const torusGeo = new THREE.TorusGeometry(0.53, 0.055, 4, 10, 3.0647);
  const boxGeo5 = new THREE.BoxGeometry(0.2, 0.05, 1.5);
  const boxGeo6 = new THREE.BoxGeometry(1.08, 0.05, 0.02);
  const boxGeo7 = new THREE.BoxGeometry(0.56, 0.56, 0.56);
  const boxGeo8 = new THREE.BoxGeometry(0.572, 0.06, 0.572);
  const boxGeo9 = new THREE.BoxGeometry(0.06, 0.572, 0.572);
  const latheGeo = lathe([[0.252, -0.125], [0.252, -0.16], [0.36, -0.16], [0.41, -0.13], [0.42, -0.08], [0.42, 0.08], [0.41, 0.13], [0.36, 0.16], [0.252, 0.16], [0.252, 0.125]], 12);
  const cylinderGeo = new THREE.CylinderGeometry(0.252, 0.252, 0.25, 12);
  const cylinderGeo2 = new THREE.CylinderGeometry(0.1058, 0.126, 0.04, 8);
  const boxGeo10 = new THREE.BoxGeometry(0.03, 0.035, 0.035);

  // Parts
  const body = new THREE.Group();
  body.name = 'body';
  root.add(body);
  const lowerBody = new THREE.Mesh(extrude([[2.56, 0.44], [2.62, 0.6], [2.62, 1.08], [2.42, 1.2], [1.15, 1.24], [-0.56, 1.24], [-0.58, 1], [-2.62, 1], [-2.64, 0.56], [-2.56, 0.44], [-2.1996, 0.44], [-2.1545, 0.6328], [-2.0406, 0.7947], [-1.8744, 0.9023], [-1.68, 0.94], [-1.4856, 0.9023], [-1.3194, 0.7947], [-1.2055, 0.6328], [-1.1604, 0.44], [1.1604, 0.44], [1.2055, 0.6328], [1.3194, 0.7947], [1.4856, 0.9023], [1.68, 0.94], [1.8744, 0.9023], [2.0406, 0.7947], [2.1545, 0.6328], [2.1996, 0.44]], 1.92, [], [0.04, 0.04, 2]), paintMat);
  lowerBody.name = 'lowerBody';
  lowerBody.rotation.set(0, deg(-90), 0);
  body.add(lowerBody);
  const chassis = new THREE.Mesh(new THREE.BoxGeometry(1.3, 0.5, 4.6), trimMat);
  chassis.name = 'chassis';
  chassis.position.set(0, 0.75, 0);
  body.add(chassis);
  const cab = new THREE.Mesh(extrude([[1.18, 1.12], [0.66, 1.84], [-0.5, 1.84], [-0.54, 1.12]], 1.76, [], [0.05, 0.05, 2]), paintMat);
  cab.name = 'cab';
  cab.rotation.set(0, deg(-90), 0);
  body.add(cab);
  const windowL = new THREE.Mesh(extrudeGeo, glassMat);
  windowL.name = 'windowL';
  windowL.position.set(0.935, 0, 0);
  windowL.rotation.set(0, deg(-90), 0);
  body.add(windowL);
  const windowR = new THREE.Mesh(extrudeGeo, glassMat);
  windowR.name = 'windowR';
  windowR.position.set(-0.935, 0, 0);
  windowR.rotation.set(0, deg(-90), 0);
  body.add(windowR);
  const windshield = new THREE.Mesh(new THREE.BoxGeometry(1.62, 0.02, 0.5428), glassMat);
  windshield.name = 'windshield';
  windshield.position.set(0, 1.5775, 0.9286);
  windshield.rotation.set(deg(-125.8377), 0, 0);
  body.add(windshield);
  const rearWindow = new THREE.Mesh(new THREE.BoxGeometry(1.5, 0.36, 0.02), glassMat);
  rearWindow.name = 'rearWindow';
  rearWindow.position.set(0, 1.56, -0.6);
  body.add(rearWindow);
  const bed = new THREE.Mesh(extrude([[-0.94, -2.6], [0.94, -2.6], [0.94, -0.66], [-0.94, -0.66]], 0.42, [[[-0.86, -2.52], [0.86, -2.52], [0.86, -0.74], [-0.86, -0.74]]], [0.02, 0.02, 1]), paintMat);
  bed.name = 'bed';
  bed.position.set(0, 1.23, 0);
  bed.rotation.set(deg(90), 0, 0);
  body.add(bed);
  const tailgateHandle = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.06, 0.02), trimMat);
  tailgateHandle.name = 'tailgateHandle';
  tailgateHandle.position.set(0, 1.34, -2.63);
  body.add(tailgateHandle);
  const taillightL = new THREE.Mesh(boxGeo, taillightMat);
  taillightL.name = 'taillightL';
  taillightL.position.set(0.88, 1.2, -2.63);
  body.add(taillightL);
  const headlightL = new THREE.Mesh(boxGeo2, headlightMat);
  headlightL.name = 'headlightL';
  headlightL.position.set(0.74, 0.92, 2.655);
  body.add(headlightL);
  const mirrorL = new THREE.Mesh(boxGeo3, trimMat);
  mirrorL.name = 'mirrorL';
  mirrorL.position.set(1, 1.42, 0.96);
  body.add(mirrorL);
  const box14 = new THREE.Mesh(boxGeo4, chromeMat);
  box14.position.set(0.942, 1.26, 0.12);
  body.add(box14);
  const flareFL = new THREE.Mesh(torusGeo, trimMat);
  flareFL.name = 'flareFL';
  flareFL.position.set(0.99, 0.42, 1.68);
  flareFL.rotation.set(0, deg(90), deg(2.2042));
  body.add(flareFL);
  const flareRL = new THREE.Mesh(torusGeo, trimMat);
  flareRL.name = 'flareRL';
  flareRL.position.set(0.99, 0.42, -1.68);
  flareRL.rotation.set(0, deg(90), deg(2.2042));
  body.add(flareRL);
  const stepL = new THREE.Mesh(boxGeo5, trimMat);
  stepL.name = 'stepL';
  stepL.position.set(0.96, 0.46, 0);
  body.add(stepL);
  const taillightR = new THREE.Mesh(boxGeo, taillightMat);
  taillightR.name = 'taillightR';
  taillightR.position.set(-0.88, 1.2, -2.63);
  body.add(taillightR);
  const headlightR = new THREE.Mesh(boxGeo2, headlightMat);
  headlightR.name = 'headlightR';
  headlightR.position.set(-0.74, 0.92, 2.655);
  body.add(headlightR);
  const mirrorR = new THREE.Mesh(boxGeo3, trimMat);
  mirrorR.name = 'mirrorR';
  mirrorR.position.set(-1, 1.42, 0.96);
  body.add(mirrorR);
  const box21 = new THREE.Mesh(boxGeo4, chromeMat);
  box21.position.set(-0.942, 1.26, 0.12);
  body.add(box21);
  const flareFR = new THREE.Mesh(torusGeo, trimMat);
  flareFR.name = 'flareFR';
  flareFR.position.set(-0.99, 0.42, 1.68);
  flareFR.rotation.set(0, deg(90), deg(2.2042));
  body.add(flareFR);
  const flareRR = new THREE.Mesh(torusGeo, trimMat);
  flareRR.name = 'flareRR';
  flareRR.position.set(-0.99, 0.42, -1.68);
  flareRR.rotation.set(0, deg(90), deg(2.2042));
  body.add(flareRR);
  const stepR = new THREE.Mesh(boxGeo5, trimMat);
  stepR.name = 'stepR';
  stepR.position.set(-0.96, 0.46, 0);
  body.add(stepR);
  const grille = new THREE.Mesh(new THREE.BoxGeometry(1.2, 0.36, 0.05), chromeMat);
  grille.name = 'grille';
  grille.position.set(0, 0.92, 2.665);
  body.add(grille);
  const box26 = new THREE.Mesh(boxGeo6, trimMat);
  box26.position.set(0, 0.82, 2.695);
  body.add(box26);
  const box27 = new THREE.Mesh(boxGeo6, trimMat);
  box27.position.set(0, 0.92, 2.695);
  body.add(box27);
  const box28 = new THREE.Mesh(boxGeo6, trimMat);
  box28.position.set(0, 1.02, 2.695);
  body.add(box28);
  const bumperFront = new THREE.Mesh(new THREE.BoxGeometry(2.06, 0.22, 0.24), chromeMat);
  bumperFront.name = 'bumperFront';
  bumperFront.position.set(0, 0.56, 2.62);
  body.add(bumperFront);
  const bumperRear = new THREE.Mesh(new THREE.BoxGeometry(2.06, 0.18, 0.22), chromeMat);
  bumperRear.name = 'bumperRear';
  bumperRear.position.set(0, 0.6, -2.62);
  body.add(bumperRear);
  const skidPlate = new THREE.Mesh(new THREE.BoxGeometry(0.5, 0.05, 0.4), trimMat);
  skidPlate.name = 'skidPlate';
  skidPlate.position.set(0, 0.44, 2.4);
  body.add(skidPlate);
  const crate1 = new THREE.Group();
  crate1.name = 'crate1';
  crate1.position.set(-0.42, 1.04, -1.05);
  crate1.rotation.set(0, deg(-8.7893), 0);
  body.add(crate1);
  const box33 = new THREE.Mesh(new THREE.BoxGeometry(0.62, 0.62, 0.62), woodMat);
  box33.position.set(0, 0.31, 0);
  crate1.add(box33);
  const box34 = new THREE.Mesh(new THREE.BoxGeometry(0.632, 0.06, 0.632), trimMat);
  box34.position.set(0, 0.309, 0);
  crate1.add(box34);
  const box35 = new THREE.Mesh(new THREE.BoxGeometry(0.06, 0.632, 0.632), trimMat);
  box35.position.set(0, 0.31, 0);
  crate1.add(box35);
  const crate2 = new THREE.Group();
  crate2.name = 'crate2';
  crate2.position.set(0.4, 1.04, -1.12);
  crate2.rotation.set(0, deg(-7.8848), 0);
  body.add(crate2);
  const box37 = new THREE.Mesh(boxGeo7, woodMat);
  box37.position.set(0, 0.28, 0);
  crate2.add(box37);
  const box38 = new THREE.Mesh(boxGeo8, trimMat);
  box38.position.set(0, 0.282, 0);
  crate2.add(box38);
  const box39 = new THREE.Mesh(boxGeo9, trimMat);
  box39.position.set(0, 0.28, 0);
  crate2.add(box39);
  const crate3 = new THREE.Group();
  crate3.name = 'crate3';
  crate3.position.set(-0.38, 1.04, -1.92);
  crate3.rotation.set(0, deg(8.5843), 0);
  body.add(crate3);
  const box41 = new THREE.Mesh(boxGeo7, woodMat);
  box41.position.set(0, 0.28, 0);
  crate3.add(box41);
  const box42 = new THREE.Mesh(boxGeo8, trimMat);
  box42.position.set(0, 0.282, 0);
  crate3.add(box42);
  const box43 = new THREE.Mesh(boxGeo9, trimMat);
  box43.position.set(0, 0.28, 0);
  crate3.add(box43);
  const crateTop = new THREE.Mesh(new THREE.BoxGeometry(0.46, 0.46, 0.46), woodMat);
  crateTop.name = 'crateTop';
  crateTop.position.set(-0.36, 1.89, -1.06);
  crateTop.rotation.set(0, deg(14), 0);
  body.add(crateTop);
  const wheels = new THREE.Group();
  wheels.name = 'wheels';
  root.add(wheels);
  const wheelFL = new THREE.Group();
  wheelFL.name = 'wheelFL';
  wheelFL.position.set(0.83, 0.42, 1.68);
  wheels.add(wheelFL);
  const tire = new THREE.Mesh(latheGeo, trimMat);
  tire.name = 'tire';
  tire.rotation.set(0, 0, deg(90));
  wheelFL.add(tire);
  const rim = new THREE.Mesh(cylinderGeo, chromeMat);
  rim.name = 'rim';
  rim.rotation.set(0, 0, deg(90));
  wheelFL.add(rim);
  const hub = new THREE.Mesh(cylinderGeo2, trimMat);
  hub.name = 'hub';
  hub.position.set(0.143, 0, 0);
  hub.rotation.set(0, 0, deg(-90));
  wheelFL.add(hub);
  const box50 = new THREE.Mesh(boxGeo10, chromeMat);
  box50.position.set(0.155, 0, 0.0806);
  wheelFL.add(box50);
  const box51 = new THREE.Mesh(boxGeo10, chromeMat);
  box51.position.set(0.155, 0.0698, 0.0403);
  box51.rotation.set(deg(60), 0, 0);
  wheelFL.add(box51);
  const box52 = new THREE.Mesh(boxGeo10, chromeMat);
  box52.position.set(0.155, 0.0698, -0.0403);
  box52.rotation.set(deg(120), 0, 0);
  wheelFL.add(box52);
  const box53 = new THREE.Mesh(boxGeo10, chromeMat);
  box53.position.set(0.155, 0, -0.0806);
  box53.rotation.set(deg(180), 0, 0);
  wheelFL.add(box53);
  const box54 = new THREE.Mesh(boxGeo10, chromeMat);
  box54.position.set(0.155, -0.0698, -0.0403);
  box54.rotation.set(deg(240), 0, 0);
  wheelFL.add(box54);
  const box55 = new THREE.Mesh(boxGeo10, chromeMat);
  box55.position.set(0.155, -0.0698, 0.0403);
  box55.rotation.set(deg(300), 0, 0);
  wheelFL.add(box55);
  const wheelFR = new THREE.Group();
  wheelFR.name = 'wheelFR';
  wheelFR.position.set(-0.83, 0.42, 1.68);
  wheels.add(wheelFR);
  const tire2 = new THREE.Mesh(latheGeo, trimMat);
  tire2.name = 'tire';
  tire2.rotation.set(0, 0, deg(90));
  wheelFR.add(tire2);
  const rim2 = new THREE.Mesh(cylinderGeo, chromeMat);
  rim2.name = 'rim';
  rim2.rotation.set(0, 0, deg(90));
  wheelFR.add(rim2);
  const hub2 = new THREE.Mesh(cylinderGeo2, trimMat);
  hub2.name = 'hub';
  hub2.position.set(-0.143, 0, 0);
  hub2.rotation.set(0, 0, deg(90));
  wheelFR.add(hub2);
  const box60 = new THREE.Mesh(boxGeo10, chromeMat);
  box60.position.set(-0.155, 0, 0.0806);
  wheelFR.add(box60);
  const box61 = new THREE.Mesh(boxGeo10, chromeMat);
  box61.position.set(-0.155, 0.0698, 0.0403);
  box61.rotation.set(deg(60), 0, 0);
  wheelFR.add(box61);
  const box62 = new THREE.Mesh(boxGeo10, chromeMat);
  box62.position.set(-0.155, 0.0698, -0.0403);
  box62.rotation.set(deg(120), 0, 0);
  wheelFR.add(box62);
  const box63 = new THREE.Mesh(boxGeo10, chromeMat);
  box63.position.set(-0.155, 0, -0.0806);
  box63.rotation.set(deg(180), 0, 0);
  wheelFR.add(box63);
  const box64 = new THREE.Mesh(boxGeo10, chromeMat);
  box64.position.set(-0.155, -0.0698, -0.0403);
  box64.rotation.set(deg(240), 0, 0);
  wheelFR.add(box64);
  const box65 = new THREE.Mesh(boxGeo10, chromeMat);
  box65.position.set(-0.155, -0.0698, 0.0403);
  box65.rotation.set(deg(300), 0, 0);
  wheelFR.add(box65);
  const wheelRL = new THREE.Group();
  wheelRL.name = 'wheelRL';
  wheelRL.position.set(0.83, 0.42, -1.68);
  wheels.add(wheelRL);
  const tire3 = new THREE.Mesh(latheGeo, trimMat);
  tire3.name = 'tire';
  tire3.rotation.set(0, 0, deg(90));
  wheelRL.add(tire3);
  const rim3 = new THREE.Mesh(cylinderGeo, chromeMat);
  rim3.name = 'rim';
  rim3.rotation.set(0, 0, deg(90));
  wheelRL.add(rim3);
  const hub3 = new THREE.Mesh(cylinderGeo2, trimMat);
  hub3.name = 'hub';
  hub3.position.set(0.143, 0, 0);
  hub3.rotation.set(0, 0, deg(-90));
  wheelRL.add(hub3);
  const box70 = new THREE.Mesh(boxGeo10, chromeMat);
  box70.position.set(0.155, 0, 0.0806);
  wheelRL.add(box70);
  const box71 = new THREE.Mesh(boxGeo10, chromeMat);
  box71.position.set(0.155, 0.0698, 0.0403);
  box71.rotation.set(deg(60), 0, 0);
  wheelRL.add(box71);
  const box72 = new THREE.Mesh(boxGeo10, chromeMat);
  box72.position.set(0.155, 0.0698, -0.0403);
  box72.rotation.set(deg(120), 0, 0);
  wheelRL.add(box72);
  const box73 = new THREE.Mesh(boxGeo10, chromeMat);
  box73.position.set(0.155, 0, -0.0806);
  box73.rotation.set(deg(180), 0, 0);
  wheelRL.add(box73);
  const box74 = new THREE.Mesh(boxGeo10, chromeMat);
  box74.position.set(0.155, -0.0698, -0.0403);
  box74.rotation.set(deg(240), 0, 0);
  wheelRL.add(box74);
  const box75 = new THREE.Mesh(boxGeo10, chromeMat);
  box75.position.set(0.155, -0.0698, 0.0403);
  box75.rotation.set(deg(300), 0, 0);
  wheelRL.add(box75);
  const wheelRR = new THREE.Group();
  wheelRR.name = 'wheelRR';
  wheelRR.position.set(-0.83, 0.42, -1.68);
  wheels.add(wheelRR);
  const tire4 = new THREE.Mesh(latheGeo, trimMat);
  tire4.name = 'tire';
  tire4.rotation.set(0, 0, deg(90));
  wheelRR.add(tire4);
  const rim4 = new THREE.Mesh(cylinderGeo, chromeMat);
  rim4.name = 'rim';
  rim4.rotation.set(0, 0, deg(90));
  wheelRR.add(rim4);
  const hub4 = new THREE.Mesh(cylinderGeo2, trimMat);
  hub4.name = 'hub';
  hub4.position.set(-0.143, 0, 0);
  hub4.rotation.set(0, 0, deg(90));
  wheelRR.add(hub4);
  const box80 = new THREE.Mesh(boxGeo10, chromeMat);
  box80.position.set(-0.155, 0, 0.0806);
  wheelRR.add(box80);
  const box81 = new THREE.Mesh(boxGeo10, chromeMat);
  box81.position.set(-0.155, 0.0698, 0.0403);
  box81.rotation.set(deg(60), 0, 0);
  wheelRR.add(box81);
  const box82 = new THREE.Mesh(boxGeo10, chromeMat);
  box82.position.set(-0.155, 0.0698, -0.0403);
  box82.rotation.set(deg(120), 0, 0);
  wheelRR.add(box82);
  const box83 = new THREE.Mesh(boxGeo10, chromeMat);
  box83.position.set(-0.155, 0, -0.0806);
  box83.rotation.set(deg(180), 0, 0);
  wheelRR.add(box83);
  const box84 = new THREE.Mesh(boxGeo10, chromeMat);
  box84.position.set(-0.155, -0.0698, -0.0403);
  box84.rotation.set(deg(240), 0, 0);
  wheelRR.add(box84);
  const box85 = new THREE.Mesh(boxGeo10, chromeMat);
  box85.position.set(-0.155, -0.0698, 0.0403);
  box85.rotation.set(deg(300), 0, 0);
  wheelRR.add(box85);

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

export default createPickupTruck;

评分与评论

—
暂无评分,快来抢先评分吧。
5
0
4
0
3
0
2
0
1
0

登录后即可评分和评论。

0 条评论

暂无评论。分享一下你是如何使用这个模型的,或者有哪些可以改进的地方。

相关模型

同一分类或相似标签