Print

Print


Hi again,

another related java3d/portrayal question,

How are you supposed to remove an item from the display?
I was trying to use,

FieldPortrayal.setPortrayalForObject(java.lang.Object obj, null)

Which should remove the portrayal from the field?
However, this doesn't seem to change the display.

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.