将 3D 模型转换为体素场
我需要编写一些代码将四边形数组转换为体素字段。 让它工作应该很容易,但让它快速运行就不是那么简单了。
有谁知道我可以使用的任何库或源代码?我确信以前一定有人这样做过。
编辑: 该算法还需要用体素填充模型内部。光有壳是不行的。
I need to write some code to convert an array of quads into a voxel field.
Making it work should be easy, but making it fast won't be so trivial.
Does anyone know of any libs or source code that I can use? I'm sure someone must've done this before.
edit:
The algorithm needs to fill the inside of the model with voxels too. Just a shell won't do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Alexandre C. 发布的体素化链接看起来不错。
以下简要概述了我们在将常规四边形/三角形模型转换为用于光子/电磁仿真的折射率/ε 值的立方阵列时如何解决此问题。
在 x/y/z 循环中的每个点,对照 BSP 树检查该点。如果它位于实体内部,则在该点创建一个体素,并根据源模型(从 BSP 节点引用)设置其属性(颜色、纹理坐标等)。
(优化提示:如果您最内层的循环沿 Y 轴(垂直轴)并且您正在创建地形或 XZ 方向的表面,则您可以随时退出 Y 循环创建一个体素。)
保存
构建 BSP 是唯一半复杂的部分(而且它比乍一看要容易得多),但它已在整个网络上被记录下来。这几乎适用于任何模型形状,并且还为您提供了一棵漂亮的树,可用于碰撞检测和可见性确定等。
另请注意,整个过程应该在编译时或使用专用工具进行(显然,这会生成一个包含运行时使用的树和体素字段的文件)。如果您使用 XNA,那么将任何内容导入到内容管道中都非常容易。
The voxelation link posted by @Alexandre C. looks good.
Here's a brief overview of how we solved this problem when converting regular quad/triangle models to a cubical array of indices of refraction/epsilon values for a photonics/EM simulation.
At each point in your x/y/z loop, check the point against the BSP tree. If it's inside an entity, create a voxel at that point, and set it's attributes (color, texture coordinates, etc) based on the source model (as referenced from your BSP node).
(Optimization Hint: If your inner-most loop is along the Y axis (vertical axis) and you're creating terrain or an XZ-oriented surface, you can exit the Y loop whenever you create a voxel.)
Save
Building the BSP is the only semi-complicated part (and it's a lot easier than it looks at first glance), but it's been documented out the ying-yang all over the web. This will work for pretty much any model shape, and also gives you a nice tree you can use for collision detection and visibility determination, among other things.
Also, note that this whole process should happen at compile time or using a dedicated tool (which would, obviously, produce a file containing the tree and voxel field that you would use at run time). If you're using XNA, it's pretty easy to import anything into the content pipeline.
检查行进立方体 算法。我想你需要根据你的问题反转它!;)
Check Marching cubes algorithm. I guess you need reverse it in context of your problem!;)