Here is an example on how to set attributes on a loaded OBJ file:

package com.xith.java3d.geometry.carpenter;

/**
 * $Id: MakeObjShape.java,v 1.2 2000/11/12 20:45:40 wizofid Exp $
 *
 * $Log: MakeObjShape.java,v $
 * Revision 1.2  2000/11/12 20:45:40  wizofid
 * Removing hard coded paths
 *
 * Revision 1.1  2000/10/08 21:38:20  entropy
 * Initial checkin
 *
 * Revision 1.3  2000/09/23 05:54:45  dyazel
 * Changed location of all the images, textures and shapes to match
 * the cosm archive locations
 *
 * Revision 1.2  2000/09/17 19:56:15  dyazel
 * Updating ID and LOG tags
 *
 */

import com.xith.utility.logs.*;
import com.xith.client.landscape.*;
import com.xith.java3d.geometry.shape.*;
import com.xith.java3d.appearance.texture.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import java.util.*;
import com.xith.client.engine.*;

public class MakeObjShape implements CarpenterInterface {

   SharedGroup highShape = null;
   SharedGroup farRock = null;
   String objName;
   String textureName;

   public MakeObjShape(String objName, String textureName) {
      this.objName = objName;
      this.textureName = textureName;
   }

   public Node getHighDetail() {

      if (highShape==null) {

         highShape = new SharedGroup();

         ObjectFile obj = new ObjectFile();

obj.setBasePath(XithEngine.getEngine().getProp().shapePath.getString());

         try {
            Scene s =
obj.load(XithEngine.getEngine().getProp().shapePath.getString()+objName);
            Enumeration en =  s.getNamedObjects().keys();
            while (en.hasMoreElements()) {

               String shapeName = (String)en.nextElement();
               Node node = (Node)s.getNamedObjects().get(shapeName);
               if (node instanceof Shape3D) {
                  Shape3D shape = (Shape3D)node;
                  Appearance app = shape.getAppearance();

                  // make sure the material is correct

                  Material m = new Material();
                  m.setEmissiveColor(0.2f,0.2f,0.2f);
                  m.setAmbientColor(0.5f,0.5f,0.5f);
                  m.setDiffuseColor(0.20f,0.20f,0.20f);
                  m.setSpecularColor(0.7f,0.7f,0.7f);
                  m.setLightingEnable(true);
                  app.setMaterial(m);

                  // create the texture attributes

                  TextureAttributes ta = new TextureAttributes();
                  ta.setTextureMode(ta.MODULATE);
                  ta.setPerspectiveCorrectionMode(ta.NICEST);
                  app.setTextureAttributes(ta);

                  // apply a texture to the appearance


app.setTexture(TextureFactory.tf.getWrappableTexture(textureName));

               }
            }

            highShape.addChild(s.getSceneGroup());


         } catch (Exception e) {
            Log.log.println(LogType.EXCEPTION,e.getMessage());
         }
      }
      return new Link(highShape);
   }

   public Node getLowDetail() {
      return null;
   }

   public Node getFarDetail() {
      return null;
   }

   public String getName() {
      return "Shape "+objName;
   }

}




> ----------
> From:         Josh Richmond[SMTP:[EMAIL PROTECTED]]
> Reply To:     Discussion list for Java 3D API
> Sent:         Friday, December 01, 2000 9:25 AM
> To:   [EMAIL PROTECTED]
> Subject:      [JAVA3D] how to set transparency of BranchGroup
>
> <<File: Josh Richmond.vcf.txt>>
> Hi,
>
> In my application, I'd like to load an .obj file and set the transparency
> value for all the geometry. I see that transparency can be set on Shape3D
> objects, but the obj file loader returns only a BranchGroup.
>
> Is there an easy way to set transparency for a BranchGroup such that all
> its children are affected?
>
> I tried BranchGroup.getAllChildren(), but when I query the list produced,
> there is only one Shape3D object; setting its transparency did not seem to
> work.
>
> I appreciate any help you can give me.
>
> Thanks!
> Josh
>
>
> ----------------------------------------------------
> Joshua L. Richmond, BASc, MSc.
> Systems Engineering (R&D)
>
> MD Robotics
> 9445 Airport Rd, Brampton, ON, Canada
> (905) 790-2800 x4332
> -----------------------------------------------------
>
>

===========================================================================
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