Codels
2864 Tris1,44 × 0,54 × 1,88 m

Im Code verwenden

Im Editor remixen
Eigenständiges ES-Modul — hängt nur von three ab. Ruf die Factory auf und füge die Gruppe deiner Szene hinzu.
/**
 * Go-Kart — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 2,864 · Size (W × H × D): 1.44 × 0.54 × 1.88 m
 *
 * Usage:
 *   import { createGoKart } from './go-kart.js';
 *   
 *   const model = createGoKart();
 *   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);
}

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

  // Materials
  const bodyMat = new THREE.MeshStandardMaterial({ name: 'body', color: 0xe9452f, roughness: 0.45, metalness: 0.05, flatShading: true });
  const frameMat = new THREE.MeshStandardMaterial({ name: 'frame', color: 0xc9ced6, roughness: 0.35, metalness: 0.6, flatShading: true });
  const seatMat = new THREE.MeshStandardMaterial({ name: 'seat', color: 0x26282c, roughness: 0.6, flatShading: true });
  const trimMat = new THREE.MeshStandardMaterial({ name: 'trim', color: 0x222327, roughness: 0.85, flatShading: true });
  const metalMat = new THREE.MeshStandardMaterial({ name: 'metal', color: 0x9ea4ab, roughness: 0.4, metalness: 0.55, flatShading: true });
  const whiteMat = new THREE.MeshStandardMaterial({ name: 'white', color: 0xf2f2ee, roughness: 0.5, flatShading: true });

  // Shared geometries
  const cylinderGeo = new THREE.CylinderGeometry(0.016, 0.016, 0.2766, 5);
  const boxGeo = new THREE.BoxGeometry(0.03, 0.08, 0.05);
  const cylinderGeo2 = new THREE.CylinderGeometry(0.016, 0.016, 0.2655, 5);
  const cylinderGeo3 = new THREE.CylinderGeometry(0.016, 0.016, 0.2218, 5);
  const boxGeo2 = new THREE.BoxGeometry(0.05, 0.08, 0.08);
  const cylinderGeo4 = new THREE.CylinderGeometry(0.016, 0.016, 0.2502, 5);
  const extrudeGeo = extrude([[0.34, 0.05], [-0.3, 0.05], [-0.32, 0.17], [0, 0.22], [0.36, 0.13]], 0.2, [], [0.015, 0.015, 1]);
  const boxGeo3 = new THREE.BoxGeometry(0.006, 0.05, 0.36);
  const extrudeGeo2 = extrude([[0.14, 0], [-0.12, 0], [-0.26, 0.42], [-0.19, 0.44], [-0.05, 0.16], [0.14, 0.12]], 0.03);
  const boxGeo4 = new THREE.BoxGeometry(0.05, 0.1, 0.02);
  const latheGeo = lathe([[0.081, -0.0494], [0.081, -0.065], [0.115, -0.065], [0.135, -0.0364], [0.135, 0.0364], [0.115, 0.065], [0.081, 0.065], [0.081, 0.0494]], 12, 0, Math.PI * 2);
  const cylinderGeo5 = new THREE.CylinderGeometry(0.081, 0.081, 0.0988, 12);
  const cylinderGeo6 = new THREE.CylinderGeometry(0.0243, 0.0292, 0.05, 8);
  const latheGeo2 = lathe([[0.084, -0.076], [0.084, -0.1], [0.1092, -0.1], [0.14, -0.056], [0.14, 0.056], [0.1092, 0.1], [0.084, 0.1], [0.084, 0.076]], 12, 0, Math.PI * 2);
  const cylinderGeo7 = new THREE.CylinderGeometry(0.084, 0.084, 0.152, 12);
  const cylinderGeo8 = new THREE.CylinderGeometry(0.0252, 0.0302, 0.05, 8);

  // Parts
  const body = new THREE.Group();
  body.name = 'body';
  root.add(body);
  const railL = new THREE.Mesh(tube([[0.16, 0.075, 0.86], [0.2, 0.075, 0.6], [0.26, 0.075, 0.2], [0.3, 0.075, -0.3], [0.3, 0.075, -0.62]], 0.016, 20, 5), frameMat);
  railL.name = 'railL';
  body.add(railL);
  const cylinder3 = new THREE.Mesh(cylinderGeo, frameMat);
  cylinder3.position.set(0.315, 0.105, 0.52);
  cylinder3.rotation.set(0, 0, deg(-77.4712));
  body.add(cylinder3);
  const box4 = new THREE.Mesh(boxGeo, metalMat);
  box4.position.set(0.45, 0.135, 0.52);
  body.add(box4);
  const cylinder5 = new THREE.Mesh(cylinderGeo2, frameMat);
  cylinder5.position.set(0.39, 0.085, 0.125);
  cylinder5.rotation.set(deg(-11.0194), deg(9.8739), deg(-83.6887));
  body.add(cylinder5);
  const cylinder6 = new THREE.Mesh(cylinderGeo3, frameMat);
  cylinder6.position.set(0.41, 0.085, -0.19);
  cylinder6.rotation.set(deg(5.1908), deg(-4.7055), deg(-84.3786));
  body.add(cylinder6);
  const box7 = new THREE.Mesh(boxGeo2, metalMat);
  box7.position.set(0.3, 0.14, -0.5);
  body.add(box7);
  const railR = new THREE.Mesh(tube([[-0.16, 0.075, 0.86], [-0.2, 0.075, 0.6], [-0.26, 0.075, 0.2], [-0.3, 0.075, -0.3], [-0.3, 0.075, -0.62]], 0.016, 20, 5), frameMat);
  railR.name = 'railR';
  body.add(railR);
  const cylinder9 = new THREE.Mesh(cylinderGeo, frameMat);
  cylinder9.position.set(-0.315, 0.105, 0.52);
  cylinder9.rotation.set(0, 0, deg(77.4712));
  body.add(cylinder9);
  const box10 = new THREE.Mesh(boxGeo, metalMat);
  box10.position.set(-0.45, 0.135, 0.52);
  body.add(box10);
  const cylinder11 = new THREE.Mesh(cylinderGeo2, frameMat);
  cylinder11.position.set(-0.39, 0.085, 0.125);
  cylinder11.rotation.set(deg(-11.0194), deg(-9.8739), deg(83.6887));
  body.add(cylinder11);
  const cylinder12 = new THREE.Mesh(cylinderGeo3, frameMat);
  cylinder12.position.set(-0.41, 0.085, -0.19);
  cylinder12.rotation.set(deg(5.1908), deg(4.7055), deg(84.3786));
  body.add(cylinder12);
  const box13 = new THREE.Mesh(boxGeo2, metalMat);
  box13.position.set(-0.3, 0.14, -0.5);
  body.add(box13);
  const tube14 = new THREE.Mesh(tube([[-0.2, 0.075, 0.6], [0.2, 0.075, 0.6]], 0.016, 8, 5), frameMat);
  body.add(tube14);
  const tube15 = new THREE.Mesh(tube([[-0.3, 0.075, -0.3], [0.3, 0.075, -0.3]], 0.016, 8, 5), frameMat);
  body.add(tube15);
  const tube16 = new THREE.Mesh(tube([[-0.3, 0.075, -0.62], [0.3, 0.075, -0.62]], 0.016, 8, 5), frameMat);
  body.add(tube16);
  const floorTray = new THREE.Mesh(new THREE.BoxGeometry(0.4, 0.008, 0.62), trimMat);
  floorTray.name = 'floorTray';
  floorTray.position.set(0, 0.063, 0.3);
  body.add(floorTray);
  const rearAxle = new THREE.Mesh(new THREE.CylinderGeometry(0.02, 0.02, 1.1, 6), metalMat);
  rearAxle.name = 'rearAxle';
  rearAxle.position.set(0, 0.14, -0.5);
  rearAxle.rotation.set(0, 0, deg(90));
  body.add(rearAxle);
  const rearBumper = new THREE.Mesh(tube([[-0.55, 0.12, -0.6], [-0.5, 0.13, -0.76], [0, 0.13, -0.8], [0.5, 0.13, -0.76], [0.55, 0.12, -0.6]], 0.016, 12, 5), frameMat);
  rearBumper.name = 'rearBumper';
  body.add(rearBumper);
  const cylinder20 = new THREE.Mesh(cylinderGeo4, frameMat);
  cylinder20.position.set(0.4, 0.1025, -0.69);
  cylinder20.rotation.set(deg(-36.9624), deg(21.5028), deg(-59.203));
  body.add(cylinder20);
  const cylinder21 = new THREE.Mesh(cylinderGeo4, frameMat);
  cylinder21.position.set(-0.4, 0.1025, -0.69);
  cylinder21.rotation.set(deg(-36.9624), deg(-21.5028), deg(59.203));
  body.add(cylinder21);
  const noseCone = new THREE.Mesh(extrude([[0.7, 0.035], [1, 0.035], [1.03, 0.08], [0.86, 0.15], [0.7, 0.165]], 0.78, [], [0.02, 0.02, 1]), bodyMat);
  noseCone.name = 'noseCone';
  noseCone.rotation.set(0, deg(-90), 0);
  body.add(noseCone);
  const noseStripe = new THREE.Mesh(new THREE.BoxGeometry(0.36, 0.035, 0.02), whiteMat);
  noseStripe.name = 'noseStripe';
  noseStripe.position.set(0, 0.125, 0.93);
  noseStripe.rotation.set(deg(-22), 0, 0);
  body.add(noseStripe);
  const frontPanel = new THREE.Mesh(new THREE.BoxGeometry(0.34, 0.24, 0.025), bodyMat);
  frontPanel.name = 'frontPanel';
  frontPanel.position.set(0.06, 0.24, 0.64);
  frontPanel.rotation.set(deg(-30), 0, 0);
  body.add(frontPanel);
  const numberPlate = new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.13, 0.01), whiteMat);
  numberPlate.name = 'numberPlate';
  numberPlate.position.set(0.06, 0.25, 0.66);
  numberPlate.rotation.set(deg(-30), 0, 0);
  body.add(numberPlate);
  const sidePodL = new THREE.Mesh(extrudeGeo, bodyMat);
  sidePodL.name = 'sidePodL';
  sidePodL.position.set(0.52, 0, 0);
  sidePodL.rotation.set(0, deg(-90), 0);
  body.add(sidePodL);
  const box27 = new THREE.Mesh(boxGeo3, whiteMat);
  box27.position.set(0.64, 0.14, 0.02);
  body.add(box27);
  const sidePodR = new THREE.Mesh(extrudeGeo, bodyMat);
  sidePodR.name = 'sidePodR';
  sidePodR.position.set(-0.52, 0, 0);
  sidePodR.rotation.set(0, deg(-90), 0);
  body.add(sidePodR);
  const box29 = new THREE.Mesh(boxGeo3, whiteMat);
  box29.position.set(-0.64, 0.14, 0.02);
  body.add(box29);
  const seat = new THREE.Group();
  seat.name = 'seat';
  seat.position.set(0.06, 0.085, -0.2);
  body.add(seat);
  const seatShell = new THREE.Mesh(extrude([[0.14, 0], [-0.12, 0], [-0.26, 0.42], [-0.21, 0.44], [-0.08, 0.06], [0.14, 0.06]], 0.34, [], [0.02, 0.015, 1]), seatMat);
  seatShell.name = 'seatShell';
  seatShell.rotation.set(0, deg(-90), 0);
  seat.add(seatShell);
  const extrude32 = new THREE.Mesh(extrudeGeo2, seatMat);
  extrude32.position.set(0.19, 0, 0);
  extrude32.rotation.set(0, deg(-90), 0);
  seat.add(extrude32);
  const extrude33 = new THREE.Mesh(extrudeGeo2, seatMat);
  extrude33.position.set(-0.19, 0, 0);
  extrude33.rotation.set(0, deg(-90), 0);
  seat.add(extrude33);
  const steeringColumn = new THREE.Mesh(new THREE.CylinderGeometry(0.014, 0.014, 0.4191, 5), frameMat);
  steeringColumn.name = 'steeringColumn';
  steeringColumn.position.set(0.06, 0.2375, 0.43);
  steeringColumn.rotation.set(deg(-54.2239), 0, 0);
  body.add(steeringColumn);
  const steeringWheel = new THREE.Mesh(new THREE.TorusGeometry(0.13, 0.016, 3, 10), trimMat);
  steeringWheel.name = 'steeringWheel';
  steeringWheel.position.set(0.06, 0.375, 0.245);
  steeringWheel.rotation.set(deg(36), 0, 0);
  body.add(steeringWheel);
  const box36 = new THREE.Mesh(new THREE.BoxGeometry(0.22, 0.03, 0.03), trimMat);
  box36.position.set(0.06, 0.375, 0.245);
  box36.rotation.set(deg(36), 0, 0);
  body.add(box36);
  const box37 = new THREE.Mesh(boxGeo4, metalMat);
  box37.position.set(0.15, 0.13, 0.66);
  box37.rotation.set(deg(-20), 0, 0);
  body.add(box37);
  const box38 = new THREE.Mesh(boxGeo4, metalMat);
  box38.position.set(-0.03, 0.13, 0.66);
  box38.rotation.set(deg(-20), 0, 0);
  body.add(box38);
  const fuelTank = new THREE.Mesh(new THREE.CylinderGeometry(0.07, 0.07, 0.16, 8), whiteMat);
  fuelTank.name = 'fuelTank';
  fuelTank.position.set(0.06, 0.16, 0.42);
  fuelTank.rotation.set(deg(90), 0, 0);
  body.add(fuelTank);
  const engine = new THREE.Group();
  engine.name = 'engine';
  engine.position.set(-0.36, 0.095, -0.22);
  body.add(engine);
  const crankcase = new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.16, 0.18), metalMat);
  crankcase.name = 'crankcase';
  crankcase.position.set(0, 0.08, 0);
  engine.add(crankcase);
  const box42 = new THREE.Mesh(new THREE.BoxGeometry(0.16, 0.012, 0.16), metalMat);
  box42.position.set(0, 0.176, 0);
  engine.add(box42);
  const box43 = new THREE.Mesh(new THREE.BoxGeometry(0.154, 0.012, 0.154), metalMat);
  box43.position.set(0, 0.2, 0);
  engine.add(box43);
  const box44 = new THREE.Mesh(new THREE.BoxGeometry(0.148, 0.012, 0.148), metalMat);
  box44.position.set(0, 0.224, 0);
  engine.add(box44);
  const box45 = new THREE.Mesh(new THREE.BoxGeometry(0.142, 0.012, 0.142), metalMat);
  box45.position.set(0, 0.248, 0);
  engine.add(box45);
  const box46 = new THREE.Mesh(new THREE.BoxGeometry(0.136, 0.012, 0.136), metalMat);
  box46.position.set(0, 0.272, 0);
  engine.add(box46);
  const box47 = new THREE.Mesh(new THREE.BoxGeometry(0.13, 0.012, 0.13), metalMat);
  box47.position.set(0, 0.296, 0);
  engine.add(box47);
  const cylinderHead = new THREE.Mesh(new THREE.BoxGeometry(0.09, 0.03, 0.09), trimMat);
  cylinderHead.name = 'cylinderHead';
  cylinderHead.position.set(0, 0.325, 0);
  engine.add(cylinderHead);
  const cylinder49 = new THREE.Mesh(new THREE.CylinderGeometry(0.01, 0.01, 0.05, 5), whiteMat);
  cylinder49.position.set(0, 0.365, 0);
  engine.add(cylinder49);
  const carburetor = new THREE.Mesh(new THREE.CylinderGeometry(0.035, 0.035, 0.08, 6), trimMat);
  carburetor.name = 'carburetor';
  carburetor.position.set(-0.13, 0.2, 0.02);
  carburetor.rotation.set(0, 0, deg(90));
  engine.add(carburetor);
  const airFilter = new THREE.Mesh(new THREE.CylinderGeometry(0.06, 0.06, 0.1, 8), trimMat);
  airFilter.name = 'airFilter';
  airFilter.position.set(-0.21, 0.2, 0.02);
  airFilter.rotation.set(0, 0, deg(90));
  engine.add(airFilter);
  const clutch = new THREE.Mesh(new THREE.CylinderGeometry(0.08, 0.08, 0.04, 10), trimMat);
  clutch.name = 'clutch';
  clutch.position.set(0.12, 0.08, 0);
  clutch.rotation.set(0, 0, deg(90));
  engine.add(clutch);
  const exhaustPipe = new THREE.Mesh(tube([[0, 0.3, -0.08], [0.02, 0.3, -0.2], [0, 0.22, -0.3], [-0.04, 0.16, -0.36]], 0.018, 8, 5), metalMat);
  exhaustPipe.name = 'exhaustPipe';
  engine.add(exhaustPipe);
  const muffler = new THREE.Mesh(new THREE.CylinderGeometry(0.05, 0.05, 0.22, 8), trimMat);
  muffler.name = 'muffler';
  muffler.position.set(-0.04, 0.16, -0.46);
  muffler.rotation.set(deg(90), 0, 0);
  engine.add(muffler);
  const sprocket = new THREE.Mesh(new THREE.CylinderGeometry(0.075, 0.075, 0.012, 12), metalMat);
  sprocket.name = 'sprocket';
  sprocket.position.set(-0.24, 0.14, -0.5);
  sprocket.rotation.set(0, 0, deg(90));
  body.add(sprocket);
  const chain = new THREE.Mesh(tube([[-0.24, 0.17, -0.22], [-0.24, 0.21, -0.5], [-0.24, 0.07, -0.5], [-0.24, 0.07, -0.22], [-0.24, 0.17, -0.22]], 0.008, 16, 3, true), trimMat);
  chain.name = 'chain';
  body.add(chain);
  const wheels = new THREE.Group();
  wheels.name = 'wheels';
  root.add(wheels);
  const wheelFL = new THREE.Group();
  wheelFL.name = 'wheelFL';
  wheelFL.position.set(0.55, 0.135, 0.52);
  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(cylinderGeo5, metalMat);
  rim.name = 'rim';
  rim.rotation.set(0, 0, deg(90));
  wheelFL.add(rim);
  const hub = new THREE.Mesh(cylinderGeo6, frameMat);
  hub.name = 'hub';
  hub.position.set(0.0694, 0, 0);
  hub.rotation.set(0, 0, deg(-90));
  wheelFL.add(hub);
  const wheelFR = new THREE.Group();
  wheelFR.name = 'wheelFR';
  wheelFR.position.set(-0.55, 0.135, 0.52);
  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(cylinderGeo5, metalMat);
  rim2.name = 'rim';
  rim2.rotation.set(0, 0, deg(90));
  wheelFR.add(rim2);
  const hub2 = new THREE.Mesh(cylinderGeo6, frameMat);
  hub2.name = 'hub';
  hub2.position.set(-0.0694, 0, 0);
  hub2.rotation.set(0, 0, deg(90));
  wheelFR.add(hub2);
  const wheelRL = new THREE.Group();
  wheelRL.name = 'wheelRL';
  wheelRL.position.set(0.6, 0.14, -0.5);
  wheels.add(wheelRL);
  const tire3 = new THREE.Mesh(latheGeo2, trimMat);
  tire3.name = 'tire';
  tire3.rotation.set(0, 0, deg(90));
  wheelRL.add(tire3);
  const rim3 = new THREE.Mesh(cylinderGeo7, metalMat);
  rim3.name = 'rim';
  rim3.rotation.set(0, 0, deg(90));
  wheelRL.add(rim3);
  const hub3 = new THREE.Mesh(cylinderGeo8, frameMat);
  hub3.name = 'hub';
  hub3.position.set(0.096, 0, 0);
  hub3.rotation.set(0, 0, deg(-90));
  wheelRL.add(hub3);
  const wheelRR = new THREE.Group();
  wheelRR.name = 'wheelRR';
  wheelRR.position.set(-0.6, 0.14, -0.5);
  wheels.add(wheelRR);
  const tire4 = new THREE.Mesh(latheGeo2, trimMat);
  tire4.name = 'tire';
  tire4.rotation.set(0, 0, deg(90));
  wheelRR.add(tire4);
  const rim4 = new THREE.Mesh(cylinderGeo7, metalMat);
  rim4.name = 'rim';
  rim4.rotation.set(0, 0, deg(90));
  wheelRR.add(rim4);
  const hub4 = new THREE.Mesh(cylinderGeo8, frameMat);
  hub4.name = 'hub';
  hub4.position.set(-0.096, 0, 0);
  hub4.rotation.set(0, 0, deg(90));
  wheelRR.add(hub4);

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

export default createGoKart;

Bewertungen & Kommentare

—
Noch keine Bewertungen — gib die erste ab.
5
0
4
0
3
0
2
0
1
0

Melde dich an, um zu bewerten und zu kommentieren.

0 Kommentare

Noch keine Kommentare. Erzähl, wie du dieses Modell genutzt hast oder was besser sein könnte.

Ähnliche Modelle

Gleiche Kategorie oder ähnliche Tags