java3D的shape3D和光照问题求助,新好没积分请谅解
shape3D的对象怎么才能被光照到啊
材质贴图纹理我都搞上去了,光源也设置了,有外观但是没光照
public class testshape extends Applet {
float vert[]={1.0f,0.5f,0f, -1.0f,0.5f,0f,
-1.0f,-0.5f,0f, 1.0f,-0.5f,0f };
public BranchGroup createSceneGraph(){
BranchGroup objRoot = new BranchGroup();
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 1000.0);
Color3f bgColor = new Color3f(1.f, 1.f, 1.f);
Background bg = new Background(bgColor);
bg.setApplicationBounds(bounds);
objRoot.addChild(bg);
TransformGroup trans = new TransformGroup();
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRoot.addChild(trans);
TextureLoader loaderball = new TextureLoader("D:\\floor.jpg","LUMINANCE", new Container());
Texture textureball = loaderball.getTexture();
textureball.setBoundaryModeS(Texture.WRAP);
textureball.setBoundaryModeT(Texture.WRAP);
textureball.setBoundaryColor( new Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) );
TextureAttributes texAttrball = new TextureAttributes();
texAttrball.setTextureMode(TextureAttributes.COMBINE);
Appearance apball = new Appearance();
apball.setTexture(textureball);
apball.setTextureAttributes(texAttrball);
Material matball = new Material();
matball.setEmissiveColor(new Color3f(.6f,1.f,0.5f));
matball.setLightingEnable(true);
apball.setMaterial(matball);
Quadshape q=new Quadshape(vert,Light.red);
//q.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
q.setAppearance(apball);
trans.addChild(q);
Transform3D transbigbox= new Transform3D();
transbigbox.setTranslation(new Vector3d(0,-0.4,0));
TransformGroup groupbigbox = new TransformGroup(transbigbox);
trans.addChild(groupbigbox);
groupbigbox.addChild(new Box(0.5f,0.03f,0.3f,1,apball));
PointLight lightP1 = new PointLight();lightP1.setColor(Light.red);
lightP1.setInfluencingBounds(bounds);
Point3f position = new Point3f(0.0f, 0.0f, 1.0f);
lightP1.setPosition(position);
objRoot.addChild(lightP1);
MouseRotate behavior = new MouseRotate();
behavior.setTransformGroup(trans);
objRoot.addChild(behavior);
behavior.setSchedulingBounds(bounds);
MouseZoom behavior2 = new MouseZoom();
behavior2.setTransformGroup(trans);
objRoot.addChild(behavior2);
behavior2.setSchedulingBounds(bounds);
MouseTranslate behavior3 = new MouseTranslate();
behavior3.setTransformGroup(trans);
objRoot.addChild(behavior3);
behavior3.setSchedulingBounds(bounds);
return objRoot;
}
public testshape(){
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center", c);
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public static void main(String[] args) {
new MainFrame(new testshape(), 400, 300);
}
}
public class Quadshape extends Shape3D{
int vCount = 4;
public Quadshape(float vert[],Color3f color) {
QuadArray qua = new QuadArray(vCount, QuadArray.COORDINATES|QuadArray.TEXTURE_COORDINATE_2|QuadArray.COLOR_3);
qua.setCoordinates(0,vert);//设置顶点坐标
float[] texCoord = { 0.0f, 0.0f,1.0f, 0.0f,1.0f,1.0f,0.0f,1.0f};
qua.setColor(0,color);
qua.setTextureCoordinates(0,0, texCoord);
this.setGeometry(qua);
}
}