将 3D 模型转换为体素场

发布于 2024-10-05 11:20:48 字数 153 浏览 5 评论 0原文

我需要编写一些代码将四边形数组转换为体素字段。 让它工作应该很容易,但让它快速运行就不是那么简单了。

有谁知道我可以使用的任何库或源代码?我确信以前一定有人这样做过。

编辑: 该算法还需要用体素填充模型内部。光有壳是不行的。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一江春梦 2024-10-12 11:20:48

@Alexandre C. 发布的体素化链接看起来不错。

以下简要概述了我们在将常规四边形/三角形模型转换为用于光子/电磁仿真的折射率/ε 值的立方阵列时如何解决此问题。

  1. 创建场景的 BSP 树。 (是的,确实如此)
  2. 在模型或解决方案空间中定期对 X、Y、Z 进行迭代。 (每个轴的间隔应等于所需的体素尺寸。)
  3. 在 x/y/z 循环中的每个点,对照 BSP 树检查该点。如果它位于实体内部,则在该点创建一个体素,并根据源模型(从 BSP 节点引用)设置其属性(颜色、纹理坐标等)。
    优化提示:如果您最内层的循环沿 Y 轴(垂直轴)并且您正在创建地形或 XZ 方向的表面,则您可以随时退出 Y 循环创建一个体素。)

  4. 保存

  5. 利润!

构建 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.

  1. Create a BSP tree of your scene. (Yes, really)
  2. Iterate at regular intervals over X,Y,Z across your model or solution space. (The interval in each axis should be equal to the desired voxel dimensions.)
  3. 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.)

  4. Save

  5. Profit!

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.

逆流 2024-10-12 11:20:48

检查行进立方体 算法。我想你需要根据你的问题反转它!;)

Check Marching cubes algorithm. I guess you need reverse it in context of your problem!;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文