Mario,

 a sugestion to change material:
 public void setSphereAppearance(Material newmat)
{
    mySphere.getAppearance().setMaterial(newmat);
}

 and add this capability to Sphere :

sphere.setCapability(ENABLE_APPEARANCE_MODIFY );




 --- "ZACZEK, MARIUSZ P. (MARIO) (JSC-DM) (NASA)"
<[EMAIL PROTECTED]> escreveu: >  Hi,
>   I've been racking my brain for over a day on this
> and can't figure out
> what I'm doing wrong or not doing.
>
> I place a 3D Sphere into my scenegraph, and later I
> want to change the
> color of it. But when I press the button to reset
> it's appearance to the
> new color/material:
>   public void setSphereAppearance(Material newmat) {
>     planetApp.setMaterial(newmat);
>     mySphere.setAppearance(planetApp);
>   }
>
> I get a error saying:  Shape3D: no capability to set
> appearance
> Although...it changes the color...wierd. I'm pretty
> sure I set all
> the needed capability flags but maybe I'm missing
> something. I've copied
> the code for my 3D sphere below...it's a BranchGroup
> so it can be
> added to a live scenegraph.
>
> I'd appreciate any suggestions..
>
> Mario
>
>
>
> CODE:
> ==================================================
> //  Import the 3D API libraries for viewing 3D
> environments.
> import com.sun.j3d.utils.geometry.*;
> import javax.media.j3d.*;
> import javax.vecmath.*;
>
> //  Import the math library.
> import java.lang.Math.*;
>
>
> /**
>  *
>  */
> public class Sphere3d extends BranchGroup {
>
>   //
>   //  Variable declarations
>   //
>   private double   _scaleValue = 1.0f;
>   private Vector3f _transValue = new Vector3f(0.0f,
> 0.0f, 0.0f);
>   private Transform3D _scaleTran;   // Scale
> transform
>   private Transform3D _transTran;   // Translation
> transform
>   private Transform3D _oldTrans = new Transform3D();
>   private TransformGroup mainTG = new
> TransformGroup();
>   private boolean _solid = false;
>   private Color3f _color = new Color3f();
>   private Vector3f _base = new Vector3f();
>   private float _scale = 1.0f;
>   private float _dim1 = 0.0f;
>   private Appearance planetApp;
>   private Sphere mySphere;
>    Color3f black  = new Color3f(0.20f,  0.20f,
> 0.20f);
>
>
>   /**
>    *  Calls the 'defineVrml' function to define the
> VRML model
>    *  by setting the initial scale, translation and
> rotation.
>    *
>    */
>   public Sphere3d(boolean solid, Color3f color,
> Vector3f base, float scale,
> float dim1){
>
>     this.addChild(mainTG);
>
this.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
>
>
>     System.out.println("\n Cannot simply define
> blank Sphere3d");
>
>     setVariables(solid, color, base, scale, dim1);
>     definePrimitive();
>
>     drawSphere(solid,dim1);
>
>     setPosition(base.x, base.y, base.z);
>     setScale(scale);
>   }
>
>
>
>   /**
>    *
>    *
>    *
>    */
>   private void setVariables(boolean solid, Color3f
> color, Vector3f base,
> float scale, float dim1) {
>     _solid = solid;
>     _color = color;
>     _base = base;
>     _scale = scale;
>     _dim1 = dim1;
>   }
>
>
>
>   public boolean getSolid() {
>     return _solid;
>   }
>
>   public Color3f getColor() {
>     return _color;
>   }
>
>   public Vector3f getBase() {
>     return _base;
>   }
>
>   public float getScaleVal() {
>     return _scale;
>   }
>
>   public float getDim1() {
>     return _dim1;
>   }
>
>
>
>
>
>
>   /**
>    *
>    *
>    *
>    */
>   private void drawSphere(boolean solid, float
> radius) {
>     if (!solid) {
>       ColoringAttributes ca = new
> ColoringAttributes();
>       ca.setColor(_color);
>
>       PolygonAttributes pa = new
> PolygonAttributes();
>       pa.setPolygonMode
> (PolygonAttributes.POLYGON_LINE);
>
>       Appearance ap = new Appearance();
>       ap.setColoringAttributes (ca);
>       ap.setPolygonAttributes (pa);
>
>       mainTG.addChild(new Sphere(radius,ap));
>     } else if (solid) {
>       planetApp = new Appearance();
>
>
planetApp.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
>
>
planetApp.setCapability.Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
>       TransparencyAttributes _transAttrs;
>       float _transparency = 0.0f;
>       float _curtransparency = 0.0f;
>
>       Transform3D _transTrans       = new
> Transform3D();
>       _transAttrs = new
> TransparencyAttributes(TransparencyAttributes.NONE,
> _transparency);
>       // Allow the transparency value to be
> overwritten.
>
>
_transAttrs.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
>       // Allow the transparency mode to be
> overwritten.
>
>
_transAttrs.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
>
> planetApp.setTransparencyAttributes(_transAttrs);
>
>
>       Material m = new
> Material(_color,black,_color,black,64.0f);
>       planetApp.setMaterial(m);
>
>       // Draw the sphere for the planet and add the
> texture to it
>       mainTG.addChild(mySphere = new Sphere(radius,
> Sphere.GENERATE_TEXTURE_COORDS |
>
> Sphere.GENERATE_NORMALS,
>
=== message truncated ===

_______________________________________________________________________
Busca Yahoo!
O servi�o de busca mais completo da Internet. O que voc� pensar o Yahoo! encontra.
http://br.busca.yahoo.com/

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to