3D model file read/write. Net SDK, 3d model. netsdk
AnyCAD. Net/C ++ SDK supports multiple 3D/2D file formats, such as BREP, STEP, IGES, STL, DXF, 3DS, OBJ, FBX, SKP, IFC, DAE ...... .
1. geometric data I/O
Supports BREP, IGES, STEP, and STL formats. BREP supports reading and saving string streams.
1.1. Read files
Supports reading BREP, IGES, STEP, and STL, and the results are saved in TopoShape.
Example of STEP file reading:
TopoShape shape = GlobalInstance. BrepTools. LoadFile ("d: \ anycad. stp "); |
Note:
L if you need to find the body, surface, edge, vertex and other information contained in TopoShape, use the GlobalInstance. TopoExplor method.
L reading STL in this way is slow. If you do not perform geometric operations on the model, it is not recommended.
1.2. Save the file
It can be saved as BREP, IGES, STEP, and STL.
TopoShapeGroup group = new TopoShapeGroup (); Group. Add (shape ); GlobalInstance. BrepTools. SaveFile (group, "d: \ anycad. brep "); |
2. file stream
Only operations are performed in the memory, and I/O is not used. The BREP format is supported.
// 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 STEP/IGES
If you want to read the color information in the STEP and IGES files, you cannot use the above API. You need to use both the IgesReader and StepReader in the TopoShapeReaderContext and AnyCAD. Exchange modules.
Code reference StpViewer project: https://github.com/anycad/StpViewer
First, inherit the subclass from TopoShapeReaderContext, such as CADBrowser, and overload its virtual function to receive the read geometric objects and colors.
Public override void OnSetFaceColor (ColorValue clr) is used to save the color of the current object.
Call TopoShapeReaderContext object as the Read parameter.
CADBrower browser = new CADBrower (this. treeViewStp, this. renderView ); AnyCAD. Exchange. IgesReader reader = new AnyCAD. Exchange. IgesReader (); Reader. Read (dlg. FileName, browser ); |
Note: You can use the same method to read the DXF file.
4. Read STL/3DS/OBJ, etc.
This type of model can only be used for display and cannot perform geometric operations on the TopoShape hierarchy. MatrixBuilder can be used to perform matrix transformation on SceneNode.
Sample Code:
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 (); } } |
We can see that the returned value of SceneReader. LoadFile is GroupSceneNode, while that of GlobalInstance. BrepTools. LoadFile is 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/