⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pictureball.java

📁 使用java3d进行,obj文件的加载.和实现全方位的3维场景交互
💻 JAVA
字号:
package csu.chailei.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() {
		// 创建宇宙    
		SimpleUniverse universe = new SimpleUniverse();  
		// 创建容纳物体的结构    
		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("g:\\2.jpg","LUMINANCE", new Container());
		Texture texture = loader.getTexture();
		texture.setBoundaryModeS(Texture.WRAP);
		texture.setBoundaryModeT(Texture.WRAP);  
		texture.setBoundaryColor( new Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) ); 
		// 建立纹理属性     
		//可以用REPLACE, BLEND 或 DECAL 代替 MODULATE
		TextureAttributes texAttr = new TextureAttributes();
		texAttr.setTextureMode(TextureAttributes.MODULATE);
		Appearance ap = new Appearance();    
		ap.setTexture(texture);  
		ap.setTextureAttributes(texAttr);   
		//建立材质    
		ap.setMaterial(new Material(red, black, red, black, 1.0f)); 
		// 创建一个球来展示纹理    
		int primflags = Primitive.GENERATE_NORMALS +Primitive.GENERATE_TEXTURE_COORDS;   
        Sphere sphere = new Sphere(0.5f, primflags, ap);
        group.addChild(sphere);    
        // 创建灯光   
        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(); 
		}

	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -