admin管理员组文章数量:1395883
I am trying to render the same 3D object dynamically. When I execute the method responsible for this, the 3D object is rendered on the screen only once. When I execute the method again, it gives me an error. I am using the Java3D API. I intend to render the same object multiple times.
I am doing it this way, but it is giving me an error: [Exception in thread "AWT-EventQueue-0" javax.media.j3d.RestrictedAccessException: Cannot modify capability bits on a live or compiled object]
class graphics_engine //extends javax.swing.JComponent
{
public static com.sun.j3d.utils.geometry.NormalGenerator normal_generator = new com.sun.j3d.utils.geometry.NormalGenerator();
public static com.sun.j3d.utils.geometry.Stripifier strip_fire = new com.sun.j3d.utils.geometry.Stripifier();
public static java.util.ArrayList < javax.vecmath.Point3f[] > model_vertices = new java.util.ArrayList < javax.vecmath.Point3f[] >();
public static BranchGroup branch_group = new BranchGroup();
public static void geometry_info()
{
model_vertices.add( new javax.vecmath.Point3f[]
{
new javax.vecmath.Point3f(-10, 30, -60),
new javax.vecmath.Point3f(-13, 63, 0),
new javax.vecmath.Point3f(-3, 3, 0),
new javax.vecmath.Point3f(5, 3, 0),
new javax.vecmath.Point3f(5, 7, 0),
new javax.vecmath.Point3f(-165, 762, 450),
new javax.vecmath.Point3f(45, -654, 550),
new javax.vecmath.Point3f(-7657, -4440, -5550),
new javax.vecmath.Point3f(-765, 660, -430),
new javax.vecmath.Point3f(-4563, 561, -4560)
});
//int model_numbers = graphics_engine.model_vertices.size();
com.sun.j3d.utils.geometry.GeometryInfo geometry_info = new com.sun.j3d.utils.geometry.GeometryInfo( com.sun.j3d.utils.geometry.GeometryInfo.POLYGON_ARRAY );
com.sun.j3d.utils.geometry.Triangulator triangulator[] = new com.sun.j3d.utils.geometry.Triangulator[graphics_engine.model_vertices.size()];
TransformGroup transform_group[] = new TransformGroup[graphics_engine.model_vertices.size()];
Shape3D shapes_3D[] = new Shape3D[graphics_engine.model_vertices.size()];
try
{
for(int i = 0; i < graphics_engine.model_vertices.size(); i++)
{
triangulator[i] = new com.sun.j3d.utils.geometry.Triangulator();
transform_group[i] = new TransformGroup();
transform_group[i].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
transform_group[i].setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
transform_group[i].setCapability(Group.ALLOW_CHILDREN_EXTEND);
shapes_3D[i] = new Shape3D();
shapes_3D[i].setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
shapes_3D[i].setCapability(Group.ALLOW_CHILDREN_EXTEND);
transform_group[i].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
branch_group.setCapability(Group.ALLOW_CHILDREN_EXTEND);
int[] StripCounts = {5,5};
int[] countourCountArray = {StripCounts.length};
geometry_info.setCoordinates(graphics_engine.model_vertices.get(i));
geometry_info.setStripCounts(StripCounts);
geometry_info.setContourCounts(countourCountArray);
triangulator[i].triangulate(geometry_info);
graphics_engine.normal_generator.generateNormals(geometry_info);
graphics_engine.strip_fire.stripify(geometry_info);
shapes_3D[i].setGeometry(geometry_info.getGeometryArray());
transform_group[i].addChild(shapes_3D[i]);
branch_group.addChild(transform_group[i]);
gui_components.objecto_branch_grupo.addChild(graphics_engine.branch_group);
}
}
catch(java.lang.NullPointerException execcao)
{
execcao.printStackTrace();
}
}
}
I am trying to render the same 3D object dynamically. When I execute the method responsible for this, the 3D object is rendered on the screen only once. When I execute the method again, it gives me an error. I am using the Java3D API. I intend to render the same object multiple times.
I am doing it this way, but it is giving me an error: [Exception in thread "AWT-EventQueue-0" javax.media.j3d.RestrictedAccessException: Cannot modify capability bits on a live or compiled object]
class graphics_engine //extends javax.swing.JComponent
{
public static com.sun.j3d.utils.geometry.NormalGenerator normal_generator = new com.sun.j3d.utils.geometry.NormalGenerator();
public static com.sun.j3d.utils.geometry.Stripifier strip_fire = new com.sun.j3d.utils.geometry.Stripifier();
public static java.util.ArrayList < javax.vecmath.Point3f[] > model_vertices = new java.util.ArrayList < javax.vecmath.Point3f[] >();
public static BranchGroup branch_group = new BranchGroup();
public static void geometry_info()
{
model_vertices.add( new javax.vecmath.Point3f[]
{
new javax.vecmath.Point3f(-10, 30, -60),
new javax.vecmath.Point3f(-13, 63, 0),
new javax.vecmath.Point3f(-3, 3, 0),
new javax.vecmath.Point3f(5, 3, 0),
new javax.vecmath.Point3f(5, 7, 0),
new javax.vecmath.Point3f(-165, 762, 450),
new javax.vecmath.Point3f(45, -654, 550),
new javax.vecmath.Point3f(-7657, -4440, -5550),
new javax.vecmath.Point3f(-765, 660, -430),
new javax.vecmath.Point3f(-4563, 561, -4560)
});
//int model_numbers = graphics_engine.model_vertices.size();
com.sun.j3d.utils.geometry.GeometryInfo geometry_info = new com.sun.j3d.utils.geometry.GeometryInfo( com.sun.j3d.utils.geometry.GeometryInfo.POLYGON_ARRAY );
com.sun.j3d.utils.geometry.Triangulator triangulator[] = new com.sun.j3d.utils.geometry.Triangulator[graphics_engine.model_vertices.size()];
TransformGroup transform_group[] = new TransformGroup[graphics_engine.model_vertices.size()];
Shape3D shapes_3D[] = new Shape3D[graphics_engine.model_vertices.size()];
try
{
for(int i = 0; i < graphics_engine.model_vertices.size(); i++)
{
triangulator[i] = new com.sun.j3d.utils.geometry.Triangulator();
transform_group[i] = new TransformGroup();
transform_group[i].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
transform_group[i].setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
transform_group[i].setCapability(Group.ALLOW_CHILDREN_EXTEND);
shapes_3D[i] = new Shape3D();
shapes_3D[i].setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
shapes_3D[i].setCapability(Group.ALLOW_CHILDREN_EXTEND);
transform_group[i].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
branch_group.setCapability(Group.ALLOW_CHILDREN_EXTEND);
int[] StripCounts = {5,5};
int[] countourCountArray = {StripCounts.length};
geometry_info.setCoordinates(graphics_engine.model_vertices.get(i));
geometry_info.setStripCounts(StripCounts);
geometry_info.setContourCounts(countourCountArray);
triangulator[i].triangulate(geometry_info);
graphics_engine.normal_generator.generateNormals(geometry_info);
graphics_engine.strip_fire.stripify(geometry_info);
shapes_3D[i].setGeometry(geometry_info.getGeometryArray());
transform_group[i].addChild(shapes_3D[i]);
branch_group.addChild(transform_group[i]);
gui_components.objecto_branch_grupo.addChild(graphics_engine.branch_group);
}
}
catch(java.lang.NullPointerException execcao)
{
execcao.printStackTrace();
}
}
}
Share
Improve this question
edited Mar 27 at 22:21
jewelsea
160k15 gold badges381 silver badges418 bronze badges
asked Mar 27 at 12:52
faztudo pedrofaztudo pedro
292 bronze badges
2
- 2 Is this AWT, or JavaFX? Can you create a minimal reproducible example; it's not at all clear what you're doing or what is causing the error from the code snippet you have posted. Also, please use standard naming conventions when posting code. – James_D Commented Mar 27 at 13:37
- This is Java3D, not JavaFX. I updated your tags accordingly. – jewelsea Commented Mar 27 at 22:21
1 Answer
Reset to default 3This is why:
public static BranchGroup branchGroup = new BranchGroup();
You have a static BranchGroup, that's it, there will exist only one.
Every time you run the method the same object is called, which is the cause of the error.
In order to avoid this, you could insert the creation of the BranchGroup at each call (so it creates a new one instead of trying to modify a live one), inside the geometryInfo method:
public static void geometryInfo()
{
//...
BranchGroup branchGroup = new BranchGroup();
//...
}
p.s: Note that I modified the names for Java naming convention.
本文标签: javaHow to Render the same model multiple timesStack Overflow
版权声明:本文标题:java - How to Render the same model multiple times - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744088143a2588916.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论