Skip to main content

(howto load vrml file using Xj3d loader)

6 replies [Last post]
jery_molan
Offline
Joined: 2004-09-25
Points: 0

what is the problem with my code?

import java.io.*;
import java.awt.*;

import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.GraphicsConfigTemplate3D;

import org.web3d.j3d.loaders.VRML97Loader;

import com.sun.j3d.loaders.Loader;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.Viewer;
import com.sun.j3d.utils.universe.ViewingPlatform;

/*
* Created on May 8, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author jery
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/

public class my_loader extends JFrame{
SimpleUniverse universe;

Canvas3D my_canvas;

BranchGroup scene_root = new BranchGroup();

BranchGroup scene_loaded;

BranchGroup my_view;

ViewPlatform vw_pltform_obj;

View vw_obj;

VRML97Loader ldr;

Scene sc;

private TransformGroup vpTransGroup;

my_loader()
{
Container content_pane = getContentPane();
content_pane.setLayout(new BorderLayout());

GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
template.setDoubleBuffer(template.REQUIRED);
GraphicsEnvironment env =
GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice dev = env.getDefaultScreenDevice();

GraphicsConfiguration gfxConfig = dev.getBestConfiguration(template);

my_canvas = new Canvas3D(gfxConfig);

content_pane.add("Center",my_canvas);

universe = new SimpleUniverse(my_canvas);

universe.setJ3DThreadPriority(Thread.NORM_PRIORITY);

ViewingPlatform viewingPlatform = universe.getViewingPlatform();
vpTransGroup = viewingPlatform.getViewPlatformTransform();
Viewer viewer = universe.getViewer();

View view = viewer.getView();

view.setBackClipDistance(1000);

scene_root.setCapability(scene_root.ALLOW_CHILDREN_EXTEND);

universe.addBranchGraph(scene_root);

setSize(1024,768);

setVisible(true);

setLocation(0,0);

ldr = new VRML97Loader(Loader.LOAD_ALL);

try
{
sc = ldr.load("c:/wz_lit.WRL");
}
catch(Exception ex)
{
ex.printStackTrace();
}

scene_loaded = sc.getSceneGroup();
scene_loaded.setCapability(BranchGroup.ALLOW_DETACH);
scene_loaded.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
scene_loaded.compile();

Transform3D viewTrans = new Transform3D();
Transform3D eyeTrans = new Transform3D();

// put the View at the standard VRML default position 0,0,10
Vector3f pos = new Vector3f(0,0,10);
eyeTrans.set(pos);
viewTrans.mul(eyeTrans);

// set the view transform
vpTransGroup.setTransform(viewTrans);

scene_root.addChild(scene_loaded);
}

public static void main(String[] args) {
my_loader obj = new my_loader();

}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nitro
Offline
Joined: 2004-09-12
Points: 0

Could you please state what is not working and if available post the message of any exception occuring

jery_molan
Offline
Joined: 2004-09-25
Points: 0

the scene not appears and no exception and when checking for light node and for all childrens they all exist why scene not appears

nitro
Offline
Joined: 2004-09-12
Points: 0

I think this doesn't anything useful:
[code]
Transform3D viewTrans = new Transform3D();
Transform3D eyeTrans = new Transform3D();

// put the View at the standard VRML default position 0,0,10
Vector3f pos = new Vector3f(0,0,10);
eyeTrans.set(pos);
viewTrans.mul(eyeTrans);

// set the view transform
vpTransGroup.setTransform(viewTrans);
[/code]

use instead:
[code]
Transform3D viewTrans = new Transform3D();

// put the View at the standard VRML default position 0,0,10
Vector3f pos = new Vector3f(0,0,10);
eyeTrans.set(pos);
vpTransGroup.setTransform(eyeTrans);
[/code]

or:
[code]
Transform3D viewTrans = new Transform3D();
Transform3D eyeTrans = new Transform3D();

// put the View at the standard VRML default position 0,0,10
Vector3f pos = new Vector3f(0,0,10);
eyeTrans.set(pos);
vpTransGroup.getTransform(viewTrans);
viewTrans.mul(eyeTrans, viewTrans);

// set the view transform
vpTransGroup.setTransform(viewTrans);
[/code]

But this isn't the cause of your problem. Probably you could check the size of your objects and lights to ensure that they are visible from your point of view.

jery_molan
Offline
Joined: 2004-09-25
Points: 0

ok could u pls use vrml file then using my app load this object and show me the result sorry for annoying u but my graduation project need work and this is my fst step plsss help

nitro
Offline
Joined: 2004-09-12
Points: 0

Have look at your vrml file check the coordinate locations of the containing shape and position your view and set the back and frontclipplanes according to this.
(you can open a vrml with any texteditor)

Alos do not forget to check if you have lights aded to your scene and their influencing bounds are big enough to light your objects.

jery_molan
Offline
Joined: 2004-09-25
Points: 0

thnx all i've solved the problem .coordinates were my problem