Hi Jay,
It looks to me like you're not setting the needed capability bits right on
the Appearance object as follows:
highLightAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
highLightAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
Hope this helps,
-guillermo
jay mistry wrote:
> I wonder if you can help me. I?m trying to change the colour of a
> Primitive when I click on it, in this case a Sphere, but I keep getting
> a ?capability not set exception?.
> I?ve tried using
> sphere.setCapability(Sphere.ENABLE_APPEARANCE_MODIFY);
>
> however I still get an exception.
> As Primitives are not inherited from Shape3D cannot use
> ALLOW_APPEARANCE_READ and ALLOW_APPEARANCE_WRITE.
>
> Is there something that I should be doing as well as the above?
>
> Thanks for your time.
>
> Here is some of my code:
>
> Class Main{
>
> //methods to set bounds, appearance etc.
>
> Sphere sphere = new Sphere(0.2f,app);
> sphere.setCapability(Sphere.ENABLE_APPEARANCE_MODIFY);
>
> //methods to add sphere to scene and add Behavior
>
> }
>
> Also: HighLightBehavior
>
> import javax.media.j3d.*;
>
> import java.util.*;
> import java.awt.*;
> import java.awt.event.*;
> import com.sun.j3d.utils.geometry.*;
> import com.sun.j3d.utils.behaviors.picking.*;
> import javax.vecmath.*;
>
> // The MusicBehavior class will process mouse events
>
> public class HighLightKeyBehavior extends Behavior {
>
> // Declare class variables and constants
>
> BoundingSphere bounds;
>
> Appearance savedAppearance = null;
>
> Appearance highLightAppearance;
>
> Primitive oldShape;
>
> int x=0;//initialse mouse x co-ordinate
>
> int y=0;//initialse mouse y co-ordinate
>
> Primitive shape;
>
> // Portion of the scene graph to operate picking on.
>
> protected PickObject pickScene;
>
> // Define the triggers that will wake up the class methods to do
> // something
>
> WakeupCriterion criterion[] = {
>
> new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED),
>
> new WakeupOnAWTEvent(WindowEvent.WINDOW_ACTIVATED),
>
> new WakeupOnElapsedTime( 15000 ) };
>
> WakeupCondition conditions = new WakeupOr(criterion);
>
> public HighLightKeyBehavior(BranchGroup root,Canvas3D canvas){
>
> pickScene = new PickObject(canvas, root);
>
> Color3f white = new Color3f(1.0f, 1.0f,1.0f);
>
> Color3f black = new Color3f(0.0f, 0.0f,0.0f);
>
> Color3f highLightColor = new Color3f(0.0f, 1.0f,0.0f);
>
> Material highLightMaterial = new Material(highLightColor, black,
>
> highLightColor, white, 80.0f);
>
> highLightAppearance = new Appearance();
>
> highLightAppearance.setMaterial(new Material(highLightColor,black,
>
> highLightColor, white, 80.f));
>
> }
>
> // Behavior class has to have an intialization method.
> // This method is invoked by the Java 3D behavior scheduler.
> // Classes that extend Behavior must provide their own init
> // method.
>
> public void initialize() {
>
> bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100);
>
> initialize(bounds);
>
> }
>
> public void initialize(BoundingSphere boundry) {
>
> wakeupOn(conditions);
>
> setSchedulingBounds(boundry);
>
> }
>
> // method that returns an ID number when a key is clicked
> // by the mouse
>
> public void highLightKey(){
>
> // Find the currently selected "key" which is a Box
>
> // subclass of Primtive.
>
> shape = (Primitive)pickScene.pickNode(
>
> pickScene.pickClosest(x, y, PickObject.USE_BOUNDS),
>
> PickObject.PRIMITIVE);
>
> /**if (oldShape != null) {
>
> oldShape.setAppearance(savedAppearance);
>
> }**/
>
> if (shape != null){
>
> shape.getShape(Sphere.BODY);
>
> shape.getCapability(Primitive.ENABLE_APPEARANCE_MODIFY);
>
> //savedAppearance = shape.getAppearance();
>
> //oldShape = shape;
>
> shape.setAppearance(highLightAppearance);
>
> System.out.println("NOTNULL");
>
> }
>
> }
>
> //method to handle mouseEvents uses super class InputEvent to filter
> raw user input
>
> // event types of MouseEvent
>
> public void processMouseEvent(MouseEvent evt) {
>
> // LEFT Mouse pressed
>
> if (evt.getID()==MouseEvent.MOUSE_PRESSED &&
>
> evt.getModifiers()==MouseEvent.BUTTON1_MASK) {
>
> switch (evt.getModifiers()) {
>
> case MouseEvent.BUTTON1_MASK:
>
> // Left Button generates X & Y
>
> x = evt.getX();
>
> y = evt.getY();
>
> break;
>
> }
>
> highLightKey();
>
> System.out.println("YES");
>
> return;
> }
>
> return;
>
> } // END processMouseEvent
>
> // This method gets called in a loop during runtime
> // execution by the Behavior scheduler when the WakeUpCondition
> // is detected. Classes that extend Behavior must provide
> // their own processStimulus method.
> public void processStimulus(Enumeration criteria) {
>
> // Define state variables
> WakeupCriterion wakeup;
> AWTEvent[] evt=null;
> boolean timer=false;
>
> while( criteria.hasMoreElements() ) {
>
> wakeup = (WakeupCriterion)criteria.nextElement();
>
> if (wakeup instanceof WakeupOnAWTEvent) {
> evt=((WakeupOnAWTEvent)wakeup).getAWTEvent();
> timer = false;
> }
> else if (wakeup instanceof WakeupOnElapsedTime) {
> timer = true;
> }
>
> // When an event has been detected, filter the event
> // type and call the appropriate method to handle the
> // event.
> if (evt!=null)
> for(int i=0; i<evt.length; i++) {
>
> if (evt[i] instanceof MouseEvent) {
> processMouseEvent((MouseEvent)evt[i]);
> timer = false;
> }
>
> } // END for loop
>
> // Inform the Java3D scheduler to wake up on specified
> // conditions.
> wakeupOn(conditions);
>
> } // END WHILE loop
>
> } // END ProcessStimulus
>
> } // END Class
>
> Next Download Attachments
>
>
>
>
> Back to Inbox
>
> Privacy Policy- Terms of Service - Guidelines
> Copyright � 1994-1999 Yahoo! Inc. All rights reserved.
>
> __________________________________________________
> Do You Yahoo!?
> Bid and sell for free at http://auctions.yahoo.com
begin:vcard
n:Gutierrez;Guillermo
tel;fax:407-984-6323
tel;work:407-984-6543
x-mozilla-html:TRUE
org:Harris Corporation;GCSD
adr:;;;;;;
version:2.1
email;internet:[EMAIL PROTECTED]
title:Software Engineer
x-mozilla-cpt:;-19648
fn:Guillermo Gutierrez
end:vcard