Click here to Skip to main content
15,905,612 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was wondering if someone had an idea of how to import a collada(.dae) or directX(.x) file from google sketchUp and convert it to multiple 2d bool arrays where the boolean is true if the coordinate was inside the object.

Essentially i need:

Multiple layers (maybe with 0.01mm between each)
Each layer containg a 2d array
Each array containing information about if this point was inside the 3d object.

I hope someone have a solution.
Thanks in advance.
Posted
Updated 17-Mar-11 8:18am
v2
Comments
Espen Harlinn 17-Mar-11 16:34pm    
Homework?
Lasse TM 19-Mar-11 16:39pm    
Nope
Espen Harlinn 19-Mar-11 18:21pm    
Care to provide some info on the pupose of those bool arrays?
Lasse TM 20-Mar-11 1:57am    
Im creating a 3d printer.
So i need to know where to put out plastic and not.

Information about loading a DirectX file can be found here[^].

Once your file is loaded then you need to iterate over each point in the array and decide if it is inside the mesh or not. The way to tell if the point is inside the mesh is to cast a ray from the point and determine how many times the ray intersects the mesh. If it intersects the mesh an odd number of times then the point is inside the mesh. An odd number means that it is outside the mesh.

If you follow the method in the first link, then you can use the Mesh.Intersect method. There is plenty of information about ray intersection methods, if you use another loading method.

There are a few articles in CP about this, I'd start with Introduction to collision detection techniques in games (prelude to collision detection in XNA)[^] and Collision detection in XNA[^]. Note that collision detection is closely related to the point in mesh problem and some of the techniques are useful here. For instance using AABB (Axis-Aligned Bounding Box) or enclosing spheres can make the determination of points well outside the mesh easier to calculate.
 
Share this answer
 
Comments
Lasse TM 20-Mar-11 2:23am    
Thanks Graham
It got me started but im struggling a bit with the Mesh.Intersect method.
The IntersectInformations i get seems odd to me.
But it could be me just not doing it right.
Can you give me a example of how to use the Mesh.Intersect?

The model is allways on the positive side of X,Y and Z. Therefore i start with Y and Z set to zero.

So far i have this:
"extrudeValues" is just a list of bools.

public void Analyze(Device device)
        {
            VertexBuffer vertices = _mesh.VertexBuffer;
            GraphicsStream stream = vertices.Lock(0, 0, LockFlags.None);
            Vector3 min,max;
            Geometry.ComputeBoundingBox(stream, _mesh.NumberVertices, _mesh.VertexFormat, out min, out max);
            vertices.Unlock();

            IntersectInformation[] intersectInformations;
            float distanceBetween = 1.0f;
            List<Layer> layers = new List<Layer>();
            Vector3 rayOrigin,rayDirection;
            for (float y = 0; y < max.Y; y += distanceBetween)
            {
                for (float z = 0; z < max.Z; z += distanceBetween)
                {
                    //Set the origin of the ray and get all intersections
                    rayOrigin = new Vector3(max.X + 10, y, z);
                    rayDirection = new Vector3(-10f, 0f, 0f);
                    UpdateRay(rayOrigin,device);
                    
                    _mesh.Intersect(rayOrigin, rayDirection, out intersectInformations);

                    //Do something with the intersectInformations
                    
                    ExtrudeValues<bool> extrudeValues = new ExtrudeValues<bool>();
                    foreach (IntersectInformation intersectInformation in intersectInformations)
                    {
                        //3D Coordinate where intersection occured
                        Vector3 intersectionPoint = rayOrigin + (rayDirection*intersectInformation.Dist);

                    }
                    //}
                }
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900