3D 通过 Java 进行格式转换
无需安装任何 3D 建模和渲染软件即可转换 3D 文件格式以构建跨平台 Java 应用程序。
对于创建、编辑、操作和保存 3D 图形应用程序,Java 3D API 提供了执行此类功能的高级方法,而无需安装任何 3D 建模和渲染软件。很少有构建不同 3D 几何形状的网格、创建 3D 场景文件、在 Cube 上设置法线或 UV、格式化元素、添加动画属性等等。
将 3D 文件转换为不同格式
转换过程很简单。只需使用加载源 3D 文件 场景类 .由于场景是具有节点、几何、纹理、材质、动画、姿势、子场景等的顶级对象。创建相关的 保存选项 例如 AmfSaveOptions、ColladaSaveOptions、Discreet3dsSaveOptions、DracoSaveOptions、FbxSaveOptions、GltfSaveOptions、RvmSaveOptions、StlSaveOptions、U3dSaveOptions 等,并相应地设置属性。最后使用输出文件调用 save 方法并创建目标格式保存选项对象。此外,使用 API 程序员甚至可以将 3D 场景保存为 HTML。
Java AMF 到 3DS 转换的代码
// load the AMF in an object of Scene | |
Scene amfto3ds = new Scene("template.amf"); | |
// create an instance of 3dsSaveOptions | |
Discreet3dsSaveOptions options = new Discreet3dsSaveOptions(); | |
// save AMF as a 3DS | |
amfto3ds.save("output.3ds", options); |
通过 Java 将 3D 场景转换为 HTML
// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-Java | |
// Initialize a scene | |
Scene scene = new Scene(); | |
// Initialize a node | |
Node node = scene.getRootNode().createChildNode(new Cylinder()); | |
// Set child node properites | |
LambertMaterial mat = new LambertMaterial(); | |
mat.setDiffuseColor(new Vector3(0.34,0.59, 0.41)); | |
node.setMaterial(mat); | |
Light light = new Light(); | |
light.setLightType(LightType.POINT); | |
scene.getRootNode().createChildNode(light).getTransform().setTranslation(10, 0, 10); | |
// Initialize HTML5SaveOptions | |
HTML5SaveOptions opt = new HTML5SaveOptions(); | |
// Turn off the grid | |
opt.setShowGrid(false); | |
//Turn off the user interface | |
opt.setShowUI(false); | |
scene.save(RunExamples.getDataDir() + "html5SaveOption.html", FileFormat.HTML5); |