Notifications
Clear all

[Closed] Bottle: how to align vertices of trimesh to spline

Hello!
In scripting the primitive of my bottle-glass, i’m having a problem with aligning the vertices of a plane [trimesh] to a spline [Lus00]
I build the primitive like this: plane, then aligning the outer vertices to a closed spline[Lus00], then a next row of vert_array and face_array , then again aligning to the next spline [Lus01]. And so on… till i have made the whole bottle-glass.

  1. i suppose the fight between locals and globals?
    2) because you can’t select the vertices of a trimesh
    – to solve (2) i can convert the plane to a edit mesh, but than i will lose my parameters?

Do you have some idea’s ? Or is the way of scripting or scripting structure wrong?

Regards!

–Jazz-arch …davy

– Davy F.
– 2007 11 17| start script
– uitzetten van de grote lijnen
– extra parameter –> volume range van 3 tot 20cl

plugin simpleObject Proefvlak
name:“Proefvlak”
category:“Davy F-Objects”
classID: #(5123456, 07)
(
parameters main rollout:params
(
width type:#float ui:width default:1
length type:#float ui:length default:1
– in future adding parameter height and volume
)
rollout params “Proefvlak Parameters”
(
spinner width “Width” range:[0,1000,1] align:#right fieldwidth:60
spinner length “Length” range:[0,1000,1] align:#right fieldwidth:60
– in future adding spinner of height and volume
)

on buildMesh do
(
vert_array = #()
face_array = #()
— tekenen van de Splines
– lus00
fn createLus00Shape =
(

    ln = line();
    splIdx = addNewSpline ln;
        addKnot ln splIdx #bezier #curve [1.25,37.6452,-1.22664e-005] [-1.4797,37.6452,-1.22664e-005] [3.9797,37.6452,-1.22664e-005];
        addKnot ln splIdx #bezier #curve [9.43911,37.6452,-1.22664e-005] [6.73828,38.0413,-1.23954e-005] [13.8607,36.9969,-1.20551e-005];
        addKnot ln splIdx #bezier #curve [22.4792,34.5325,-1.12521e-005] [18.285,36.0749,-1.17547e-005] [25.583,33.3912,-1.08802e-005];
        addKnot ln splIdx #bezier #curve [31.1267,29.6699,-9.6677e-006] [28.3395,31.4496,-1.02476e-005] [33.4845,28.1645,-9.17716e-006];
        addKnot ln splIdx #bezier #curve [37.8856,24.6954,-8.0468e-006] [35.6839,26.4211,-8.6091e-006] [39.1997,23.6654,-7.71118e-006];
        addKnot ln splIdx #bezier #curve [41.6659,21.4092,-6.976e-006] [40.5344,22.637,-7.37607e-006] [42.658,20.3326,-6.6252e-006];
        addKnot ln splIdx #bezier #curve [44.2121,17.8305,-5.80991e-006] [43.7031,19.2032,-6.25719e-006] [45.4814,14.4071,-4.69444e-006];
        addKnot ln splIdx #bezier #curve [46.9273,7.21911,-2.35228e-006] [46.4386,10.8373,-3.53125e-006] [47.3454,4.12457,-1.34395e-006];
        addKnot ln splIdx #bezier #curve [46.9109,-2.14882,7.00173e-007] [47.2377,0.956679,-3.11726e-007] [46.5911,-5.18721,1.69021e-006];
        addKnot ln splIdx #bezier #curve [44.998,-11.1125,3.62092e-006] [46.0333,-8.23811,2.68432e-006] [43.7873,-14.474,4.71622e-006];
        addKnot ln splIdx #bezier #curve [40.2256,-20.7099,6.74815e-006] [41.8331,-17.5191,5.70845e-006] [39.2625,-22.6218,7.37113e-006];
        addKnot ln splIdx #bezier #curve [37.2865,-26.4204,8.60885e-006] [38.6643,-24.7818,8.07494e-006] [35.7962,-28.1927,9.18634e-006];
        addKnot ln splIdx #bezier #curve [31.8196,-30.7067,1.00055e-005] [33.7996,-29.5059,9.61424e-006] [29.3584,-32.1995,1.04919e-005];
        addKnot ln splIdx #bezier #curve [24.0397,-34.4546,1.12267e-005] [26.7857,-33.5911,1.09454e-005] [20.3431,-35.617,1.16055e-005];
        addKnot ln splIdx #bezier #curve [12.6409,-36.7376,1.19706e-005] [16.4172,-35.8681,1.16873e-005] [9.809,-37.3896,1.21831e-005];
        addKnot ln splIdx #bezier #curve [4.22605,-39.0166,1.27132e-005] [7.07521,-38.4446,1.25269e-005] [3.25344,-39.2119,1.27769e-005];
        addKnot ln splIdx #bezier #curve [1.25,-39.0244,1.27158e-005] [2.24202,-39.0244,1.27158e-005] [0.257979,-39.0244,1.27158e-005];
        addKnot ln splIdx #bezier #curve [-1.72605,-39.0166,1.27132e-005] [-0.753438,-39.2119,1.27769e-005] [-4.57521,-38.4446,1.25269e-005];
        addKnot ln splIdx #bezier #curve [-10.1409,-36.7376,1.19706e-005] [-7.309,-37.3896,1.21831e-005] [-13.9172,-35.8681,1.16873e-005];
        addKnot ln splIdx #bezier #curve [-21.5397,-34.4546,1.12267e-005] [-17.8431,-35.617,1.16055e-005] [-24.2857,-33.5911,1.09454e-005];
        addKnot ln splIdx #bezier #curve [-29.3197,-30.7067,1.00055e-005] [-26.8584,-32.1995,1.04919e-005] [-31.2996,-29.5059,9.61424e-006];
        addKnot ln splIdx #bezier #curve [-34.7865,-26.4204,8.60885e-006] [-33.2962,-28.1927,9.18634e-006] [-36.1642,-24.7818,8.07494e-006];
        addKnot ln splIdx #bezier #curve [-37.7256,-20.7099,6.74815e-006] [-36.7625,-22.6218,7.37113e-006] [-39.3331,-17.5191,5.70845e-006];
        addKnot ln splIdx #bezier #curve [-42.498,-11.1125,3.62092e-006] [-41.2873,-14.474,4.71622e-006] [-43.5333,-8.23811,2.68432e-006];
        addKnot ln splIdx #bezier #curve [-44.4109,-2.14882,7.00173e-007] [-44.0911,-5.18721,1.69021e-006] [-44.7377,0.956679,-3.11726e-007];
        addKnot ln splIdx #bezier #curve [-44.4273,7.21911,-2.35228e-006] [-44.8453,4.12457,-1.34395e-006] [-43.9386,10.8373,-3.53125e-006];
        addKnot ln splIdx #bezier #curve [-41.7121,17.8305,-5.80991e-006] [-42.9814,14.4071,-4.69444e-006] [-41.2031,19.2032,-6.25719e-006];
        addKnot ln splIdx #bezier #curve [-39.1659,21.4092,-6.976e-006] [-40.158,20.3326,-6.6252e-006] [-38.0344,22.637,-7.37607e-006];
        addKnot ln splIdx #bezier #curve [-35.3856,24.6954,-8.0468e-006] [-36.6997,23.6654,-7.71118e-006] [-33.1839,26.4211,-8.6091e-006];
        addKnot ln splIdx #bezier #curve [-28.6267,29.6699,-9.6677e-006] [-30.9845,28.1645,-9.17716e-006] [-25.8395,31.4496,-1.02476e-005];
        addKnot ln splIdx #bezier #curve [-19.9792,34.5325,-1.12521e-005] [-23.083,33.3912,-1.08802e-005] [-15.785,36.0749,-1.17547e-005];
        addKnot ln splIdx #bezier #curve [-6.93911,37.6452,-1.22664e-005] [-11.3607,36.9969,-1.20551e-005] [-4.23828,38.0413,-1.23954e-005];
    close ln splIdx;
    updateShape ln;
    convertToSplineShape ln;
    ln.wireColor = (color 28 149 177);
    ln.name = uniqueName "Lus00";
    select ln;
    return ln;

)
Lus00.pos = [0, 0, 0]

--- Bodem
    -- bovenste rij
    vert_array[1]=[-width/2,length/2,0]
    vert_array[2]=[-width/4,length/2,0]
    vert_array[3]=[0,length/2,0]
    vert_array[4]=[width/4,length/2,0]
    vert_array[5]=[width/2,length/2,0]
    -- tweede rij
    vert_array[6]=[-width/2,length/4,0]
    vert_array[7]=[-width/4,length/4,0]
    vert_array[8]=[0,length/4,0]
    vert_array[9]=[width/4,length/4,0]
    vert_array[10]=[width/2,length/4,0]
    -- derde rij
    vert_array[11]=[-width/2,0,0]
    vert_array[12]=[-width/4,0,0]
    vert_array[13]=[0,0,0]
    vert_array[14]=[width/4,0,0]
    vert_array[15]=[width/2,0,0]
    -- vierde rij
    vert_array[16]=[-width/2,-length/4,0]
    vert_array[17]=[-width/4,-length/4,0]
    vert_array[18]=[0,-length/4,0]
    vert_array[19]=[width/4,-length/4,0]
    vert_array[20]=[width/2,-length/4,0]
    -- onderste rij
    vert_array[21]=[-width/2,-length/2,0]
    vert_array[22]=[-width/4,-length/2,0]
    vert_array[23]=[0,-length/2,0]
    vert_array[24]=[width/4,-length/2,0]
    vert_array[25]=[width/2,-length/2,0]
    --lus01
    --lus02
    --lus03
    --lus04
    --lus05
    --lus06
    --lus07
    --lus08
    --lus09
    --lus10
    -- build faces
    -- upper faces
    append face_array[1,2,6]
    append face_array[2,6,7]
    -- 
    append face_array[2,3,8]
    append face_array[2,7,8]
    --
    append face_array[3,4,8]
    append face_array[4,8,9]
    --
    append face_array[4,5,10]
    append face_array[4,9,10]
    -- second row faces
    append face_array[6,7,12]
    append face_array[6,11,12]
    --
    append face_array[7,8,12]
    append face_array[8,13,12]
    --
    append face_array[8,9,14]
    append face_array[8,13,14]
    --
    append face_array[9,10,14]
    append face_array[10,14,15]
    -- third row faces
    append face_array[11,12,16]
    append face_array[12,16,17]
    --
    append face_array[12,13,18]
    append face_array[12,17,18]
    --
    append face_array[13,14,18]
    append face_array[14,18,19]
    --
    append face_array[14,15,20]
    append face_array[14,19,20]
    -- fourth row faces
    append face_array[16,17,22]
    append face_array[16,21,22]
    --
    append face_array[17,18,22]
    append face_array[18,22,23]
    --
    append face_array[18,19,24]
    append face_array[18,23,24]
    --
    append face_array[19,20,24]
    append face_array[20,24,25]
    
    
    -- align vertices to Lus00  --> here i have troubles     1) i suppose the fight between locals and globals?
    --                                                        2) because you can't select the vertices of a trimesh
    --                                                            to solve (2) i can convert the plane to edit mesh, but than i will lose my parameters?
    
    -- input of a align to spline script --> only tihng added = k = obj1.selectedverts.count - 1 = vert_array[1,2,3,4,5,10,15,20,25,24,23,22,21,16,11,6] is the vert_array
    -- don't know how to solve this
    -- Globals
-------------------------------------------------------------------------------

global Motif = undefined
global Distr = undefined
global AvPos = undefined

-------------------------------------------------------------------------------    
-------------------------------------------------------------------------------    
    -- Functions

fn move_vertices obj1 snap type =
(

j = 0
k = obj1.selectedverts.count - 1 = vert_array[1,2,3,4,5,10,15,20,25,24,23,22,21,16,11,6]
init = 0
if (isclosed Motif 1)==true do k=k+1
Arrat = for i=1 to obj1.selectedverts.count collect obj1.selectedverts[i].index

– Distribute the vertex on the spline
if (snap == 2) then
(

-- the vertex are moved close to the spline
    for i in Arrat do 
    (
        if type == 1 then    
            setvert obj1 i ((getvert obj1 i)+Motif.pos-AvPos) 
        if type == 2 then
            polyop.setvert obj1 i ((polyop.getvert obj1 i)+Motif.pos-AvPos)
    )
        if type == 1 then
        positions=for i=1 to obj1.selectedverts.count collect ((nearestPathParam Motif  (getvert obj1 Arrat[i])))
        if type == 2 then
        positions=for i=1 to obj1.selectedverts.count collect ((nearestPathParam Motif  (polyop.getvert obj1 Arrat[i])))

        sor = #()
        for i=1 to obj1.selectedverts.count do sor[i]=positions[i] 
        sort sor

        D = #()

-- smart sort function    
        for i=1 to positions.count do 
        (
            for j=1 to positions.count do 
            (
                if sor[i]==positions[j] do 
                (
                    D[i] = Arrat[j]
                    continue
                )
            )
        )
-- end of sort function

        if type == 1 then
            init = nearestPathParam Motif  (getvert obj1 D[1])
        if type == 2 then
            init = nearestPathParam Motif  (polyop.getvert obj1 D[1])
        if (isclosed Motif 1)==false do init = 0
        for i in D do 
        (
            Plus = (j/(k as float))+(init as float)

            if Plus > 1 do Plus = Plus-1
            if Plus < 0 do Plus = 1+Plus
            if type == 1 then
                setvert obj1 i (lengthInterp Motif Plus)
            if type == 2 then
                polyop.setvert obj1 i (lengthInterp Motif Plus)
            j=j+1
        )

-- Snap the vertex on the spline            
) 
else 
(
    for i in Arrat do 
    (
        if type == 1 then
            setvert obj1 i (lengthInterp Motif (nearestPathParam Motif (getvert obj1 i))) 
        if type == 2 then
            polyop.setvert obj1 i (lengthInterp Motif (nearestPathParam Motif (polyop.getvert obj1 i))) 
    )
)
subobjectlevel = 1

)

fn kind_of_object obj snap clone =
(
if (obj.selectedverts.count < 2) do (
MessageBox “Please select at least 2 vertex.” title:“Bug”
return false
)

Motif = copy Distr = copy Lus00

if ((converttosplineshape Motif) == undefined) do 
(
    MessageBox "You must use a shape." title:"Bug"
    return false
)

    X=0
    Y=0
    Z=0
    for i=1 to obj.selectedverts.count do 
    (
        X = X + obj.selectedverts[i].pos.x
        Y = Y + obj.selectedverts[i].pos.y
        Z = Z + obj.selectedverts[i].pos.Z
    )
    AvPos = [X/obj.selectedverts.count,Y/obj.selectedverts.count,Z/obj.selectedverts.count]
    
if (clone == 2) then 
( 
    Motif.pos = AvPos 
)
if obj.modifiers.count == 0 and classof obj == Editable_mesh then    
(
    Move_vertices obj snap 1
) 
else if classof obj == Editable_Poly then 
(
    Move_vertices obj snap 2
)
else 
(
    MessageBox "This script only works with collapsed meshes." title:"Bug"
)
    
delete Motif

)

fn filter_src obj = 
(
    if (classof obj == splineshape) or (classof obj == simple_spline)  then
        return true    
    return false;
)
    
    -- create mesh with all these vertices and faces
    setMesh mesh verts:vert_array faces:face_array
    for i=1 to mesh.numfaces do setFaceSmoothGroup mesh i 0
    --         set diagonal edges invisible so we have proper quads
    for i=1 to (12*8) by 2 do
    (    
        setEdgeVis mesh i 2 false
        setEdgeVis mesh (i+1) 1 false
    )

) – end build mesh

tool create
(
on mousePoint click do
(
case click of
(
1: nodeTM.translation = worldPoint
)
)
on mouseMove click do
(
case click of
(
2:
(
width = length = sqrt ((gridDist.y)^2+(gridDist.x)^2)
)
3: #stop
)
) – en on mouseMove
) – end create tool
) – end plugin