Duplicating a Node
John Hendrikx
hjohn at xs4all.nl
Tue Mar 19 08:15:26 PDT 2013
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));
> rect.setEffect(r);
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));
rect.setEffect(r);
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:
OOOO
OOOOOOOO
OOOOOOOO
OOOOOOOO
OOOORRRR
RRRRRRRR
RRRRRRRR
RRRRRR
RRR
Instead of:
OOOO
OOOOOOOO
OOOOOOOO
OOOOOOOO
OOOO
RRRR
RRRRRRRR
RRRRRRRR
RRRRRRRR
RRRR
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 :)
--John
>
> Regards,
> Pavel
>
> 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
>> Reflection).
>>
>> 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 effects/clips/transforms.
>>
>> 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?
>>
>> --John
>
More information about the openjfx-dev
mailing list