3D Mesh Entity (MeshEnt)
3D Mesh Entity (MeshEnt)
MeshEnt represents 3D mesh entities in CAD and serves as the unified frontend representation for all 3D entity types.
Overview
MeshEnt is used to represent 3D entities imported from DWG files, including:
| DWG Entity Type | sourceType | Description |
|---|---|---|
| AcDb3dSolid | 3DSOLID | 3D solid (box, cylinder, etc.) |
| AcDbRegion | REGION | Region |
| AcDbSurface and derived classes | SURFACE | Surface (extruded, revolved, etc.) |
| AcDbPolyFaceMesh | POLYFACE | Polyface mesh |
| AcDbPolygonMesh | POLYMESH | Polygon mesh |
| AcDbFace / AcDb3dFace | 3DFACE | 3D face |
All 3D entities are converted to triangular meshes (vertices + triangle indices) on import and rendered in wireframe mode. Full 3D coordinate data (including Z values) is preserved to support future 3D viewing plugins.
Constructor
import { MeshEnt } from 'vjcad';
const mesh = new MeshEnt();Typically MeshEnt does not need to be created manually; it is generated automatically when importing DWG files. To create manually:
import { MeshEnt, DbMesh } from 'vjcad';
const mesh = new MeshEnt();
mesh.fromDb({
type: "MESH",
sourceType: "3DSOLID",
vertices: [0,0,0, 100,0,0, 100,100,0, 0,100,0, 50,50,80],
indices: [0,1,4, 1,2,4, 2,3,4, 3,0,4, 0,1,2, 0,2,3],
color: 5
} as DbMesh);
mesh.setDefaults();Properties
| Property | Type | Description |
|---|---|---|
sourceType | string | Original DWG entity type (read-only) |
vertexCount | number | Vertex count (read-only) |
triangleCount | number | Triangle face count (read-only) |
vertices | Float64Array | Vertex data, flattened [x,y,z, x,y,z, ...] (read-only) |
indices | Uint32Array | Triangle face indices, flattened [i,i,i, ...] (read-only) |
Methods
| Method | Description |
|---|---|
fromDb(dbData) | Load from database object |
toDb() | Serialize to database object |
boundingBox() | Get 2D projection bounding box |
getProjectedEdges() | Get projected visible edges (for rendering) |
move(from, to) | Move (supports 3D offset) |
rotate(center, angle) | Rotate around point |
scale(center, factor) | Scale |
mirror(start, end) | Mirror |
stretch(from, to, box) | Stretch |
clone() | Clone |
getPoints() | Get all vertices (Point2D array, with Z) |
Rendering Mode
Currently MeshEnt is rendered in wireframe mode:
- Contour edges (edges referenced by only one triangle) are always drawn
- Internal edges (edges shared by two triangles) are drawn only when marked as visible
- 3D coordinates are projected onto the XY plane for display
Export Restoration
When exporting to DWG, attempts are made to restore the original entity type based on sourceType:
| sourceType | Export Target | Restoration Level |
|---|---|---|
3DFACE | OdDbFace | Exact restoration |
POLYFACE | OdDbPolyFaceMesh | Exact restoration |
POLYMESH | OdDbPolygonMesh (requires meshSize) | Exact/approximate |
REGION / SURFACE / 3DSOLID | Multiple OdDbFace groups | Degraded restoration |
Tips
REGION, SURFACE, and 3DSOLID types are downgraded to 3D face combinations on export because the original parametric data (ACIS/SAT) is lost. This is expected behavior.
Examples
Create Cube Mesh
import { Engine, MeshEnt } from 'vjcad';
const vertices = [
0,0,0, 100,0,0, 100,100,0, 0,100,0,
0,0,100, 100,0,100, 100,100,100, 0,100,100
];
const indices = [
0,1,2, 0,2,3, // bottom
4,6,5, 4,7,6, // top
0,1,5, 0,5,4, // front
2,3,7, 2,7,6, // back
0,3,7, 0,7,4, // left
1,2,6, 1,6,5 // right
];
const cube = new MeshEnt();
cube.fromDb({
type: "MESH",
sourceType: "3DSOLID",
vertices,
indices,
color: 5
});
cube.setDefaults();
Engine.addEntities(cube);
Engine.zoomExtents();Online Examples
| Example | Description | Link |
|---|---|---|
| Create 3D Mesh | MeshEnt basic creation example (cube, pyramid, terrain) | Online Demo{target="_blank"} |