资源简介
自己写的一个简单的java3D实例,能过理解3D中的简单实现和蒙皮过程
代码片段和文件信息
import java.applet.*;
import java.awt.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.applet.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.*;
//1.创建texture2类,扩展applet
public class texture2 extends applet {
//2.创建createSceneGraph方法,改方法返回一个BranchGroup
private BranchGroup createSceneGraph(){
BranchGroup objroot = new BranchGroup();
//3.创建六组Point3f类型的四边形的顶点数组,用于创建6个四边形面
Point3f[] p1 = new Point3f[4];
p1[0] = new Point3f(-.5f .5f 0.5f);
p1[1] = new Point3f(-.5f -.5f 0.5f);
p1[2] = new Point3f(.5f -.5f 0.5f);
p1[3] = new Point3f(.5f .5f 0.5f);
Point3f[] p2 = new Point3f[4];
p2[0] = new Point3f(-.5f .5f -0.5f);
p2[1] = new Point3f(-.5f -.5f -0.5f);
p2[2] = new Point3f(-.5f -.5f 0.5f);
p2[3] = new Point3f(-.5f .5f 0.5f);
Point3f[] p3 = new Point3f[4];
p3[0] = new Point3f(.5f .5f -0.5f);
p3[1] = new Point3f(.5f -.5f -0.5f);
p3[2] = new Point3f(-.5f -.5f -0.5f);
p3[3] = new Point3f(-.5f .5f -0.5f);
Point3f[] p4 = new Point3f[4];
p4[0] = new Point3f(.5f .5f 0.5f);
p4[1] = new Point3f(.5f -.5f 0.5f);
p4[2] = new Point3f(.5f -.5f -0.5f);
p4[3] = new Point3f(.5f .5f -0.5f);
Point3f[] p5 = new Point3f[4];
p5[0] = new Point3f(-.5f .5f 0.5f);
p5[1] = new Point3f(.5f .5f 0.5f);
p5[2] = new Point3f(.5f .5f -0.5f);
p5[3] = new Point3f(-.5f .5f -0.5f);
Point3f[] p6 = new Point3f[4];
p6[0] = new Point3f(-.5f -.5f -0.5f);
p6[1] = new Point3f(.5f -.5f -0.5f);
p6[2] = new Point3f(.5f -.5f 0.5f);
p6[3] = new Point3f(-.5f -.5f 0.5f);
//4.对于每一组四边形面,调用shapeMaker(java.awt.Component observer
// String filenamePoint3f[] p)第一参数是图像观察者,第二个参数用于纹理的图形文件,
// 第三个参数是顶点的坐标,返回结果是 Shape3D 类型的集合对象
Shape3D shape1 = shapeMaker(this“1.png“p1);
Shape3D shape2 = shapeMaker(this“2.png“p2);
Shape3D shape3 = shapeMaker(this“3.png“p3);
Shape3D shape4 = shapeMaker(this“4.png“p4);
Shape3D shape5 = shapeMaker(this“5.png“p5);
Shape3D shape6 = shapeMaker(this“6.png“p6);
//5.定义坐标系 trans 将四边形面添加到坐标系中
Transform3D t3d = new Transform3D();
TransformGroup trans = new TransformGroup();
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
trans.addChild(shape1);
trans.addChild(shape2);
trans.addChild(shape3);
trans.addChild(shape4);
trans.addChild(shape5);
trans.addChild(shape6);
objroot.addChild(trans);
//6.定义鼠标旋转变换坐标系
MouseRotate behavior = new MouseRotate();
behavior.setTransformGroup(trans);
behavior.setSchedulingBounds(new BoundingSphere());
objroot.addChild(behavior);
objroot.compile();
return objroot;
}
//7.定义 shapeMaker 方法,该方法返回 Shape3D 对象
public Shape3D shapeMaker(java.awt.Component observer
String filename Point3f[] p){
TextureLoader loader = new TextureLoader(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6258 2018-04-01 17:07 3D\1.PNG
文件 8691 2018-04-01 18:56 3D\2.PNG
文件 12603 2018-04-01 17:12 3D\3.PNG
文件 16008 2018-04-01 17:12 3D\4.PNG
文件 19316 2018-04-01 17:12 3D\5.PNG
文件 21146 2018-04-01 17:13 3D\6.PNG
文件 9421 2018-04-01 16:05 3D\b4070688a9441b0fd78ca31572f06bc1.jpg
文件 3281 2018-04-01 16:03 3D\cover2.jpg
文件 3765 2018-04-01 17:32 3D\texture2.class
文件 4509 2018-04-01 17:32 3D\texture2.java
文件 58162 2018-04-01 17:22 3D\骰子.PNG
目录 0 2018-04-01 19:21 3D
----------- --------- ---------- ----- ----
163160 12
- 上一篇:这是一份很合适初学者的Java练习题
- 下一篇:Hibernate日志jar包
相关资源
- Java3D驱动程序
- java3d-1_5_1-windows-amd64.exe2
- Java3D的jar包
- JAVA3D官方
- JAVA3D.zip
- java3d-1_5_1-windows-amd64
- java3D (32位和64位)
- JAVA3D的网络三维技术的设计与实现(
- JAVA3D安装程序
- Java 3D实验报告及课程设计
- java3D安装教程
- java3D显示一个球的代码
- 利用Java3D1.4制成的动态爬山算法
- Java3D魔方代码
- obj模型,java3d加载
- java3d设置视点的初始位置
- Java 平移坐标轴
- java3D所需的jar包
- java3d dll(4个)+jar包(for x64)
- java3D使用键盘对场景中物体的一些控
评论
共有 条评论