Skip to content

Agent skill for creative 3D visualization: turn an idea into a Three.js/Blender scene worth exploring. Claude Code + Codex plugin, 223 recipes, 440 knowledge records, 22 proved kits, 37 runnable studies.

4.7 KB
Raw Blame
import {THREE,mat,line,label} from '../scene-kit.js';
import {study} from '../study-kit.js';
import {loadAnatomy,anatomySources,anatomyCredit} from '../anatomy-assets.js';
const PARTS=['FMA61822','FMA67944','FMA67943','FMA62004','FMA61993nsn','FMA72653','FMA72654','FMA72655','FMA72656','FMA72661','FMA72662','FMA72665','FMA72666','FMA72667','FMA72668','FMA72669','FMA72670','FMA72685','FMA72686','FMA72687','FMA72688','FMA72800','FMA72801','FMA72804','FMA72805','FMA72975','FMA72976','FMA72689','FMA72690','FMA72705','FMA72706','FMA72717','FMA72718'];
function family(name){return /cerebellum/.test(name)?'cerebellum':/pons|medulla|midbrain/.test(name)?'stem':/white matter/.test(name)?'white':/cingulate|parahippocampal/.test(name)?'medial':/frontal|precentral/.test(name)?'frontal':/postcentral|supramarginal|angular/.test(name)?'parietal':/occipital/.test(name)?'occipital':'temporal';}
export async function createScene(){
 const colors={medial:'#c09da6',white:'#cfb8a3',cerebellum:'#ae807c',stem:'#b8a084',frontal:'#d3a496',parietal:'#bdac92',temporal:'#ae91ac',occipital:'#91aaba'};
 const {group,objects}=await loadAnatomy(PARTS,{center:[0,-101,1562],scale:.025,material:(id,name)=>new THREE.MeshPhysicalMaterial({color:colors[family(name)],roughness:.64,clearcoat:.05,side:THREE.DoubleSide})});
 let separation=0,focus='all',section=0,context=false;const clip=new THREE.Plane(new THREE.Vector3(-1,0,0),3);
 const labels=new THREE.Group();group.add(labels);for(const [text,p,q] of [['FRONTAL',[.5,.7,1.6],[1.7,1.5,1.2]],['CEREBELLUM',[.6,-1.2,-.8],[1.8,-1.4,-.6]],['BRAINSTEM',[0,-1.3,0],[-1.2,-1.8,.4]]]){const mark=new THREE.Group();mark.userData.family=text==='BRAINSTEM'?'stem':text.toLowerCase();mark.userData.anchor=new THREE.Vector3(...p);line([p,q],'#a89588',mark,.5);label(text,q,'#d8c4b1',.13,mark);labels.add(mark);}labels.visible=false;
 function refresh(){clip.constant=section===0?3:1.8-section*2.4;for(const mark of labels.children){const f=mark.userData.family;mark.position.x=f==='frontal'?separation*.9:0;const anchor=mark.userData.anchor.clone().add(mark.position);mark.visible=(focus==='all'||focus===f||focus==='cortex'&&f==='frontal')&&(!section||clip.distanceToPoint(anchor)>=0);}for(const o of objects){const f=family(o.userData.name),side=/right/.test(o.userData.name)?-1:/left/.test(o.userData.name)?1:0;o.position.x=side*separation*.9;const selected=focus==='all'||f===focus||focus==='cortex'&&!['white','stem','cerebellum'].includes(f);o.visible=selected||context;o.material.transparent=context&&!selected;o.material.opacity=selected?1:.065;o.material.depthWrite=selected;o.castShadow=selected;o.material.clippingPlanes=section?[clip]:[];}}
 const reset=()=>{separation=section=0;focus='all';context=false;labels.visible=false;refresh();};reset();
 return study(group,{lighting:{exposure:.84,key:9,fill:2.5,rim:10},reset,controls:[{id:'structure',label:'Inspect a structure',type:'select',options:[{value:'all',label:'Selected brain assembly'},{value:'cortex',label:'Cortical gyri'},{value:'frontal',label:'Frontal group'},{value:'parietal',label:'Parietal group'},{value:'temporal',label:'Temporal group'},{value:'occipital',label:'Occipital group'},{value:'medial',label:'Medial cortical gyri'},{value:'white',label:'White-matter structure'},{value:'cerebellum',label:'Cerebellum'},{value:'stem',label:'Brainstem components'}],get:()=>focus,set:v=>{focus=v;refresh();}},{id:'separation',label:'Separate left / right cortical parts',type:'range',min:0,max:1,step:.01,get:()=>separation,set:v=>{separation=v;refresh();}},{id:'section',label:'Open a sagittal section',type:'range',min:0,max:1,step:.01,get:()=>section,set:v=>{section=v;refresh();}},{id:'context',label:'Ghost / hide surrounding structures',type:'button',set:()=>{context=!context;refresh();}},{id:'labels',label:'Show / hide anatomical labels',type:'button',set:()=>labels.visible=!labels.visible}],stats:()=>[{label:'Geometry',value:PARTS.length+' registered parts'},{label:'View',value:focus},{label:'Section',value:section?'Sagittal clip':'Intact selection'}],views:{overview:{position:[4,2.7,8],target:[0,-.2,0]},detail:{position:[2.4,1.4,4.8],target:[0,0,0]}},note:'Source-derived cortical gyri, white matter, cerebellum and brainstem components. This is a selected assembly; omitted gyri are not anatomical holes or missing tissue. Color groups aid identification, not functional localization. A faint surrounding assembly can retain spatial context during isolation; it is an inspection overlay, not transparent biological tissue. Separation and open-boundary clipping are inspection devices. Display scale is enlarged 25× if scene units are metres.',craft:anatomyCredit,sources:[...anatomySources,{title:'OpenStax — The central nervous system',url:'https://openstax.org/books/anatomy-and-physiology-2e/pages/13-2-the-central-nervous-system'}]});
}