3D model file read-write. Net SDK

Source: Internet
Author: User

Anycad. Net/c++ SDK supports a variety of 3d/2d file formats, such as Brep, STEP, IGES, STL, DXF, 3DS, OBJ, FBX, SKP, IFC, DAE ... And so on, depending on the use of the scene to provide different APIs.

1. Geometric data I/O

Supports Brep, IGES, STEP, and STL formats, where BREP supports reading and saving string streams.

1.1. Reading files

Supports reading of Brep, IGES, step, and STL, with results stored in toposhape.

Step File Read Example:

Toposhape shape = GlobalInstance.BrepTools.LoadFile ("D:\\ANYCAD.STP");

Attention:

L If you need to find the toposhape contains the body, polygon, edge, vertex and other information, so Globalinstance.topoexplor method.

Using this method to read the STL is slow and is not recommended if the model is not geometrically manipulated.

1.2. Save the file

Support is saved as Brep, IGES, step, and STL.

Toposhapegroup Group = new Toposhapegroup ();

Group. ADD (Shape);

GlobalInstance.BrepTools.SaveFile (Group, "D:\\anycad.brep");

2. File stream

operates only in memory and does not occupy I/O. Supports BREP format.

Save to Buffer

Toposhape sphere = GlobalInstance.BrepTools.MakeSphere (Vector3.zero, 100);

byte[] buffer = GlobalInstance.BrepTools.SaveBuffer (sphere);

Load from Buffer

Toposhape newsphere = GlobalInstance.BrepTools.LoadBuffer (buffer);

3. Read the color of the Step/iges

If you want to read the color information in the step and iges files, you cannot use the API above. The Igesreader and Stepreader in the Toposhapereadercontext and Anycad.exchange modules need to be used together.

Code Reference Stpviewer Project: Https://github.com/anycad/StpViewer

First, inheriting subclasses, such as Cadbrowser, from Toposhapereadercontext, overloads its virtual functions to receive the geometry and color that is read.

public override void Onsetfacecolor (ColorValue CLR) is used to hold the color of the current object.

Then, call the Toposhapereadercontext object as read parameter passed in.

Cadbrower browser = new Cadbrower (THIS.TREEVIEWSTP, This.renderview);

AnyCAD.Exchange.IgesReader reader = new AnyCAD.Exchange.IgesReader ();

Reader. Read (dlg. FileName, browser);

Note: DXF files can also be read using the same method

4. Read Stl/3ds/obj, etc.

This type of model can only be used for display, not for toposhape-level geometry operations, and for matrix transformation of Scenenode with Matrixbuilder.

code example:

OpenFileDialog Opendlg = new OpenFileDialog ();

Opendlg.filter = "STL (*.stl) |*.stl|3ds (*.3DS) |*.3ds|obj (*.obj) |*.obj";

if (opendlg.showdialog () = = DialogResult.OK)

{

Scenereader reader = new Scenereader ();

Groupscenenode node = reader. LoadFile (Opendlg.filename);

if (node! = NULL)

{

Node. SetName (Opendlg.safefilename);

Renderview.showscenenode (node);

Renderview.requestdraw ();

}

}

You can see that Scenereader.loadfile is returning Groupscenenode, and GlobalInstance.BrepTools.LoadFile is returning toposhape.

5. References

L Stpviewer:https://github.com/anycad/stpviewer

L Dxfviewer:https://github.com/anycad/dxfviewer

L SDK Download: http://www.anycad.net/sdk/

3D model file read-write. Net SDK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.