• 大小: 62.37 KB
    文件类型: .rar
    金币: 1
    下载: 1 次
    发布日期: 2024-12-13
  • 语言: Java
  • 标签: JAVA3D  

资源简介

JAVA3D编程示例,关于简单多边形的建模方式,鼠标等和三维图形的交互等。

资源截图

代码片段和文件信息

package java3D;

import java.awt.Container;

import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.Texture;
import javax.media.j3d.TextureAttributes;
import javax.vecmath.Color3f;
import javax.vecmath.Color4f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

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;

//================================================================
//贴图
//=================================================================
public class APictureBall {


public APictureBall() {


// >创建宇宙

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(“./image/1.bmp““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.00.00.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 APictureBall();

}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        382  2009-04-24 17:11  JAVA3D\.project

     文件        226  2009-04-20 09:39  JAVA3D\.classpath

     文件        141  2009-04-20 10:11  JAVA3D\java.policy.applet

     文件       5407  2009-04-28 07:18  JAVA3D\java3D\BSupermanInterp.java

     文件       2803  2009-04-28 07:18  JAVA3D\java3D\APictureBall.java

     文件       4288  2009-04-28 07:18  JAVA3D\java3D\DBouncingBall.java

     文件       3762  2009-04-28 07:18  JAVA3D\java3D\CTest_Pyramid.java

     文件       3390  2009-04-28 07:18  JAVA3D\java3D\APictureBall.class

     文件       5719  2009-04-28 07:18  JAVA3D\java3D\BSupermanInterp.class

     文件       3050  2009-04-28 07:18  JAVA3D\java3D\CTest_Pyramid.class

     文件       5326  2009-04-28 07:18  JAVA3D\java3D\DBouncingBall.class

     文件     254070  2009-04-24 17:36  JAVA3D\image\1.BMP

     文件      26334  2009-04-24 17:42  JAVA3D\image\2.bmp

     文件        625  2009-04-28 07:18  JAVA3D\sha\SimpleCone.java

     文件       1015  2009-04-28 07:18  JAVA3D\sha\SimpleCone.class

     文件       1156  2009-04-28 07:18  JAVA3D\sha\Ball.java

     文件       1757  2009-04-28 07:18  JAVA3D\sha\Ball.class

     文件      20965  2009-04-28 07:18  JAVA3D\sha\Rubik.java

     文件      14951  2009-04-28 07:18  JAVA3D\sha\Rubik.class

     文件       2203  2009-04-28 07:18  JAVA3D\sha\Position.java

     文件       2776  2009-04-28 07:18  JAVA3D\sha\Position.class

     文件       3964  2009-04-28 07:14  JAVA3D\org\netbeans\lib\awtextra\AbsoluteConstraints.java

     文件       1973  2009-04-28 07:14  JAVA3D\org\netbeans\lib\awtextra\AbsoluteConstraints.class

     文件       6367  2009-04-28 07:18  JAVA3D\org\netbeans\lib\awtextra\AbsoluteLayout.java

     文件       3462  2009-04-28 07:18  JAVA3D\org\netbeans\lib\awtextra\AbsoluteLayout.class

     目录          0  2009-04-28 07:14  JAVA3D\org\netbeans\lib\awtextra

     目录          0  2009-04-28 07:14  JAVA3D\org\netbeans\lib

     目录          0  2009-04-28 07:14  JAVA3D\org\netbeans

     目录          0  2009-04-21 17:42  JAVA3D\java3D

     目录          0  2009-04-24 17:30  JAVA3D\image

............此处省略6个文件信息

评论

共有 条评论