jazz3d, JView3D
package jazz3d;
import java.applet.Applet;
import java.awt.*;
import com.sygem.jazz3d3.*;
import com.sygem.jazz3d3.primitive.Checkerboard3d;
import com.sygem.jazz3d3.primitive.Cube3d;
import com.sygem.jazz3d3.primitive.Cylinder3d;
import com.sygem.jazz3d3.primitive.Hemisphere3d;
import com.sygem.jazz3d3.primitive.Pyramid3d;
import com.sygem.jazz3d3.primitive.Sphere3d;
import com.sygem.jazz3d3.primitive.Torus3d;
public class test_sphere extends Applet implements Runnable{
Thread my_thread;
World new_world;
int light1;
int obj_id;
int pid;
public test_sphere(){
}
public void init(){
new_world=new World(this);
add(new_world);
RenderSolid gouraud_shader = new RenderSolid();
//Sphere3d sph=new Sphere3d(10,10,0,0,5);
//Cube3d cube3 = new Cube3d(1.5, 1, 20);
//Pyramid3d pyr3 = new Pyramid3d(5,1,1,20);
//Cylinder3d cyl3 = new Cylinder3d(50, 1,1,20);
//Torus3d tor3 = new Torus3d(5,1,3,10,10,1,1,50);
//Checkerboard3d chk3 = new Checkerboard3d(5,5,1,1,15);
Hemisphere3d hem3 = new Hemisphere3d(10,10,1,1,15);
gouraud_shader.setDrawingMode(Render.FLAT); //GOURAUD
gouraud_shader.setTransparency(0.5);
//sph.setRenderer(gouraud_shader);//
hem3.setRenderer(gouraud_shader);
// Line
/*
RenderOutline wireframe = new RenderOutline();
wireframe.setDrawingMode(Render.LINE);
wireframe.setPenColour(255,255,0);
sph.setRenderer(wireframe);//
*/
//pid=new_world.addObject(sph);
//pid=new_world.addObject(cube3);
//pid=new_world.addObject(pyr3);
//pid=new_world.addObject(cyl3);
//pid=new_world.addObject(tor3);
//pid=new_world.addObject(chk3);
pid=new_world.addObject(hem3);
//sph.scaleObject(1,1,1);
//sph.setAmbientColour(255,0,0);
//sph.setVisible(true);
//sph.rotateWorld(1,1,1);
//chk3.setColour1(0,0,255);
//chk3.setColour2(0,255,0);
Light temp_light=new Light(0,0,1);
light1=new_world.addLight(temp_light);
}
public void start(){
if(my_thread == null){
my_thread=new Thread(this);
my_thread.start();
}
}
public void stop(){
if(my_thread != null) {
my_thread.stop();
my_thread=null;
}
}
public void run(){
int x,y,z;
x=2;y=3;z=-1;
new_world.prep();
while(true){
//new_world.rotateObjectXYZ(pid,x,y,z);
Object3d myObj = new_world.getObject(pid);
myObj.rotateLocal(x,y,z);
new_world.redraw();
}
}
}
package jazz3d;
import java.applet.Applet;
import java.awt.*;
import com.sygem.jazz3d3.*;
import com.sygem.jazz3d3.loader.LoadFactory;
import com.sygem.jazz3d3.loader.LoaderASC;
import com.sygem.jazz3d3.loader.Model3d;
import com.sygem.jazz3d3.primitive.Checkerboard3d;
import com.sygem.jazz3d3.primitive.Cube3d;
import com.sygem.jazz3d3.primitive.Cylinder3d;
import com.sygem.jazz3d3.primitive.Hemisphere3d;
import com.sygem.jazz3d3.primitive.Pyramid3d;
import com.sygem.jazz3d3.primitive.Sphere3d;
import com.sygem.jazz3d3.primitive.Torus3d;
public class test_sphere extends Applet implements Runnable{
Thread my_thread;
World new_world;
int light1;
int obj_id;
int pid, pid2;
public test_sphere(){
}
public void init(){
new_world=new World(this);
setLayout(new BorderLayout());
add(“Center”, new_world);
add(new_world);
RenderTextured texture_mapper=new RenderTextured();
//String temp=”http://meritsu.dothome.co.kr/testimages/201609/earth.gif”;
String temp=”file:///D:/adt-bundle-windows/eclipse/workspace/JAVA3D-exam01/src/jazz3d/images/earth.gif”;
Texture tx = TextureLoader.loadImage(temp);
texture_mapper.setTexture(tx);
texture_mapper.wrapUV(true);
//RenderSolid gouraud_shader = new RenderSolid();
//Sphere3d sph=new Sphere3d(10,10,0,0,5);
Sphere3d sp1=new Sphere3d(10,10,0.5,0,8);
Sphere3d sp2=new Sphere3d(10,10,-0.5,0,8);
//Cube3d cube3 = new Cube3d(1.5, 1, 20);
//Pyramid3d pyr3 = new Pyramid3d(5,1,1,20);
//Cylinder3d cyl3 = new Cylinder3d(50, 1,1,20);
//Torus3d tor3 = new Torus3d(5,1,3,10,10,1,1,50);
//Checkerboard3d chk3 = new Checkerboard3d(5,5,1,1,15);
//Hemisphere3d hem3 = new Hemisphere3d(10,10,1,1,15);
//gouraud_shader.setDrawingMode(Render.FLAT); //GOURAUD
//gouraud_shader.setTransparency(0.5);
//sph.setRenderer(gouraud_shader);//
//sp1.setRenderer(gouraud_shader);
//sp2.setRenderer(gouraud_shader);
//hem3.setRenderer(gouraud_shader);
sp1.setRenderer(texture_mapper);
sp2.setRenderer(texture_mapper);
// Line
/*
RenderOutline wireframe = new RenderOutline();
wireframe.setDrawingMode(Render.LINE);
wireframe.setPenColour(255,255,0);
sph.setRenderer(wireframe);//
*/
//pid=new_world.addObject(sph);
//pid=new_world.addObject(sp1);
pid=new_world.addObject(sp1);
pid2=new_world.addObject(sp2);
//pid=new_world.addObject(cube3);
//pid=new_world.addObject(pyr3);
//pid=new_world.addObject(cyl3);
//pid=new_world.addObject(tor3);
//pid=new_world.addObject(chk3);
//pid=new_world.addObject(hem3);
//sph.scaleObject(1,1,1);
//sph.setAmbientColour(255,0,0);
//sph.setVisible(true);
//sph.rotateWorld(1,1,1);
//chk3.setColour1(0,0,255);
//chk3.setColour2(0,255,0);
//Light temp_light=new Light(0,0,1);
Lightpoint temp_light=new Lightpoint(0,0,1);
temp_light.setIntensity(0.5);
temp_light.setColour(0,255,0);
light1=new_world.addLight(temp_light);
/*LoadFactory lf=new LoadFactory();
lf.assignLoader(“ASC”,new LoaderASC());
Model3d dragon = new Model3d(0,0,8);
dragon.loadModel(“Dragon.geo”,lf);*/
}
public void start(){
if(my_thread == null){
my_thread=new Thread(this);
my_thread.start();
}
}
public void stop(){
if(my_thread != null) {
my_thread.stop();
my_thread=null;
}
}
public void run(){
int iCount = 0;
long lTime0=System.currentTimeMillis();
int x,y,z;
x=2;y=3;z=-1;
new_world.prep();
while(true){
//new_world.rotateObjectXYZ(pid,x,y,z);
Object3d myObj = new_world.getObject(pid);
Object3d myObj2 = new_world.getObject(pid2);
myObj.rotateLocal(x,y,z);
myObj2.rotateLocal(x,y,z);
new_world.redraw();
//애플릿의 fps를 홈페이지 상태바에 출력시키는 루틴
iCount++;
if((iCount%50)==0){
lTime0-=System.currentTimeMillis();
lTime0=-lTime0;
getAppletContext().showStatus((50000./lTime0)+”frames/second”);
lTime0=System.currentTimeMillis();
}
}
}
}
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
JView3D
jar download site:
http://landspurg.net/VisualBeans/View3D/
public class MyApplet extends Applet{
View3DCanvas myView;
public void init(){
setLayout(new BorderLayout());
myView = new View3DCanvas();
add(“Center”,myView);
try{
String name=”Dirigabl.m3d”;
myView.setObj(new URL(getDocumentBase(),name).openStream(),name);
} catch(Exception e){
System.out.println(e);
}
}
}
package jview3d;
import tom.graphic.ThreeD.*;
import java.awt.*;
import java.applet.*;
import java.net.*;
public class MyApplet2 extends Applet{
View3DCanvas myView;
public void init(){
setLayout(new BorderLayout());
myView = new View3DCanvas(false);
add(“Center”,myView);
Object3D myObj=new Object3D();
myObj.addVert(-1,-1,0);
myObj.addVert(1,-1,0);
myObj.addVert(1,1,0);
myObj.addVert(-1,-1,0);
myObj.addVert(0,0,2);
Face f=new Face(0,1,4,4,Color.red);
myObj.addElem(f);
f=new Face(1,2,4,4,Color.green);
myObj.addElem(f);
f=new Face(2,3,4,4,Color.green);
myObj.addElem(f);
f=new Face(3,0,4,4,Color.green);
myObj.addElem(f);
f=new Face(0,3,2,1,Color.yellow);
myObj.addElem(f);
myView.view().world().addObj(myObj);
}
}
hierarchical.java
package jview3d;
import tom.graphic.ThreeD.*;
import java.awt.*;
import java.io.*;
import java.applet.*;
import java.net.*;
public class hierarchical extends Applet{
hFrame frame=null;
public boolean handleEvent(Event evt) {
if(evt.id ==Event.ACTION_EVENT){
if(frame==null){
frame=new hFrame();
frame.view.view().world().remAllObj();
frame.view.setPosZ(2000f);
for(int i=0;i<10;i++){
Object3D m=Object3D.getCube(1,1,1,Color.yellow);
Object3D rot=new Object3D();
rot.addChild(m);
m.pos.x=10;
rot.angle.y=360*i/10;
rot.spRot.x=5;
frame.view.view().world().addObj(rot);
}
}
frame.show();
}
return super.handleEvent(evt);
}
public void init(){
super.init();
setLayout(new BorderLayout());
add(“Center”,new Button(“여기를 누르세요!”));
}
}
hFrame.java
package jview3d;
import tom.graphic.ThreeD.*;
import java.awt.*;
import java.io.*;
import java.applet.*;
import java.net.*;
public class hFrame extends Frame implements Runnable {
public View3DCanvas view;
boolean keepGoing=true;
boolean suspended=false;
boolean stopThread=false;
boolean Threadsstopped=false;
Thread displayThread=null;
hFrame()
{
super(“ThreeD applet”);
System.out.println(“init hframe”);
setLayout(new BorderLayout());
resize(300,300);
add(“Center”,view=new View3DCanvas());
view.setBackground(Color.black); // 배경을 검은색으로
}
public boolean handleEvent(Event evt){
if(evt.id==Event.WINDOW_DESTROY) //창을 닫으면
{
removeNotify(); //창을 제거
hide();
}
return super.handleEvent(evt);
}
public synchronized void removeNotify(){
keepGoing=false;
stopThread=false;
if(displayThread!=null){
displayThread.setPriority(Thread.MAX_PRIORITY);
displayThread.resume();
}
while(displayThread!=null)
try{Thread.sleep(10);}catch(Exception e){};
}
@Override
public void run() {
// TODO Auto-generated method stub
try{
do{
view.repaint(); //이미지를 다시 그림
Thread.sleep(5); //0.005초간 지연
} while(keepGoing);
Thread.sleep(30); //0.03초간 지연
displayThread=null;
} catch(Exception e){
}
}
public void show(){
super.show();
startThread();
}
public synchronized void startThread(){
keepGoing=true;
displayThread=new Thread(this);
displayThread.setPriority(Thread.MIN_PRIORITY);
displayThread.start();
}
}
picker.java
package jazz3d;
import java.applet.Applet;
import java.awt.*;
import com.sygem.jazz3d3.*;
import com.sygem.jazz3d3.loader.LoadFactory;
import com.sygem.jazz3d3.loader.LoaderASC;
import com.sygem.jazz3d3.loader.Model3d;
import com.sygem.jazz3d3.primitive.Cube3d;
import com.sygem.jazz3d3.primitive.Sphere3d;
import com.sygem.jazz3d3.primitive.Torus3d;
public class picker extends Applet implements Runnable {
Thread m_ce;
World p_world;
int light1;
int pid, pid2, pid3, pid4;
Label display;
public picker() {
}
public void init(){
resize(320,240);
p_world = new World(this);
display=new Label(“아직 객체가 선택되지 않았습니다…”);
setLayout(new BorderLayout());
add(“Center”, p_world);
add(“South”, display);
RenderSolid flat_shader = new RenderSolid();
RenderSolid gourard_shader = new RenderSolid();
Torus3d torus = new Torus3d(0.4,0.2,0.2,15,15,0.5,0,12);
torus.setColour(255,0,128);
Cube3d cube = new Cube3d(-0.5,0.5,12);
cube.setColour(75,50,220);
cube.scaleObject(0.8,0.8,0.8);
Sphere3d sphere=new Sphere3d(10,10,-0.5,-0.5,12);
sphere.setColour(0,255,128);
pid=p_world.addObject(sphere);
sphere.setRenderer(gourard_shader);
pid2=p_world.addObject(torus);
torus.setRenderer(gourard_shader);
pid3=p_world.addObject(cube);
cube.setRenderer(flat_shader);
Light temp_light = new Light(0,0,1);
light1=p_world.addLight(temp_light);
}
public void start(){
if(m_ce == null){
m_ce=new Thread(this);
m_ce.start();
}
}
public void stop(){
if(m_ce!=null){
m_ce.stop();
m_ce=null;
}
}
public void destroy(){
}
@Override
public void run() {
// TODO Auto-generated method stub
p_world.prep();
while(true){
Object3d myObj = p_world.getObject(pid);
myObj.rotateLocal(0,3,0);
Object3d myObj2 = p_world.getObject(pid2);
myObj2.rotateLocal(1,3,2);
Object3d myObj3 = p_world.getObject(pid3);
myObj3.rotateLocal(0,2,5);
p_world.redraw();
}
}
public boolean mouseUp(Event e, int x, int y){
//int id=p_world.getObjectAt(x,y);
// mouse tracking
p_world.pickClosest(x,y);
int id = HitPoint.getObjectId()-1;
String click_string=”그것은 객체가 아닙니다…”;
if(id==0) click_string = “당신은 녹색 구를 선택했습니다.”;
if(id==1) click_string = “당신은 빨간 색 토로스를 선택했습니다.”;
if(id==2) click_string = “당신은 파란색 정육면체를 선택했습니다.”;
display.setText(click_string);
return true;
}
}
Wow! Great to find a post with such a clear meesags!