乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 67|回复: 4

碰撞检测

[复制链接]

5

主题

10

帖子

2

银币

初来乍到

Rank: 1

铜币
30
发表于 2007-2-12 08:03:44 | 显示全部楼层 |阅读模式

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2007-2-12 09:59:07 | 显示全部楼层
不。您必须检查每个块是否存在固体,然后将每个块引用与模型空间的其余部分进行检查。
(当然,您可以检查块本身中的冲突。)
一个更简单的方法,尽管很乱,是分解块引用(这使块引用保持不变)将它们添加到数组中并删除不冲突的。
回复

使用道具 举报

5

主题

10

帖子

2

银币

初来乍到

Rank: 1

铜币
30
发表于 2007-2-12 10:55:58 | 显示全部楼层

您能解释一下。
如何分解块引用并保持块引用不变?什么是blockref?是积木本身吗?
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2007-2-12 14:21:04 | 显示全部楼层
就像CmdrDuh说的,一个块就像一个对象列表,它们相对于零的位置。
块和块引用是完全不同的,你需要掌握差异才能编写成功的代码。
尝试使用分解的小子,然后查看结果。
回复

使用道具 举报

5

主题

10

帖子

2

银币

初来乍到

Rank: 1

铜币
30
发表于 2007-2-12 21:57:08 | 显示全部楼层
在花了更多的时间之后,感觉“足够好”,可以与你们分享产品。
请参阅代码 + 结果窗口的附件。
下面是代码。我用我的SSet和Arrays愚弄了一下。对我来说,感觉一定有一种更简单的方法来处理这个问题。但是,某些函数不接受数组,而其他函数则不接受 Sset。
  1. '#####################################
  2. '# ClashDetect creates 3D solids from
  3. '# selected 3D solids where they
  4. '# interfere with eachother
  5. '# Sub by J.v.d.Staaij
  6. '# V1.0
  7. '#####################################
  8. Sub ClashDetect()
  9.     'original
  10.     Dim originalItems As AcadSelectionSet
  11.     'copy
  12.     Dim copyItem As AcadEntity
  13.     Dim CopiedItemsSSet As AcadSelectionSet
  14.     'explode
  15.     Dim TempEntity As AcadEntity
  16.     Dim TempItem As Variant
  17.     Dim TempArray(0 To 0) As AcadBlockReference
  18.     Dim Counter As Integer
  19.     Dim TempSubEntity As Acad3DSolid
  20.     'clas detect
  21.     Dim ClashSolid As Acad3DSolid
  22.     Dim newLayer, oldLayer
  23.     Dim ChecksExecuted As Long
  24.     Dim FoundClash As Long
  25.     Dim counterNotChecked As Long
  26.     Dim SolidCreationErrorCount As Long
  27.     'pre check
  28.     Dim obj1 As AcadEntity
  29.     Dim obj2 As AcadEntity
  30.     Dim pmin As Variant
  31.     Dim pmax As Variant
  32.     Dim qmin As Variant
  33.     Dim qmax As Variant
  34.     Dim Clash As Integer
  35.    
  36.    
  37.     'Let user select items
  38.     Set originalItems = ThisDrawing.SelectionSets.Add("block")
  39.     originalItems.SelectOnScreen
  40.     'Create templayer
  41.     Set tempLayer = ThisDrawing.Layers.Add("TEMPLAYER")
  42.     'Jumpout when nothing selected
  43.     If originalItems.Count = 0 Then GoTo Einde
  44.     'define dynamic copyarray
  45.     ReDim copyArray(0 To originalItems.Count - 1) As AcadEntity
  46.     'copy each item in original selection
  47.     For i = 0 To originalItems.Count - 1
  48.         Set copyItem = originalItems(i).Copy()
  49.         copyItem.Layer = "TEMPLAYER"
  50.         Set copyArray(i) = copyItem
  51.     Next
  52.     'create copy selectionset
  53.     Set CopiedItemsSSet = ThisDrawing.SelectionSets.Add("ArrayName")
  54.     'store copyarray in selectionset
  55.     CopiedItemsSSet.AddItems copyArray
  56.    
  57.     'Explode blockrefs (and re-explode if necesary)
  58. ExplodeAgain:
  59.     Counter = 0
  60.     For Each TempEntity In CopiedItemsSSet
  61.             If TypeOf TempEntity Is AcadBlockReference Then
  62.                     Set TempArray(0) = TempEntity
  63.                     CopiedItemsSSet.RemoveItems TempArray
  64.                     TempItem = TempEntity.Explode
  65.                     TempEntity.Delete
  66.                     CopiedItemsSSet.AddItems (TempItem)
  67.                     Counter = Counter + 1
  68.             End If
  69.         Next
  70.     If Counter  0 Then GoTo ExplodeAgain
  71.     'store currenty layer
  72.     Set oldLayer = ThisDrawing.ActiveLayer
  73.     'create layer for clashing items
  74.     Set newLayer = ThisDrawing.Layers.Add("DetectedClash")
  75.     ThisDrawing.ActiveLayer = newLayer
  76.     ThisDrawing.ActiveLayer.color = 6
  77.     'Set results counters
  78.     ChecksExecuted = 0
  79.     FoundClash = 0
  80.     counterNotChecked = 0
  81.    
  82.     For i = 0 To CopiedItemsSSet.Count - 1
  83.         'Check if item is 3D Solid
  84.         If Not (CopiedItemsSSet(i).ObjectName = "AcDb3dSolid") Then
  85.         counterNotChecked = counterNotChecked + 1
  86.         GoTo SkipCheckObject
  87.         End If
  88.         ' start checking
  89.         For j = i + 1 To CopiedItemsSSet.Count - 1
  90.             If Not (CopiedItemsSSet(j).ObjectName = "AcDb3dSolid") Then GoTo SkipCheckAgainst 'Check if against-item is 3D Solid
  91.                 If Not (CopiedItemsSSet(i) Is CopiedItemsSSet(j)) Then 'Don't do self check
  92.                     'Do pre check (easier for acad to compare bounding boxes (10-20x faster))
  93.                     CopiedItemsSSet(i).GetBoundingBox pmin, pmax
  94.                     CopiedItemsSSet(j).GetBoundingBox qmin, qmax
  95.                     Clash = 0
  96.                     For k = 0 To 2
  97.                         limiet = (pmax(k) - pmin(k) + qmax(k) - qmin(k))
  98.                         afstand = Abs(pmax(k) + pmin(k) - qmax(k) - qmin(k))
  99.                         If afstand < limiet Then
  100.                             Clash = Clash + 1
  101.                         End If
  102.                     Next k
  103.                     If Clash = 3 Then ' Precheck is true
  104.                         On Error GoTo ErrorSolidCreate 'Take care of Modeling Operation Errors
  105.                         Set ClashSolid = CopiedItemsSSet(i).CheckInterference(CopiedItemsSSet(j), True)
  106.                         On Error GoTo ErrorTrap
  107.                         ' set found clash to DetectedClash layer
  108.                         If Not (ClashSolid Is Nothing) Then
  109.                             ClashSolid.Layer = "DetectedClash"
  110.                             FoundClash = FoundClash + 1
  111.                         End If 'Not (ClashSolid Is Nothing) Then
  112.                         ChecksExecuted = ChecksExecuted + 1
  113.                     End If 'If Clash = 3 Then
  114.                 Else
  115.             End If 'If Not (CopiedItemsSSet(i) Is CopiedItemsSSet(j)) Then 'Don't do self check
  116. SkipCheckAgainst:
  117.         Next
  118. SkipCheckObject:
  119.     Next
  120.     'result window
  121.     ClashDetectResults.Results.Caption = "" & ChecksExecuted & vbCrLf & _
  122.                                             FoundClash & vbCrLf & _
  123.                                             counterNotChecked & vbCrLf & _
  124.                                             SolidCreationErrorCount & ""
  125.    
  126.     ClashDetectResults.Show
  127.     'Restore original layer
  128.     ThisDrawing.ActiveLayer = oldLayer
  129.     'delete templayer
  130.     'ThisDrawing.Layers.Delete (TO DO)
  131.    
  132.     'Error trapping
  133. ErrorTrap:
  134.     CopiedItemsSSet.Erase
  135.     CopiedItemsSSet.Delete
  136.    
  137. Einde:
  138.     originalItems.Delete
  139.     Exit Sub
  140.    
  141. ErrorSolidCreate:
  142.     SolidCreationErrorCount = SolidCreationErrorCount + 1
  143.     Resume Next
  144.    
  145. End Sub
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-7 09:15 , Processed in 2.287773 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表