107
|
1 package alice.test.topology.fishmodel.alpha;
|
88
|
2
|
|
3 import java.awt.Image;
|
|
4 import java.awt.MediaTracker;
|
|
5 import java.awt.Toolkit;
|
109
|
6 import java.io.FileNotFoundException;
|
107
|
7 //import java.io.File;
|
88
|
8
|
|
9 import javax.media.j3d.Appearance;
|
|
10 import javax.media.j3d.BranchGroup;
|
|
11 import javax.media.j3d.Canvas3D;
|
|
12 import javax.media.j3d.Texture;
|
|
13 import javax.media.j3d.Transform3D;
|
|
14 import javax.media.j3d.TransformGroup;
|
|
15 import javax.vecmath.Vector3f;
|
|
16
|
109
|
17 import com.sun.j3d.loaders.IncorrectFormatException;
|
|
18 import com.sun.j3d.loaders.ParsingErrorException;
|
|
19 import com.sun.j3d.loaders.Scene;
|
|
20 import com.sun.j3d.loaders.objectfile.ObjectFile;
|
88
|
21 import com.sun.j3d.utils.geometry.Box;
|
|
22 import com.sun.j3d.utils.image.TextureLoader;
|
|
23
|
|
24 public class MakeObject {
|
|
25
|
|
26 public Vector3f vector;
|
93
|
27 Transform3D transform;
|
|
28 TransformGroup transform_group;
|
|
29 Canvas3D canvas;
|
|
30 KeyInput key;
|
|
31 KeyInputCodeSegment KIC;
|
88
|
32
|
89
|
33 public MakeObject(MakeFrame MF){
|
|
34 this.canvas = MF.getCanvas();
|
109
|
35 //this.key = MF.getKey();
|
93
|
36 this.KIC = MF.getKeySegment();
|
88
|
37 }
|
|
38
|
89
|
39
|
91
|
40 public BranchGroup createKeyBranch(){
|
|
41 BranchGroup scene = new BranchGroup();
|
|
42 Box box = new Box(0.1f,0.1f,0.0f,
|
|
43 Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());
|
|
44 key.transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
|
|
45 key.transformGroup.addChild(box);
|
|
46 scene.addChild(key.transformGroup);
|
|
47 return scene;
|
|
48
|
|
49 }
|
|
50
|
88
|
51 public BranchGroup createBranch(){
|
|
52 BranchGroup scene = new BranchGroup();
|
109
|
53 /*Box box = new Box(0.1f,0.1f,0.0f,
|
|
54 Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS,createAppearance());*/
|
|
55 ObjectFile obj = new ObjectFile(ObjectFile.RESIZE);
|
|
56 Scene S = null;
|
|
57 try{
|
|
58 S = obj.load("../image/galleon.obj");
|
|
59 } catch(FileNotFoundException e){
|
|
60 System.err.println(e);
|
|
61 System.exit(1);
|
|
62 } catch(ParsingErrorException e){
|
|
63 System.err.println(e);
|
|
64 System.exit(1);
|
|
65 } catch(IncorrectFormatException e){
|
|
66 System.err.println(e);
|
|
67 System.exit(1);
|
|
68 }
|
|
69
|
88
|
70 transform_group = new TransformGroup();
|
|
71 transform_group.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
|
109
|
72 transform_group.addChild(S.getSceneGroup());
|
88
|
73 scene.addChild(transform_group);
|
109
|
74 return scene;
|
88
|
75 }
|
|
76
|
|
77 private Appearance createAppearance(){
|
|
78 Appearance app = new Appearance();
|
|
79 Image image = null;
|
|
80 Toolkit toolkit = Toolkit.getDefaultToolkit();
|
|
81 //image = toolkit.getImage("image/fish.jpg");
|
|
82 image = toolkit.getImage("../image/fish.jpg");//jar
|
|
83 MediaTracker mt = new MediaTracker(canvas);
|
|
84 mt.addImage(image, 0);
|
|
85 mt.checkAll(true);
|
|
86 try {
|
|
87 mt.waitForID(0);
|
|
88
|
|
89 }catch (InterruptedException e){
|
|
90 e.printStackTrace();
|
|
91
|
|
92 }
|
|
93 Texture texture = new TextureLoader(image,canvas).getTexture();
|
|
94 app.setTexture(texture);
|
|
95 return app;
|
|
96
|
|
97 }
|
|
98
|
|
99 public void setLocation(float x,float y){
|
|
100 transform = new Transform3D();
|
|
101 vector = new Vector3f(x,y,0.0f);
|
|
102 transform.setTranslation(vector);
|
|
103 transform_group.setTransform(transform);
|
|
104 }
|
110
|
105
|
|
106 public void setLocation(float x,float y,float z){
|
|
107 transform = new Transform3D();
|
|
108 vector = new Vector3f(x,y,z);
|
|
109 transform.setTranslation(vector);
|
|
110 transform_group.setTransform(transform);
|
|
111 }
|
88
|
112 }
|
|
113
|