The capability bits I included below allow you to REPLACE the
transparency object of the appearance, but not MODIFY that
transparency object. Hence #1 won't work.
You could probably get #1 working with adding something like this to
the constructor:
TransparencyAttributes ta = appearance.getTransparencyAttributes();
ta.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
ta.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
ta.setCapabilityIsFrequent(TransparencyAttributes.ALLOW_VALUE_READ);
ta.setCapabilityIsFrequent(TransparencyAttributes.ALLOW_VALUE_WRITE);
Sean
On Nov 15, 2006, at 6:58 AM, Michael Lees wrote:
> Hi Sean (and Bruno)
>
> Thanks for the replies.
>
> First of, let me say I've tried 3 different ways of changing the
> transparency.
>
> From my previous mail....
> >> public sim.portrayal3d.simple.CubePortrayal3D representation;
> >> representation = new sim.portrayal3d.simple.CubePortrayal3D
> (colour,size)
>
> The 3 different ways...
> 1. - Modifying transparency component directly
> representation.appearance.getTransparencyAttributes
> ().setTransparency(trans);
>
> 2. - Creating a new colour with new alpha value
> java.awt.Color colour2 = new java.awt.Color(colour.getRed(),
> colour.getGreen(), colour.getBlue(), (int)Math.round(trans*255));
> representation.appearance = CubePortrayal3D.appearanceForColor
> (colour2);
>
> 3. - Creating a new transparency attribute object
> representation.appearance.setTransparencyAttributes(new
> TransparencyAttributes(TransparencyAttributes.BLENDED, trans));
>
> First off, 2 works without any modification to MASON
>
> I tried as Sean suggested and...
> 3 now works.
>
> However, 1 still does not work, exception given:
>
> javax.media.j3d.CapabilityNotSetException: Transparency: no
> capability to set component
>
>
> Sorry, I appreciate this is probably a java3d question and thanks
> again for you help.
>
> Is there a right way to do this?
>
> Thanks
>
> -Mike
>
> Sean Luke wrote:
>> Michael, you don't want to replace the appearance of an object.
>> That's what Shape3D.ALLOW_APPEARANCE_WRITE does. What you want to
>> do is be able to do is change the Appearance's attributes itself,
>> something like this:
>> public CubePortrayal3D(Appearance appearance, boolean
>> generateNormals,
>> boolean generateTextureCoordinates, float scale)
>> {
>> this.generateNormals = generateNormals;
>> this.generateTextureCoordinates = generateTextureCoordinates;
>> this.appearance = appearance;
>> // changed here
>> appearance.setCapability
>> (Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
>> appearance.clearCapabilityIsFrequent
>> (Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
>> appearance.setCapability
>> (Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
>> appearance.clearCapabilityIsFrequent
>> (Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
>> this.scale = scale;
>> for(int i=0;i<scaledVerts.length;i++)
>> scaledVerts[i] = verts[i]*scale;
>> }
>> But that might not work, because when the portrayal creates the
>> scene object, assigning it the Appearance, Java3D may *copy* the
>> appearance, and so changing the appearance later on doesn't change
>> the copy that's being used. You'll have to see for yourself to
>> determine this. If it's the case that it doesn't work, then I
>> have some other ideas.
>> Sean
>> On Nov 14, 2006, at 9:41 AM, Michael Lees wrote:
>>> Hi,
>>>
>>> I'm trying to vary the transparency of a cube during the
>>> simulation execution.
>>>
>>> I define the following....
>>>
>>> public sim.portrayal3d.simple.CubePortrayal3D representation;
>>> representation = new sim.portrayal3d.simple.CubePortrayal3D
>>> (colour,size)
>>>
>>>
>>> And then attempt to change the transparency by...
>>>
>>> representation.appearance.getTransparencyAttributes
>>> ().setTransparency(1.0f);
>>>
>>>
>>> I noticed that nothing was appearing, looked like the cubes had 0
>>> transparency.
>>>
>>> Surrounding the setTransparency call with a try catch I realised
>>> the follow exception was being thrown...
>>>
>>> javax.media.j3d.CapabilityNotSetException: Appearance: no
>>> capability to get transparencyAttributes
>>>
>>>
>>> Looking into CubePortrayal3D.getModel I found the following...
>>>
>>> 131: Shape3D localShape = new Shape3D(quadArray,appearance);
>>> 132: localShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
>>>
>>> Which should allow you to change the appearance properties of the
>>> Shape3D.
>>>
>>> However, is the problem that I'm calling getTransparencyAttributes
>>> () when localShape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
>>> has not been set?
>>>
>>> Or I'm I going about this all the wrong way? How should I change
>>> the transparency of a CubePortrayal3D (or more generally any
>>> Portrayal3D).
>>>
>>> Thanks
>>>
>>> --Michael Lees
>>>
>>>
>>> This message has been checked for viruses but the contents of an
>>> attachment
>>> may still contain software viruses, which could damage your
>>> computer system:
>>> you are advised to perform your own checks. Email communications
>>> with the
>>> University of Nottingham may be monitored as permitted by UK
>>> legislation.
>
>
>
>
> This message has been checked for viruses but the contents of an
> attachment
> may still contain software viruses, which could damage your
> computer system:
> you are advised to perform your own checks. Email communications
> with the
> University of Nottingham may be monitored as permitted by UK
> legislation.
|