Notifications
Clear all

[Closed] working with Splines

Im using this bit of code to make a spline shape, what I would like to know is there a simple way to add a 90 degrees curve ? like in the picture.

thanks for reading

 
(
Sp_line = line name:"Sp_line" wirecolor:Objcolor
 
addnewspline Sp_line
 
for o = 1 to len do
 
(
 
	addKnot Sp_line 1 #corner #line [sp_x,sp_y,sp_z]
	Sp_line.name = "Sp_line_"+(a as string) 
 
)
 

7 Replies

Can anyone help me with this ?? maybe point me too some place that will help ???

can any one help Im stuck with this right now and my math is crap so some of the things I did find are a bit over my head

anyone has a chance to make it better:


--try(delete objects) catch()
fn roundCornerSpline width length radius roundness:0.5 tm: name:"roundCorner" = 
(
 local circle_round = 0.551785 -- perfect circle
 if roundness == unsupplied do roundness = circle_round
 radius = amin #(width,length,radius)
 r = radius*roundness
 x = width - radius
 y = length - radius
 p1 = [0,0,0]
 p2 = p1 + [x,0,0]
 p4 = p1 + [width,length,0]
 p3 = p4 - [0,y,0]
 
 corner = line name:(uniquename name)
 addnewspline corner
 addKnot corner 1 #corner #line p1
 if x > 0 do addKnot corner 1 #corner #line p2
 addKnot corner 1 #bezierCorner #curve p2 p2 (p2 + [r,0,0])
 addKnot corner 1 #bezierCorner #curve p3 (p3 - [0,r,0]) p3
 if y > 0 do addKnot corner 1 #corner #line p4
 updateshape corner
 convertToSplineShape corner
 if iskindof tm Matrix3 do corner.transform = tm
 corner
)
roundCornerSpline 20 40 10 
roundCornerSpline 20 40 10 tm:(scalematrix [-1,1,1])
roundCornerSpline 20 20 5 tm:(translate (scalematrix [1,-1,1]) [0,60,0])
roundCornerSpline 20 20 5 tm:(translate (scalematrix [-1,-1,1]) [0,60,0])

at last someone replyed Thanks DenisT I will let you know how I get on

thanks DenisT I used the code you gave me and got my script working using that code but its not right yet , I’m posting it up here and I hope no one minds. I cant get this working , so maybe some one here would have a look and offer some help .it should grow a spline by clicking the buttons and it startout ok but the script scews up when the spline turns a corner like Im not setting the spline tranform thing right ?? . click the step button and then a corner button , all looks ok at this point but if you click on a corner button again things go wrong , the spline shoots out from the sides.

Thanks for readinng

 
 updated see below
 

ok , how can I tell what direction my spline is facing , if I can work this out maybe I can fix this problem.
thanks for reading and I hope someone can help @_

OK I got this working a bit better but its still not right and I dont know where Im going wrong … Please PLEASE can someone have a look and give me some pointers ?

if you can help that would be great as Im stuck fast with this right now

 
-------------------------------------
gc()
clearlistener()
 
 
----------------------------------
 
(
global objColor = random white orange
local direction = 1
local magicNum = 0.551784
global firstrun = 0
global sp_line
local sp_x = 0.0
local sp_y = 0.0
local sp_z = 0.0 
local sp_x_old = 0.0
local sp_y_old = 0.0
local sp_z_old = 0.0 
	local p3verts = 0
global verts = 0
global lengh1 = 5
local AxisA = [0,0,0]
local AxisB = [0,0,0]
local sid1 = 12
local thi = 10
 
 
 
if main_pipe != undefined do closerolloutfloater main_pipe
main_pipe = newRolloutFloater " Pipe " 210 470
 
rollout PipeMaxDialog " Max Pipe v0.001" width:200 height:440
(
group "Main"
(
button sdel "kill" pos:[15,25] width:25 height:20 tooltip:"* it"
button sminus_x "X -" pos:[24,55] width:41 height:25 tooltip:"* it"
button step "Step" pos:[80,55] width:41 height:25 tooltip:"* it"
button splus_x "X +" pos:[136,55] width:41 height:25 tooltip:"* it"
button sminus_z "Z +" pos:[80,23] width:41 height:25 tooltip:"* it"
button splus_z "Z -" pos:[80,95] width:41 height:25 tooltip:"* it"
 
checkbox chk1 "Solid" pos:[16,128] checked: true triState:1 width:72 height:16
 
Spinner sd1 "Sides" range:[3,64,12] type:#integer width:56 pos:[112,224]
Spinner thic1 "thickness" range:[1,360,15] type:#integer width:56 pos:[112,272] 
Spinner len1 "Length" range:[2,1000,10] width:56 pos:[25,296] type:#float
)
 
 
 
fn drawCurveBetweenTwoAxis AxisA AxisB dist thi sid1 =
( 
if chk1.checked == true then ( ss = SplineShape name:"Sp_line" render_renderable:true render_displayRenderMesh:true render_thickness: thi render_sides: sid1 render_mapcoords:true wirecolor:Objcolor ) 
if chk1.checked != true then ( ss = SplineShape name:"Sp_line" render_renderable:false render_displayRenderMesh:false render_thickness: thi render_sides: sid1 render_mapcoords:true wirecolor:Objcolor )
 
addNewSpline ss 
addKnot ss 1 #bezier #curve AxisA.pos AxisA.row4((axisA.row2*dist*magicNum)*AxisA) 
addKnot ss 1 #bezier #curve AxisB.pos (((-1*axisB.row2*dist*magicNum)*AxisA)+axisB.row4) AxisB.row4 
updateShape ss 
ss
verts = numKnots ss --------------------- count knots 
p3verts = getKnotPoint ss 1 verts ---- in spline
)
 
 
fn drawlineBetweenTwoAxis AxisA AxisB dist thi sid1 =
( 
if chk1.checked == true then ( ss = SplineShape name:"Sp_line" render_renderable:true render_displayRenderMesh:true render_thickness: thi render_sides: sid1 render_mapcoords:true wirecolor:Objcolor ) 
if chk1.checked != true then ( ss = SplineShape name:"Sp_line" render_renderable:false render_displayRenderMesh:false render_thickness: thi render_sides: sid1 render_mapcoords:true wirecolor:Objcolor ) 
 
addNewSpline ss 
addKnot ss 1 #corner #line AxisA.pos AxisA.row4((axisA.row2*dist*magicNum)*AxisA) 
addKnot ss 1 #corner #line AxisB.pos (((-1*axisB.row2*dist*magicNum)*AxisA)+axisB.row4) AxisB.row4 
updateShape ss 
ss
verts = numKnots ss --------------------- count knots 
p3verts = getKnotPoint ss 1 verts ---- in spline
)
on sdel pressed do (
 
try(delete $Sp_line*) catch()
try(delete $Ref*) catch()
try(delete $Point01*) catch()
try(delete $Point02*) catch()
print "Kill"
global firstrun = 0
startloop = 0
local sp_x = 0.0
local sp_y = 0.0
local sp_z = 0.0 
local sp_x_old = 0.0
local sp_y_old = 0.0
local sp_z_old = 0.0 
local verts = 0
local p3verts =[0,0,0]
global curve = 0
local myTransform = 0
local myTransform2 = 0
)
 
on splus_x pressed do (
direction = 1
curve = 1
)
 
on sminus_x pressed do (
direction = 2
curve = 1
)
 
on splus_z pressed do (
direction = 5
curve = 1
)
 
on sminus_z pressed do (
direction = 6
curve = 1
 
 
)
 
on step pressed do (
 
print"step pressed"
 
lengh1 = len1.Value + 1 
sid1 = sd1.Value
thi = thic1.Value
 
if chk1.checked == true do (vis = 0)
if chk1.checked != true do (vis = 1)
print vis
 
	 case direction of
			 (
			 1: sp_x = sp_x + (lengh1)
			 2: sp_x = sp_x - (lengh1)
			 3: sp_y = sp_y + (lengh1)
			 4: sp_y = sp_y- (lengh1) 
			 5: sp_z = sp_z - (lengh1)
			 6: sp_z = sp_z + (lengh1)
			 )
 
			 if firstrun == 1 do ( print"Not First Run "
 
					 sp_x_old = p3verts[1]
					 sp_y_old = p3verts[2]
					 sp_z_old = p3verts[3]
 
		 if curve == 0 do (
 
							myTransform = $point01.transform 
							myTransform.row4 = [sp_x_old,sp_y_old,sp_z_old] 
							$Point01.transform = myTransform
 
 
 
							 myTransform2 = $point02.transform 
							 myTransform2.row4 = [sp_x,sp_y,sp_z] 
							 $Point02.transform = myTransform2 
 
					drawlineBetweenTwoAxis $Point01.transform $Point02.transform lengh1 thi sid1
								curve = 0
 
 
				) -- end if curve == 0 do ( 
	 if curve == 1 do ( print"from curve function"
 
 
 
	case direction of ( 
 
1: ( myTransform = $point01.transform --this is the original matrix
myTransform.row1 = [sp_x_old,sp_y_old,sp_z_old] 
$Point01.transform = myTransform
 
myTransform2 = $point02.transform 
myTransform2.row1 = [sp_x,sp_y,sp_z] 
$Point02.transform = myTransform2 
print "turn 1"
) 
 
2: ( myTransform = $point01.transform --this is the original matrix
myTransform.row2 = [sp_x_old,sp_y_old,sp_z_old] 
$Point01.transform = myTransform
 
myTransform2 = $point02.transform 
myTransform2.row2 = [sp_x,sp_y,sp_z] 
$Point02.transform = myTransform2 
print "turn 2"
) 
 
2: ( myTransform = $point01.transform --this is the original matrix
myTransform.row3= [sp_x_old,sp_y_old,sp_z_old] 
$Point01.transform = myTransform
 
myTransform2 = $point02.transform 
myTransform2.row3 = [sp_x,sp_y,sp_z] 
$Point02.transform = myTransform2 
print "turn 3"
)
 
)
 
myTransform = $point01.transform --this is the original matrix
myTransform.row4 = [sp_x_old,sp_y_old,sp_z_old] 
$Point01.transform = myTransform
 
myTransform2 = $point02.transform 
myTransform2.row4 = [sp_x,sp_y,sp_z] 
$Point02.transform = myTransform2 
 
drawCurveBetweenTwoAxis $Point01.transform $Point02.transform lengh1 thi sid1
curve = 0
) -- end if curve == 1 do 
 
)-- end if fsirstrun == 1 do (
 
-------------------------------------------------------------------------------------------------				 
if firstrun == 0 do ( print"First Run"
 
point transform:(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])
point transform:(matrix3 [0,-1,0] [1,0,0] [0,0,1] [lengh1,0,0])
 
-- point transform:(matrix3 [1,0,0] [0,1,0] [0,0,0] [-10,0,0])
-- point transform:(matrix3 [0,-1,0] [1,0,0] [0,0,1] [0,0,0])
 
drawlineBetweenTwoAxis $Point01.transform $Point02.transform lengh1 thi sid1
 
curve =0
firstrun = 1
 
) -- end if firstrun == 1 do (
) -- end on step pressed do
 
 
)
addRollout PipeMaxDialog main_pipe-- End of Script
)