如何计算Flash/动作脚本中形状之间的交集? (访问形状的段和节点?)

发布于 2024-10-08 19:01:20 字数 310 浏览 2 评论 0原文

我需要计算 Flash/动作脚本中两个形状之间的交集。
问题是我无法访问形状的节点和线段以及它们的坐标,因此我无法计算它。
你知道一个方法吗?

编辑:进一步解释: 我将不规则多边形从 EPS 文件导入到其中包含形状的影片剪辑中。
该问题的数学解决方案很简单,但要做到这一点,我需要通过 AS 代码访问构成多边形的节点的坐标,但我尝试过但没有成功。
这就是我正在努力实现的目标。

edit2:驳回这个问题。 这是不可能的。我应用的解决方法是将多边形保存在 SVG 中并解析它们以获取节点列表。然后将该列表提供给闪存以在运行时计算交叉点和面积。

I need to calculate the intersection between two shapes in flash / action script.
The problem is I can't access the shape's nodes and segments, and their coordinates, so there's no way I can calculate this.
Do you know a way?

edit: further explanation:
I imported irregular polygons from an EPS file to a movieclip with shapes in it.
The mathematical solution to the problem is trivial, but to do that, I need to access by AS code to the coordinates of the nodes that make up the polygons, which I tried with no success.
That is what I'm trying to accomplish.

edit2: dismiss this question.
It's not possible. The workaround I'm applying is to save the polygons in SVG and parse them to get a list of nodes. then will feed that list to flash to calculate the intersection and areas on runtime.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

梦一生花开无言 2024-10-15 19:01:20

AFAIK,无法检索闪存中任何给定形状的数据。不幸的是,这是内部的事情。但是,您仍然应该能够使用 Pixel Bender 内核计算两个形状之间面积的足够近似值。使用 ShaderJob,您可以异步运行计算,从而不会锁定 UI。

这个想法是这样的:

  1. 捕获第一个形状的位图
  2. 捕获第二个形状的位图
  3. 使用 Pixel Bender 内核创建 ShaderJob,并使用两个位图作为输入。对于每个像素,内核将计算形状是否相交,以及可能相交的程度。使用输出通道之一作为计算结果。
  4. 获取结果输出并将其全部求和以获得最终的 alpha 值。

我不确定这是否比使用 SVG 方法更麻烦,但它至少是一种替代方案。计算两个形状边界的交集并仅捕获形状中相交矩形的位图可能有意义。这是一个额外的步骤,但至少它可能会提高内存效率,并且在 CPU 时间方面也可能会更高效。

AFAIK, there's no way of retrieving the data for any given shape in flash. It's something internal unfortunately. However, you should still be able to calculate a sufficient approximation of the area between your two shapes by using a Pixel Bender kernel. Using a ShaderJob, you can run the calculation asynchronously and thus not locking the UI.

The idea goes something like:

  1. Capture bitmap of the first shape
  2. Capture bitmap of the second shape
  3. Create ShaderJob using your Pixel Bender kernel, using the two bitmaps as inputs. For each pixel, the kernel will calculate wether the shapes intersect or not, and possibly by how much. Use one of the output channels for the result of the calculation.
  4. Take the resulting output and sum it all up for a final alpha value.

I'm not sure if this is less of a hassle to you than using your SVG approach, but it's an alternative at least. It might make sense to calculate the intersection of the two shape's bounds and only capture a bitmap of the intersecting rectangles in the shapes. It is an extra step, but at the very least it's likely more memory efficient, possibly more efficient in terms of cpu time as well.

风尘浪孓 2024-10-15 19:01:20

如果有答案,我会很着迷,但据我所知,AS3 的 Shape 类非常稀疏。

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3 /flash/display/Shape.html

令人烦恼的是,等效的 JSFL 类充满了您想要的好东西。我想这对你没有任何用处吧?

http://livedocs.adobe.com/flash/9.0/main/00004384 .html#wp119221

I'll be fascinated if there is an answer, but as far as I know the Shape class of AS3 is pretty sparse.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Shape.html

Annoyingly, the equivalent JSFL class is full of goodies for exactly what you want. I don't suppose that would be of any use to you?

http://livedocs.adobe.com/flash/9.0/main/00004384.html#wp119221

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