 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Bald Eagle" <cre### [at] netscape net> wrote:
> "ingo" <nomail@nomail> wrote:
>
> .....
>
> Yes, yes. That's oranges to my apples.
>
Ah, misunderstood. No, the #read directive expects quoted strings, not just text
and thus fails straight away on the stl 'keywords'.
An annoyance of STL is that the number of faces is not given beforehand. Makes
declaring arrays hard or one has to do a two pass run and count faces.
A conversion script in a scripting lang is the way out.
ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"ingo" <nomail@nomail> wrote:
Yeah, sorry, I'm kinda thinking one thing and typing another.
I'm using too many systems at once and hopping between them all in rapid
succession.
> An annoyance of STL is that the number of faces is not given beforehand. Makes
> declaring arrays hard or one has to do a two pass run and count faces.
But we no longer have to declare the size of an array in SDL when constructing
one, unless it's a multidimensional array.
And I'm really talking about somehow doing this in the same way that we use
image_maps. So we'd be doing this under the hood in c++.
So the thought process is actually more that what we feed the parser through SDL
when we make a mesh {} is nearly identical to the data structure of the ASCII
stl. And so therefor it ought to be easy to bypass converting to SDL and just
read the triangle vertices in directly from the stl file.
So, I guess it would actually be
#declare MyObject = stl {"MyObject.stl"}
Now, whether or not we create a new keyword, or spruce up the mesh {} keyword to
allow something like #declare MyObject = mesh {stl "MyObject.stl"} is something
that would be a decision for someone with more development experience than I.
Another idea is to code the conversion script into source - because it would be
nice to convert stl to mesh and save it as a file. And convert both mesh {} and
stl to mesh2 {}. And to have an array automatically populated with the triangle
vertices if desired.
(I'd also like to see a similar mechanism to populate an array with rgb data
from an image map and other related finction & pigment data)
So, I can envision both:
#declare MyObject = mesh {stl "MyObject.stl" make_array MyArray}
and
#declare MyObject = mesh2 {stl "MyObject.stl" make_arrays ...}
where there would some mechanism to specify what arrays for vertices, faces, and
normals would exist.
> A conversion script in a scripting lang is the way out.
I mean, yeah - I just hate all the extra steps, and the generation of a whole
new file that takes up space next to the original stl.
#read could probably use some fixing, and we all are intimately familiar with
the long-standing need to have some sort of data-typing mechanism.
- BW
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 10/09/2025 16:23, ingo wrote:
>
> A conversion script in a scripting lang is the way out.
>
I agree with you.
The wiki page shows that the structure is very simple, and I think Perl*
is a very good candidate for this.
* : (from WIKIPEDIA) Perl was developed by Larry Wall in 1987 and STL
was invented by the Albert Consulting Group for 3D Systems in 1987 too LOL
--
kurtz le pirate
compagnie de la banquise
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Bald Eagle" <cre### [at] netscape net> wrote:
> I mean, yeah - I just hate all the extra steps, and the generation of a whole
> new file that takes up space next to the original stl.
for the current POV-Ray situation, I'm mostly writing my own little tools "that
do things" and then call POV-Ray on the generated scene. The opposite of POV-Ray
should be able to do it "all". Although I would like the latter,
ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"ingo" <nomail@nomail> wrote:
> for the current POV-Ray situation, I'm mostly writing my own little tools "that
> do things" and then call POV-Ray on the generated scene. The opposite of POV-Ray
> should be able to do it "all". Although I would like the latter,
>
> ingo
Well, given "the current POV-Ray situation", I'm trying to break out of that,
since "what is tolerated is what will continue".
I suppose I have a Persistence of Vision. ;)
I'm not exclusionarily averse to things like macros and separate utilities,
however, it would be highly desireable to in some way integrate those things
into the POV-Ray "package".
An official repository on the website, a folder in the official distro, scripts
to run whatever conversion or creation needs to be done, or most preferable -
the inclusion of an additional module in the source.
I'm especially pushing for this stl module, since it appears so straightforward
a task (for a c++ programmer), and the availability of millions of free stl
files available. We don't have a modeler - but there are models.
And it there are modelers available to make/edit stls.....
- BW
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Bald Eagle" <cre### [at] netscape net> wrote:
> #declare MyObject = mesh2 {stl "MyObject.stl" make_arrays ...}
#declare MyStlObject = mesh2{stl "MyObject.stl"}
#declare MyObjObject = mesh2{obj "MyObject.obj"}
that's quite elegant, to extract from a file format, what POV-Ray understands
based on mesh2.
I'd separate extracting array into something like:
mesh2array(mySTLObject, verticesname, normalsname, facesname, uvname,
vertexcoulours etc..)
could result in a bunch of arrays declared with the given names. It should take
mesh & mesh2.
and/or
mesharrays{obj "MyObjObject.obj"} and extract everything the file supports into
arrays, even what's not understood by mesh2, like boning, face normals or non
triangle faces.
ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 09/09/2025 02:32, Bald Eagle wrote:
> ........... what's that?!!!
>
> He provides not one but TWO .stl files . . .
>
Blender can import STL and export POV.
--
YB
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 10/09/2025 17:11, kurtz le pirate wrote:
>
> The wiki page shows that the structure is very simple, and I think Perl*
> is a very good candidate for this.
>
Finally, I spent an hour and here is my first result ;)
I found this template on the web :
<https://www.thingiverse.com/thing:7119375>. The downloaded STL file is
in binary mode. I converted it to ASCII on this website :
<https://3dcustomizer.net/tests/stl-bin-to-ascii.html>
Here is the first image to compare with the one on Thingiverse.
I also added an archive that contains :
* Stackable_crate_gridfinity-ascii.stl : the ascii stl file
* stl2pov.pl : the perl script
* Stackable_crate_gridfinity-ascii.inc : the mesh{} include file
generated by the script
* test.pov : demo scene
* test.png : the image
Of course, there are quite a few things to add such as binary format,
normals & mesh2{}, colors, etc.
--
kurtz le pirate
compagnie de la banquise
Post a reply to this message
Attachments:
Download 'test.png' (376 KB)
Download 'stl2pov.tar.gz' (1239 KB)
Preview of image 'test.png'

|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 11/09/2025 16:51, kurtz le pirate wrote:
>
> Of course, there are quite a few things to add such as binary format,
> normals & mesh2{}, colors, etc.
>
Three more attempts always from Thingiverse.
The lack of normals is clearly visible :(
--
kurtz le pirate
compagnie de la banquise
Post a reply to this message
Attachments:
Download 'aat.low.jpeg.jpg' (75 KB)
Download 'fish.low.jpeg.jpg' (80 KB)
Download 'lamp.low.jpeg.jpg' (65 KB)
Preview of image 'aat.low.jpeg.jpg'

Preview of image 'fish.low.jpeg.jpg'

Preview of image 'lamp.low.jpeg.jpg'

|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
A quicky in Nim, not much tested:
---%<------%<------%<------%<---
#asciistl2pov.nim
import std/[math, sequtils, strformat, strutils]
type
Vec3 = array[3, float]
Face = array[3, int]
proc vec3(x,y,z: float): Vec3 = [x,y,z]
proc `+`(a,b: Vec3): Vec3 = [a[0]+b[0], a[1]+b[1], a[2]+b[2]]
proc `/`(a: Vec3, s: float): Vec3 = [a[0]/s, a[1]/s, a[2]/s]
proc dot(a,b: Vec3): float = a[0]*b[0]+a[1]*b[1]+a[2]*b[2]
proc length(v: Vec3): float = sqrt(dot(v,v))
proc normalize(v: Vec3): Vec3 =
let l = length(v)
if l > 1e-9: v / l else: vec3(0,1,0)
# Load STL, ASCII only
proc loadSTL(path: string): (seq[Vec3], seq[Face], seq[Vec3]) =
var verts: seq[Vec3] = @[]
var faces: seq[Face] = @[]
var norms: seq[Vec3] = @[]
var curVerts: seq[int] = @[]
var curNormal = vec3(0,0,0)
for line in lines(path):
let l = line.strip()
if l.startsWith("facet normal"):
let p = l.splitWhitespace()
curNormal = vec3(p[2].parseFloat, p[3].parseFloat, p[4].parseFloat)
elif l.startsWith("vertex"):
let p = l.splitWhitespace()
let v = vec3(p[1].parseFloat, p[2].parseFloat, p[3].parseFloat)
verts.add(v)
curVerts.add(verts.len-1)
elif l.startsWith("endfacet"):
if curVerts.len == 3:
faces.add([curVerts[0], curVerts[1], curVerts[2]])
norms.add(curNormal)
curVerts.setLen(0)
return (verts, faces, norms)
proc vertexToFaces(faces: seq[Face], vertexCount: int): seq[seq[int]] =
result = newSeqWith(vertexCount, newSeq[int]())
for fIdx, f in faces:
for vi in f:
result[vi].add(fIdx)
proc computeVertexNormals(
vertexCount: int, faceNormals: seq[Vec3], v2f: seq[seq[int]]
): seq[Vec3] =
result = newSeqWith(vertexCount, vec3(0,0,0))
for vIdx in 0..<vertexCount:
var accum = vec3(0,0,0)
for fIdx in v2f[vIdx]:
accum = accum + faceNormals[fIdx]
result[vIdx] = normalize(accum)
proc mesh2ToString(
verts: seq[Vec3], faces: seq[Face], normals: seq[Vec3]
): string =
var sb = newStringOfCap(verts.len * 100) # Preallocate rough size
sb.add("#declare MSH = mesh2 {\n")
# Vertex vectors
sb.add(" vertex_vectors {\n")
sb.add(" " & $verts.len & ",\n")
for v in verts:
sb.add(&" <{v[0]}, {v[1]}, {v[2]}>,\n")
sb.add(" }\n")
# Normal vectors
sb.add(" normal_vectors {\n")
sb.add(" " & $normals.len & ",\n")
for n in normals:
sb.add(&" <{n[0]}, {n[1]}, {n[2]}>,\n")
sb.add(" }\n")
# Face indices
sb.add(" face_indices {\n")
sb.add(" " & $faces.len & ",\n")
for f in faces:
sb.add(&" <{f[0]}, {f[1]}, {f[2]}>,\n")
sb.add(" }\n")
sb.add("}\n")
result = sb
proc writeMesh2(outPath: string, verts: seq[Vec3], faces: seq[Face], normals:
seq[Vec3]) =
let s = mesh2ToString(verts, faces, normals)
writeFile(outPath, s)
when isMainModule:
let (verts, faces, faceNorms) = loadSTL("mesh_output.stl")
let v2f = vertexToFaces(faces, verts.len)
let vertexNorms = computeVertexNormals(verts.len, faceNorms, v2f)
writeMesh2("model.inc", verts, faces, vertexNorms)
echo "Converted STL to POV-Ray mesh2 with normals."
---%<------%<------%<------%<---
ingo
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |