Duplicating a Node
John_Smith at symantec.com
Wed Mar 20 10:56:45 PDT 2013
Another user was encountering a similar (but different) requirement to John where they wanted to take a Reflection and blur it, which seemed a reasonable request, but was quite difficult to achieve with the current APIs, so I can see where the request for "something (an Effect or NodeReference)" is coming from. Today the only way to get such a thing is to chain the input effects on the Node (which doesn't always do what you need), or snapshot the nodes (but then you need to keep retaking snapshots if you have dynamic content).
The Node duplication request seems to be a relatively infrequent requirement and perhaps it would be difficult to implement, so, though it seems like a nice feature, I'd guess it's implementation wouldn't be high priority. Also, maybe in the future it will be easy to create your own custom effects on Nodes, which might obviate the Node duplication request in some cases.
> The best approximation I can suggest is rendering the node to image via Node.snapshot(...) method (you can specify transform to it) and use this image for the reflection.
The solution I used for blurring a reflection was the same approximation method Pavel suggests of taking a Snapshot:
https://forums.oracle.com/forums/thread.jspa?threadID=2496389 "Thread: Effects on effects"
From: openjfx-dev-bounces at openjdk.java.net [mailto:openjfx-dev-bounces at openjdk.java.net] On Behalf Of Pavel Safrata
Sent: Wednesday, March 20, 2013 7:39 AM
To: openjfx-dev at openjdk.java.net
Subject: Re: Duplicating a Node
I'm afraid something like this is not really supported. The best approximation I can suggest is rendering the node to image via
Node.snapshot(...) method (you can specify transform to it) and use this image for the reflection. With dynamic contents, you will have to find your own way to tell when to re-generate the image..
On 19.3.2013 16:15, John Hendrikx wrote:
> On 18/03/2013 10:22, Pavel Safrata wrote:
>> Hi John,
>> I tried to use reflection on node with PerspectiveTransform and I
>> don't see anything wrong with it - no alternating size, no incorrect
>> reflection. Could you please elaborate on what you are trying to
>> achieve? Code that I used:
>> Rectangle rect = new Rectangle(100, 50, Color.RED);
>> Reflection r = new Reflection();
>> r.setInput(new PerspectiveTransform(50, 40, 100, 40, 170, 80,
>> 0, 80));
> Look at the reflection for this Rectangle instead:
> Rectangle rect = new Rectangle(100, 50, Color.RED);
> Reflection r = new Reflection();
> r.setInput(new PerspectiveTransform(50, 40, 100, 50, 100, 70,
> 50, 80));
> Notice that the Reflection is not what you'd expect for a Node that
> has the appearance of being 3D.
> So, that is not the problem. It is perfectly possible to create a
> Reflection from an object that has a PerspectiveTransform applied to
> it. The problem is that the reflection created is simplistic in that
> it assumes the object must be reflected in a horizontal line somewhere
> below the object (which is fine for 2D stuff, but not if you are
> trying to make your Nodes look 3D with reflections). Please see
> http://www.youtube.com/watch?v=8Mb15bOwIyE and look how the
> reflections there are exactly attached to the bottom of
> PerspectiveTransform'ed Nodes, no spacing.
> When you apply a PerspectiveTransform, the idea is to make the object
> look 3D. The Reflection therefore must also be 3D, which means you
> cannot just create it by copying an upside-down image of the object
> below the PerspectiveTransformed object. Instead the Reflection
> should also be 3D and the line it should reflect in is the bottom line
> of the object AFTER the PerspectiveTransform was applied (and this
> line is not always horizontal). Here's some ASCII art:
> Instead of:
> Now, it is possible to achieve this by reversing the inputs, first
> doing the Reflection, then looking at how Reflection changed the Node,
> then applying a PerspectiveTransform that gets the correct 3D result.
> However, this is very cumbersome, makes assumptions about how
> Reflection will change your Node and does not allow for creation of
> Reflections for Objects that have more than just a rotation on the Y
> axis applied to them.
> This is why I really need something (an Effect or NodeReference) that
> could create a duplicate of a Node :)
>> On 15.3.2013 19:07, John Hendrikx wrote:
>>> Hi list,
>>> I'm trying to achieve an effect that requires me to make a copy of a
>>> Node, apply some effect(s) on it (PerspectiveTransform, Clip, Blend
>>> and perhaps DisplacementMap) and place it in the same scenegraph
>>> together with the original.
>>> It is very similar to what Reflection achieves, but without
>>> alternating the size of the Node, and without the limitations
>>> (specifically, creating the correct Reflection for an object that
>>> has a PerspectiveTransform applied to it already cannot be done with
>>> I would prefer not to have to make an actual copy of the Node, as
>>> they might get out of sync and not display the same content when
>>> they should be. Something like a NodeReference class, that takes
>>> another Node as parameter but applies different
>>> Since the code I'm using for this is based on Cells getting laid
>>> out, I'm toying with the idea of actually asking the provider of
>>> those cells twice for the same cell and applying different
>>> transformations on each, but they might get out of sync and it seems
>>> there should be a better way.
>>> Any ideas or suggestions at how I could best achieve this, or would
>>> it be a new feature?
More information about the openjfx-dev