Advertisement
Al3XXX

Push with UI

May 12th, 2021 (edited)
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. rollout pusher "Normal push" width:150 height:66
  2. (
  3.     --Normal Push Works with Editable Poly only
  4.     button 'btn1' "Push" pos:[10,33] width:130 height:23 align:#left
  5.     spinner 'spn1' "Dist:" type:#worldunits pos:[10,8] width:140 height:16 align:#left range:[-10000,10000,1]
  6.    
  7.     fn GetVectorsAngle v1 v2 =
  8.     (
  9.         ang = acos(dot (normalize v1) (normalize v2))
  10.         if bit.isNAN ang then 0.0 else ang
  11.     )
  12.    
  13.     fn GetProportionalityFactor a = (
  14.         1/(cos a)
  15.     )
  16.    
  17.     fn pushIt _ = (
  18.         undo on(
  19.             val = spn1.value
  20.             obj = $
  21.             faces = polyop.getFaceSelection obj
  22.             vertices = #()
  23.             directions = #()            
  24.             vert_normals = #()
  25.            
  26.             for face in faces do(  
  27.                 polyVerts = polyop.getFaceVerts obj face
  28.                 normal = polyop.getFaceNormal obj face         
  29.                
  30.                 for v in polyVerts do (
  31.                     foundResult = findItem vertices v
  32.                    
  33.                     if foundResult == 0 then(
  34.                         append vertices v
  35.                         append directions normal                        
  36.                         append vert_normals normal
  37.                     ) else (                        
  38.                         oldDirection = directions[foundResult]                      
  39.                         newDirection = oldDirection + normal                        
  40.                         directions[foundResult] = newDirection
  41.                     )  
  42.                 )
  43.             )            
  44.            
  45.             for i = 1 to vertices.count do(
  46.                 curVert = vertices[i]
  47.                 curDir = normalize directions[i]
  48.                 k = GetProportionalityFactor (GetVectorsAngle curDir vert_normals[i])              
  49.                 offset = curDir*val*k              
  50.                 polyop.moveVert obj curVert offset
  51.             )      
  52.         )      
  53.     )
  54.    
  55.     on btn1 pressed do
  56.         pushIt 0
  57. )
  58. createDialog pusher
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement