POV-Ray : Newsgroups : povray.text.scene-files : robot_fish.zip Server Time
28 Apr 2024 21:05:26 EDT (-0400)
  robot_fish.zip (Message 1 to 6 of 6)  
From: Mike Miller
Subject: robot_fish.zip
Date: 11 Aug 2023 19:35:00
Message: <web.64d6c4b677da4dd878f7f9ccdabc9342@news.povray.org>
Scene file and .x3d to POV converter. I set up a simple blender file to demo the
use of the converter. I'm using this file to model a robotic fish that will be
added to some sci-fi themed renderings.

The x3d_blender_points.exe is in the blender folder of this zip along with a
read_me file. There's a stripped-down Blender file with some of the point arrays
and model data.

Blender is free and the x3d format is easy to parse for a hack programmer. It
also helps with visualizing the modeling process by using the POV rendered
elevations as underlays in blender.
Miller


Post a reply to this message


Attachments:
Download 'robot_fish.zip' (3359 KB)

From: jr
Subject: Re: robot_fish.zip
Date: 12 Aug 2023 10:35:00
Message: <web.64d798425aa5c67a80c03e9d6cde94f1@news.povray.org>
hi,

"Mike Miller" <mil### [at] gmailcom> wrote:
> Scene file and .x3d to POV converter. ... x3d_blender_points.exe ...

thanks, any chance of a different format (or source) ?  have no Microsoft OS.


regards, jr.


Post a reply to this message

From: Mike Miller
Subject: Re: robot_fish.zip
Date: 12 Aug 2023 12:55:00
Message: <web.64d7b5f05aa5c67a78f7f9ccdabc9342@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> hi,
>
> "Mike Miller" <mil### [at] gmailcom> wrote:
> > Scene file and .x3d to POV converter. ... x3d_blender_points.exe ...
>
> thanks, any chance of a different format (or source) ?  have no Microsoft OS.
>
>
> regards, jr.

I'm using PureBasic for this. ...I'm leaning on free programs.. haha
I did see Unix & Mac OS versions available. I'm using 64bit Windows 11.

I have another compile that parses most of the other Blender types (blobs,
cubes, cylinders, torus, etc.) if you can compile to your OS.

Below is the PB code. I also attached the .PB file
good luck,
Mike

; 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


Post a reply to this message


Attachments:
Download 'x3d_blender_points.pb.txt' (15 KB)

From: Bald Eagle
Subject: Re: robot_fish.zip
Date: 12 Aug 2023 15:25:00
Message: <web.64d7dbbb5aa5c67a1f9dae3025979125@news.povray.org>
"Mike Miller" <mil### [at] gmailcom> wrote:
> I'm using this file to model a robotic fish that will be
> added to some sci-fi themed renderings.

250 years ago, some maniac made "robot" fish for an animated swan to eat.

Truly incredible.

https://www.itv.com/news/tyne-tees/2021-10-06/conservation-experts-study-the-bowes-museums-18th-century-silver-swan


Post a reply to this message

From: Mike Miller
Subject: Re: robot_fish.zip
Date: 12 Aug 2023 18:45:00
Message: <web.64d80ae75aa5c67a78f7f9ccdabc9342@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Mike Miller" <mil### [at] gmailcom> wrote:
> > I'm using this file to model a robotic fish that will be
> > added to some sci-fi themed renderings.
>
> 250 years ago, some maniac made "robot" fish for an animated swan to eat.
>
> Truly incredible.
>
>
https://www.itv.com/news/tyne-tees/2021-10-06/conservation-experts-study-the-bowes-museums-18th-century-silver-swan

Wow..had not seen that. very cool!


Post a reply to this message

From: jr
Subject: Re: robot_fish.zip
Date: 13 Aug 2023 11:05:00
Message: <web.64d8f0295aa5c67a80c03e9d6cde94f1@news.povray.org>
hi,

"Mike Miller" <mil### [at] gmailcom> wrote:
> ...
> Below is the PB code. I also attached the .PB file
> good luck,
> Mike

thank you / cheers.


regards, jr.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.