Jump to content
  • Advertisement
Sign in to follow this  
luckyyyyyy

convert 3D model to 2D slices

This topic is 3960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello guys... i want to convert my 3D model into 2D slices...means for marching cube algorithm...i need to convert 3D model into 2D model(no of 2D slices)... how can i do this... plz help me...

Share this post


Link to post
Share on other sites
Advertisement
If I understood you correctly, just compute the intersection between the 'slice plane' and each triangle of the mesh. If the triangle intersects the plane, get the intersection points(one point if the one vertex of the triangle touches the plane, two points(one segment) if the triangle crosses the plane, no points if the triangle does not cross the plane or if the triangle is parallel to the plane, get each edge of the triangle) and build the edges of the 2D slice from them . . . well, not sure if this helps nor if its the best approach, I'm just trying to clear things up, but anyway HTH :)

Share this post


Link to post
Share on other sites
This gives you a wireframe representation


for each polygon P
for each line L in polygon P
if line intersects polygon
if line (L-1 wrapped to last polygon if L == 0) also hits polygon
draw a line between those intersection points
else
draw a point for the intersection point.
end if
end if
next
next





this fails in the (possibly?) rare case that all lines on the polygon intersect the plane, such as when the polygon is on the same plane as the slice.

I have code for triangles and planes to collide with rays, lines and line segments and return the collision points. If you want to learn this stuff yourself, start with vector maths, then learn to collide lines with planes. rays and line segments are a subset of lines. You will need to be able to do the following functions:


bool line_vs_plane(line * l, g_vector t1,
plane * p, g_vector t2,
g_vector & contact_point
);
//line is assumed to be infinate in both directions

bool ray_vs_plane(line * l, g_vector t1,
plane * p, g_vector t2,
g_vector & contact_point
);
//ray is assumed to be infinate in + direction away from its origin

bool point_inside_triangle(g_vector pt, g_vector t1,
triangle * p, g_vector t2
);
//using the angle test

bool line_vs_triangle(line * l, g_vector t1,
triangle * t, g_vector t2,
g_vector & contact_point);
//infinite in all directions

bool ray_vs_triangle(line * l, g_vector t1,
triangle * t, g_vector t2,
g_vector & contact_point);
//infinate along its direction vector

bool lineseg_vs_triangle(line * l, g_vector t1,
triangle * t, g_vector t2,
g_vector & contact_point);
//between two points

bool triangle_vs_triangle(triangle * p1, g_vector t1,
triangle * p2, g_vector t2,
g_vector & contact_point);
//uses up to six edge tests, returns true on the first contact

bool line_vs_aabb(line * l, g_vector t1,
aabb * b, g_vector t2,
float & contact_point);


bool line_vs_mesh(line * l, g_vector t1,
collision_mesh * m, g_vector t2,
g_vector & contact_point);
//brute force method; recursively test every polygon until an intersection occurs






from there, testing compound shapes such as a triangle simply involves a series of lower level collision tests, such as line vs plane followed by point vs polygon.

Share this post


Link to post
Share on other sites
You could possibly try using rendering your 3d model using your favourite API and using orthogonal projection and a combination of z testing and clipping to get the 2d render at different projection along the slice axis.

Might be an easier way to do it then doing intersection tests.

Share this post


Link to post
Share on other sites
my model is a triangular mesh......
which one from above function is useful for me......

line vs plane
or
line vs triangle

please clear me...



and is there any other method to marching cube......just first convert triangular data to cube data.....then draw mesh of voxels...

Share this post


Link to post
Share on other sites
I dont understand you clearly what you wana do but heres possibility that this libbrary will help you: http://www.geuz.org/gl2ps/

It has export to pdf, svg and postscript. You can use output files to coopeate with your application. Just parse it.

Also usefull can be svgl lib to draw svg in opengl.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!