在 raphaeljs 中设置不是真正的组?变换顺序 [英] Sets in raphaeljs not real groups? Transform order

查看:21
本文介绍了在 raphaeljs 中设置不是真正的组?变换顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了关于集合以及如何应用转换的问题.我来自图形背景,所以我熟悉场景图以及普通的 SVG 组语法,但 Raphael 使我感到困惑.假设我有一个圆和一个集合,我想对其应用变换.

I'm having an issue with sets and how transforms are applied. I'm coming from a graphics background, so I'm familiar with scene graphs as well as the normal SVG group syntax, but Raphael is confusing me. Say I have a circle and a set, on which I want to apply a transform.

circle = paper.circle(0,0.5)
set = paper.set()

如果我先添加圆圈,然后变换,它就可以工作.

If I add the circle first, and then transform, it works.

set.push circle
set.transform("s100,100")

制作一个半径为 50 的圆.但是,如果我颠倒顺序,

To make a 50 radius circle. If I reverse the order, however,

set.transform("s100,100")
set.push circle

未应用转换.

这似乎会破坏许多渲染和动画类型算法,其中您的组/变换保存您的关节状态,您可以向它们添加或删除对象,而不是每次都重新创建整个变换.文档中是否有我没有看到的选项可以解决这个问题,还是为了简化而放弃了这个功能?缺少它似乎很奇怪,因为它在 SVG 本身的组层次结构中直接和轻松地得到支持......我是否需要手动将集合中的变换应用到在集合被转换了?

This seems as though it will break many, many rendering and animation type algorithms, where your groups/transforms hold your articulation state, and you add or remove objects to them instead of recreating the entire transform every time. Is there an option somewhere in the documentation that I am not seeing that addresses this, or was this functionality discarded in favor of simplicity? It seems very odd to be missing, given that it is supported directly and easily in the group hierarchy of SVG itself... do I need to manually apply the transform from the set to any children added after the set is transformed?

推荐答案

Raphaël 的 set 仅旨在通过聚合 element 相关动作并将它们(通过代理设置级别中的相应方法)依次委托给每个形状.

Raphaël's sets are merely intended to provide a convenient way of managing groups of shapes as unified sets of objects, by aggregating element related actions and delegating them (by proxying the corresponding methods in the set level) to each shape sequentially.

缺失似乎很奇怪,因为它是直接支持的并且很容易在 SVG 本身的组层次结构中...

It seems very odd to be missing, given that it is supported directly and easily in the group hierarchy of SVG itself...

好吧,Raphaël 并不是试图将 SVG 规范提升为基于 JavaScript 的 API,而是提供矢量图形操作的抽象,而不管底层实现(无论是现代浏览器中的 SVG,还是 IE 中的 VML<9).因此,sets 绝不是 SVG 组的表示.

Well, Raphaël is not an attempt to elevate the SVG specs to a JavaScript based API, but rather to offer an abstraction for vector graphics manipulation regardless of the underlying implementation (be it SVG in modern browsers, or VML in IE<9). Thus, sets are by no means representations of SVG groups.

我是否需要手动将转换从集合应用到任何设置转换后添加的子项?

do I need to manually apply the transform from the set to any children added after the set is transformed?

绝对不是,您只需要确保在应用转换之前将任何形状添加到集合中即可.

Absolutely not, you only need to make sure to add any shapes to the set before applying transformations.

这篇关于在 raphaeljs 中设置不是真正的组?变换顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆