?? pictureball.java
字號(hào):
package com.java3d.test;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.Container;
public class PictureBall {
public PictureBall() {
// >創(chuàng)建宇宙
SimpleUniverse universe = new SimpleUniverse();
// >創(chuàng)建容納物體的結(jié)構(gòu)
BranchGroup group = new BranchGroup();
// >建立顏色
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Color3f red = new Color3f(0.7f, .15f, .15f);
// >建立紋理帖圖
TextureLoader loader = new TextureLoader("E:\\workplace\\java3d\\src\\com\\java3d\\test\\Arizona.jpg","", new Container());
Texture texture = loader.getTexture();
//texture.setBoundaryModeS(Texture.CLAMP);
//texture.setBoundaryModeT(Texture.CLAMP);
//texture.setBoundaryColor( new Color4f( 1.0f, 1.0f, 1.0f, 1.0f ) );
//System.out.println(texture.getBoundaryModeT());
// >建立紋理屬性
//>可以用REPLACE, BLEND >或 DECAL >代替 MODULATE
//TextureAttributes texAttr = new TextureAttributes();
//texAttr.setTextureMode(TextureAttributes.MODULATE);
Appearance ap = new Appearance();
ap.setTexture(texture);
//ap.setTextureAttributes(texAttr);
//>建立材質(zhì)
ap.setMaterial(new Material(red, black, red, black, 1.0f));
// >創(chuàng)建一個(gè)球來展示紋理
int primflags = Primitive.GENERATE_NORMALS +
Primitive.GENERATE_TEXTURE_COORDS;
//Sphere sphere = new Sphere(0.5f, primflags, ap);
//group.addChild(sphere);
Box box = new Box(0.5f,0.5f,0.4f,primflags,ap);
group.addChild(box);
// >創(chuàng)建燈光
Color3f light1Color = new Color3f(1f, 1f, 1f);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
group.addChild(light1);
AmbientLight ambientLight = new AmbientLight(new Color3f(.5f,.5f,.5f));
ambientLight.setInfluencingBounds(bounds);
group.addChild(ambientLight);
// >注視球體
universe.getViewingPlatform().setNominalViewingTransform();
// >把物體組加入宇宙
universe.addBranchGraph(group);
}
public static void main(String[] args) {
new PictureBall();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -