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

📄 pictureball.java

📁 这个就是目前我收集,以及自己写的一些java3d的原码,大部分都可以运行,适合和我一样,刚刚开始对java3D心动的菜鸟
💻 JAVA
字号:
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() {


// >创建宇宙

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("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);


//>建立材质

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);


Box  box = new Box(0.5f,0.5f,0.4f,primflags,ap);
group.addChild(box);


// >创建灯光

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