Generate Point Cloud to GLTF via C#
Build your own .NET apps to generate point cloud to GLTF files using server-side APIs.
How to Generate Point Cloud to GLTF File Using C#
In order to generate point cloud to GLTF file, we’ll use
API which is a feature-rich, powerful and easy to use API for C# platform to be used with generate point cloud. Open
package manager, search for Aspose.3D and install. You may also use the following command from the Package Manager Console.
Package Manager Console Command
PM> Install-Package Aspose.3D
Steps to Generate Point Cloud to GLTF via C#
Aspose.3D makes it easy for the developers to generate point cloud to the GLTF file with just few lines of code.
- Load GLTF 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 .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with .NET Framework, .NET Core, Mono
- Development environment like Microsoft Visual Studio
- Aspose.3D for .NET referenced in your project
C# code to Generate Point Cloud to GLTF
//The source file that needs to generate the point cloud
string file = "template.gltf";
// create an instance of Scene
Scene scene = new Scene(file);
//Get pointcloud object of Aspose.3D and generate a point cloud
var pc = new PointCloud();
scene.RootNode.Accept((Node n) =>
{
if (n.Entities.Count > 0)
{
var transform = n.EvaluateGlobalTransform(true);
foreach (var entity in n.Entities)
{
if (entity is Geometry g)
{
Merge(pc, g, transform);
}
else if (entity is IMeshConvertible mc)
{
var mesh = mc.ToMesh();
Merge(pc, mesh, transform);
}
}
}
return true;
});
//Merge method for generating point clouds
private void Merge(PointCloud pc, Geometry g, Matrix4 transform)
{
var tmp = PointCloud.FromGeometry(g, 10);
for (int i = 0; i < tmp.ControlPoints.Count; i++)
{
var pt = transform * tmp.ControlPoints[i];
pc.ControlPoints.Add(pt);
}
}
// create an instance of newScene
var newScene = new Scene(pc);
//When saving, you need to create a SaveOptions object of the save format
string output=System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".ply";
PlySaveOptions ply = new PlySaveOptions();
ply.PointCloud = true;
newScene.Save(output,ply);
About Aspose.3D for .NET API
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.Free App to Generate Point Cloud to GLTF
Check our live demos to Point Cloud 3DS with following benefits.
GLTF What is GLTF File Format?
glTF (GL Transmission Format) is a 3D file format that stores 3D model information in JSON format. The use of JSON minimizes both the size of 3D assets and the runtime processing needed to unpack and use those assets. It was adopted for the efficient transmission and loading of 3D scenes and models by applications.
Read MoreOther Supported App to Generate Point Cloud to Formats
Using C#, One can also generate point cloud to many other file formats including.