I'm looking for a simple way to create a solid voxel sphere in Maya—something that looks like this: https://minecraftcirclesgenerator.com/ . Any suggestions?
isn't it just compute a grid of points (center of the voxel) if the point is inside the sphere (it's distance from the center is less than the radius) create the voxel else don't .
fn voxel_sphere radius segs =
(
size = 2 * radius/segs;
for h = 1 to segs do -- height (z)
for w = 1 to segs do -- width (x)
for l = 1 to segs do -- length (y)
(
-- compute the grid point
pos = [-radius + ((w - 1) * size), -radius + ((l - 1) * size), -radius + ((h - 1) * size)];
-- in sphere test (also a culling spherical test to stop max chugging like puffing billy)
if (length pos) < radius and (length pos) >= radius - size then
(
box width:size length:size height:size pos:(pos + [0,0,-size * 0.5]) wirecolor:blue;
)
)
)
delete geometry
voxel_sphere 10.0 30
result p.s. seems to work best with an odd number of segments
Blender does have a Remesh modifier with a Blocks option and using an icosphere might get more consistent results than an UVsphere (difference on the "north/south" poles and the other "axis poles"). To replicate the exact rasterization you might want to play with the scale factor of the modifier
Replies
I'm looking for a simple way to create a solid voxel sphere in Maya—something that looks like this: https://minecraftcirclesgenerator.com/ . Any suggestions?
Pretty simple for a sphere. I imagine a robot could probably generate some Maya python for it
It gets more complex if you need it to align with a world grid.
Can MASH do it?
result
p.s. seems to work best with an odd number of segments
--********************************************************************************** fn make_cube_side tmesh fi f1verts f2verts matid smg = ( setface tmesh fi f1verts; setEdgeVis tmesh fi 1 true; setEdgeVis tmesh fi 2 true; setFaceMatID tmesh fi matid; setFaceSmoothGroup tmesh fi smg; fi += 1; setface tmesh fi f2verts; setEdgeVis tmesh fi 1 true; setEdgeVis tmesh fi 2 true; setFaceMatID tmesh fi matid; setFaceSmoothGroup tmesh fi smg; fi += 1; ) --********************************************************************************** fn make_cube pos size sides = ( tmesh = trimesh(); setnumverts tmesh 8; setnumfaces tmesh (sides.numberSet * 2); setvert tmesh 1 [pos.x - size, pos.y - size, pos.z - size]; setvert tmesh 2 [pos.x + size, pos.y - size, pos.z - size]; setvert tmesh 3 [pos.x - size, pos.y + size, pos.z - size]; setvert tmesh 4 [pos.x + size, pos.y + size, pos.z - size]; setvert tmesh 5 [pos.x - size, pos.y - size, pos.z + size]; setvert tmesh 6 [pos.x + size, pos.y - size, pos.z + size]; setvert tmesh 7 [pos.x - size, pos.y + size, pos.z + size]; setvert tmesh 8 [pos.x + size, pos.y + size, pos.z + size]; fi = 1; if sides[1] then -- +x fi = make_cube_side tmesh fi [2,4,8] [8,6,2] 1 1; if sides[2] then -- -x fi = make_cube_side tmesh fi [3,1,5] [5,7,3] 2 2; if sides[3] then -- +y fi = make_cube_side tmesh fi [4,3,7] [7,8,4] 3 4; if sides[4] then -- -y fi = make_cube_side tmesh fi [1,2,6] [6,5,1] 4 8; if sides[5] then -- +z fi = make_cube_side tmesh fi [5,6,8] [8,7,5] 5 16; if sides[6] then -- -z fi = make_cube_side tmesh fi [1,3,4] [4,2,1] 6 32; tmesh; ) --********************************************************************************** fn block_sphere radius segs = ( vmesh = editable_mesh(); hsize = radius/segs; size = 2 * hsize; for h = 1 to segs do -- height (z) for w = 1 to segs do -- width (x) for l = 1 to segs do -- length (y) ( -- compute the grid point pos = [-radius + ((w - 1) * size), -radius + ((l - 1) * size), -radius + ((h - 1) * size)]; -- in sphere test (also a culling spherical test to stop max chugging like puffing billy) len = length pos; if len < radius and len > radius - size then ( sides_to_keep = #{1..6}; -- test for neighbours on x axis temp = pos + [size,0,0]; if length temp < radius then sides_to_keep[1] = false; temp = pos - [size,0,0]; if length temp < radius then sides_to_keep[2] = false; -- test for neighbours on y axis temp = pos + [0,size,0]; if length temp < radius then sides_to_keep[3] = false; temp = pos - [0,size,0]; if length temp < radius then sides_to_keep[4] = false; -- test for neighbours on z axis temp = pos + [0,0,size]; if length temp < radius then sides_to_keep[5] = false; temp = pos - [0,0,size]; if length temp < radius then sides_to_keep[6] = false; -- create the geometry local cube = make_cube pos (size * 0.5) sides_to_keep; attach vmesh cube; free cube; ) ) meshOps.removeIsolatedVerts vmesh; meshop.weldVertsByThreshold vmesh #all 0.01f; update vmesh; vmesh; ) delete geometry block_sphere 10.0 31.. or better yet decides to have it fill arbitrary meshes