- UID
- 5798
- 积分
- 1046
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-5-28
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
虽然VBA中不含有某些复杂功能,但可通过调用MDL API来实现。下面的例子就是用VBA 调用MDL API中的Mesh创建函数来绘制一个底面为正六边形的楔形多边体!
Option Explicit
Declare Function mdlMesh_newVariablePolyface Lib "stdbspline.dll" _
(ByRef ppMeshED As Long, ByVal pTemplate As Long, ByRef pIndices As Long, _
ByVal numIndices As Long, ByRef pXYZ As Point3d, ByVal numVertex As Long) As Long
Declare Function mdlElmdscr_add Lib "stdmdlbltin.dll" (ByVal elemDescr As Long) As Long
Declare Sub mdlElmdscr_display Lib "stdmdlbltin.dll" _
(ByVal elemDescr As Long, ByVal modelRef As Long, ByVal drawMode As Long)
Declare Sub mdlElmdscr_freeAll Lib "stdmdlbltin.dll" (ByRef elemDescr As Long)
Function createMesh() As Long
Dim pMeshED As Long
Dim aXYZ() As Point3d
Dim aIndex() As Long
Dim nXYZ As Long, nIndex As Long
Dim lStatus As Long
'--------顶点坐标
nXYZ = 8
ReDim aXYZ(1 To nXYZ)
aXYZ(1) = Point3dFromXYZ(0, 0, 0)
aXYZ(2) = Point3dFromXYZ(1, 0, 0)
aXYZ(3) = Point3dFromXYZ(2, 1, 0)
aXYZ(4) = Point3dFromXYZ(2, 2, 0)
aXYZ(5) = Point3dFromXYZ(1, 2, 0)
aXYZ(6) = Point3dFromXYZ(0, 1, 0)
aXYZ(7) = Point3dFromXYZ(0.5, 0.5, 3)
aXYZ(8) = Point3dFromXYZ(1.5, 1.5, 3)
'--------顶点索引(按可变大小的面循环方式)
nIndex = 33
ReDim aIndex(0 To nIndex - 1)
'正六边形底面
aIndex(0) = 6: aIndex(1) = 5: aIndex(2) = 4
aIndex(3) = 3: aIndex(4) = 2: aIndex(5) = 1: aIndex(6) = 0
'第1面
aIndex(7) = 2: aIndex(8) = 3: aIndex(9) = 8: aIndex(10) = 7: aIndex(11) = 0
'第2面
aIndex(12) = 5: aIndex(13) = 6: aIndex(14) = 7: aIndex(15) = 8: aIndex(16) = 0
'第3面
aIndex(17) = 1: aIndex(18) = 2: aIndex(19) = 7: aIndex(20) = 0
'第4面
aIndex(21) = 3: aIndex(22) = 4: aIndex(23) = 8: aIndex(24) = 0
'第5面
aIndex(25) = 4: aIndex(26) = 5: aIndex(27) = 8: aIndex(28) = 0
'第6面
aIndex(29) = 6: aIndex(30) = 1: aIndex(31) = 7: aIndex(32) = 0
pMeshED = 0
lStatus = mdlMesh_newVariablePolyface(pMeshED, 0, aIndex(LBound(aIndex)), nIndex, aXYZ(LBound(aXYZ)), nXYZ)
createMesh = pMeshED
End Function
Sub addMesh()
Dim pED As Long
pED = createMesh
If Not pED = 0 Then
If mdlElmdscr_add(pED) = 0 Then: MsgBox "添加失败! "
mdlElmdscr_display pED, 0, 0
mdlElmdscr_freeAll pED
End If
End Sub
绘制出的效果图如附图所示。 |
|