Another Script Challenge


#1

for everyone to ignore :wink: Make a contrived mesh convex…

(
	fn gen_mesh numpts steps =
	(
		convertToMesh (star radius1:50 radius2:20 fillet1:7.5 fillet2:7.5 numPoints:numpts steps:steps wirecolor:gray)
	)	
	
	fn make_convex mobj =
	(
		-- your code goes here
	)	
		
	delete objects;
	mobj = gen_mesh (random 3 25) (random 0 4);
	make_convex mobj;
)

the result should look something like this…


You can make the assumption all verts are in order as they are (ie no need to script the generic get verts in order unless of course you want to) also you can assume the code only has to work in 2d with z as up. Also note theres no passing the num pnts and num steps to the make_concave function.


#2

a more random gen function

fn gen_mesh numpts steps =
	(
		star_shp = star radius1:50 radius2:20 fillet1:7.5 fillet2:7.5 numPoints:numpts steps:steps optimize:true wirecolor:black;
		star_shp.mat = standard();
		star_shp = convertToSplineShape star_shp;
		count = random 1 numpts;
		for i = 1 to count do deleteKnot star_shp 1 (random 1  (numKnots star_shp 1));
		convertToMesh star_shp;
	)

#3

you say “concave”, but I see the result is convex … I’m missing the result rules.


#4

yep brain fart :slight_smile:


#5

so… is it not a “convex hull” algorithm a kind? it might not be ‘topologically equal’ … but maybe that’s the point of the challenge?


#6

try it and see. then we can compare it to what I came up with and see if a I reinvented the wheel without realizing :wink:


#7

lets say we have something like this:
image

what is the ‘result’?

I just want to understand, is the “result” always convex? or does it need to somehow “guess” the topology?


#8

post the code and I’ll see what the result is… but this is a bit similar…


#9

I don’t understand what the challenge is … find a convex hull or make triangulation after that?
and more … why is it originally Mesh? doesn’t it make sense to do everything in splines, and then build the mesh?


#10

a new mesh gen without splines

    fn gen_mesh2 sides r1 offset = 
	(
		local nverts = sides * 2;
		local nfaces = sides * 2;	
		mobj = mesh numverts:nverts numfaces:nfaces;
		
		local incr = 360.0/sides;
		cs = for j = 1 to  sides  collect 
		(	
			u = incr * (j - 1);
			[cos u, sin u,  random 0.01 1.0];
		)	
		
		local vi = 1;
		for j = 1 to sides do
		(
			r = r1 + offset * cs[j].z;
			setvert mobj vi  [r * cs[j].x, r * cs[j].y, 0];
			vi += 1;
		)	
		for j = 1 to sides do	
		(
			setvert mobj vi [r1 * cs[j].x, r1 * cs[j].y, 0]
			vi += 1;
		)

		local fi = 1;
		for j = 1 to sides do
		(	
			a = j;
			b = a + 1;
			if j == sides then b -= sides; 
				
			c = a + sides;
			d = b + sides;
			
			setface mobj fi [a,d,c];
			setEdgeVis mobj fi 2 true;
			setEdgeVis mobj fi 3 true;
			fi += 1;
			
			setface mobj fi [a,b,d];
			setEdgeVis mobj fi 1 true;
			setEdgeVis mobj fi 2 true;
			fi += 1;
		)		
		update mobj;
		mobj.mat = standard();
		mobj.wirecolor = black;
		mobj
	)

so without destroying the existing mesh or without adding additional verts. By just adding faces make the “exterior” edge of the mesh convex.


#11

it’s clear enough