Skip to main content

VrmlLoader Morph

2 replies [Last post]
huanghongbo
Offline
Joined: 2006-02-17

Scene s[] = new Scene[3];
GeometryArray g[] = new GeometryArray[3];
Shape3D shape[] = new Shape3D[3];
VrmlLoader loader = new VrmlLoader();
for (int i = 0; i < 3; i++) {
s[i] = null;
g[i] = null;
shape[i] = null;
}

if (objFiles == null) {
objFiles = new java.net.URL[3];
objFiles[0] = getClass().getResource("r0.wrl");
objFiles[1] = getClass().getResource("r1.wrl");
objFiles[2] = getClass().getResource("r2.wrl");
}
for (int i = 0; i < 3; i++) {
try {
s[i] = loader.load(objFiles[i]);
} 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);
}

BranchGroup b = s[i].getSceneGroup();
shape[i] = (Shape3D)b.getChild(0);
b.getAllChildren();
g[i] = (GeometryArray) shape[i].getGeometry();

shape[i].setGeometry(g[i]);
}

Appearance app = new Appearance();
Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
app.setMaterial(new Material());
Morph morph = new Morph(g, app);

*************************************
shape[i] = (Shape3D)b.getChild(0);
why error!
java.lang.ClassCastException
*************************************

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nikolai
Offline
Joined: 2003-06-10

Because it is not a shape3d!

Try this line before your classcast to find out what type it is:

System.out.println(b.getChild(0).getClass());

huanghongbo
Offline
Joined: 2006-02-17

Scene s[] = new Scene[3];
GeometryArray g[] = new GeometryArray[3];
Shape3D shape[] = new Shape3D[3];
///////////////////////////////////
ObjectFile loader = new ObjectFile(ObjectFile.RESIZE);
///////////////////////////////////
for (int i = 0; i < 3; i++) {
s = null;
g = null;
shape = null;
}

if (objFiles == null) {
objFiles = new java.net.URL[3];
objFiles[0] = getClass().getResource("r0.obj");
objFiles[1] = getClass().getResource("r1.obj");
objFiles[2] = getClass().getResource("r2.obj");
}
for (int i = 0; i < 3; i++) {
try {
s = loader.load(objFiles);
} 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);
}

BranchGroup b = s.getSceneGroup();
shape = (Shape3D)b.getChild(0);
b.getAllChildren();
g = (GeometryArray) shape.getGeometry();

shape.setGeometry(g);
}

Appearance app = new Appearance();
Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
app.setMaterial(new Material());
Morph morph = new Morph(g, app);

*************************************
shape = (Shape3D)b.getChild(0);
why right!
*************************************