Notifications
Clear all

[Closed] Challenge #NEXT. Poly Grow and Shrink by element

here is the task setup:

delete objects
gc()
(
	mesh_attach = meshop.attach
	fn fastAttach meshes =
	(
		k = 1
		while meshes.count > 1 do
		(
			k += 1
			mesh_attach meshes[k-1] meshes[k]
			deleteItem meshes k
			if k >= meshes.count do k = 1
		)
		meshes[1]
	)

	size = [32,32]
	
	global poly = editable_mesh()
	meshes = #()

	for y=0 to size.y-1 do for x=0 to size.x-1 do
	(
		m = copy (createinstance plane width:1 length:1 widthsegs:2 lengthsegs:2).mesh
		meshop.movevert m #all [x*1.2, y*1.2,0]
		append meshes m
	)
	poly.mesh = fastAttach meshes
	converttopoly poly
	update poly
	select poly
)


the challenge is –

Design quick and convenient UI to Grow and Shrink element selection for this poly node.

8 Replies

Because the most interesting of this challenge is User Interface solution let’s make all more simpler. Do Growing and Shrinking by face index (not position!).

Had some play for fun. *Still would not know how to grow


clearlistener()
gc()
try(DestroyDialog _Grow_Poly)catch()
global Obj = undefined
global numberOfElements = 0
global alledges = #{}
global MainFaceList = #(#{})
   
rollout _Grow_Poly "GrowPoly" width:155 height:60(
   pickButton _PickObject_btn " < Pick Poly Object > " pos:[5,5] width:145 height:20
   button _Shrink "Shrink" pos:[5,30] width:40 height:20 enabled:false
   spinner _spn_element "" pos:[45,30] type:#integer fieldwidth:50 range:[1,100,100] visible:true enabled:false
   button _Grow "Grow" pos:[110,30] width:40 height:20 enabled:false
   
   FN FN_FindElementCount PickedObJ = (
      addElement = false
      emptyedges = #{}
      alledges += polyop.getOpenEdges PickedObJ.baseobject
      alledgesComp = alledges
      numberOfElements = 0;
      for i in alledges do (
         PickedObJ.EditablePoly.SetSelection #Edge #{i}
         PickedObJ.EditablePoly.ConvertSelection #Edge #Element
         PickedObJ.EditablePoly.ConvertSelection #Element #Edge
         alledges -= polyOp.getEdgeSelection PickedObJ.baseobject
            for i in (alledgesComp - alledges) do
            (
               addElement = true
            )
            if (addElement == true) *do
            (
               numberOfElements += 1
               MainFaceList[numberOfElements] = alledges
            )
            addElement = false
         alledgesComp = alledges
      )
   )
   
   on _PickObject_btn picked Obj do(
      if classOf Obj == editable_poly then(
         FN_FindElementCount Obj
         _PickObject_btn.text = Obj.name
         _spn_element.enabled = true
         _Shrink.enabled = true
         _Grow.enabled = true
         _spn_element.range = [1,numberOfElements,numberOfElements]
      )   
      else(
         Obj = undefined
         _PickObject_btn.text = " < Pick Poly Object > "
         _spn_element.enabled = false
         _Shrink.enabled = false
         _Grow.enabled = false
      )
   )
   
   on _spn_element changed val do (
      print MainFaceList[val]
   )
)
CreateDialog _Grow_Poly

My next step would have been change face selection on element spinner

But had to do some work

Or I guess select element by face spinner


clearlistener()
gc()
try(DestroyDialog _Grow_Poly)catch()
global TheObj = undefined
   
rollout _Grow_Poly "GrowPoly" width:155 height:60(
   pickButton _PickObject_btn " < Pick Poly Object > " pos:[5,5] width:145 height:20
   button _Shrink "Shrink" pos:[5,30] width:40 height:20 enabled:false
   spinner _spn_element "" pos:[45,30] type:#integer fieldwidth:50 range:[1,100,100] visible:true enabled:false
   button _Grow "Grow" pos:[110,30] width:40 height:20 enabled:false
   
   on _PickObject_btn picked Obj do(
      if classOf Obj == editable_poly then(
         TheObj = Obj
         _PickObject_btn.text = Obj.name
         _spn_element.enabled = true
         _Shrink.enabled = true
         _Grow.enabled = true
         FC = PolyOp.getNumfaces TheObj
         _spn_element.range = [1,FC,FC]
      )   
      else(
         Obj = undefined
         _PickObject_btn.text = " < Pick Poly Object > "
         _spn_element.enabled = false
         _Shrink.enabled = false
         _Grow.enabled = false
      )
   )
   
   on _spn_element changed val do (
      select TheObj
      subobjectLevel = 4
      FacesList = #{}
      FacesList = polyOp.getElementsUsingFace TheObj val
      polyop.setFaceSelection TheObj FacesList
   )
   
   on _Render_Manager close do(
      clearSelection()
   )
)
CreateDialog _Grow_Poly

Now for the impossible part grow by face ID and not by position. *Will it always be this object from your code?

Hmmm…

Ok, I think I have solved it


clearlistener()
gc()
try(DestroyDialog _Grow_Poly)catch()
global TheObj = undefined
global FacesList = #{}
rollout _Grow_Poly "GrowPoly" width:155 height:60(
   pickButton _PickObject_btn " < Pick Poly Object > " pos:[5,5] width:145 height:20
   button _Shrink "Shrink" pos:[5,30] width:40 height:20 enabled:false
   spinner _spn_element "" pos:[45,30] type:#integer fieldwidth:50 range:[1,100,100] visible:true enabled:false
   button _Grow "Grow" pos:[110,30] width:40 height:20 enabled:false
   
   on _PickObject_btn picked Obj do(
      if classOf Obj == editable_poly then(
         TheObj = Obj
         _PickObject_btn.text = Obj.name
         _spn_element.enabled = true
         _Shrink.enabled = true
         _Grow.enabled = true
         FC = PolyOp.getNumfaces TheObj
         _spn_element.range = [1,FC,2000]
         FacesList = polyOp.getElementsUsingFace TheObj 2000
         polyop.setFaceSelection TheObj FacesList
      )   
      else(
         Obj = undefined
         _PickObject_btn.text = " < Pick Poly Object > "
         _spn_element.enabled = false
         _Shrink.enabled = false
         _Grow.enabled = false
      )
   )
   
   on _spn_element changed val do (
      select TheObj
      subobjectLevel = 4
      FacesList = #{}
      FacesList = polyOp.getElementsUsingFace TheObj val
      polyop.setFaceSelection TheObj FacesList
   )
   on _Shrink pressed do(
      TextList = FacesList as string
      TextList = trimright TextList "}"
      TextList = trimleft TextList "#{"
      Nums = filterString TextList ".."
      if ((Nums[2] as number) - (Nums[1] as number)) > 3 do(
         FacesList_L = polyOp.getElementsUsingFace TheObj (Nums[1] as number)
         FacesList_H = polyOp.getElementsUsingFace TheObj (Nums[2] as number)
         FacesList = FacesList - FacesList_H
         FacesList = FacesList - FacesList_L
      )
      polyop.setFaceSelection TheObj FacesList
      completeRedraw()
   )
   on _Grow pressed do(
      TextList = FacesList as string
      TextList = trimright TextList "}"
      TextList = trimleft TextList "#{"
      Nums = filterString TextList ".."
      if Nums[1] as number != 1 do(
         FacesList_L = polyOp.getElementsUsingFace TheObj ((Nums[1] as number) - 1)
         FacesList = FacesList + FacesList_L
      )
      if Nums[2] as number != (PolyOp.getNumfaces TheObj) do(
         FacesList_H = polyOp.getElementsUsingFace TheObj ((Nums[2] as number) + 1)
         FacesList = FacesList + FacesList_H
      )
      polyop.setFaceSelection TheObj FacesList
      completeRedraw()
   )
   
   on _Render_Manager close do(
      TheObj.EditablePoly.SetSelection #Face #{}
      completeRedraw()
   )
)
CreateDialog _Grow_Poly

Just some small changes to work with teapots and all Geo

Here is a version using distance. *Just a bit different


------ The Angry Bear
------ SiNiSoftware
------ 28/06/2017
------ grow and shrink elements *
------
----------------------------------------------------------------------------------------------------------------
clearlistener()
gc()
try(DestroyDialog _Find_Face_Dis)catch()
global TheObj = undefined
global FacesList
global Dis_Thresh = 1
rollout _Find_Face_Dis "Find Close Faces" width:155 height:60(
   pickButton _PickObject_btn " < Pick Poly Object > " pos:[5,5] width:145 height:20
   button _Shrink "Shrink" pos:[5,30] width:40 height:20 enabled:false
   spinner _spn_element "" pos:[45,30] type:#integer fieldwidth:50 range:[1,100,100] visible:true enabled:false
   button _Grow "Grow" pos:[110,30] width:40 height:20 enabled:false
   on _PickObject_btn picked Obj do(
      if SuperClassOf Obj == GeometryClass then(
         TheObj = Obj
         ConvertToPoly TheObj
         _PickObject_btn.text = Obj.name
         _spn_element.enabled = true
         _Shrink.enabled = true
         _Grow.enabled = true
         FC = PolyOp.getNumfaces TheObj
         MN =FC / 2
         _spn_element.range = [1,FC,MN]
         max modify mode
         select TheObj
         subobjectLevel = 4
         FacesList = polyOp.getElementsUsingFace TheObj MN
         polyop.setFaceSelection TheObj FacesList
      )   
      else(
         Obj = undefined
         _PickObject_btn.text = " < Pick Poly Object > "
         _spn_element.enabled = false
         _Shrink.enabled = false
         _Grow.enabled = false
      )
   )
   
   on _spn_element changed val do (
      Dis_Thresh = 1
      max modify mode
      select TheObj
      subobjectLevel = 4
      FacesList = #{}
      FacesList = polyOp.getElementsUsingFace TheObj val
      polyop.setFaceSelection TheObj FacesList
   )
   
   on _Grow pressed do(
      Dis_Thresh = Dis_Thresh + 1
      F = _spn_element.value
      FP = polyop.getFaceCenter TheObj F
      FacesList2 = #{}
      N_FacesList = #{}
      FacesList2 = polyOp.getElementsUsingFace TheObj F
      for i = 1 to (PolyOp.getNumfaces TheObj) do(
         if (distance FP (polyop.getFaceCenter TheObj i)) < Dis_Thresh do(
            N_FacesList = polyOp.getElementsUsingFace TheObj i
            FacesList2 = FacesList2 + N_FacesList
*            
         )
      )
      polyop.setFaceSelection TheObj FacesList2
      completeRedraw()
   )
   
   on _Shrink pressed do(
      Dis_Thresh = Dis_Thresh - 1
      F = _spn_element.value
      FP = polyop.getFaceCenter TheObj F
      FacesList2 = #{}
      N_FacesList = #{}
      FacesList2 = polyOp.getElementsUsingFace TheObj F
      for i = 1 to (PolyOp.getNumfaces TheObj) do(
         if (distance FP (polyop.getFaceCenter TheObj i)) < Dis_Thresh do(
            N_FacesList = polyOp.getElementsUsingFace TheObj i
            FacesList2 = FacesList2 + N_FacesList
         )
      )
      polyop.setFaceSelection TheObj FacesList2
      completeRedraw()
   )
)
CreateDialog _Find_Face_Dis

This site add random * to the code so you might need to check and remove them