Home Technical Talk

Mesh outline generation for leaves?

somawheels
polycounter lvl 3
Offline / Send Message
somawheels polycounter lvl 3
Hi.
In speedtree (software), there is an automatic mesh generation feature for leaves.
nwfxwo.png
However, it only creates up to 20 edges.
I need something like this, but not so limited on the deatail of the generated mesh.
Any ideas?
I would try photoshop, but the 3d functions are not currently compatible with my latest gpu driver.
thanks

Replies

  • Octo
    Options
    Offline / Send Message
    Octo polycounter lvl 18
    Houdini does this with the trace node.
  • somawheels
    Options
    Offline / Send Message
    somawheels polycounter lvl 3
    I have never used houdini, so would appreciate any other suggestions (Would rather not learn/use a new software just for this little function.)
    If there are none, of-course ill try houdini, thanks.
  • throttlekitty
    Options
    Offline / Send Message
    Maya has a function for generating polys out of an image, I believe Max does too.

    I've never had a whole lot of luck controlling the one in maya, but this guy got a nice result.

    [ame]http://www.youtube.com/watch?v=73okywUTWjg[/ame]
  • somawheels
    Options
    Offline / Send Message
    somawheels polycounter lvl 3
    My attempts with maya were not very good, it seems to work best for non organic shapes; my tracing has got to be very exact.
    Cant find a function like this in 3ds max... There is a good looking script called "spline trace" but it costs money.
  • SonicBlue
    Options
    Offline / Send Message
    SonicBlue polycounter lvl 10
    [ame]http://www.youtube.com/watch?v=ZougNpp2GKM[/ame]

    This is with Blender and Inkscape, I'm not sure if 3ds Max supports .svg files, anyway you can export the mesh from Blender and import it back in Max.
  • poopipe
    Options
    Online / Send Message
    poopipe grand marshal polycounter
    This piqued my interest so I hacked a macroscript I'd cobbled together a while back for turning sprites into 3d objects (it's a hack squared)

    It appears to work - it's not fully automated or clever but I actually got some decent results out of it

    bad things :
    It starts from a very inefficient mesh (quad per pixel) and relies on pro-optimise to sort it out
    It's very slow on images bigger than 128 pixels when processing at native resolution.
    I'm a terrible programmer

    plus sides :
    it'll process anything
    it UVs the object using the original image


    settings :
    Pixel grid : set it to 4 and it will process every 4th pixel and so on
    Detail : vertex count % setting for pro-optimise

    it uses alpha to determine whether to make a poly or not

    so yeah, copy the script below out, run it and make yourself a button - you'll find it in MK_Tools.

    if it's useful it'd be nice to hear back, if it blows your computer up it'd be nice to not hear back ;)
    macroScript tracebitmap category:"MK_Tools"
    (
    	clearListener()
    	gc()
    	local elementWidth	=	75
    	
    	
    	
    	-- defaults
    	local hmMax 			= 1
    	local hmIncrement	= 1
    	local pxIncrement	= 1
    	local vertPercent 	= 30
    	global transpColor = [255,0,255]
    
    	
    	-- functions
    	fn roundFloatToIncrement valFloat valIncrement = 
    	(
    		
    		/* round float to nearest valIncrement */
    		(floor( 1.0 * valFloat / valIncrement + 0.5) * valIncrement) as integer
    	)
    	
    	fn createPixelFace obj pixelPosition height colorValue pixelGridSize= 
    	(
    		height = height as integer
    	--	print (height as string)
    		-- create 4 verts
    		tempVertArray = #()
    			
    		v1 = polyop.createVert obj pixelPosition
    		v2 = polyop.createVert obj (pixelPosition + [pixelGridSize,0,0])
    		v3 = polyop.createVert obj (pixelPosition + [pixelGridSize,pixelGridSize,0])
    		v4 = polyop.createVert obj (pixelPosition + [0,pixelGridSize,0])
    
    		
    		append tempVertArray v1
    		append tempVertArray v2
    		append tempVertArray v3
    		append tempVertArray v4
    			
    		f1 = polyop.createPolygon obj tempVertArray
    		
    
    		for v in tempVertArray do
    		(
    			polyop.setvertcolor obj 0 v (colorValue)
    		)
    		/*
    		if height >0 then
    		(
    			
    			polyop.setFaceSelection obj f1 
    			obj.extrudeFaces height
    		)	
    		*/
    
    
    		free tempVertArray
    	)
    	
    	
    	fn createMeshObject nm maxHeight heightGrid pixelGrid vertPercent= 
    	(
    		
    			local hmMax 			= maxHeight
    			local hmIncrement	= heightGrid
    		/* get bitmap */
    		srcBitmap = selectBitMap caption:"Select a Bitmap"
    		--print aBitmap.fileName 
    		local bitmapHeight = srcBitmap.height
    		local bitmapWidth = srcBitmap.width
    		
    		
    	
    		undo off
    		(
    			
    			-- create a mesh and convert to poly
    			local polyObj = editable_mesh name:(uniquename nm) --create an empty EMesh
    			convertTo polyObj Editable_Poly --convert to Editable_Poly 
    			--create and assign material
    			--polyObj.material =  standard  diffuseMap: (Bitmaptexture fileName:srcBitmap.fileName ) showInViewport:true
    			
    			for currentRow = 0 to (bitmapHeight-1) by pixelGrid do
    			(
    
    				pixelRow = getPixels srcBitmap [0,currentRow] bitmapWidth
    				
    				for currentColumn = 1 to (bitmapWidth) by pixelGrid do
    				(
    					
    					p=pixelRow[currentColumn]
    					pixelColor = [ p.red, p.green, p.blue, p.alpha]
    					pixelVertColor = [ p.red, p.green, p.blue]
    					pixelAlpha = p.alpha
    
    					/*
    					WORK OUT A WAY TO COMBINE SIMILAR HEIGHT PIXELS INTO SAME POLY
    					GEOMETRY IS GETTING EXPENSIVE  64x64 gives 40960 tris at worst
    					
    					yeah - nevermind  that for now, requires rearchitecture
    								*/	
    					-- posterize heightmap
    					hmDivision = 255/hmMax
    					
    					if pixelAlpha != 0 do  -- change this to a  silly colour rather than using alpha - will give us more range in height and allow for zero height planes(which will save polys)
    					(
    						-- establish height based on alpha channel
    						hm = pixelAlpha / hmDivision
    						-- round height off to nearest integer
    						hm = roundFloatToIncrement hm hmIncrement
    						-- invert Y coords cos its upside down in bitmaps
    						invI = currentRow*-1
    						--subtract 1 from x coord because max is an arse and starts at 1
    		
    
    						createPixelFace polyObj  [currentColumn-1,invI-1,0] hm pixelVertColor pixelGrid
    					)
    				)
    			)
    			-- add UVs etc.
    
    
    			select polyObj
    
    			polyObj.showVertexColors = true
    			polyObj.vertexColorsShaded = false
    			polyObj.VertexColorType = #color
    			polyop.collapsedeadstructs polyObj
    			
    			addModifier polyObj (Uvwmap())		
    			polyObj.modifiers[#UVW_Map].length = bitmapHeight
    			polyObj.modifiers[#UVW_Map].width = bitmapWidth
    				
    			addModifier polyObj (Vertex_Weld ())
    			addModifier polyObj (ProOptimizer ())
    				
    			polyObj.modifiers[#ProOptimizer].KeepUV = on	
    			polyObj.modifiers[#ProOptimizer].MergeFaces = on
    			polyObj.modifiers[#ProOptimizer].MergeFacesAngle = 10
    			--polyObj.modifiers[#ProOptimizer].KeepVC = on
    			polyObj.modifiers[#ProOptimizer].Calculate = on
    			--polyObj.modifiers[#ProOptimizer].vertexCount = 40
    			polyObj.modifiers[#ProOptimizer].VertexPercent = vertPercent
    		
    			close srcBitmap
    			free srcBitmap
    	
    		)
    		--undo back on
    	)
    	
    	
    	rollout pixelate_rollout "trace_bitmap"
    	(
    		
    
    		
    		--edittext t_hmMax "Max Height" offset: ([-6,4]) width:elementWidth readOnly: False	text:(hmMax as string) labelOnTop:true
    		--edittext t_hmIncrement "Height Grid" offset: ([-6,4]) width:elementWidth readOnly: False	text:(hmIncrement as string) labelOnTop:true
    		edittext t_pxIncrement "Pixel Grid" offset: ([-6,4]) width:elementWidth readOnly: False	text:(pxIncrement as string) labelOnTop:true
    		edittext t_vertPercent "Detail" offset: ([-6,4]) width:elementWidth readOnly: False	text:(vertPercent as string) labelOnTop:true
    		button b_getViewerPath "Choose Bitmap" offset: ([0,4]) width: elementWidth  tooltip:"Choose Bitmap"
    		
    		on b_getViewerPath pressed do
    		(
    			
    			createMeshObject "pixelMesh001" (hmMax as integer) (hmIncrement as integer) (t_pxIncrement.text as integer) (t_vertPercent.text as integer) 
    		)
    		
    	)
    	try (destroyDialog pixelate_rollout)	catch()
    	createDialog pixelate_rollout 100 250
    )
    
    
    
    
  • cptSwing
  • poopipe
    Options
    Online / Send Message
    poopipe grand marshal polycounter
    oh, my original script did that - I expect theirs is better
Sign In or Register to comment.