POV-Ray : Newsgroups : povray.binaries.utilities : Wireframe Generator (from meshes) Server Time: 23 Mar 2019 06:58:27 GMT
  Wireframe Generator (from meshes) (Message 1 to 1 of 1)  
From: CShake
Subject: Wireframe Generator (from meshes)
Date: 13 Jul 2010 15:37:46
Message: <4c3c884a@news.povray.org>
I've been working lately with a bunch of models exported from 
milkshape3d to render higher quality versions of game objects, and 
decided that finding a way to make a wireframe version of the model 
should be possible. And without any existing things I could find via web 
searches, I made one.

Attached is a php script that reads a given .inc file that contains all 
the meshes and produces a new file with two macros for both edges and 
vertices. The names for these come from the filename of the original 
include file: for example, if you pass a file named "my_model.inc" to 
the script is will write out a file in the same directory named 
"my_model_wireframe.inc" that contains the macros 
"my_model_vertices(vertex_radius,vertex_texture)" and 
"my_model_edges(edge_radius,edge_texture)", with the parameters being 

Because the exporter I'm using always writes the meshes the same way, 
this script will only make wires for triangles that were defined like:
#declare mesh_0 = mesh{
<2.858558, 18.455250, 11.117654> <-0.000000, 0.257028, -0.966404>,
<0.002201, 18.455250, 11.117655> <0.000001, 0.257028, -0.966404>,
<2.858560, 35.636593, 15.687251> <0.000000, 0.257028, -0.966404>
uv_vectors <0.830126, 0.804765>, <0.884714, 0.804765>, <0.830126, 0.499519>
<0.002201, 18.455250, 11.117655> <0.000001, 0.257028, -0.966404>,
<0.002203, 35.636593, 15.687252> <0.000001, 0.257028, -0.966404>,
<2.858560, 35.636593, 15.687251> <0.000000, 0.257028, -0.966404>
uv_vectors <0.884714, 0.804765>, <0.884714, 0.499519>, <0.830126, 0.499519>
It picks out the three vertex/normal definition lines (ignoring anything 
on either side of them like indents, commas, or comments), and after 
finding three such lines it treats that like a triangle. This is a 
fairly dumb script that only looks for those lines and can't handle 
other shapes or anything, but works perfectly for well-formed files like 
you get from an exporter.
The matching is done with a simple perl-style regular expression which 
should be easy to change if your exporter works slightly differently, as 
is it currently needs each value to have 6 decimals for it to be recognized.

To deal with shared edges it assumes that the triangles are sanely 
defined (in that they are defined counter-clockwise around the normal, 
facing out). This means that each edge could be defined twice but each 
time would be in the opposite direction, so this checks for the reverse 
direction of each edge before adding it to the grid.

I've been using it on my windows box in the command line as "@>php 
C:\path\to\make_wireframe.php E:\path\to\my_model.inc", but included the 
shebang and accounted for forward slashes in the filename so it should 
work on a bash command line with simply "@>/path/to/make_wireframe.php 

An example image: http://cshake.homeip.net/disco/renders/Atka_wireframe.png
(the 'hidden' lines were made by using a semi-transparent solid-color 
version of the original model inside the wires)

On the off-chance this is useful to someone, let me know if there are 
any bugs that aren't due to the dumb way it finds triangles.


Post a reply to this message

Download 'make_wireframe.php.txt' (3 KB)

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