Download code/tools/scene_export.js from StarpowerTechnology/WVY-3D-1M: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/StarpowerTechnology/WVY-3D-1M/resolve/main/code/tools/scene_export.js
- Command line
-
hf download hf://StarpowerTechnology/WVY-3D-1M/code/tools/scene_export.js
-
curl -L -o scene_export.js https://huggingface.co/StarpowerTechnology/WVY-3D-1M/resolve/main/code/tools/scene_export.js
1.57 kB
| // Build a scene with the same engine as the web page and dump everything the offline renderer needs. | |
| ['sculpt','species','objects','brain'].forEach(f=>require('../engine/'+f+'.js')); | |
| const B=globalThis.RigBrain, fs=require('fs'); | |
| const [scriptPath, nFrames, out, weights]=[process.argv[2], +process.argv[3], process.argv[4], process.argv[5]||'browser_weights_fp16.json']; | |
| B.loadWeights(JSON.parse(fs.readFileSync(weights))); | |
| const script=JSON.parse(fs.readFileSync(scriptPath)); | |
| (async()=>{ | |
| const b=await B.buildScene(script,{seed:script.seed||11}); | |
| const r=(a,d=4)=>a.map(v=>+v.toFixed(d)); | |
| const objects=b.objects.map(o=>({type:o.type,key:o.key,pos:o.pos,yaw:o.yaw,scale:o.scale,light:o.light,emissive:o.emissive})); | |
| const meshes={}; b.objects.forEach(o=>{ if(!meshes[o.key]) meshes[o.key]={verts:o.verts.map(v=>r(v)),faces:o.faces,colors:o.colors.map(c=>r(c,3))}; }); | |
| const actors=b.actors.map((a,i)=>({name:a.name,family:a.fam,rig:a.rigSource,verts:a.cr.verts.map(v=>r(v)),faces:a.cr.faces,colors:a.cr.colors.map(c=>r(c,3)),weights:a.rig.weights,joints:a.rig.joints,parent:globalThis.RigSculpt.FAMILIES[a.fam].parent,stats:b.stats[i]})); | |
| const frames=[]; | |
| for(let t=0;t<nFrames;t++){ frames.push(b.actors.map(a=>{const tr=a.tick(t,b.actors); return {root:r(tr.root),yaw:+tr.yaw.toFixed(4),Rw:tr.Rw.map(m=>r(m)),pw:tr.pw.map(p=>r(p)),action:tr.action};})); } | |
| fs.writeFileSync(out,JSON.stringify({script,env:b.env,world:b.world,objects,meshes,actors,frames})); | |
| console.error('exported',out,b.actors.length,'actors',b.objects.length,'objects'); | |
| })(); | |