旧版Java应用正在读取CAD X3D文件和缺少的几何数据。我已经在网上搜索并寻找“ 动手专家意见/建议”以获取用于读取X3D文件的组件或Java代码段。
谢谢
示例代码:
public Element loadGraphicsFile(File graphicsFile) throws Exception {
Element sceneRoot = null;
InputStream stream = null;
try {
String fileName = graphicsFile.getName();
if(fileName.endsWith(".gz") || fileName.endsWith(".x3dz")) {
stream = new GZIPInputStream(new FileInputStream(graphicsFile));
}
else {
stream = new FileInputStream(graphicsFile);
}
SAXBuilder builder = new SAXBuilder();
Document fileDocument = builder.build(stream);
Element docRoot = fileDocument.getRootElement(); // <X3D/>
Element topSceneRoot = docRoot.getChild("Scene"); // <Scene>
sceneRoot = topSceneRoot.getChild("Transform"); // <Transform>
Element tempRoot = sceneRoot.getChild("Transform"); // Nested <Transform>
if(tempRoot != null) { //some (CATIA?) have 2nd transform level
sceneRoot = tempRoot;
} finally {
if(stream != null) stream.close();
}
return sceneRoot;
}
}