Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

Building a voxel sphere?

I'm trying to find an easy way to make a voxel sphere. Basically it needs to look like this, ideally solid rather than hollow: http://www.plotz.co.uk/_gfx/voxel_sphere_1.png

I'm using Maya? Any ideas?

Replies

  • adam213

    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?

  • Klunk
    Offline / Send Message
    Klunk quad damage
    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 .
  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter
    Yes

    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?
  • Noren
    Offline / Send Message
    Noren greentooth
    Not a Maya user, but some particle systems can do this pretty much out of the box, so Bifrost, perhaps?
  • Klunk
    Offline / Send Message
    Klunk quad damage
    some maxscript may help you do the same in maya
    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
  • okidoki
    Offline / Send Message
    okidoki greentooth
    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


  • Klunk
    Offline / Send Message
    Klunk quad damage
    a slight variation or how you simplify the geometry....
    --**********************************************************************************
    
    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

  • poopipe
    Offline / Send Message
    poopipe grand marshal polycounter
    i give it two days before he decides to generate and cache chunks 

    .. or better yet decides to have it fill arbitrary meshes
  • ZacD
    Offline / Send Message
    ZacD ngon master
    Just for fun, I did it with a UE5 construction script. Anything above 20^3 (which is 8000 instances) is too laggy to move around in real time :\ 




  • Klunk
    Offline / Send Message
    Klunk quad damage
    I tried 129 in max..... it was unresponsive for about 5 mins then drew the lower third and thought fuck this and crashed :)
  • ZacD
    Offline / Send Message
    ZacD ngon master
    I tried 50^3 and it worked but took like 15 seconds, at 100 it decided not to do anything.
  • tsungyuw
    Offline / Send Message
    tsungyuw polycounter lvl 10
    I made a script before to create voxel out of a model, but I think use maya Mash is a faster option
    https://www.youtube.com/watch?v=i_Y1m4AuD3M
Sign In or Register to comment.