144 üçgen0,46 × 3,00 × 0,46 m
Kodda kullan
Editörde remix’legrid-pillar.js · 106 satır
Bağımsız bir ES modülü — yalnızca three paketine bağımlıdır. Fabrika fonksiyonunu çağırıp dönen grubu sahnene ekle.
/**
* Modular Grid Pillar — Codels 3D model library
* License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
* Triangles: 144 · Size (W × H × D): 0.46 × 3.00 × 0.46 m
*
* Usage:
* import { createGridPillar } from './grid-pillar.js';
*
* const model = createGridPillar();
* model.position.set(0, 0, 0);
* scene.add(model);
*/
import * as THREE from 'three';
// Deterministic vertex displacement (organic low-poly look).
function jitter(geometry, amount, seed) {
const pos = geometry.attributes.position;
const h = (a, b, c, s) => {
let x = Math.imul(a, 73856093) ^ Math.imul(b, 19349663) ^ Math.imul(c, 83492791) ^ Math.imul(s, 2654435761);
x = Math.imul(x ^ (x >>> 16), 2246822507);
x = Math.imul(x ^ (x >>> 13), 3266489909);
return ((x ^ (x >>> 16)) >>> 0) / 4294967295 - 0.5;
};
for (let i = 0; i < pos.count; i++) {
const x = pos.getX(i), y = pos.getY(i), z = pos.getZ(i);
const qx = Math.round(x * 1000), qy = Math.round(y * 1000), qz = Math.round(z * 1000);
pos.setXYZ(i, x + h(qx, qy, qz, seed) * 2 * amount, y + h(qx, qy, qz, seed + 1) * 2 * amount, z + h(qx, qy, qz, seed + 2) * 2 * amount);
}
pos.needsUpdate = true;
geometry.computeVertexNormals();
return geometry;
}
export function createGridPillar() {
const root = new THREE.Group();
root.name = 'GridPillar';
// Materials
const stoneMat = new THREE.MeshStandardMaterial({ name: 'stone', color: 0x7c7871, roughness: 0.95, flatShading: true });
const stone2Mat = new THREE.MeshStandardMaterial({ name: 'stone2', color: 0x67635c, roughness: 0.95, flatShading: true });
const stone3Mat = new THREE.MeshStandardMaterial({ name: 'stone3', color: 0x8b867c, roughness: 0.95, flatShading: true });
const mortarMat = new THREE.MeshStandardMaterial({ name: 'mortar', color: 0x3f3c38, roughness: 1, flatShading: true });
const plinthMat = new THREE.MeshStandardMaterial({ name: 'plinth', color: 0x57534d, roughness: 0.95, flatShading: true });
const dressedMat = new THREE.MeshStandardMaterial({ name: 'dressed', color: 0x9a9488, roughness: 0.9, flatShading: true });
// Parts
const plinth = new THREE.Mesh(new THREE.BoxGeometry(0.46, 0.35, 0.46), plinthMat);
plinth.name = 'plinth';
plinth.position.set(0, 0.175, 0);
root.add(plinth);
const cap = new THREE.Mesh(new THREE.BoxGeometry(0.46, 0.25, 0.46), dressedMat);
cap.name = 'cap';
cap.position.set(0, 2.875, 0);
root.add(cap);
const core = new THREE.Mesh(new THREE.BoxGeometry(0.37, 2.4, 0.37), mortarMat);
core.name = 'core';
core.position.set(0, 1.55, 0);
root.add(core);
const block = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.23, 0.412), 0.004, 40), stone3Mat);
block.name = 'block';
block.position.set(0, 0.475, 0);
root.add(block);
const block2 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.412, 0.28, 0.4), 0.004, 41), stone3Mat);
block2.name = 'block';
block2.position.set(0, 0.75, 0);
root.add(block2);
const block3 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.255, 0.412), 0.004, 42), stone3Mat);
block3.name = 'block';
block3.position.set(0, 1.0375, 0);
root.add(block3);
const block4 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.412, 0.255, 0.4), 0.004, 43), stoneMat);
block4.name = 'block';
block4.position.set(0, 1.3125, 0);
root.add(block4);
const block5 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.255, 0.412), 0.004, 44), stone2Mat);
block5.name = 'block';
block5.position.set(0, 1.5875, 0);
root.add(block5);
const block6 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.412, 0.255, 0.4), 0.004, 45), stone2Mat);
block6.name = 'block';
block6.position.set(0, 1.8625, 0);
root.add(block6);
const block7 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.18, 0.412), 0.004, 46), stoneMat);
block7.name = 'block';
block7.position.set(0, 2.1, 0);
root.add(block7);
const block8 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.412, 0.28, 0.4), 0.004, 47), stone3Mat);
block8.name = 'block';
block8.position.set(0, 2.35, 0);
root.add(block8);
const block9 = new THREE.Mesh(jitter(new THREE.BoxGeometry(0.4, 0.23, 0.412), 0.004, 48), stone3Mat);
block9.name = 'block';
block9.position.set(0, 2.625, 0);
root.add(block9);
root.traverse((o) => {
if (o.isMesh) {
o.castShadow = true;
o.receiveShadow = true;
}
});
return root;
}
export default createGridPillar;
Puanlar ve yorumlar
0 yorum
Henüz yorum yok. Bu modeli nasıl kullandığını ya da neyin daha iyi olabileceğini paylaş.
Benzer modeller
Aynı kategori ya da benzer etiketler









