如何计算Flash/动作脚本中形状之间的交集? (访问形状的段和节点?)
我需要计算 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AFAIK,无法检索闪存中任何给定形状的数据。不幸的是,这是内部的事情。但是,您仍然应该能够使用 Pixel Bender 内核计算两个形状之间面积的足够近似值。使用 ShaderJob,您可以异步运行计算,从而不会锁定 UI。
这个想法是这样的:
我不确定这是否比使用 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:
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.
如果有答案,我会很着迷,但据我所知,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