Announcement

Collapse
No announcement yet.

Tool to convert opacity mapped faces into geometry leaves

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #76
    Originally posted by MattClark View Post
    The reason it runs out of memory is the undo system gets overwhelmed trying to keep a copy of the mesh as each leaf is attached. Lose the garbage collection in the main loop, as thats going to be very slow. Instead put an 'undo off ()' around the main loop. Memory stays low this way and there's a fair speed increase.

    It's worth noting that the attaching gets slower as polycount increases, you might notice the progress bar seems to slow down as it goes on. One way round this is to attach the leaves into clumps, then attach the clumps at the end. There was some discussion here about that.
    Matt you lovely man. I modelled a bottle with some weird grooves cut into it about two weeks ago and your wrapit tool would have rocked for it!

    Comment


    • #77
      This only semi-works for me. Sometimes the leaves are 180 the wrong way.

      Comment


      • #78
        Yep the problem is it's only using the normals of the leaf its replacing - if the direction of the source plane is wrong then the new leaf is also going to be wrong

        Comment


        • #79
          Does anyone know how i'd do this except replace them with proxies? I don't want to replace with meshes and end up with a combined mesh, I want it to replace them with VRay Proxies and end up with a bunch of VRay Proxies.

          Comment


          • #80
            Code:
            macroScript LeafConvert category:"John O'Connell Tools"
            
            /*
            
            This script is provded as is and is in no way to be considered a bug free utility.
            Any loss of time or information as a result of using this script is not the responsibility
            of John O'Connell so use it at your own risk!
            
            To be done:
            
            1. Add random scaling and rotation offsets
            2. Add in the option to use more than one type of leaf
            3. Add the ability to convert multiple objects and have automatic conversion of objects into editable poly
            4. Add in stability and more error checking
            
            The latest version of this should always be available in the stuff section of
            http://www.joconnell.com so check back often
            
            */
            
            (
            
               rollout LeafConvert "Copy objects to faces"
               (
                  fn polyFilter obj = superclassof obj == GeometryClass
                  
                  Spinner replaceID "Replace Mat ID" type:#integer range:[-1000,1000,5]
                  pickbutton LeafObject "Pick Object to distribute" width:200 align:#right filter:polyfilter
                  button MakeLeaves "Copy objects" width:200 align:#right
               
                  on LeafObject picked obj do
                  (
                     leafobject.text = LeafObject.object.name
                  )
                  
                  on makeleaves pressed do
                  (
               
                     the_sel = selection as array
                     
                     copy_obj = leafobject.object
                     
                     mat_id = replaceID.value
                     
                     for o = 1 to the_sel.count do
                     (
                     
                        
                        
                        try(convertToPoly the_sel[o])catch()
                        face_count = getnumfaces the_sel[o]
                        print face_count
                        face_array = #()
                        
                        -- Get faces with the specified mat id
                        
                        for i = 1 to face_count do
                        (
                           if (polyop.getfaceMatId the_sel[o] i == mat_id) then
                           (
                              append face_array i
                           )
                        )
                        
                        copy_obj_mesh = editable_mesh()
                        copy_obj_mesh.name = (the_sel[o].name + "_leaves")
                        copy_obj_mesh.pos = the_sel[o].pos
                        
                        disableSceneRedraw()
                        
                        -- Begin progress bar
                        
                        progressStart "Making leaves"
                        escapeEnable = false
                        itemnum = face_count
                        curitem = 0
                        
                        for f = 1 to face_array.count do
                        (
                           curitem += 1
                           the_pos = polyop.getfacecenter the_sel[o] (face_array[f])
                           the_dir = polyop.getfacenormal the_sel[o] (face_array[f])
                           the_dist_obj = copy copy_obj
                           the_dist_obj.pos = the_pos
                           the_dist_obj.dir = the_dir
                           
                           -- Update progress bar
                           
                           total_progress = ((curitem as float)/(itemnum as float))*100
                           
                           gc()
                           progressUpdate total_progress
                        )
                        
                        progressEnd()
                        
                        enableSceneRedraw()         
                        completeRedraw()
                     )
                  )
               
               )
               
               createdialog LeafConvert width:360
            
            )

            Comment


            • #81
              Thanks! I've PM'd you a flower <3

              Comment


              • #82
                I cant seem to get this script to work. Should it work with Max 2010 ?
                Regards

                Steve

                My Portfolio

                Comment


                • #83
                  Yep - I'm still on max 9 64 - what type of error are you getting?

                  Comment


                  • #84
                    Ah - found the thread!

                    Any news on an update to this to get it to work faster?
                    Kind Regards,
                    Richard Birket
                    ----------------------------------->
                    http://www.blinkimage.com

                    ----------------------------------->

                    Comment


                    • #85
                      I'll look at it alright - someone suggested something along the way that'd do it - must dig it out!

                      Comment


                      • #86
                        By the way I found a better version of it than the one posted here and I'm looking into optimisations now.

                        Code:
                        macroScript LeafConvert category:"John O'Connell Tools"
                        
                        (
                        
                        	rollout LeafConvert "AEC Leaf convertor"
                        	(
                        		fn polyFilter obj = superclassof obj == GeometryClass
                        		
                        		Group "Source parameters"
                        		(
                        			Spinner replaceID "Replace Mat ID" type:#integer range:[-1000,1000,5]
                        		)
                        		
                        		group "Leaf Parameters"
                        		(
                        			button LeafObject "Define leaf Object(s)" width:200 align:#right filter:polyfilter
                        			Spinner Random_scale_min "Random leaf scale min" type:#float range:[-100.0,100.0,0.5]
                        			Spinner Random_scale_max "Random leaf scale max" type:#float range:[-100.0,100.0,0.5]
                        			Spinner Random_rotate "Random leaf rotate" type:#float range:[-360.0,360.0,0.0]
                        		)
                        		
                        		button MakeLeaves "Make Leaves" width:200 align:#right enabled:false
                        	
                        		on LeafObject pressed do
                        		(
                        			if (selection.count == 0) then
                        			(
                        				messagebox "Please select an object to use as a leaf"
                        			) 
                        			else if (selection.count == 1) then
                        			(
                        				leafobject.text = $.name
                        				global copy_obj = selection as array
                        				makeleaves.enabled = true
                        				LeafObject.enabled = false
                        			) 
                        			else 
                        			(
                        				leafobject.text = ("There are " + selection.count as string + " Leaf objects")
                        				global copy_obj = selection as array
                        				makeleaves.enabled = true
                        				LeafObject.enabled = false
                        			)
                        		)
                        		
                        		on makeleaves pressed do
                        		(
                        			the_sel = selection as array
                        			
                        			if (the_sel.count == 0) then
                        			(
                        				messagebox "Please select an object to replace leaves on"
                        				
                        			) else (
                        
                        				mat_id = replaceID.value
                        	
                        				for o = 1 to the_sel.count do
                        				(
                        				
                        					try(convertToPoly the_sel[o])catch()
                        					face_count = getnumfaces the_sel[o]
                        					print face_count
                        					face_array = #()
                        					
                        					-- Get faces with the specified mat id
                        					
                        					for i = 1 to face_count do
                        					(
                        						if (polyop.getfaceMatId the_sel[o] i == mat_id) then
                        						(
                        							append face_array i
                        						)
                        					)
                        					
                        					copy_obj_mesh = editable_mesh()
                        					copy_obj_mesh.name = (the_sel[o].name + "_leaves")
                        					copy_obj_mesh.pos = the_sel[o].pos
                        					
                        					disableSceneRedraw()
                        					
                        					-- Begin progress bar
                        					
                        					progressStart "Making leaves"
                        					escapeEnable = false
                        					itemnum = face_count
                        					curitem = 0
                        					
                        					for f = 1 to face_array.count do
                        					(
                        						curitem += 1
                        						the_pos = polyop.getfacecenter the_sel[o] (face_array[f])
                        						the_dir = polyop.getfacenormal the_sel[o] (face_array[f])
                        						leaf = random 1 copy_obj.count
                        						print (leaf)
                        						leaf_obj = copy_obj[(random 1 copy_obj.count)]
                        						the_dist_obj = copy leaf_obj
                        						the_dist_obj.pos = the_pos
                        						the_dist_obj.dir = the_dir
                        						the_dist_obj.scale = the_dist_obj.scale * [(random Random_scale_min.value Random_scale_max.value),(random Random_scale_min.value Random_scale_max.value),(random Random_scale_min.value Random_scale_max.value)]
                        						random_rot = eulerangles (random -Random_rotate.value Random_rotate.value) (random -Random_rotate.value Random_rotate.value) (random -Random_rotate.value Random_rotate.value)
                        						rotate the_dist_obj random_rot
                        						attach copy_obj_mesh the_dist_obj
                        						
                        						-- Update progress bar
                        						
                        						total_progress = ((curitem as float)/(itemnum as float))*100
                        						
                        						gc()
                        						progressUpdate total_progress
                        					)
                        									
                        					progressEnd()
                        					
                        					enableSceneRedraw()			
                        					completeRedraw()
                        				)
                        	
                        				LeafObject.enabled = true
                        			)
                        		)
                        	
                        	)
                        	
                        	createdialog LeafConvert width:360
                        
                        )

                        Comment


                        • #87
                          Will be interested in seeing the optimisations. What performance increase do you expect to get?

                          <also, I've just been trying the above script as it stands. If I replace a bunch of low-poly diamond-shaped leaves with a plane object (with UVW mapping), how do I make each of the generated leaves hold the same UVW mapping? I basically want to apply an opacity mapped texture to the new 'plane' leaves>
                          Last edited by tricky; 02-09-2010, 01:51 AM.
                          Kind Regards,
                          Richard Birket
                          ----------------------------------->
                          http://www.blinkimage.com

                          ----------------------------------->

                          Comment


                          • #88
                            has any recent work been done on this?

                            ---------------------------------------------------
                            MSN addresses are not for newbies or warez users to contact the pros and bug them with
                            stupid questions the forum can answer.

                            Comment


                            • #89
                              To be honest I've kind of dropped it, I haven't done an arch vis type job in ages, will give it a look again for speed though.

                              Comment


                              • #90
                                I figured out a way some time ago, just forgot to post it.

                                Use leafs that are just one simple quad. If you have subdivided leafs select open boarders go to edge, turn selection to vertice, go back to edge and simply use remove to get rid of the interior edges, then go to vertice and remove the vertices that belonged to the.
                                Now use Populate: Panels to place any given object on the quads!
                                Last edited by tzaar; 14-01-2013, 06:34 AM.

                                Comment

                                Working...
                                X