2012年2月16日木曜日

scriptのすすめ11 ~選択ポリゴンの円形変形~ maxscript tips

Hi
It's been a while since I posted last time.
As I told you before I will explain about revising last script for modeling,
but it's more difficult than what i expected.
You need a function skill for qsort.

I'd like to explain that but it's little bit complicated,so before that I will explain basic functions.
after that I will explain this with detail.

This is  polygon circlizer script.You could use it for only editable poly.



-----------------------------------------------------------------------------------------------------------------------
CP = [0,0,0]
fn compareVector Vector01 Vector02 =
(   
    local Base = CP
    local D01 = distance Base Vector01
    local D02 = distance Base Vector02
    case of
     (
        (D01 < D02) :    -1
        (D01 > D02) :    1
        default : 0
    )
)

fn FnCircle PosArry =
(
    AllPos = [0,0,0]
    pc = PosArry.count
   
    for i =1 to pc do
    (
        AllPos+= PosArry[i]
    )
    center = AllPos/pc--Center pos
   
    AllLength = 0
    for i = 1 to pc do
    (
        AllLength += length(center-PosArry[i])
    )
    radius = AllLength/pc--radius
   
    CircleArry = #()
    for i = 1 to pc do
    (
        pos = [0,0,0]
        pos.x=sin(i*360/pc)*radius + center.x
        pos.y=cos(i*360/pc)*radius + center.y
        pos.z=0 + center.z
        append CircleArry pos
    )
    return CircleArry
)

obj = $


faces = (polyop.getFaceSelection obj) as array

AllEdges = #()
ShareEdges = #()
for i = 1 to faces.count do
(
    LocalEdges =polyop.getFaceEdges obj faces[i]
    for j = 1 to LocalEdges.count do
    (
        F = findItem AllEdges LocalEdges[j]
        if F != 0 then append ShareEdges LocalEdges[j]
        else append AllEdges LocalEdges[j]
    )
)

--format "AllEdges: %\n" AllEdges
for j = 1 to ShareEdges.count do
(
    F = findItem AllEdges ShareEdges[j]
    deleteItem AllEdges F
)
subobjectLevel = 2


polyop.setEdgeSelection obj Alledges
obj.EditablePoly.ConvertSelection #Edge #Vertex
subobjectLevel = 1


vertsArry = (polyop.getVertSelection obj) as array
VC = vertsArry.count
VertsPosArry = #()
for i = 1 to Vc do
(
    append VertsPosArry (polyop.getVert obj vertsArry[i])
)

--print VertsPosArry
CArry = FnCircle VertsPosArry

for i = 1 to Vc do
(
    CP = VertsPosArry[i]
    qsort CArry compareVector
    polyop.setVert obj vertsArry[i] CArry[1]
)
-----------------------------------------------------------------------------------------------------------------------

See you next time.

0 件のコメント :