CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
reply share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 02-26-2014, 02:07 PM   #16
Klvnk
Lord of the posts
 
Klvnk's Avatar
portfolio
Klunk
United Kingdom
 
Join Date: Feb 2014
Posts: 699
did you see this line ?

Code:
polyop.setFaceSmoothGroup sph1 #{1..96} 2 -- some added normal quirkyness
 
Old 02-26-2014, 02:16 PM   #17
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by Klvnk
did you see this line ?

Code:
polyop.setFaceSmoothGroup sph1 #{1..96} 2 -- some added normal quirkyness

Sorry I miss that
We use sphere here where we detache some faces to get 2 separate objects.
You are right. It's better copy all normals before we use detach operation.
But in real I need to assigne this method to already detached objects (two or more)
edit: Can we consider also only faces and verts of open Edges to speedup the process?
__________________
Looking in the right side. [bgaTools]

Last edited by gazybara : 02-26-2014 at 02:21 PM.
 
Old 02-26-2014, 02:24 PM   #18
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,420
Send a message via ICQ to denisT
... deleted ... never mind

Last edited by denisT : 02-26-2014 at 02:32 PM.
 
Old 02-26-2014, 02:39 PM   #19
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
... deleted ... never mind

Denis? Are you tried to add something?
__________________
Looking in the right side. [bgaTools]
 
Old 02-26-2014, 02:51 PM   #20
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,420
Send a message via ICQ to denisT
Quote:
Originally Posted by gazybara
Denis? Are you tried to add something?

no. i've deleted .
 
Old 02-27-2014, 11:18 AM   #21
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
I've managed to correct first function
Code:
( fn setCommandPanelRedraw act = ( WM_SETREDRAW = 0x000B windows.sendmessage (windows.getchildhwnd #max "Command Panel")[1] WM_SETREDRAW act 0 ) fn fixNormals objA objB = with redraw off ( local getOpenEdge = meshop.getOpenEdges local getVertByEdge = meshop.getVertsUsingEdge local objA_borderE = getOpenEdge objA local objA_borderV = getVertByEdge objA objA_borderE local objB_borderE = getOpenEdge objB local objB_borderV = getVertByEdge objB objB_borderE local norm = Edit_Normals() local vertToNorm = norm.ConvertVertexSelection local avgTwo = norm.AverageTwo local vData = #() for i in objA_borderV do (for j in objB_borderV where (distance (getVert objA i) (getVert objB j)) < 0.1 do join vData #(#{i},#{j})) select #(objA,objB) ; max modify mode modPanel.addModToSelection norm setCommandPanelRedraw 0 disableRefMsgs() for i = 1 to vData.count by 2 do ( n = #{} nData = join (vertToNorm vData[i] &n node:objA ; n as array) (vertToNorm vData[i+1] &n node:objB ; n as array) avgTwo objA nData[1] objB nData[2] ) enableRefMsgs() ; clearSelection() setCommandPanelRedraw 1 converttomesh #(objA,objB) ) -- example delete objects sp = converttopoly (sphere name:"A" radius:50 segs:24 wirecolor:[30,110,0]) polyop.detachFaces sp #{145..288} delete:on asNode:on name:"B" objA = $A ; objB = $B converttomesh #($A,$B) with redraw off fixNormals objA objB CompleteRedraw() )

edit: Optimized code : edit_Normal methods are stored in variable
__________________
Looking in the right side. [bgaTools]

Last edited by gazybara : 02-27-2014 at 06:18 PM.
 
Old 02-27-2014, 11:43 AM   #22
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Adjust vert normals between multiple parts

Now is the time for the next challenge
Example scene
Code:
delete objects cube = (Box name:"part6" lengthsegs:10 widthsegs:10 heightsegs:10 length:100 width:100 height:100 mapcoords:on) addmodifier cube (spherify()) parts = #(convertTomesh cube) for id = 1 to 5 do ( faces = for f = 1 to cube.numfaces where (getFaceMatID cube f) == id collect f part = mesh mesh:(meshop.detachFaces cube faces delete:on asMesh:on) name:("part"+id as string) wirecolor:(random black white) append parts part ) parts.mat = standard()
__________________
Looking in the right side. [bgaTools]
 
Old 02-27-2014, 06:27 PM   #23
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
For above example the most difficult task is to collect open edges verts of six object parts which
share same position and after that find normals of these verst.
__________________
Looking in the right side. [bgaTools]
 
Old 02-27-2014, 10:43 PM   #24
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by gazybara
For above example the most difficult task is to collect open edges verts of six object parts which
share same position and after that find normals of these verst.

This will be pseudo code.
Let's imagine that vars p1..p6 represent objects parts and array values are verts pos (not vert index). We need to collect some data with parts which verts share same position in space.
Code:
p1 = #(1,2,3,4,9,10,11,12) p2 = #(1,2,7,8,9,16,18,20) p3 = #(2,3,6,7,11,14,19,20) p4 = #(3,4,5,6,12,13,17,19) p5 = #(1,4,5,8,10,15,17,18) p6 = #(5,6,7,8,13,14,15,16) arr = #(p1,p2,p3,p4,p5,p6) data = #() cnt = 0 while arr.count != 1 do ( for i in arr[arr.count] do ( cnt += 1 for j = 1 to arr.count-1 do ( for n = arr[j].count to 1 by -1 where arr[j][n]-i == 0 do ( if data[cnt] == null then ( append data #(#(("p"+ arr.count as string),("p"+j as string)),#(i,arr[j][n])) ) else ( append data[cnt][1] ("p"+j as string) append data[cnt][2] arr[j][n] ) deleteItem arr[j] n ) ) ) deleteItem arr arr.count ) print data /* result >>> #(#("p6", "p4", "p5"), #(5, 5, 5)) #(#("p6", "p3", "p4"), #(6, 6, 6)) #(#("p6", "p2", "p3"), #(7, 7, 7)) #(#("p6", "p2", "p5"), #(8, 8, 8)) #(#("p6", "p4"), #(13, 13)) #(#("p6", "p3"), #(14, 14)) #(#("p6", "p5"), #(15, 15)) #(#("p6", "p2"), #(16, 16)) #(#("p5", "p1", "p2"), #(1, 1, 1)) #(#("p5", "p1", "p4"), #(4, 4, 4)) #(#("p5", "p1"), #(10, 10)) #(#("p5", "p4"), #(17, 17)) #(#("p5", "p2"), #(18, 18)) #(#("p4", "p1", "p3"), #(3, 3, 3)) #(#("p4", "p1"), #(12, 12)) #(#("p4", "p3"), #(19, 19)) #(#("p3", "p1", "p2"), #(2, 2, 2)) #(#("p3", "p1"), #(11, 11)) #(#("p3", "p2"), #(20, 20)) #(#("p2", "p1"), #(9, 9)) */

Is there faster and better way for this method?
__________________
Looking in the right side. [bgaTools]
 
Old 03-01-2014, 12:14 PM   #25
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Solved pseudo code (collect array groups which share same index). Not perfect but works.
This concept can be also used for collecting verst which have same position on multiple objects.
Code:
( p1 = #(1,2,3,4,9,10,11,12,25,30) p2 = #(1,2,7,8,9,16,18,20,81,999,214) p3 = #(2,3,6,7,11,14,19,20,458,111,5468) p4 = #(3,4,5,6,12,13,17,19,454,5789) p5 = #(1,4,5,8,10,15,17,18,111223,12456,547,886) p6 = #(5,6,7,8,13,14,15,16,989,777,48795,221) arr = #(p1,p2,p3,p4,p5,p6) an = #("p1","p2","p3","p4","p5","p6") data = #() for a = 1 to arr.count-1 while a < arr.count where arr[a].count > 0 do ( for c = 1 to arr[a].count do ( ar = #(#(),#()) for b = (limit=a+1) to arr.count where arr[b].count > 0 do ( for d = arr[b].count to 1 by -1 where arr[a][c]-arr[b][d] == 0 do ( append ar[1] an[b] append ar[2] arr[b][d] deleteItem arr[b] d ) ) if ar[1].count > 0 do (append data #((join #(an[a]) ar[1]), join #(arr[a][c]) ar[2])) ) ) print data )
__________________
Looking in the right side. [bgaTools]
 
Old 03-01-2014, 05:40 PM   #26
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Fix Open Edges Normals

This is my last try. Result is not correct, unfortunately
I'm trying all day to solve the puzzle
Code:
( fn setCommandPanelRedraw act = ( WM_SETREDRAW = 0x000B windows.sendmessage (windows.getchildhwnd #max "Command Panel")[1] WM_SETREDRAW act 0 ) fn sortByCount arr1 arr2 = ( case of ( (arr1[1].count < arr2[1].count): 1 (arr1[1].count > arr2[1].count): -1 default:0 ) ) fn arrangeData vData minDist: = ( local data = #() local arr = for d in vData collect d[3] for a = 1 to arr.count-1 while a < arr.count where arr[a].count > 0 do ( for c = 1 to arr[a].count do ( ar = #(#(),#()) for b = (a+1) to arr.count where arr[b].count > 0 do ( for d = arr[b].count to 1 by -1 where (distance arr[a][c] arr[b][d] < minDist) do ( append ar[1] vData[b][1] append ar[2] vData[b][2][d] deleteItem arr[b] d ) ) if ar[1].count > 0 do (append data #((join #(vData[a][1]) ar[1]), join #(vData[a][2][c]) ar[2])) ) ) ; data ) fn fixOpenEdgesNormals nodes = with redraw off ( if getCommandPanelTaskMode() != #create do setCommandPanelTaskMode mode:#create clearSelection() local getOpenEdges = meshop.getOpenEdges local getVertsByEdge = meshop.getVertsUsingEdge local eNorm = Edit_Normals(), n = #{} local vertToNorm = eNorm.ConvertVertexSelection local avgTwo = eNorm.AverageTwo local pickNormal = eNorm.Select local clearPicked = eNorm.SetSelection local avgPicked = eNorm.AverageGlobal local vData = with undo off for node in nodes collect ( nodeVData = #(node,#(),#()) borderVerts = getVertsByEdge node (getOpenEdges node) for v in borderVerts do (append nodeVData[2] #{v} ; append nodeVData[3] (getVert node v)) nodeVData ) vData = arrangeData vData minDist:0.01 qsort vData sortByCount --print vData with redraw off ( select nodes setCommandPanelTaskMode mode:#modify modPanel.addModToSelection eNorm --setCommandPanelRedraw 0 --disableRefMsgs() for i = 1 to vData.count do ( if vData[i][1].count == 2 then ( nData = join (vertToNorm vData[i][2][1] &n node:vData[i][1][1] ; n as array) (vertToNorm vData[i][2][2] &n node:vData[i][1][2] ; n as array) avgTwo vData[i][1][1] nData[1] vData[i][1][2] nData[2] ) else ( for v = 1 to vData[i][2].count do pickNormal (vertToNorm vData[i][2][v] &n node:vData[i][1][v] ; n) node:vData[i][1][v] avgPicked() ; clearPicked #{} ) ) --enableRefMsgs() ; clearSelection() --setCommandPanelRedraw 1 --converttomesh nodes ) ) -- example delete objects cube = (Box name:"part6" lengthsegs:10 widthsegs:10 heightsegs:10 length:100 width:100 height:100 mapcoords:on) addmodifier cube (spherify()) parts = #(convertTomesh cube) for id = 1 to 5 do ( faces = for f = 1 to cube.numfaces where (getFaceMatID cube f) == id collect f part = mesh mesh:(meshop.detachFaces cube faces delete:on asMesh:on) name:("part"+id as string) wirecolor:(random black white) append parts part ) parts.mat = standard() fixOpenEdgesNormals parts CompleteRedraw() )
__________________
Looking in the right side. [bgaTools]
 
reply share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:34 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.