Codels
1432 ポリゴン3.99 × 2.00 × 4.26 m
自己完結型の ES モジュールで、依存先は three のみです。ファクトリー関数を呼び出し、返された group をシーンに追加してください。
/**
 * Ringed Planet — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the model (it floats — pickups, planets)
 * Triangles: 1,432 · Size (W × H × D): 3.99 × 2.00 × 4.26 m
 *
 * Usage:
 *   import { createRingedPlanet } from './ringed-planet.js';
 *   
 *   const model = createRingedPlanet();
 *   model.position.set(0, 0, 0);
 *   scene.add(model);
 *   
 *   // Animations: idle
 *   const mixer = new THREE.AnimationMixer(model);
 *   mixer.clipAction(THREE.AnimationClip.findByName(model.animations, 'idle')).play();
 *   // in your render loop: mixer.update(clock.getDelta());
 */
import * as THREE from 'three';

const deg = THREE.MathUtils.degToRad;

// Build animation clips from simple descriptions (Codels). Play them with THREE.AnimationMixer.
function codelsClips(THREE, entries) {
  var TAU = Math.PI * 2;
  var DEG = Math.PI / 180;
  var AX = { x: new THREE.Vector3(1, 0, 0), y: new THREE.Vector3(0, 1, 0), z: new THREE.Vector3(0, 0, 1) };
  var periodOf = function (a) { return a.type === 'spin' ? 360 / Math.abs(a.speed) : a.period; };
  var clips = [];

  // loops → 'idle'
  var loops = [];
  entries.forEach(function (e) {
    var l = e.anim.filter(function (a) { return a.type !== 'hinge'; });
    if (l.length) loops.push({ target: e.target, anim: l });
  });
  if (loops.length) {
    var periods = [];
    loops.forEach(function (e) { e.anim.forEach(function (a) { periods.push(periodOf(a)); }); });
    var longest = Math.max.apply(null, periods);
    var D = longest;
    var bestErr = Infinity;
    for (var m = 1; m <= 6 && bestErr > 0.01; m++) {
      var err = 0;
      periods.forEach(function (p) {
        var n = Math.max(1, Math.round((longest * m) / p));
        err = Math.max(err, Math.abs((longest * m) / n - p) / p);
      });
      if (err < bestErr - 1e-9) { bestErr = err; D = longest * m; }
    }
    var cycles = function (a) { return Math.max(1, Math.round(D / periodOf(a))); };
    var steps = 24;
    loops.forEach(function (e) { e.anim.forEach(function (a) { steps = Math.max(steps, cycles(a) * 24); }); });
    steps = Math.min(steps, 720);
    var tracks = [];
    loops.forEach(function (e) {
      var o = e.target;
      var q0 = o.quaternion.clone(), p0 = o.position.clone(), s0 = o.scale.clone();
      var q = new THREE.Quaternion(), turn = new THREE.Quaternion(), p = new THREE.Vector3(), s = new THREE.Vector3();
      var has = function (type) { return e.anim.some(function (a) { return a.type === type; }); };
      var turns = has('spin') || has('swing'), moves = has('bob'), grows = has('pulse');
      var times = [], qv = [], pv = [], sv = [];
      for (var k = 0; k <= steps; k++) {
        var t = (D * k) / steps;
        q.copy(q0); p.copy(p0); s.copy(s0);
        e.anim.forEach(function (a) {
          var n = cycles(a);
          var w = Math.sin(TAU * ((n * t) / D + (a.phase || 0)));
          if (a.type === 'spin') q.multiply(turn.setFromAxisAngle(AX[a.axis], (a.speed < 0 ? -TAU : TAU) * ((n * t) / D)));
          else if (a.type === 'swing') q.multiply(turn.setFromAxisAngle(AX[a.axis], a.angle * DEG * w));
          else if (a.type === 'bob') p.addScaledVector(AX[a.axis], a.distance * w);
          else if (a.type === 'pulse') s.multiplyScalar(1 + a.amount * w);
        });
        times.push(t);
        if (turns) qv.push(q.x, q.y, q.z, q.w);
        if (moves) pv.push(p.x, p.y, p.z);
        if (grows) sv.push(s.x, s.y, s.z);
      }
      if (turns) tracks.push(new THREE.QuaternionKeyframeTrack(o.uuid + '.quaternion', times, qv));
      if (moves) tracks.push(new THREE.VectorKeyframeTrack(o.uuid + '.position', times, pv));
      if (grows) tracks.push(new THREE.VectorKeyframeTrack(o.uuid + '.scale', times, sv));
    });
    clips.push(new THREE.AnimationClip('idle', D, tracks));
  }

  // hinge moves → one-shot clips ('open' …)
  var shots = {};
  entries.forEach(function (e) {
    e.anim.forEach(function (a) {
      if (a.type !== 'hinge') return;
      var name = a.clip || 'open';
      (shots[name] = shots[name] || []).push({ target: e.target, a: a });
    });
  });
  Object.keys(shots).forEach(function (name) {
    var tracks = [];
    var length = 0;
    shots[name].forEach(function (h) {
      var o = h.target, q0 = o.quaternion.clone(), q = new THREE.Quaternion(), turn = new THREE.Quaternion();
      var n = Math.max(4, Math.ceil(Math.abs(h.a.angle) / 10));
      var times = [], qv = [];
      for (var k = 0; k <= n; k++) {
        var f = k / n;
        var eased = f * f * (3 - 2 * f);
        q.copy(q0).multiply(turn.setFromAxisAngle(AX[h.a.axis], h.a.angle * DEG * eased));
        times.push(h.a.duration * f);
        qv.push(q.x, q.y, q.z, q.w);
      }
      length = Math.max(length, h.a.duration);
      tracks.push(new THREE.QuaternionKeyframeTrack(o.uuid + '.quaternion', times, qv));
    });
    clips.push(new THREE.AnimationClip(name, length, tracks));
  });
  return clips;
}

export function createRingedPlanet() {
  const root = new THREE.Group();
  root.name = 'RingedPlanet';

  // Materials
  const baseMat = new THREE.MeshStandardMaterial({ name: 'base', color: 0xe8b86a, roughness: 0.75, flatShading: true });
  const bandMat = new THREE.MeshStandardMaterial({ name: 'band', color: 0xb9703f, roughness: 0.75, flatShading: true });
  const midMat = new THREE.MeshStandardMaterial({ name: 'mid', color: 0xd19455, roughness: 0.75, flatShading: true });
  const lightMat = new THREE.MeshStandardMaterial({ name: 'light', color: 0xefcd97, roughness: 0.75, flatShading: true });
  const ringInnerMat = new THREE.MeshStandardMaterial({ name: 'ringInner', color: 0xdcc497, roughness: 0.6, flatShading: true, side: THREE.DoubleSide });
  const ringOuterMat = new THREE.MeshStandardMaterial({ name: 'ringOuter', color: 0xd0a778, roughness: 0.6, flatShading: true, side: THREE.DoubleSide });

  // Parts
  const planet = new THREE.Group();
  planet.name = 'planet';
  planet.rotation.set(deg(8), 0, deg(22));
  root.add(planet);
  const band1 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 3, 0, Math.PI * 2, 0, 0.4538), lightMat);
  band1.name = 'band1';
  planet.add(band1);
  const band2 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 2, 0, Math.PI * 2, 0.4538, 0.3142), bandMat);
  band2.name = 'band2';
  planet.add(band2);
  const band3 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 2, 0, Math.PI * 2, 0.7679, 0.2793), baseMat);
  band3.name = 'band3';
  planet.add(band3);
  const band4 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 2, 0, Math.PI * 2, Math.PI / 3, 0.2793), midMat);
  band4.name = 'band4';
  planet.add(band4);
  const band5 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 2, 0, Math.PI * 2, 1.3265, 0.2443), baseMat);
  band5.name = 'band5';
  planet.add(band5);
  const band6 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 2, 0, Math.PI * 2, Math.PI / 2, 0.2094), bandMat);
  band6.name = 'band6';
  planet.add(band6);
  const band7 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 2, 0, Math.PI * 2, 1.7802, 0.2793), baseMat);
  band7.name = 'band7';
  planet.add(band7);
  const band8 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 2, 0, Math.PI * 2, 2.0595, 0.3142), midMat);
  band8.name = 'band8';
  planet.add(band8);
  const band9 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 2, 0, Math.PI * 2, 2.3736, 0.3142), bandMat);
  band9.name = 'band9';
  planet.add(band9);
  const band10 = new THREE.Mesh(new THREE.SphereGeometry(1, 28, 3, 0, Math.PI * 2, 2.6878, 0.4538), lightMat);
  band10.name = 'band10';
  planet.add(band10);
  const ringInner = new THREE.Mesh(new THREE.RingGeometry(1.35, 1.78, 64), ringInnerMat);
  ringInner.name = 'ringInner';
  ringInner.rotation.set(deg(-90), 0, 0);
  planet.add(ringInner);
  const ringOuter = new THREE.Mesh(new THREE.RingGeometry(1.86, 2.15, 64), ringOuterMat);
  ringOuter.name = 'ringOuter';
  ringOuter.rotation.set(deg(-90), 0, 0);
  planet.add(ringOuter);

  // Animations ('idle') — play them with THREE.AnimationMixer
  root.animations = codelsClips(THREE, [
    { target: planet, anim: [{ type: 'spin', axis: 'y', speed: 20 }] },
  ]);

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

export default createRingedPlanet;

評価とコメント

—
まだ評価はありません。最初の評価をしてみましょう。
5
0
4
0
3
0
2
0
1
0

評価やコメントをするにはログインしてください。

0 件のコメント

まだコメントはありません。このモデルの使い方や改善できる点を共有しましょう。

関連モデル

同じカテゴリまたは似たタグ