MC/tools/build-quest-npc-skins.mjs
2026-11-27 23:43:05 +00:00

50 lines
5.2 KiB
JavaScript

// Original 64x64 Minecraft classic-arm UV skins for the DuneRealms character registry.
// Pixel drawing is deterministic; no copied game/film texture or external skin is used.
import {mkdirSync,writeFileSync} from 'node:fs';
import {deflateSync} from 'node:zlib';
import {dirname,resolve} from 'node:path';
import {fileURLToPath} from 'node:url';
const root=resolve(dirname(fileURLToPath(import.meta.url)),'..'),out=resolve(root,'DuneRealmsGUI/npc-skins');mkdirSync(out,{recursive:true});
const colors={
thufir_hawat:['ba8964','51463f','a0a0a0','25352b','929c65','d6bb77','trim'],
piter_de_vries:['a69586','433f40','50454c','332d35','6b394f','b9957b','trim'],
glossu_rabban:['bc8a67','704633','4f322c','3a2e2c','7b4242','b48b56','trim'],
hasimir_fenring:['ba916e','705241','493d32','3b2427','855445','d3a25e','trim'],
roma_atani:['b69b77','514d3b','635a45','263c31','6b9272','c7b06e','hood'],
stilgar:['ac7950','533b2c','49372c','695145','a48a60','c9af79','hood'],
shadout_mapes:['b17e54','62422d','272e30','4a5146','b29873','d0b27e','hood'],
liet_kynes:['b98c62','6a4935','755749','564f37','9da271','c2ad79','hood'],
chani:['a87551','5c3a2b','372b27','45483a','9b805e','c7a978','hood'],
duncan_idaho:['bc8e67','5e412f','3d302c','334044','84919a','b99465','trim'],
irulan_corrino:['dfbb92','925f3f','c2a465','49382c','9b765b','ebcb82','trim'],
jessica_atreides:['c8a17d','76533e','5c4235','343a3b','61736d','a89371','hood'],
gaius_helen_mohiam:['b69b85','746052','92928a','323335','5a5666','a9a5a3','hood'],
alia_atreides:['c79e78','755142','543b34','4c5040','9a956e','d2b485','hood'],
edric:['a38f75','50473e','625344','314b4a','819b93','c5b283','hood'],
esmar_tuek:['b48d63','674733','44352d','55493c','887458','c5a873','hood'],
staban_tuek:['aa7c56','5a3c31','46342b','484438','988564','c6a674','hood'],
imperial_attendant:['bf9a76','755942','5d4c3c','3c3032','87705a','d3b16d','trim']
};
const rgb=s=>[parseInt(s.slice(0,2),16),parseInt(s.slice(2,4),16),parseInt(s.slice(4,6),16)];
const shade=(c,d)=>c.map(x=>Math.max(0,Math.min(255,x+d)));const rgba=(c,a=255)=>[...c,a];
function crc32(buf){let c=0xffffffff;for(const n of buf){c^=n;for(let i=0;i<8;i++)c=(c>>>1)^((c&1)?0xedb88320:0);}return (c^0xffffffff)>>>0;}
const int=n=>{const buf=Buffer.alloc(4);buf.writeUInt32BE(n);return buf;};
function chunk(type,body){const b=Buffer.concat([Buffer.from(type),body]);return Buffer.concat([int(body.length),b,int(crc32(b))]);}
function png(w,h,pixels){const rows=[];for(let y=0;y<h;y++)rows.push(Buffer.from([0]),pixels.subarray(y*w*4,(y+1)*w*4));return Buffer.concat([Buffer.from([137,80,78,71,13,10,26,10]),chunk('IHDR',Buffer.concat([int(w),int(h),Buffer.from([8,6,0,0,0])])),chunk('IDAT',deflateSync(Buffer.concat(rows))),chunk('IEND',Buffer.alloc(0))]);}
function skin(key,values){const [skin,shadow,hair,base,cloth,metal]=values.slice(0,6).map(rgb),hood=values[6]==='hood',pixels=Buffer.alloc(64*64*4);
const rect=(x,y,w,h,c)=>{for(let yy=y;yy<y+h;yy++)for(let xx=x;xx<x+w;xx++)pixels.set(rgba(c),4*(yy*64+xx));};
const p=(x,y,c)=>rect(x,y,1,1,c);
// Head base, side shading, hand-authored facial features and cap/hood.
for(const [x,y,w,h]of [[0,8,8,8],[8,8,8,8],[16,8,8,8],[24,8,8,8],[8,0,8,8],[16,0,8,8]])rect(x,y,w,h,shade(skin,x===8?0:-9));
rect(8,8,8,2,hood?cloth:hair);rect(8,10,1,6,hood?cloth:shadow);rect(15,10,1,6,hood?shade(cloth,-12):shadow);
rect(9,11,2,1,shade(shadow,-12));rect(13,11,2,1,shade(shadow,-12));p(10,12,[235,225,203]);p(13,12,[235,225,203]);p(11,12,hood?[90,154,161]:[57,57,51]);p(12,12,hood?[90,154,161]:[57,57,51]);p(12,13,shade(skin,-19));rect(11,15,3,1,shadow);
if(['stilgar','thufir_hawat','liet_kynes','esmar_tuek','staban_tuek','duncan_idaho'].includes(key)){rect(9,14,1,2,hair);rect(14,14,1,2,hair);rect(10,16-1,4,1,hair);p(11,14,shade(hair,10));}
for(const x of [0,16,24]){rect(x,8,8,3,hood?shade(cloth,-10):hair);rect(x,11,2,5,hood?cloth:shadow);if(hood)rect(x+6,11,2,5,shade(cloth,-15));}rect(8,0,8,8,hood?cloth:hair);
// Torso (front x20, back x32), both arm and leg mirrored UV islands.
for(const [x,y,w,h]of [[16,20,4,12],[20,20,8,12],[28,20,4,12],[32,20,8,12],[20,16,8,4],[28,16,8,4]])rect(x,y,w,h,shade(base,x===20?8:0));
rect(20,20,8,2,cloth);rect(20,22,2,7,shade(cloth,-9));rect(26,22,2,7,cloth);for(let i=0;i<6;i++)p(21+i,21+Math.floor(i/2),shade(metal,-15));rect(20,28,8,2,shade(base,-24));rect(23,28,2,2,metal);rect(32,20,8,3,shade(cloth,-13));rect(35,24,2,5,shade(base,9));
for(const ox of [40,32]){const by=ox===40?16:48;for(const [dx,dy,w,h]of [[0,4,4,12],[4,4,4,12],[8,4,4,12],[12,4,4,12],[4,0,4,4],[8,0,4,4]])rect(ox+dx,by+dy,w,h,shade(base,dx===4?8:0));for(const dx of [0,4,8,12]){rect(ox+dx,by+4,4,2,cloth);rect(ox+dx,by+12,4,1,metal);rect(ox+dx,by+13,4,3,skin);}}
for(const [ox,by]of [[0,16],[16,48]]){for(const [dx,dy,w,h]of [[0,4,4,12],[4,4,4,12],[8,4,4,12],[12,4,4,12],[4,0,4,4],[8,0,4,4]])rect(ox+dx,by+dy,w,h,shade(base,dx===4?-9:-18));for(const dx of [0,4,8,12]){rect(ox+dx,by+8,4,1,shade(cloth,-12));rect(ox+dx,by+11,4,5,shade(base,-38));rect(ox+dx,by+15,4,1,shade(base,-56));}}
return pixels;}
for(const [key,values]of Object.entries(colors))writeFileSync(resolve(out,`${key}.png`),png(64,64,skin(key,values)));
console.log(`Generated ${Object.keys(colors).length} original 64x64 character skins.`);