将3D模型转换为多个布尔数组 [英] Converting a 3d model to multiple bool arrays

查看:79
本文介绍了将3D模型转换为多个布尔数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人想过如何从google sketchUp导入collada(.dae)或directX(.x)文件并将其转换为多个2d bool数组,如果坐标在对象.

本质上我需要:

多层(每层之间可能有0.01mm)
每层包含一个二维数组
每个数组都包含有关此点是否在3d对象内部的信息.

希望有人能解决.
在此先谢谢您.

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.

推荐答案

有关加载DirectX文件的信息,请参见^ ].

加载文件后,您需要遍历数组中的每个点并确定它是否在网格内.判断点是否在网格内的方法是从该点投射射线并确定射线与网格相交的次数.如果与网格相交的次数是奇数次,则该点位于网格内.奇数表示它在网格之外.

如果遵循第一个链接中的方法,则可以使用Mesh.Intersect方法.如果使用其他加载方法,则有关射线相交方法的信息很多.

CP中有一些与此有关的文章,我将从游戏中的碰撞检测技术简介(XNA中的碰撞检测先例) [ XNA中的碰撞检测 [
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.


能否举个例子说明如何使用Mesh.Intersect?

该模型始终位于X,Y和Z的正侧.因此,我从Y和Z设置为零开始.

到目前为止,我有这个:
"extrudeValues"只是布尔列表.

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);

                    }
                    //}
                }
            }
        }


这篇关于将3D模型转换为多个布尔数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆