JSFL - Element.rotation 为 NaN

发布于 2024-12-08 19:12:09 字数 586 浏览 0 评论 0原文

我正在用 JSFL 编写一个导出器,将 Flash 动画导出为可以在自定义播放器中重播的格式。导出器基本上遍历时间线和每个关键帧处的所有元素,并写出有关元素的信息,包括其位置、旋转、比例等。

我在获取某些元素的旋转时遇到问题,它出来了作为 NaN。最常见的原因是元素被翻转(修改->变换->水平翻转),尽管我认为在其他情况下也可能发生这种情况。到目前为止,如果 someElement.rotation 为 NaN,我已经通过写出 someElement.skewX 而不是 someElement.rotation 来解决这个问题(请参阅 这里是我的一些相关代码,它也尝试检测是否翻转已经发生)。

到目前为止,这是有效的,因为在这些情况下 skewX 值与我期望的旋转值相同。但现在我希望导出器能够处理倾斜和旋转的导出元素,因此我确实需要为旋转提供适当的值。如何从 Flash 中提取正确的旋转值?我可以做些什么来从矩阵中获取旋转值,或者首先阻止旋转为 NaN 吗?

I'm writing an exporter in JSFL, to export Flash animations into a format that can be replayed in a custom player. The exporter basically iterates through the timeline and through all the elements at each keyframe, and writes out information about the element, including its position, rotation, scale, etc.

I have a problem with getting the rotation out of certain elements, it comes out as NaN. The most common cause of this is if an element has been flipped (Modify->Transform->Flip Horizontal), although I think it can happen in other circumstances as well. Up until now I've got around the problem by writing out someElement.skewX instead of someElement.rotation if someElement.rotation is NaN (See here for some of my related code, which also tries to detect if flipping has occurred).

This has worked so far because in those cases the skewX value is the same as the value I'd expect for the rotation. But now I want the exporter to be able to handle exporting elements which are skewed as well as rotated, so I really need to have proper values for the rotation. How can I extract proper rotation values from Flash? Is there something I can do to get rotation values out of the matrix, or to stop rotation from being NaN in the first place?

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

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

发布评论

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

评论(1

最冷一天 2024-12-15 19:12:09

我找到了一种从对象矩阵获取旋转角度的方法。

element = someobject;
//Angle in radians
var angle = Math.atan2(element.matrix.b, element.matrix.a);
//convert to degrees
var degrees = angle * 180 / Math.PI;

不确定这会考虑到物体是否倾斜。

从旋转矩阵中提取角度 (inkscapeforum.com)

I found a way to get the rotation angle from the object's matrix.

element = someobject;
//Angle in radians
var angle = Math.atan2(element.matrix.b, element.matrix.a);
//convert to degrees
var degrees = angle * 180 / Math.PI;

I am not sure this takes into account if the object is skewed.

extract angle from rotation matrix (inkscapeforum.com)

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