java - Light and textures in Java3D -


my problem difference between this:

earths

and this:

spheres

i'm trying create nice looking solar system java3d when apply texture lighting effect disappears , 3d effect (when not looking @ planet top-down) goes it. how can have kind of shading on textured surfaces?

the code used earth example available below. texture downloadable here.

import com.sun.j3d.utils.geometry.primitive; import com.sun.j3d.utils.geometry.sphere; import com.sun.j3d.utils.image.textureloader; import com.sun.j3d.utils.universe.simpleuniverse;  import javax.imageio.imageio; import javax.media.j3d.*; import javax.vecmath.color3f; import javax.vecmath.point3d; import javax.vecmath.vector3d;  import java.awt.*;  import static java.lang.math.pi; import static java.lang.math.cos; import static java.lang.math.sin;  public class hello3d {      public hello3d()      {          simpleuniverse universe = new simpleuniverse();          branchgroup group = new branchgroup();          for(double i=0; i<2*pi; i+=pi/5) {             group.addchild(basicsphere(0.8*cos(i),0.8*sin(i),0));         }          universe.getviewingplatform().setnominalviewingtransform();          boundingsphere bounds = new boundingsphere(new point3d(0.0,0.0,0.0), 10000000.0);          pointlight light = new pointlight();         light.setcolor(new color3f(color.white));         light.setposition(0.0f,0.0f,0.0f);         light.setinfluencingbounds(bounds);         group.addchild(light);           universe.addbranchgraph(group);      }      public static void main( string[] args ) {          new hello3d();      }      private transformgroup basicsphere(double x, double y, double z) {         try {         int primflags = primitive.generate_normals + primitive.generate_texture_coords;          texture tex = new textureloader(                 imageio.read(getclass().getresource("earthmap.jpg"))         ).gettexture();         tex.setboundarymodes(texture.wrap);         tex.setboundarymodet(texture.wrap);          textureattributes texattr = new textureattributes();         texattr.settexturemode(textureattributes.replace);          appearance ap = new appearance();         ap.settexture(tex);         ap.settextureattributes(texattr);          sphere sphere = new sphere(0.1f, primflags, 100, ap);          transform3d transform = new transform3d();         transform.settranslation(new vector3d(x, y, z));          transformgroup transformgroup = new transformgroup();         transformgroup.settransform(transform);          transformgroup.addchild(sphere);          return transformgroup;         } catch(exception e) { e.printstacktrace(); }         return null;     }  } 

with this:

   texattr.settexturemode(textureattributes.replace); 

you saying replace computed lighting value value texture. want use modulate or blend, depending on how want look. check this see different methods do.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -