'\\ Copyright 2003 by Andrea Padovan All rights reserved. '\\ Redistribution and use in source and binary forms, with or without '\\ modification, are permitted provided that the following conditions are '\\ met: '\\ Redistributions of source code must retain the above copyright notice, '\\ this list of conditions and the following disclaimer. '\\ Redistributions in binary form must reproduce the above copyright '\\ notice, this list of conditions and the following disclaimer in the '\\ documentation and/or other materials provided with the distribution. '\\ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED '\\ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF '\\ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN '\\ NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, '\\ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, '\\ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS '\\ OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND '\\ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR '\\ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE '\\ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH '\\ DAMAGE. '\\***************************************************************//' '\\**** Created by Andrea Padovan Date 19/06/2003 Time 21:30 *****//' '\\*** xsi@fastwebnet.it pd@fastwebnet.it padovan@playstos.com ***//' '\\********************** VERSION 1.5 **************************//' '\\***************************************************************//' '\\ ------------------------------------------------------------- //' '\\ Border tool works on LOCAL "YX" plane of the source curve //' '\\ For an optimal result Freeze SRT of souce curve //' '\\ Select curve and run script... //' '\\ ------------------------------------------------------------- //' '\\ CREATE CURVE LINEAR OPTION //' '\\ Create a linear border curve //' '\\ ------------------------------------------------------------- //' '\\ CREATE PIPE OPTION //' '\\ Create a Pipe curve merging source curve and border curve //' '\\ ------------------------------------------------------------- //' '\\ Conver pipe to mesh //' '\\ ApplyOp "CurveListToMesh" to Pipe Curve //' '\\ ------------------------------------------------------------- //' '\\ DELETE SOURCE OPTION //' '\\ Delete source curve //' '\\ ------------------------------------------------------------- //' '\\***************************************************************//' OPTION EXPLICIT Dim Arcotan_1, Arcotan_2, oCollPipe, oRepar, ID_Plane, oPropCRT Dim oPPOpenclose, oPointOpenclose Dim oRoot, Isetup, ErrorBorder, oLinear Dim BorderLenght, PipeValue, Pipe2Mesh, ExtPipe, DelSource, PI, HardCorner Dim oSel, oGeom, oCrvBorder, oPoints, i, u, k Dim RotFac, oPosX_a, oPosY_a, oPosX_b, oPosY_b Dim a1, a2, Ua, Xi, Yi Dim oGeomCB, oPointsCB, oGeomCB_2, oPointsCB_2 Dim uC, aDel, bDel, cDel Dim Sx, Sy, Sz, Rx, Ry, Rz, Tx, Ty, Tz Dim oPipeColl, oPipe, oPoint_1, oPoint_2, oPoint_1i, oPoint_2i, oPoint_1Pos, oPoint_2Pos Dim oClosedCurve, CL, CorBug_X, CorBug_Y if selection.count > 0 then oClosedCurve = 2 PI = 4 * Atn(1) Set oCollPipe = CreateObject ("xsi.collection") Set oRoot = activesceneroot Set Isetup = AddProp ("Custom_parameter_list", oroot, , "Border_Setup created by Andrea Padovan") Set Isetup = Isetup.value("Value") SIAddCustomParameter Isetup , "Contact me", siString,"<> OR <>" , 0, 1, , 6, 0, 1 SIAddCustomParameter Isetup , "Info", siString,"If you don't ceck Create_Curve_Linear I create NURBS curve" , 0, 1, , 6, 0, 1 SIAddCustomParameter Isetup , "ID Info", siString,"0 = TOP XZ 1 = FRONT XY 2 = RIGHT YZ " , 0, 1, , 6, 0, 1 SIAddCustomParameter Isetup , "ID PLANE", siInt4, 0, 0, 2, , 4, 0, 2 SIAddCustomParameter Isetup , "Border_Radius", siDouble, 1, -10000, 10000, , 4, -50, 50 SIAddCustomParameter Isetup , "Crete_curve_Linear", siBool, 0, 0, 1,True , 4, 0, 1 SIAddCustomParameter Isetup , "Crete_curve_with_hard_corner", siBool, 0, 0, 1,True , 4, 0, 1 SIAddCustomParameter Isetup , "Create_Pipe", siBool, 0, 0, 1, , 4, 0, 1 SIAddCustomParameter Isetup , "Convert_Pipe_To_Mesh", siBool, 0, 0, 1, , 4, 0, 1 SIAddCustomParameter Isetup , "Delete_source", siBool, 0, 0, 1, , 4, 0, 1 ON ERROR RESUME NEXT InspectObj Isetup,,,4 IF Err.Number = 0 THEN BorderLenght = GetValue (Isetup & ".Border_Radius") PipeValue = GetValue (Isetup & ".Create_Pipe") Pipe2Mesh = GetValue (Isetup & ".Convert_Pipe_To_Mesh") DelSource = GetValue (Isetup & ".Delete_source") oLinear = GetValue (Isetup & ".Crete_curve_Linear") HardCorner = GetValue (Isetup & ".Crete_curve_with_hard_corner") ID_Plane = GetValue (Isetup & ".ID_PLANE") if BorderLenght = 0 then Msgbox "Border Radius is 0! Process Exit..." DeselectAll end if Logmessage "Border radius is : " & BorderLenght DeleteObj Isetup ON ERROR GOTO 0 Set oSel = selection(0) oPlane_rot oSel , ID_PLANE Set oGeom = oSel.activeprimitive.geometry if oLinear = True then Set oCrvBorder = SICreateCurve ("Border_Line", 1, 0) else Set oCrvBorder = SICreateCurve ("Border_Line", 3, 0) end if oPoints = oGeom.points.PositionArray Logmessage "Process Border Line..." For i = Lbound(oPoints , 2) to Ubound(oPoints , 2) - 1 oPosPoint BorderLenght, oPoints(1,i+1),oPoints(1,i),oPoints(0,i+1),oPoints(0,i) SIAddPointOnCurveAtend oCrvBorder , oPosX_b , oPosY_b ,0 , True SIAddPointOnCurveAtend oCrvBorder , oPosX_a , oPosY_a ,0 , True next if oGeom.closed then oClosedCurve = 1 oPosPoint BorderLenght, oPoints(1,0),oPoints(1,Ubound(oPoints , 2)),oPoints(0,0),oPoints(0,Ubound(oPoints , 2)) SIAddPointOnCurveAtend oCrvBorder , oPosX_b , oPosY_b ,0 , True SIAddPointOnCurveAtend oCrvBorder , oPosX_a , oPosY_a ,0 , True end if Set oGeomCB = oCrvBorder.activeprimitive.geometry oPointsCB = oGeomCB.points.PositionArray u = 0 k = 1 For i = Lbound(oPoints , 2) to Ubound(oPoints , 2) - oClosedCurve oCorrect oPointsCB(0,u),oPointsCB(0,u+1),oPointsCB(0,u+2),oPointsCB(0,u+3),oPointsCB(1,u),oPointsCB(1,u+1),oPointsCB(1,u+2),oPointsCB(1,u+3) SIAddPointOnCurve oCrvBorder, k , Xi, Yi, 0, False u = u + 2 k = K + 3 next if HardCorner = False then Set oGeomCB_2 = oCrvBorder.activeprimitive.geometry oPointsCB_2 = oGeomCB_2.points.PositionArray oClean oCrvBorder , oPointsCB_2 end if if oClosedCurve = 1 then if oLinear = True then Set oGeomCB = oCrvBorder.activeprimitive.geometry oPointsCB = oGeomCB.points.PositionArray CL = Ubound(oPointsCB,2) oCorrect oPointsCB(0,CL -1),oPointsCB(0,CL ),oPointsCB(0,0),oPointsCB(0,1),oPointsCB(1,CL -1),oPointsCB(1,CL),oPointsCB(1,0),oPointsCB(1,1) SIAddPointOnCurveAtStart oCrvBorder, Xi, Yi, 0, False ApplyTopoOp "NurbsCrvDeletePoint", oCrvBorder & ".pnt[1,LAST]", siUnspecified, siPersistentOperation ApplyTopoOp "CrvOpenClose", oCrvBorder, 3, siPersistentOperation else Set oGeomCB = oCrvBorder.activeprimitive.geometry oPointsCB = oGeomCB.points.PositionArray CorBug_X = oPointsCB(0,1) CorBug_Y = oPointsCB(1,1) logmessage CorBug_X logmessage CorBug_Y CL = Ubound(oPointsCB,2) oCorrect oPointsCB(0,CL -1),oPointsCB(0,CL ),oPointsCB(0,0),oPointsCB(0,1),oPointsCB(1,CL -1),oPointsCB(1,CL),oPointsCB(1,0),oPointsCB(1,1) SIAddPointOnCurveAtStart oCrvBorder, Xi, Yi, 0, False if HardCorner = False then ApplyTopoOp "NurbsCrvDeletePoint", oCrvBorder & ".pnt[1,LAST]", siUnspecified, siPersistentOperation ApplyTopoOp "CrvOpenClose", oCrvBorder, 3, siPersistentOperation Translate oCrvBorder & ".pnt[1]", CorBug_X , CorBug_Y , 0, siAbsolute , siGlobal, siObj, siXYZ else ApplyTopoOp "CrvOpenClose", oCrvBorder, 3, siPersistentOperation Translate oCrvBorder & ".pnt[2]", CorBug_X , CorBug_Y , 0, siAbsolute, siGlobal, siObj, siXYZ end if oRepar = ApplyTopoOp ("CrvReparam", oCrvBorder , 3, siPersistentOperation) SetValue oRepar & ".reparam", 0 end if end if FreezeObj oCrvBorder MatchSTR oCrvBorder, osel Set oGeomCB_2 = oCrvBorder.activeprimitive.geometry oPointsCB_2 = oGeomCB_2.points.PositionArray if (Ubound(oPointsCB_2 , 2)+1) <> (Ubound(oPoints , 2)+1) then MsgBox "The Border Line don't have same number of points of the Curve source", 64 , "Ceck point curve..." end if Logmessage "Curve Border Line Created!" if oClosedCurve = 1 then oCollPipe.add oSel oCollPipe.add oCrvBorder if PipeValue = True then if Pipe2Mesh = True then ExtPipe = ApplyOp ("CurveListToMesh", oCollPipe , 3, siPersistentOperation) InspectObj ExtPipe,,True SetValue ExtPipe & ".tesselationmethod", 2 SetValue ExtPipe & ".quadnbloops", 0 SetValue ExtPipe & ".stepcontour", 1 SetValue ExtPipe & ".stepholes", 1 SetValue Split(ExtPipe,".")(0) & ".Name", oPipe & "_Mesh" end if else if Pipe2Mesh = True then Msgbox "You have selected the Convert_Pipe_To_Mesh option but don't ceck Create_Pipe..." & chr(10) &_ "I Create for you" , 64 , "Information..." ExtPipe = ApplyOp ("CurveListToMesh", oCollPipe , 3, siPersistentOperation) InspectObj ExtPipe,,True SetValue ExtPipe & ".tesselationmethod", 2 SetValue ExtPipe & ".quadnbloops", 0 SetValue ExtPipe & ".stepcontour", 1 SetValue ExtPipe & ".stepholes", 1 SetValue Split(ExtPipe,".")(0) & ".Name", oPipe & "_Mesh" end if end if else if PipeValue = True then Pipe oSel , oCrvBorder Logmessage "Curve Pipe Created!" if Pipe2Mesh = True then ExtPipe = ApplyOp ("CurveListToMesh", oPipe , 3, siPersistentOperation) InspectObj ExtPipe,,True SetValue ExtPipe & ".tesselationmethod", 2 SetValue ExtPipe & ".quadnbloops", 0 SetValue ExtPipe & ".stepcontour", 1 SetValue ExtPipe & ".stepholes", 1 SetValue Split(ExtPipe,".")(0) & ".Name", oPipe & "_Mesh" end if else if Pipe2Mesh = True then Msgbox "You have selected the Convert_Pipe_To_Mesh option but don't ceck Create_Pipe..." & chr(10) &_ "I Create for you" , 64 , "Information..." Pipe oSel , oCrvBorder ExtPipe = ApplyOp ("CurveListToMesh", oPipe , 3, siPersistentOperation) InspectObj ExtPipe,,True SetValue ExtPipe & ".tesselationmethod", 2 SetValue ExtPipe & ".quadnbloops", 0 SetValue ExtPipe & ".stepcontour", 1 SetValue ExtPipe & ".stepholes", 1 SetValue Split(ExtPipe,".")(0) & ".Name", oPipe & "_Mesh" end if end if end if if DelSource = True then Logmessage "Curve Source Deleted!" DeleteObj oSel else oPlane_rotReturn oSel , ID_PLANE oDelCenterMove oSel , ID_PLANE end if ELSE DeleteObj Isetup logMessage "User has pressed CANCEL..." END IF else Logmessage "Select Curve!!!" end if '\\** BEGIN WITH SUB **//' Sub oPosPoint (In_Border,Ya,Yb,Xa,Xb) if Xb =< Xa then if ((Xb - Xa) = 0) then RotFac = (Atn((Yb - Ya) / (-0.000001))) * 180/PI oPosX_a = (Cos((RotFac + 90)* PI/180) * In_Border) + Xa oPosY_a = (Sin((RotFac + 90)* PI/180) * In_Border) + Ya oPosX_b = (Cos((RotFac + 90)* PI/180) * In_Border) + Xb oPosY_b = (Sin((RotFac + 90)* PI/180) * In_Border) + Yb else RotFac = (Atn((Yb - Ya) / (Xb - Xa))) * 180/PI oPosX_a = (Cos((RotFac + 90)* PI/180) * In_Border) + Xa oPosY_a = (Sin((RotFac + 90)* PI/180) * In_Border) + Ya oPosX_b = (Cos((RotFac + 90)* PI/180) * In_Border) + Xb oPosY_b = (Sin((RotFac + 90)* PI/180) * In_Border) + Yb end if else RotFac = (Atn((Yb - Ya) / (Xb - Xa))) * 180/PI oPosX_a = (Cos((RotFac + 90)* PI/180) * -In_Border) + Xa oPosY_a = (Sin((RotFac + 90)* PI/180) * -In_Border) + Ya oPosX_b = (Cos((RotFac + 90)* PI/180) * -In_Border) + Xb oPosY_b = (Sin((RotFac + 90)* PI/180) * -In_Border) + Yb end if end sub sub oCorrect (p1x,p2x,p3x,p4x,p1y,p2y,p3y,p4y) '\\This is the Playstos Team Developer formula's :) '\\Thanks to: '\\Filippo Solimando '\\Marco Salvi '\\Maurizio Werner Milano '\\Tiziano Lena If (Round (p2y , 6) = Round (p3y , 6)) And (Round (p2x , 6) = Round (p3x , 6)) then Xi = (p2x + p3x ) / 2 Yi = (p2y + p3y ) / 2 else a1 = (p4x - p3x) * (p1y - p3y) - (p4y - p3y) * (p1x - p3x) a2 = (p4y - p3y) * (p2x - p1x) - (p4x - p3x) * (p2y - p1y) If a2 = 0 then Ua = a1 / -0.000001 else Ua = a1 / a2 end if Xi = p1x + Ua * (p2x - p1x) Yi = p1y + Ua * (p2y - p1y) end if end sub sub oClean ( oBj_1 , in_1 ) for uC = 0 to ((Ubound(in_1,2)-1) / 3)-2 aDel = (uC+1) * 3 bDel = aDel + 1 cDel = aDel & "," & bDel & "," & cDel next on error resume next cDel = cDel & "1" & "," & Ubound(in_1,2)-1 ApplyTopoOp "NurbsCrvDeletePoint" , oBj_1 & ".pnt[" & cDel & "]" on error goto 0 end sub sub MatchSTR ( in_1 , in_2 ) Sx = GetValue (in_2 & ".kine.global.sclx") Sy = GetValue (in_2 & ".kine.global.scly") Sz = GetValue (in_2 & ".kine.global.sclz") Rx = GetValue (in_2 & ".kine.global.rotx") Ry = GetValue (in_2 & ".kine.global.roty") Rz = GetValue (in_2 & ".kine.global.rotz") Tx = GetValue (in_2 & ".kine.global.posx") Ty = GetValue (in_2 & ".kine.global.posy") Tz = GetValue (in_2 & ".kine.global.posz") SetValue (in_1 & ".kine.global.sclx"),Sx SetValue (in_1 & ".kine.global.scly"),Sy SetValue (in_1 & ".kine.global.sclz"),Sz SetValue (in_1 & ".kine.global.rotx"),Rx SetValue (in_1 & ".kine.global.roty"),Ry SetValue (in_1 & ".kine.global.rotz"),Rz SetValue (in_1 & ".kine.global.posx"),Tx SetValue (in_1 & ".kine.global.posy"),Ty SetValue (in_1 & ".kine.global.posz"),Tz end sub sub Pipe (in_1 , in_2 ) '\\** in_1 = osel in2 = border **//' Set oPipeColl = createObject ("xsi.collection") oPipeColl.add in_1 oPipeColl.add in_2 ResetTransform oPipeColl, siCtr, siSRT, siXYZ ApplyTopoOp "CrvInverse", in_2, 3, siPersistentOperation if oLinear = True then Set oPipe = SICreateCurve ("Pipe_Line", 1, 0) else Set oPipe = SICreateCurve ("Pipe_Line", 3, 0) end if Set oPoint_1 = in_1.activeprimitive.geometry.points Set oPoint_2 = in_2.activeprimitive.geometry.points oPoint_1Pos = oPoint_1.PositionArray for oPoint_1i = Lbound(oPoint_1Pos , 2 ) to Ubound(oPoint_1Pos , 2 ) SIAddPointOnCurveAtEnd oPipe , oPoint_1Pos(0,oPoint_1i), oPoint_1Pos(1,oPoint_1i), oPoint_1Pos(2,oPoint_1i), True next oPoint_2Pos = oPoint_2.PositionArray for oPoint_2i = Lbound(oPoint_2Pos , 2 ) to Ubound(oPoint_2Pos , 2 ) SIAddPointOnCurveAtEnd oPipe , oPoint_2Pos(0,oPoint_2i), oPoint_2Pos(1,oPoint_2i), oPoint_2Pos(2,oPoint_2i), True next ApplyTopoOp "CrvOpenClose", oPipe, 3, siPersistentOperation DeleteObj in_2 FreezeObj oPipe SelectObj oPipe end sub sub oPlane_rot (in_1 , ID) if ID = 0 then Rotate in_1 , -90, 0, 0, siAbsolute, siParent, siCtr, siX end if if ID = 1 then Logmessage "Working about default plane" end if if ID = 2 then Rotate in_1 , 0, 90, 0, siAbsolute, siParent, siCtr, siY end if end sub sub oPlane_rotReturn (in_1 , ID) if ID = 0 then Rotate in_1 , 0, 0, 0, siAbsolute, siParent, siCtr, siX end if if ID = 1 then Logmessage "Working about default plane" end if if ID = 2 then Rotate in_1 , 0, 0, 0, siAbsolute, siParent, siCtr, siY end if end sub sub oDelCenterMove (in_1 , ID) if ID = 0 or ID = 2 then Set oPropCRT = in_1.ActivePrimitive.ConstructionHistory.Find( "center" ) DeleteObj oPropCRT end if end sub