目標
- 讀入obj檔或wrl檔來更換3D模組
來源
參考:Java3D類說明
- 修改NyARJava3D.java
- 讀入obj檔
| 讀入Obj檔3D模組 |
- Code修改
開啟NyARJava3D.java
public NyARJava3D() throws Exception
{
...
//バックグラウンドの作成
Background background = new Background();
BoundingSphere bounds = new BoundingSphere();
bounds.setRadius(10.0);
background.setApplicationBounds(bounds);
background.setImageScaleMode(Background.SCALE_FIT_ALL);
background.setCapability(Background.ALLOW_IMAGE_WRITE);
BranchGroup root = new BranchGroup();
root.addChild(background);
// Add the column 17, 18, and mark the column 21 ~ 24
// Use the obj 3D module
TransformGroup transform = loadObjFile();
root.addChild(transform);
// TransformGroupで囲ったシーングラフの作成
// TransformGroup transform = new TransformGroup();
// transform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// transform.addChild(createSceneGraph());
// root.addChild(transform);
...
}
加入loadObjFile()private TransformGroup loadObjFile()
{
TransformGroup objTG = new TransformGroup();
Transform3D objTrans = new Transform3D(); objTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTG.getTransform(objTrans);
objTrans.setScale(0.6); objTG.setTransform(objTrans);
int flags = ObjectFile.RESIZE;
ObjectFile f = new ObjectFile(flags, (float) (49 * Math.PI / 180));
Scene s = null;
try
{
s = f.load("Liit.obj");
} catch (FileNotFoundException e)
{
System.err.println(e);
System.exit(1);
} catch (ParsingErrorException e)
{
System.err.println(e);
System.exit(1);
} catch (IncorrectFormatException e)
{
System.err.println(e);
System.exit(1);
}
objTG.addChild(s.getSceneGroup());
return objTG;
}
問題- 模組無法調整大小
- 只能將模組檔案放在根目錄中才能貼出模組
- 讀入VRML檔
| 讀入VRML檔3D模組 |
- Code修改
開啟NyARJava3D.java
public NyARJava3D() throws Exception
{
...
//バックグラウンドの作成
Background background = new Background();
BoundingSphere bounds = new BoundingSphere();
bounds.setRadius(10.0);
background.setApplicationBounds(bounds);
background.setImageScaleMode(Background.SCALE_FIT_ALL);
background.setCapability(Background.ALLOW_IMAGE_WRITE);
BranchGroup root = new BranchGroup();
root.addChild(background);
// Use the obj 3D module
// TransformGroup transform = loadObjFile();
// root.addChild(transform);
// Mark the column 16, 17
// TransformGroupで囲ったシーングラフの作成
TransformGroup transform = new TransformGroup();
transform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
transform.addChild(createSceneGraph());
root.addChild(transform);
...
}
修改createSceneGraph()private Node createSceneGraph()
{
TransformGroup tg = new TransformGroup();
Transform3D mt = new Transform3D();
mt.setTranslation(new Vector3d(0.00, 0.0, 20 * 0.001));
// Addition --
// Rotation
Matrix3d mtx3dx = new Matrix3d();
mtx3dx.rotX(Math.PI * 0.5); // Rotation by radius
Matrix3d mtx3d = new Matrix3d();
mtx3d.add(mtx3dx);
mt.setRotation(mtx3d);
// --
// 大きさ 40mmの色付き立方体を、Z軸上で20mm動かして配置)
tg.setTransform(mt);
// tg.addChild(new ColorCube(20 * 0.001));
// Addition --
String vrmlFile = null;
try
{
URL codebase = getWorkingDirectory();
vrmlFile = codebase.toExternalForm() + "Data/001_1.wrl"; // The VRML file path
} catch (Exception e)
{
e.printStackTrace();
}
tg.addChild(loadVrmlFile(vrmlFile));
// --
return tg;
}
問題- 模組沒有顏色
- 解:打光後出現模組形狀,但為黑白
- 無法將材質貼上模組
- 由max檔轉成wrl檔的路徑設定後不知如何對應
參考:Java3D類說明
安安
回覆刪除請問一下
這些程式用在android可以用嗎??
因為我點選載點時
連結不見了
可以寄給我code嗎??
最近在學這
想參考看看
信箱:determination_abjure@yahoo.com.tw
感恩
Sorry, 已經修復好連結了
刪除Source code的話我是參照ARToolKit裡的sample code
來修改而成的
修改部份都寫在上面