; Read .x3d ; m.miller 3.20.23 ; 8.8 revised to handle multiple POV types from the same pointData ; removed all other blender types StandardFile$ = "C:\file.x3d" ; Pattern$ = "x3d (*.x3d)|*.x3d" Pattern = 0 ; use the first of the three possible patterns x3d_File$ = OpenFileRequester("open x3d file", StandardFile$, Pattern$, Pattern) Path$ = GetPathPart(x3d_File$) fileName$ = GetFilePart(x3d_File$) fileName$ = Mid(fileName$, 1, Len(fileName$) -4) exportFile$ = Path$ + fileName$ + ".inc" objectCount = 0 pointDataCount = 0 arraySize = 5000 Dim aName$ (arraySize) Dim aPosX$ (arraySize) Dim aPosY$ (arraySize) Dim aPosZ$ (arraySize) Dim aPos_POV$ (arraySize) Dim aScaleX$ (arraySize) Dim aScaleY$ (arraySize) Dim aScaleZ$ (arraySize) Dim aScale_POV$ (arraySize) Dim aRotX$ (arraySize) Dim aRotY$ (arraySize) Dim aRotZ$ (arraySize) Dim aRot_POV$ (arraySize) If x3d_File$ File = ReadFile(#PB_Any, x3d_File$) While Eof(File) = 0 search_1$ = "Transform DEF=" search_2$ = "ifs" search_3$ = "_TRANSFORM" quote$ = Chr(34) ; " space$ = Chr(32) ; space equal$ = Chr(61) ; = lineStr$ = ReadString(File, #PB_Ascii) p = FindString(lineStr$, search_1$, 1) p2 = FindString(lineStr$, search_2$, 1) p3 = FindString(lineStr$, equal$, 1) ; find transform def without IndexedFaceSet If p > 0 And p2 = 0 ;found object objectCount +1 l = Len(lineStr$) - p s$ = Mid(lineStr$, p, l) ; find first quote q = FindString(s$, quote$, 1) ; find _TRANSFORM t = FindString(s$, "_TRANSFORM", 1) name$ = Mid(s$, q+1, (Len(s$) - q+1)-11) ; ----- find types If Mid(name$, 0, 9) = "pointData" pointDataCount+1 EndIf ; -------------------------------------------------------------------------------------- ; read TRANSLATION (position) ; -------------------------------------------------------------------------------------- temp$ = ReadString(File, #PB_Ascii) ; find first quote mark p = FindString(temp$, quote$, 1) ; trim from quote mark trans$ = Mid(temp$,p+1,l) ; remove end quote mark trans$ = Mid(trans$, 0, Len(trans$) - 1) ; find first space p1 = FindString(trans$, space$, 1) ; x data x$ = Mid(trans$, 0, p1) x$ = Left(x$, FindString(x$,".")+3) ; ---flip X ?? .x3d exported as Z-forward Y-up outputs -X pN = FindString(x$, "-", 1) If ( pN > 0 ) x$ = Right(x$, Len(x$) - 1) Else x$ = "-" + x$ EndIf ; re-trim temp$ = Mid(trans$,p1+1) ;find second space p2 = FindString(temp$, space$, 1) ; y data y$ = Mid(temp$, 0, p2) y$ = Left(y$, FindString(y$,".")+3) ; z data z$ = Mid(temp$, p2+1) z$ = Left(z$, FindString(z$,".")+3) aName$(objectCount) = name$ aPosX$(objectCount) = x$ aPosY$(objectCount) = y$ aPosZ$(objectCount) = z$ aPos_POV$(objectCount) = "<" + x$ + ", " + y$ + ", " + z$ + "> " ; --------------------------------------------------------------- ; read SCALE ; --------------------------------------------------------------- temp$ = ReadString(File, #PB_Ascii) ; find first quote mark p = FindString(temp$, quote$, 1) ; trim from quote mark trans$ = Mid(temp$,p+1,l) ; remove end quote mark trans$ = Mid(trans$, 0, Len(trans$) - 1) ; find first space p1 = FindString(trans$, space$, 1) ; x data x$ = Mid(trans$, 0, p1) x$ = Left(x$, FindString(x$,".")+3) ; re-trim temp$ = Mid(trans$,p1+1) ;find second space p2 = FindString(temp$, space$, 1) ; y data y$ = Mid(temp$, 0, p2) y$ = Left(y$, FindString(y$,".")+3) ; z data z$ = Mid(temp$, p2+1) z$ = Left(z$, FindString(z$,".")+3) aScaleX$(objectCount) = x$ aScaleY$(objectCount) = y$ aScaleZ$(objectCount) = z$ aScale_POV$(objectCount) = "<" + x$ + ", " + z$ + ", " + y$ + "> " ; --------------------------------------------------------------- ; read ROTATION ; --------------------------------------------------------------- temp$ = ReadString(File, #PB_Ascii) ; find first quote mark p = FindString(temp$, quote$, 1) ; trim from quote mark trans$ = Mid(temp$,p+1,l) ; remove end quote mark trans$ = Mid(trans$, 0, Len(trans$) - 1) ; find first space p1 = FindString(trans$, space$, 1) ; x data x$ = Mid(trans$, 0, p1) x$ = Left(x$, FindString(x$,".")+3) ; re-trim temp$ = Mid(trans$,p1+1) ;find second space p2 = FindString(temp$, space$, 1) ; y data y$ = Mid(temp$, 0, p2) y$ = Left(y$, FindString(y$,".")+3) ; z data z$ = Mid(temp$, p2+1) z$ = Left(z$, FindString(z$,".")+3) aRotX$(objectCount) = x$ aRotY$(objectCount) = y$ aRotZ$(objectCount) = z$ aRot_POV$(objectCount) = "<" + x$ + ", " + y$ + ", " + z$ + "> " EndIf Wend CloseFile(File) ; --------------------------------------------------------------- ; write header ; --------------------------------------------------------------- ; Create temp file name. Path$ = GetPathPart(x3d_File$) fileName$ = GetFilePart(x3d_File$) fileName$ = Mid(fileName$, 1, Len(fileName$) -4) exportFile$ = Path$ + fileName$ + ".inc" File = CreateFile(#PB_Any, exportFile$) Debug exportFile$ Debug ".x3d convert to POV object types" Debug "pointData Count: " + pointDataCount ; write header tab$ = " " s0$ = "// pointData from " + fileName$ + ".x3d" s1$ = "// m.miller 8.8.2023" + Chr(13) s2$ = "// note: lathe requires positive x for all points" s3$ = "// prisms are plotted on z plane and extrude in y" s4$ = "" + Chr(13) WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) WriteStringN(File, s2$, #PB_Ascii) WriteStringN(File, s3$, #PB_Ascii) WriteStringN(File, s4$, #PB_Ascii) WriteStringN(File, s4$, #PB_Ascii) ; --------------------------------------------------------------- ; write ARRAY ; --------------------------------------------------------------- If pointDataCount > 0 n=0 WriteStringN(File,"//--- pointArray " , #PB_Ascii) WriteStringN(File,"#declare pointDataCount = " + pointDataCount + " ;" , #PB_Ascii) WriteStringN(File,"#declare pointArray = array mixed [pointDataCount][2]" + " ;", #PB_Ascii) For i = 1 To objectCount If Mid(aName$(i), 0, 9) = "pointData" s0$ = "#declare pointArray[" + n + "][0] = " + aPos_POV$(i) + " ;" s1$ = "#declare pointArray[" + n + "][1] = " + aScaleX$(i) + " ;" WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) n+1 EndIf Next WriteStringN(File, "", #PB_Ascii) EndIf ; --------------------------------------------------------------- ; write PRISM Z ; --------------------------------------------------------------- If pointDataCount > 0 n=0 c=pointDataCount+1 s0$ = "//--- prism Z" s1$ = "#declare " + fileName$ +"_prism_z =" s2$ = "prism {" s3$ = " linear_spline" WriteStringN(File,Chr(13), #PB_Ascii) WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) WriteStringN(File, s2$, #PB_Ascii) WriteStringN(File, s3$, #PB_Ascii) s$ = " 0, 1, " + c + "," WriteStringN(File,s$ , #PB_Ascii) For i = 1 To objectCount If Mid(aName$(i), 0, 9) = "pointData" s$ = " <" + aPosX$(i) + "," + aPosZ$(i) + ">," If i = objectCount s$ = " <" + aPosX$(i) + "," + aPosZ$(i) + ">" EndIf WriteStringN(File, s$, #PB_Ascii) n+1 EndIf Next s$ = " <" + aPosX$(1) + "," + aPosZ$(1) + ">" s1$ = "}" WriteStringN(File, s$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) WriteStringN(File, "", #PB_Ascii) EndIf ; --------------------------------------------------------------- ; write PRISM Y ; --------------------------------------------------------------- If pointDataCount > 0 n=0 c=pointDataCount+1 s0$ = "//--- prism Y" s1$ = "#declare " + fileName$ +"_prism_y =" s2$ = "prism {" s3$ = " linear_spline" WriteStringN(File,Chr(13), #PB_Ascii) WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) WriteStringN(File, s2$, #PB_Ascii) WriteStringN(File, s3$, #PB_Ascii) s$ = " 0, 1, " + c + "," WriteStringN(File,s$ , #PB_Ascii) For i = 1 To objectCount If Mid(aName$(i), 0, 9) = "pointData" s$ = " <" + aPosX$(i) + "," + aPosY$(i) + ">," If i = objectCount s$ = " <" + aPosX$(i) + "," + aPosY$(i) + ">" EndIf WriteStringN(File, s$, #PB_Ascii) n+1 EndIf Next s$ = " <" + aPosX$(1) + "," + aPosY$(1) + ">" s1$ = "}" WriteStringN(File, s$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) EndIf ; --------------------------------------------------------------- ; write Lathe ; --------------------------------------------------------------- If pointDataCount > 0 s0$ = "#declare " + fileName$ +"_lathe =" s1$ = "lathe{ " s2$ = " cubic_spline" s3$ = " " + Str(pointDataCount) + "," s4$ = " }" ; write Lathe header WriteStringN(File, "", #PB_Ascii) WriteStringN(File, "//--- lathe", #PB_Ascii) WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) WriteStringN(File, s2$, #PB_Ascii) WriteStringN(File, s3$, #PB_Ascii) For i = 1 To objectCount-1 s0$ = " <" + aPosX$(i) + "," + aPosY$(i) + ">, " WriteStringN(File, s0$, #PB_Ascii) Next s0$ = " <" + aPosX$(objectCount) + "," + aPosY$(objectCount) + ">" WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s4$, #PB_Ascii) EndIf ; --------------------------------------------------------------- ; write Sweep Cubic ; --------------------------------------------------------------- If pointDataCount > 0 c=pointDataCount+2 s0$ = "#declare " + fileName$ + "_sweep_cubic =" s1$ = "sphere_sweep {" s2$ = " cubic_spline" s3$ = " tolerance 0.000001" s4$ = " }" ; write Lathe header WriteStringN(File, "", #PB_Ascii) WriteStringN(File, "//--- cubic spline sweep", #PB_Ascii) WriteStringN(File, "#declare sf=1;", #PB_Ascii) WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) WriteStringN(File, s2$, #PB_Ascii) WriteStringN(File, " " + c + ",", #PB_Ascii) s0$ = " " + aPos_POV$(1) + "," + " " + aScaleX$(1) + "*sf, " WriteStringN(File, s0$, #PB_Ascii) For i = 1 To objectCount s0$ = " " + aPos_POV$(i) + "," + " " + aScaleX$(i) + "*sf, " WriteStringN(File, s0$, #PB_Ascii) Next s0$ = " " + aPos_POV$(objectCount) + "," + " " + aScaleX$(objectCount) + "*sf" WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s3$, #PB_Ascii) WriteStringN(File, s4$, #PB_Ascii) EndIf ; --------------------------------------------------------------- ; write Sweep linear ; --------------------------------------------------------------- If pointDataCount > 0 c=pointDataCount+2 s0$ = "#declare " + fileName$ + "_sweep_linear =" s1$ = "sphere_sweep {" s2$ = " linear_spline" s3$ = " tolerance 0.000001" s4$ = " }" ; write Lathe header WriteStringN(File, "", #PB_Ascii) WriteStringN(File, "//--- linear spline sweep", #PB_Ascii) WriteStringN(File, "#declare sf=1;", #PB_Ascii) WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) WriteStringN(File, s2$, #PB_Ascii) WriteStringN(File, " " + c + ",", #PB_Ascii) s0$ = " " + aPos_POV$(1) + "," + " " + aScaleX$(1) + "*sf, " WriteStringN(File, s0$, #PB_Ascii) For i = 1 To objectCount s0$ = " " + aPos_POV$(i) + "," + " " + aScaleX$(i) + "*sf, " WriteStringN(File, s0$, #PB_Ascii) Next s0$ = " " + aPos_POV$(objectCount) + "," + " " + aScaleX$(objectCount) + "*sf" WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s3$, #PB_Ascii) WriteStringN(File, s4$, #PB_Ascii) EndIf ; --------------------------------------------------------------- ;--- Plot spheres ; --------------------------------------------------------------- If pointDataCount > 0 s0$ = "#declare " + fileName$ + "_spheres =" s1$ = "union {" s2$ = " }" ; write Lathe header WriteStringN(File, "", #PB_Ascii) WriteStringN(File, "//--- plotted spheres", #PB_Ascii) WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) For i = 1 To objectCount s0$ = " sphere{<0,0,0>, " + aScaleX$(i) + " translate " + aPos_POV$(i) + " }" WriteStringN(File, s0$, #PB_Ascii) Next WriteStringN(File, s4$, #PB_Ascii) EndIf ; --------------------------------------------------------------- ;--- Plot cones ; --------------------------------------------------------------- If pointDataCount > 0 s0$ = "#declare " + fileName$ + "_cones =" s1$ = "union {" s2$ = " }" ; write Lathe header WriteStringN(File, "", #PB_Ascii) WriteStringN(File, "//--- plotted cones", #PB_Ascii) WriteStringN(File, s0$, #PB_Ascii) WriteStringN(File, s1$, #PB_Ascii) For i = 1 To objectCount-1 s0$ = " cone{" + aPos_POV$(i) + "," + aScaleX$(i) + "," + aPos_POV$(i+1) + "," + aScaleX$(i+1) + "}" WriteStringN(File, s0$, #PB_Ascii) Next WriteStringN(File, s4$, #PB_Ascii) EndIf ; --------------------------------------------------------------- ;--- close file ; --------------------------------------------------------------- CloseFile(File) ; --------------------------------------------------------------- ;--- Verbose message ; --------------------------------------------------------------- s$ = fileName$ + ".inc created " + Chr(13) s1$ = "" + pointDataCount + " points" + Chr(13) s2$ = "- array added" + Chr(13) s3$ = "- prism added" + Chr(13) s4$ = "- lathe added" + Chr(13) s5$ = "- cubic sweep added" + Chr(13) s5$ = "- linear sweep added" + Chr(13) s6$ = "- spheres added" + Chr(13) s7$ = "- cones added" + Chr(13) MessageRequester(".x3d to POV 0.5 m.miller 8.8.23", s$+s1$+s2$+s3$+s4$+s5$+s6$+s7$, 0) Else MessageRequester("Info:", "canceled", 0) EndIf ; IDE Options = PureBasic 5.73 LTS (Windows - x64) ; Markers = 16,61,199,292 ; EnableXP ; Executable = headspin\00 projects\POV 2022\x3DtoPOV\x3d_blender_points.exe