找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 719|回复: 0

[分享]:VBA调用MDL绘制楔形多边体

[复制链接]
发表于 2004-9-16 11:37:23 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
虽然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
绘制出的效果图如附图所示。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-21 04:27 , Processed in 0.284588 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表