// Minimal orthographic depth-buffer renderer used only for CAD preview PNGs. // CAD geometry is exported separately as analytic STEP solids. #include #include #include #include extern "C" void rasterize(int n, const double* xyz, const float* normals, const float* colours, int width, int height, const double* light, const double* view, uint8_t* image) { std::vector depth(static_cast(width)*height, -1e40); for(int y=0;y(y)*width+x)*3; image[j]=uint8_t(246-10*k);image[j+1]=uint8_t(248-9*k);image[j+2]=uint8_t(251-8*k); } double halfv[3];double hl=0; for(int c=0;c<3;++c){halfv[c]=light[c]+view[c];hl+=halfv[c]*halfv[c];} for(int c=0;c<3;++c)halfv[c]/=std::sqrt(hl); for(int t=0;t(y)*width+x; if(z<=depth[idx]+1e-9)continue; depth[idx]=z; double nx=b0*nn[0]+b1*nn[3]+b2*nn[6]; double ny=b0*nn[1]+b1*nn[4]+b2*nn[7]; double nz=b0*nn[2]+b1*nn[5]+b2*nn[8]; double norm=std::sqrt(nx*nx+ny*ny+nz*nz); if(norm<1e-10)norm=1; nx/=norm;ny/=norm;nz/=norm; double lam=std::max(0.,nx*light[0]+ny*light[1]+nz*light[2]); double facing=std::max(0.,nx*view[0]+ny*view[1]+nz*view[2]); double spec=std::pow(std::max(0.,nx*halfv[0]+ny*halfv[1]+nz*halfv[2]),44.); double bright=.47+.47*lam+.06*facing; double metal=std::max({col[0],col[1],col[2]}); for(int c=0;c<3;++c){ double value=col[c]*bright+spec*(metal>.5?.18:.055); image[idx*3+c]=uint8_t(255*std::clamp(value,0.,1.)); } } } }