Generate Point Cloud to STL via Java
Generate Point Cloud to STL using Java library without any 3D modeling software.
How to Generate Point Cloud to STL File Using Java
In order to generate point cloud to STL file, we’ll use
API which is a feature-rich, powerful and easy to use point cloud API for Java platform. You can download its latest version directly from
and install it within your Maven-based project by adding the following configurations to the pom.xml.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-3d</artifactId>
<version>version of aspose-3d API</version>
<classifier>jdk17</classifier>
</dependency>
Steps to Generate Point Cloud to STL via Java
Java programmers can easily generate point cloud to STL in just a few lines of code.
- Load STL file via the constructor of Scene class
- Get pointcloud object of Aspose.3D
- Create a transform object through the EvaluateGlobalTransform method
- Generate point cloud using Merge method
- Call the Scene.Save method with object
System Requirements
Aspose.3D for JAVA is supported on all major operating systems. Just make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- Get latest version of Aspose.3D for Java directly from Maven.
JAVA code to Generate Point Cloud to STL
//The source file that needs to generate the point cloud and the output file after saving
String file = "template.stl";
String output = "outFile.ply";
//create an instance of Scene
Scene scene = new Scene(file);
//Get pointcloud object of Aspose.3D and generate a point cloud
PointCloud pc=new PointCloud();
scene.getRootNode().accept((Node n) ->
{
if(n.getEntities().size()>0)
{
Matrix4 transform=n.evaluateGlobalTransform(true);
for(Entity entity : n.getEntities())
{
if(entity instanceof Geometry){
Geometry g= (Geometry) entity;
Merge(pc, g, transform);
}
else if(entity instanceof IMeshConvertible){
IMeshConvertible mc = (IMeshConvertible) entity;
Mesh mesh=mc.toMesh();
Merge(pc, mesh, transform);
}
}
}
return true;
});
// create an instance of newScene
Scene newScene= new Scene(pc);
PlySaveOptions ply = new PlySaveOptions();
ply.setPointCloud(true);
newScene.save(output, ply);
//Merge method for generating point clouds
private void Merge(PointCloud pc, Geometry g, Matrix4 transform)
{
PointCloud tmp = PointCloud.fromGeometry(g, 10);
for (int i = 0; i < tmp.getControlPoints().size(); i++)
{
Vector4 pt=Matrix4.mul(transform, tmp.getControlPoints().get(i));
pc.getControlPoints().add(pt);
}
}
Free App to Generate Point Cloud to STL
Point Cloud STL right now by visiting our Live Demos website.The live demo has the following benefits
Java 3D Scene Manipulation Library
Aspose.3D is a CAD and Gameware API to load, modify and convert 3D files. API is a standalone and does not require any any 3D modeling or rendering software. One can easily use API for Discreet3DS, WavefrontOBJ, STL (ASCII, Binary), Universal3D, FBX (ASCII, Binary), Collada, glTF, PLY, GLB, DirectX and more formats.STL What is STL File Format?
STL, abbreviation for stereolithrography, is an interchangeable file format that represents 3-dimensional surface geometry. The file format finds its usage in several fields such as rapid prototyping, 3D printing and computer-aided manufacturing. It represents a surface as a series of small triangles, known as facets, where each facet is described by a perpendicular direction and three points representing the vertices of the triangle.
Read MoreOther Supported App to Generate Point Cloud to Formats
Using JAVA, One can also generate point cloud to many other file formats including.