PDA

View Full Version : mesh/object exporter for flash


48design
07-19-2007, 07:46 PM
hey!

I found a nice 3d engine for flash on the web and thought about programming an exporter.
what I got so far are the vertex coords.

the flash syntax is this one (a pyramid in this case):
// Define the object co-ordinate arrays, based on a standard Cartesian coordinate system
var XCoords = [0,100,100,-100,-100];
var YCoords = [-200,100,100,100,100];
var ZCoords = [0,-100,100,100,-100];
// Imagine this as a 'join-the-dots' type of array. Each entry points to an index into the Screen arrays. Each pair represents a single line. For instance '0,1' represents a line from point '0' to point '1'.
var Lines = [0,1,0,2,0,3,0,4,1,2,2,3,3,4,4,1];

The problem is to connect the vertices with lines. I don't know how to get the edges/connections!

I attached the maxscript I got so far...

mustan9
07-19-2007, 08:51 PM
I think you would want to use the edge visibily of the mesh to define the lines. Otherwise just create 3 lines for each triangle. (or 4 for quads).

48design
07-19-2007, 11:57 PM
mhhh.... it helped a bit! thx

a simple box should have this (was included in 3d engine):
var Lines = [0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7];

when I export a box I get:
var Lines = [0,2,3,1,4,5,7,6,0,1,5,4,1,3,7,5,3,2,6,7,2,0,4,6];

my function:

-- LINES
format "var Lines = [" to:out_file
num_faces = tmesh.numfaces
vis_faces = #()
for f = 1 to num_faces do
(
theF = 1

face = getFace tmesh f
ec = 1
for a = 1 to 3 do
(
if (getEdgeVis tmesh f a) == true then
(
vis_faces[ec] = face[a]
ec += 1
)
)

vis_face_verts = ""
for l = 1 to vis_faces.count do
(
vis_face_verts = (vis_faces[theF] as integer - 1) as string + "," + (vis_faces[l] as integer - 1) as string
)

format "%" vis_face_verts to:out_file
if f != num_faces then
(
format "," to:out_file
)

theF += 1
)
format "];" to:out_file


looks really cmplicated, I know :D
but it's late here in germany and I am very tired...

48design
07-20-2007, 12:40 PM
I don't find an answer :shrug:

what I try to do is:
- find all faces (triangles)
- for each face get the visible edges
- write an array for the connections (vertex to vertex)


it does not work :sad:

mustan9
07-20-2007, 07:47 PM
a simple box should have this (was included in 3d engine):
var Lines = [0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7];

when I export a box I get:
var Lines = [0,2,3,1,4,5,7,6,0,1,5,4,1,3,7,5,3,2,6,7,2,0,4,6];

Your first example has the list of edges sorted from least to most, and organized. Where as the second line as them in the winding order found in the geometry.

I think the second line is perfectly valid. If I re-order some of the edge (I won't do all, because that to much work). You would get this.

var lines = [0,1,0,2,2,0];

As you can see, the triangle that uses vertexs 0,1,2 are represented in the exported box correctly. I assume the other triangles are as well.

I did not review your source code, because your varialble names are hard to read. Also the syntax coloring makes it hard to read.

CGTalk Moderation
07-20-2007, 07:47 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.