Box to Sphere
-- Script function to spherify a box
-- Requires model size <= 1, rescale after spherify
function Script:sphereit(x,y,z)
    sx = x * math.sqrt(1.0 - (y*y*0.5) - (z*z*0.5) + (y*y*z*z/3.0));
    sy = y * math.sqrt(1.0 - (z*z*0.5) - (x*x*0.5) + (z*z*x*x/3.0));
    sz = z * math.sqrt(1.0 - (x*x*0.5) - (y*y*0.5) + (x*x*y*y/3.0));
    --print(x,sx)
    --print(y,sy)
    --print(z,sz)
    return sx,sy,sz
end

function Script:Start()
    surface=self.entity:GetSurface(0)
    for v=0,surface:CountVertices()-1 do
        vpos = surface:GetVertexPosition(v)
        x,y,z = self:sphereit(vpos.x,vpos.y,vpos.z)
        surface:SetVertexPosition(v,Vec3(x,y,z))
        surface:UpdateNormals(true,0.01,180)
       end
end
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License