27 Dec
POV CAD spline utility

I was interested in facilitating 2D CAD into the modeling process of POV. Drafting elevations, plans, and sections for a 3D scene is the basis for much of my current work. Fortunately, POV can handle some types of 2D & 3D data if formatted correctly. One of POV's object types is the Lathe. 

The lathe is an object generated from rotating a two-dimensional curve about an axis. This curve is defined by a set of points which are connected by linear, quadratic, cubic or bezier spline curves.

This process starts with a scanned hand sketch used as an underlay in FreeCAD. I draft the profiles and export the 2D splines as DXF.  I then convert the DXF to POV lathe objects using a basic program I wrote in PureBasic. This writes the bezier_splines and linear_splines "include" files for POV scene file.

Below is an example of a linear_spline part.

// line profile from freeCAD dxf export
#declare bridge_light_metal_D =
lathe {
linear_spline
17
<0, 32.0754>
<6.49385, 32.0754>
<8.12215, 31.5751>
<9.35523, 30.6977>
<9.35523, 29.9547>
<15.6057, 29.9547>
<16.2071, 30.4582>
<18.6604, 30.4582>
<18.6604, 29.4818>
<15.583, 27.2009>
<14.7812, 27.2009>
<14.5099, 27.6961>
<10.9724, 27.6961>
<10.9724, 7.16436>
<14.9261, 7.16437>
<16.0259, 6.25581>
<16.0259, -7.00112>
}

 Below is the Basic code to convert the DXF to a POV Lathe object

; Read DXF
StandardFile$ = "C:\file.dxf" ;
Pattern$ = "DXF (*.dxf)|*.dxf"
Pattern = 0

; use the first of the three possible patterns as standard
dxf_File$ = OpenFileRequester("Please choose file to load", StandardFile$, Pattern$, Pattern)

If dxf_File$
File = ReadFile(#PB_Any, dxf_File$)
pointCount = 0
splineFound = 0

Dim pointData$(0)
While Eof(File) = 0
found_point = 0
searchSpline$ = "AcDbSpline"
searchPoint$ = "10"
lineStr$ = ReadString(File, #PB_Ascii)
fSpline = FindString(lineStr$, searchSpline$ , 1 )
fPoint = FindString(lineStr$, searchPoint$ , 1 )
If fSpline > 0
splineFound = 1
EndIf

If splineFound = 1 And fPoint > 0 And Len(Trim(lineStr$)) = 2
pX$ = Trim(ReadString(File, #PB_Ascii))
lineStr$ = Trim(ReadString(File, #PB_Ascii))
pY$ = Trim(ReadString(File, #PB_Ascii))
lineStr$ = Trim(ReadString(File, #PB_Ascii))
pZ$ = Trim(ReadString(File, #PB_Ascii))
verb$ = ("<" + pX$ + ", " + pZ$ + ">")
ReDim pointData$(pointCount)
pointData$(pointCount) = verb$
pointCount = pointCount + 1
fPoint = 0
EndIf
Wend

CloseFile(File)

; Create a temporary file name.
Path$ = GetPathPart(dxf_File$)
fileName$ = GetFilePart(dxf_File$)
fileName$ = Mid(fileName$, 1, Len(fileName$) -4)
exportFile$ = Path$ + fileName$ + ".inc"

Debug exportFile$

File = CreateFile(#PB_Any, exportFile$)
tab$ = " "
s$ = "// line profile from freeCAD dxf export"
s2$ = "#declare " + fileName$ + " ="
s3$ = " lathe {"
s4$ = " bezier_spline"
s5$ = tab$ + Str(pointCount)
s6$ = " }"
Debug s$
Debug s2$
Debug s3$
Debug s4$
Debug s5$
WriteStringN(File, s$, #PB_Ascii)
WriteStringN(File, s2$, #PB_Ascii)
WriteStringN(File, s3$, #PB_Ascii)
WriteStringN(File, s4$, #PB_Ascii)
WriteStringN(File, s5$, #PB_Ascii)
For c = 0 To pointCount -1
d$ = pointData$(c)
Debug d$
WriteStringN(File, tab$ + d$, #PB_Ascii)
Next

WriteStringN(File, s6$, #PB_Ascii)
Debug s6$
CloseFile(File)

Else
MessageRequester("Info:", "canceled", 0)
EndIf 
Comments
* The email will not be published on the website.
I BUILT MY SITE FOR FREE USING