Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problems with Text3D: java.lang.IllegalArgumentException

843799Mar 20 2004 — edited Jun 4 2004
Hello,
I try to modify an Java3D example,
I want to display a 3D-Text,
but the setString(String s) of the Text3D-class causes this execption,
if String s is not null:

***** polygon with only one vertex?! *****

java.lang.IllegalArgumentException: TriangleArray: illegal vertexCount
at javax.media.j3d.TriangleArray.<init>(TriangleArray.java:119)
at com.sun.j3d.utils.geometry.GeometryInfo.getGeometryArray(GeometryInfo.java:2557)
at javax.media.j3d.Font3D.triangulateGlyphs(Font3D.java:402)
at javax.media.j3d.Text3DRetained.updateCharacterData(Text3DRetained.java:684)
at javax.media.j3d.Text3DRetained.setString(Text3DRetained.java:234)
at javax.media.j3d.Text3D.setString(Text3D.java:350)
at Static3DWorld.createSceneGraph(Static3DWorld.java:138)
at Static3DWorld.<init>(Static3DWorld.java:44)
at Static3DWorld.main(Static3DWorld.java:185)

Here is the source-code:

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.j3d.Appearance;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.Font3D;
import javax.media.j3d.FontExtrusion;
import javax.media.j3d.Material;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Text3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.vecmath.Color3f;

import com.sun.j3d.utils.universe.SimpleUniverse;
public class Static3DWorld extends JFrame {
private Transform3D rotate1 = new Transform3D();
private Transform3D rotate2 = new Transform3D();

/**
* There are three fundamental
* steps in creating a 3D world:
* Create a Canvas3D object.
* Create a scene graph.
* Connect the Canvas3D object to a BranchGroup object
* that points to the root of the scene graph.
*
*/
public Static3DWorld()
{
super("Static3DWorld");

//Create a Canvas 3D Object
Canvas3D canvas3D = createCanvas3D();

//Create a BranchGroup Object,
//that points to the root of the scene graph
BranchGroup scene = createSceneGraph();

//Connect them
connect(canvas3D, scene);


this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
this.repaint();
}

/**
* The createCanvas3D() method adjusts
* the size of a JFrame.
* The method then creates a canvas3D object
* and adds it to the center of the JFrame.
* The Java 3D API specific task is to call
* the static method getPreferredConfiguration(),
* and pass the result into the Canvas3D constructor.
* @return the Canvas3D Object
*/
private Canvas3D createCanvas3D()
{
//JFrame size
setSize(300, 300);


//Set BorderLayout
getContentPane().setLayout(new BorderLayout());

//Java3D-Specific Task
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();

//Create the Canvas3D Object and pass the
//configuration to the Construktor
Canvas3D canvas3D = new Canvas3D(config);

//add the Canvas to the JFrame
getContentPane().add(canvas3D);

//return it
return canvas3D;
}

/**
* The createSceneGraph() method.
* The BranchGroup object, objRoot,
* points to the root of the scene graph.
* The rotator object is a TransformGroup
* that rotates an object Pi/4 over the x axis
* and Pi/4 over the y axis.
* This TransformGroup is added
* as a child of the objRoot.
* @return
*/
private BranchGroup createSceneGraph()
{

//create the BranchGroup (root of the scenegraph)
BranchGroup objRoot = new BranchGroup();

//create a TransformGroup
TransformGroup rotator = new TransformGroup(
rotateCube());
//add it to the root of the scene Graph
objRoot.addChild(rotator);

//create a new Shape3D-Object
Shape3D s3d = new Shape3D();

//create a Font
Font f = new
Font("SansSerif",32,Font.PLAIN);


//create a 3D-Font
Font3D f3d = new Font3D(f,new FontExtrusion());

//create a 3DText
Text3D txt = new Text3D();
txt.setFont3D(f3d);

/*
* The line, that causes the
* java.lang.IllegalArgumentException.
* txt.setString(null) will not throw it.
*/
txt.setString("Test");
//End of the problem-line

txt.setCapability(Text3D.ALLOW_STRING_WRITE);

//add the Text3D-Object to the Shape3D Object
s3d.setGeometry(txt);

//create a new Appearance-Object
Appearance a = new Appearance();
Material m = new Material();
m.setLightingEnable(true);
ColoringAttributes y =
new ColoringAttributes(new Color3f(1.0f,1.0f,0.0f),ColoringAttributes.FASTEST);
a.setColoringAttributes(y);
a.setMaterial(m);

//add it to the Shape3D-Object
s3d.setAppearance(a);

//Part of the original Example
//add a ColorCube
//rotator.addChild(new ColorCube(0.3));

//add the Shape3D-Object to the TransformGroup-Object
rotator.addChild(s3d);

//compile the BranchGroup
objRoot.compile();

return objRoot;
}

private Transform3D rotateCube()
{
rotate1.rotX(Math.PI / 4.0d);
rotate2.rotY(Math.PI / 4.0d);
rotate1.mul(rotate2);
return rotate1;
}
private void connect(Canvas3D canvas3D,
BranchGroup scene) {
SimpleUniverse simpleU =
new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().
setNominalViewingTransform();
simpleU.addBranchGraph(scene);
}
public static void main(String[] args) {
new Static3DWorld().setVisible(true);
}
}

It must be a stupid mistake,
because it?s my first experience with java3D.
Thanx for reading and thinking!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 2 2004
Added on Mar 20 2004
1 comment
181 views