Home Coding, Scripting, Shaders

[MaxScript] Polygon to mesh projection

polycounter lvl 11
Offline / Send Message
FishMan polycounter lvl 11
Hi. Does anyone know how to do it?
Lets say I have a flat concave/convex polygon with N vertexes and I would like to project it on the surface of a mesh along some direction vector. Basically like a decal or imprint in pro-boolean. The result mesh should have the topology of the mesh on which proijection was done.

Example (was done using pro-boolean):


Any clues? Known methods? Or existing functions that I can dig in?

Thanks.

Replies

  • Klunk
    Options
    Online / Send Message
    Klunk ngon master
    try this (convex only though so concave would need to split into convex then recombined after being wrapped individually)...
    -- creates a ray point along the edge
    
    fn getEdgeRay msh edg =
    (
    	ze = edg - 1;
    	a = (mod ze 3) + 1;
    	b = mod a 3;	
    	fverts = getface msh (ze/3 + 1);
    	
    	v0 = getvert msh fverts[a];
    	v1 = getvert msh fverts[b + 1];
    	
    	ray v0 (normalize (v1 - v0));
    )	
    
    -- create tranform matrix from the edge dir and the face normal
    
    fn get_edge_planes mobj =
    (
    	edges = meshop.getOpenEdges mobj;
    	y = getFaceNormal mobj 1;
    
    	for edg in edges collect
    	(	
    		eray = getEdgeRay mobj edg;
    		x = eray.dir;
    		z = normalize (cross x y);
    		matrix3 x y z eray.pos;
    	)	
    )	
    
    fn wrap_planar_poly_to targ srce =
    (
    	setCommandPanelTaskMode #create; -- being in modify is slow
    	
    	wrapped = snapshot targ; -- duplicate the target
    	
    	iotm = inverse wrapped.objecttransform;
    	xforms = get_edge_planes srce;
    	for tm in xforms do 
    	(
    		m = sliceModifier();
    		m.Slice_Type = 2;
    		m.slice_plane.transform = tm * iotm;
    		addModifier wrapped m;
    	)		
    	
    	convertToMesh wrapped; -- collapse to mesh
    	
    	srce_normal = getFaceNormal srce 1;
    	
    	backfacing = for f = 1 to wrapped.numfaces collect
    	(
    		normal = getFaceNormal wrapped f;	
    		if dot normal srce_normal < 0 then f else dontcollect;
    	)		
    	meshop.deleteFaces wrapped backfacing;
    	setCommandPanelTaskMode #modify;
    	
    	wrapped;
    )
    
    wrap_planar_poly_to $GeoSphere01 $NGon01
    this was the test set up


  • Klunk
    Options
    Online / Send Message
    Klunk ngon master
    It'll handle any planar shape now even something with a hole, though if the shape is concave or has a hole/holes it'll add seams...

  • FishMan
    Options
    Offline / Send Message
    FishMan polycounter lvl 11
    Hey! Thank you!
    So from what I see you just slicing the copy of the mesh along its eges in the direction of polygon normal?

    convex only though so concave would need to split into convex then recombined after being wrapped individually
    Yeah but I also have no idea how to understand how it should be splitted to convex...

    I mean. I could just do the same as you did but for every single triangle and then combine and weld it back. But something tells me there's a better way to do it.
  • FishMan
    Options
    Offline / Send Message
    FishMan polycounter lvl 11
    Klunk said:
    It'll handle any planar shape now even something with a hole, though if the shape is concave or has a hole/holes it'll add seams...


    Yo! This seems exactly what I was looking for thanks.
  • Klunk
    Options
    Online / Send Message
    Klunk ngon master
    it has a few issue, the biggest is it can create t junction when recombing the meshes, looking to see if there's a suitable solution. Also moved from the slice modifier to the polyops.slice makes it considerably faster. 
  • Klunk
    Options
    Online / Send Message
    Klunk ngon master
    a faster version using polyop.slice which fixes t-junctions and removes the seams

  • FishMan
    Options
    Offline / Send Message
    FishMan polycounter lvl 11
    Dude stop! You just did everything for me :D
  • Klunk
    Options
    Online / Send Message
    Klunk ngon master
    it was an interesting script to write :)
Sign In or Register to comment.