简体   繁体   English

如何将 3d 模型转换为点数组

[英]How to convert a 3d model into an array of points

I'm building my own 3d engine, I need to import 3d models into it, but I don't know how to do it.我正在构建自己的 3d 引擎,我需要将 3d 模型导入其中,但我不知道该怎么做。 I wonder if it is possible to convert a 3d model into an array of points;我想知道是否可以将 3d 模型转换为点数组; if it is possible, how do you do it?如果可能,你是怎么做的?

This isn't something I've done before;这不是我以前做过的事情; but the premise is interesting so I thought I'd share my idea as I have worked with grids (pretty much an array) in 3D space during my time at university.但前提很有趣,所以我想我会分享我的想法,因为我在大学期间曾在 3D 空间中使用过网格(几乎是一个数组)。

If you consider 3D space, you could represent that space as a three dimensional array quite simply with each dimension representing an axis.如果您考虑 3D 空间,您可以将该空间表示为一个 3 维数组,非常简单,每个维度代表一个轴。 You could then treat each element in that array as a point in space and populate that with a value (say a Boolean of true/false, 1/0) to identify the points of your model within that three dimensional space.然后,您可以将该数组中的每个元素视为空间中的一个点,并用一个值(例如布尔值 true/false,1/0)填充该点,以识别模型在该三维空间中的点。

All you'd need is the Height, Width and Depth of your model, with each one of these being the dimensions in your array.您只需要模型的高度、宽度和深度,其中每一项都是数组中的尺寸。 Populate the values with 0/false if the model does not have a point in that space, or 1/true if it does.如果模型在该空间中没有点,则使用 0/false 填充值,如果有,则使用 1/true 填充值。 This would then give you a representation of your model as a 3D array.然后,这将为您提供模型的 3D 数组表示。

3d models come in file formats such as .obj, .stl, .fbx and many many more. 3d 模型采用 .obj、.stl、.fbx 等文件格式。 These files, which represent the 3d model, are usually lists of vertices themselves (or other data about the model, such as normals or texture coordinates).这些表示 3d 模型的文件通常是顶点列表本身(或有关模型的其他数据,例如法线或纹理坐标)。 You can find the formats of these files online and in your engine, read from the file just as you would any other file and put the data you want into arrays.您可以在线和在您的引擎中找到这些文件的格式,就像读取任何其他文件一样从文件中读取并将所需的数据放入数组中。

I would recommend starting by downloading some 3d model in a .obj format and then opening it in a text editor.我建议首先下载一些 .obj 格式的 3d 模型,然后在文本编辑器中打开它。 Look at what is inside and think about you can read the information you want from it.看看里面是什么,想想你可以从中读取你想要的信息。 You can also find more about the .obj file format here您还可以在此处找到有关 .obj 文件格式的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM