468 tris0,29 × 1,03 × 0,06 m
Úsalo en código
Hacer remix en el editorsword.js · 117 líneas
Módulo ES autónomo — solo depende de three. Llama a la función factory y añade el grupo a tu escena.
/**
* Sword — Codels 3D model library
* License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
* Triangles: 468 · Size (W × H × D): 0.29 × 1.03 × 0.06 m
*
* Usage:
* import { createSword } from './sword.js';
*
* const model = createSword();
* 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);
}
export function createSword() {
const root = new THREE.Group();
root.name = 'Sword';
// Materials
const bladeMat = new THREE.MeshStandardMaterial({ name: 'blade', color: 0xd9e1ea, roughness: 0.3, metalness: 0.7, flatShading: true });
const hiltMat = new THREE.MeshStandardMaterial({ name: 'hilt', color: 0xd0a24a, roughness: 0.35, metalness: 0.75, flatShading: true });
const gripMat = new THREE.MeshStandardMaterial({ name: 'grip', color: 0x6b4226, roughness: 0.85, flatShading: true });
const wrapMat = new THREE.MeshStandardMaterial({ name: 'wrap', color: 0x3f2516, roughness: 0.9, flatShading: true });
// Shared geometries
const cylinderGeo = new THREE.CylinderGeometry(0.0205, 0.0205, 0.01, 8);
const sphereGeo = new THREE.SphereGeometry(0.02, 6, 4);
// Parts
const pommel = new THREE.Mesh(new THREE.SphereGeometry(0.038, 8, 6), hiltMat);
pommel.name = 'pommel';
pommel.position.set(0, 0.035, 0);
pommel.scale.set(1, 0.92, 0.78);
root.add(pommel);
const pommelNeck = new THREE.Mesh(new THREE.CylinderGeometry(0.016, 0.022, 0.02, 8), hiltMat);
pommelNeck.name = 'pommelNeck';
pommelNeck.position.set(0, 0.072, 0);
root.add(pommelNeck);
const grip = new THREE.Mesh(new THREE.CylinderGeometry(0.0185, 0.0175, 0.16, 8), gripMat);
grip.name = 'grip';
grip.position.set(0, 0.158, 0);
root.add(grip);
const wrap1 = new THREE.Mesh(cylinderGeo, wrapMat);
wrap1.name = 'wrap1';
wrap1.position.set(0, 0.0913, 0);
wrap1.rotation.set(0, 0, deg(16));
root.add(wrap1);
const wrap2 = new THREE.Mesh(cylinderGeo, wrapMat);
wrap2.name = 'wrap2';
wrap2.position.set(0, 0.118, 0);
wrap2.rotation.set(0, 0, deg(16));
root.add(wrap2);
const wrap3 = new THREE.Mesh(cylinderGeo, wrapMat);
wrap3.name = 'wrap3';
wrap3.position.set(0, 0.1447, 0);
wrap3.rotation.set(0, 0, deg(16));
root.add(wrap3);
const wrap4 = new THREE.Mesh(cylinderGeo, wrapMat);
wrap4.name = 'wrap4';
wrap4.position.set(0, 0.1713, 0);
wrap4.rotation.set(0, 0, deg(16));
root.add(wrap4);
const wrap5 = new THREE.Mesh(cylinderGeo, wrapMat);
wrap5.name = 'wrap5';
wrap5.position.set(0, 0.198, 0);
wrap5.rotation.set(0, 0, deg(16));
root.add(wrap5);
const wrap6 = new THREE.Mesh(cylinderGeo, wrapMat);
wrap6.name = 'wrap6';
wrap6.position.set(0, 0.2247, 0);
wrap6.rotation.set(0, 0, deg(16));
root.add(wrap6);
const guard = new THREE.Mesh(new THREE.BoxGeometry(0.24, 0.0289, 0.04), hiltMat);
guard.name = 'guard';
guard.position.set(0, 0.255, 0);
root.add(guard);
const guardEndR = new THREE.Mesh(sphereGeo, hiltMat);
guardEndR.name = 'guardEndR';
guardEndR.position.set(0.125, 0.255, 0);
root.add(guardEndR);
const guardEndL = new THREE.Mesh(sphereGeo, hiltMat);
guardEndL.name = 'guardEndL';
guardEndL.position.set(-0.125, 0.255, 0);
root.add(guardEndL);
const guardCenter = new THREE.Mesh(new THREE.BoxGeometry(0.05, 0.05, 0.048), hiltMat);
guardCenter.name = 'guardCenter';
guardCenter.position.set(0, 0.255, 0);
guardCenter.rotation.set(0, 0, deg(45));
root.add(guardCenter);
const blade = new THREE.Mesh(extrude([[-0.013, 0], [0.013, 0], [0.007, 0.615], [0, 0.7284], [-0.007, 0.615]], 0.001, [], [0.0045, 0.018, 1]), bladeMat);
blade.name = 'blade';
blade.position.set(0, 0.273, 0);
root.add(blade);
root.traverse((o) => {
if (o.isMesh) {
o.castShadow = true;
o.receiveShadow = true;
}
});
return root;
}
export default createSword;
Valoraciones y comentarios
0 comentarios
Aún no hay comentarios. Cuenta cómo usaste este modelo o qué se podría mejorar.
Modelos relacionados
Misma categoría o etiquetas similares









