找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 845|回复: 2

[他山之石] m2s Mesh-to-Solid

[复制链接]

已领礼包: 264个

财富等级: 日进斗金

发表于 2016-9-19 01:10:59 | 显示全部楼层 |阅读模式

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

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

×


  1. ;;    M2S  (Mesh-to-Solid)
  2. ;;    Creates an ACIS solid from an open 3d polygon mesh.
  3. ;;
  4. ;;    Take 2 - Updated 7/7/1998
  5. ;;       - Works with REVSURF'd meshes that touch or cross axis of revolution.
  6. ;;       - Works even if solid being constructed is not fully visible on screen.
  7. ;;       - Works with all open meshes created with REVSURF, RULESURF,
  8. ;;          EDGESURF, TABSURF, AI_MESH, and 3DMESH. Most of the stock 3D
  9. ;;          surfaces will work if you use DDMODIFY to open them in the M
  10. ;;          and N directions.
  11. ;;       - Does not work with polyface entities.
  12. ;;
  13. ;;    (c) Copyright 1998 Bill Gilliss.  
  14. ;;        All rights reserved... such as they are.
  15. ;;
  16. ;;    bill.gilliss@aya.yale.edu    gilliss@iglou.com
  17. ;;
  18. ;;       I wrote this to create sculptable ACIS terrain models
  19. ;;    for architectural site renderings. It could also be used
  20. ;;    to create thin shells from meshes, by subtracting a moved
  21. ;;    copy of the solid from the original solid. Let me know of
  22. ;;    other uses you find for it, or problems you encounter.
  23. ;;
  24. ;;       The solid is created by projecting each mesh facet "down"
  25. ;;    the current z-axis to a plane a user-specified distance below
  26. ;;    the lowest vertex. To assure that all parts of the mesh are
  27. ;;    generated as solids, this distance can not be zero, but the
  28. ;;    solid can be SLICEd later if need be.
  29. ;;
  30. ;;       The solid will match the displayed mesh: if the mesh has
  31. ;;    been smoothed and SPLFRAME is set to 0, the solid will be
  32. ;;    smoothed. Otherwise, it will not be. The mesh itself is not
  33. ;;    changed at all.
  34. ;;


  35. (defun c:m2s (/  ent ename entlst M N MN SN SM ST smooth oldecho vtx d1
  36.                  low vtxcnt vtxmax bot bottom p1 p2 p3 p4 c1 c2 c3 c4
  37.                  b1 b2 b3 b4 soldepth ssall ssrow)

  38. (setq oldecho (getvar "cmdecho"))
  39. (setq oldsnap (getvar "osmode"))
  40. (setq oldblip (getvar "blipmode"))
  41. (setvar "cmdecho" 0)
  42. (setvar "osmode" 0)
  43. (setvar "blipmode" 0)
  44. (command "undo" "begin")

  45. ;;select the mesh
  46.   (setq ent (entsel "Select a polygon mesh to solidify: "))
  47.   (setq ename (car ent))
  48.   (setq entlst (entget ename))

  49.   (if (not (= (cdr (assoc 0 entlst)) "POLYLINE"))
  50.     (progn
  51.       (alert "That is not a polygon mesh.")
  52.       (exit)
  53.       (princ)
  54.     );progn
  55.   );endif

  56.   (if
  57.     (not
  58.       (or
  59.        (= (cdr (assoc 70 entlst)) 16) ;open 3d polygon mesh
  60.        (= (cdr (assoc 70 entlst)) 20) ;open mesh w/ spline-fit vertices
  61.         );or
  62.        );not
  63.      (progn
  64.        (alert "That is not an *open* polygon mesh.")
  65.        (exit)
  66.        (princ)
  67.      );progn
  68.   );endif

  69. ;; decide whether to use smoothed or unsmoothed vertices
  70.   (setq M (cdr (assoc 71 entlst)))   ;M vertices
  71.   (setq N (cdr (assoc 72 entlst)))   ;N vertices
  72.   (setq SM (cdr (assoc 73 entlst)))  ;smoothed M vertices
  73.   (setq SN (cdr (assoc 74 entlst)))  ;smoothed N vertices
  74.   (setq ST (cdr (assoc 75 entlst)))  ;surface type
  75.   (if
  76.     (or
  77.       (= (getvar "splframe") 1)      ;use MxN vertices when splframe = 1
  78.       (= ST 0)                       ;or mesh has not been smoothed
  79.       )
  80.     (setq smooth 0
  81.          MN (* M N))
  82.     (setq smooth 1                   ;use SMxSN vertices when mesh is smoothed
  83.           MN (* SM SN)               ;and SPLFRAME = 0
  84.           M SM
  85.           N SN)
  86.     );if

  87. ;; determine lowest vertex
  88.   (grtext -2 "Checking out the mesh...")
  89.   (setq vtx ename)
  90.   (setq vtx (entnext vtx))
  91.   (setq d1 (entget vtx))
  92.   (setq bottom (caddr (trans (cdr (assoc 10 d1)) 0 1)))

  93.   (repeat (1- MN)   ;compare with each vertex's z coord
  94.     (setq vtx (entnext vtx))
  95.     (setq d1 (entget vtx))
  96.     (setq low (caddr (trans (cdr (assoc 10 d1)) 0 1)))
  97.     (setq bottom (min bottom low))
  98.     );repeat

  99. ;; get desired thickness of solid
  100.   (setq soldepth 0)
  101.   (while
  102.      (zerop soldepth)
  103.      (progn
  104.        (setq soldepth
  105.           (getdist "\nEnter desired thickness of solid below lowest vertex <1>: "))
  106.        (if (not soldepth) (setq soldepth 1.0))
  107.        (if (zerop soldepth)
  108.           (princ "\nThickness can be small, but not zero. (Slice it later, if need be.)"))
  109.         );progn
  110.      );while
  111.   (setq bot (- bottom (abs soldepth)))

  112.   (setq p1 ename)
  113.   (if (= smooth 1)
  114.       (setq p1 (entnext p1))) ;skip 1st vtx of smoothed mesh - not true vtx
  115.   (setq ssrow (ssadd))        ;initialize set of extruded segments to be unioned as a row
  116.   (setq ssall (ssadd))        ;initialize set of rows to be unioned into the whole
  117.   (grtext -2 "Creating row...")
  118.   (setq vtxmax (- MN N))  
  119.   (setq vtxcnt 1)

  120. ;;create row of solid segments
  121.   (while (< vtxcnt vtxmax)

  122.     (if (= 0 (rem vtxcnt N))  ;at end of each row...
  123.         (progn
  124.           (setq rowmsg (strcat "Unioning row "
  125.                        (itoa (/ vtxcnt N)) " of "
  126.                        (itoa (1- M)) "... "))
  127.           (grtext -2 rowmsg)
  128.           (command "union" ssrow "")
  129.           (setq row (entlast))
  130.           (ssadd row ssall)
  131.           (setq ssrow (ssadd))
  132.           (setq p1 (entnext p1)         ;skip to the next vertex
  133.                 vtxcnt (1+ vtxcnt))
  134.           );progn
  135.         );if

  136.     (grtext -2 "Creating row...")
  137.     (setq p1 (entnext p1)                  ;first vertex of mesh square
  138.           p2 (entnext p1)                  ;second vertex
  139.           p3 p2)
  140.     (repeat (1- n) (setq p3 (entnext p3))) ;walk along to 3rd (p1 + N) vertex
  141.     (setq p4 (entnext p3))                 ;4th vertex of mesh square

  142.     (setq c1 (trans (cdr (assoc 10 (entget p1))) 0 1) ;top coordinates
  143.           c2 (trans (cdr (assoc 10 (entget p2))) 0 1)
  144.           c3 (trans (cdr (assoc 10 (entget p3))) 0 1)
  145.           c4 (trans (cdr (assoc 10 (entget p4))) 0 1)
  146.           b1 (list (car c1) (cadr c1) bot)            ;bottom coordinates
  147.           b2 (list (car c2) (cadr c2) bot)
  148.           b3 (list (car c3) (cadr c3) bot)
  149.           b4 (list (car c4) (cadr c4) bot))
  150.           (LOFT c1 c2 c3 b1 b2 b3)
  151.           (LOFT c2 c3 c4 b2 b3 b4)

  152.     (setq vtxcnt (1+ vtxcnt))
  153.   );while

  154. (grtext -2 "Unioning last row...")
  155.   (command "union" ssrow "")
  156.   (setq row (entlast))
  157.   (ssadd row ssall)
  158.   (if (> M 2)       ;bypass final union for N x 1 meshes (i.e., RULESURF)
  159.     (progn
  160.       (grtext -2 "Unioning all rows...")
  161.        (command "union" ssall "")
  162.         );progn
  163.      );if

  164. ;;cleanup
  165.   (command "undo" "end")
  166.   (setvar "cmdecho" oldecho)
  167.   (setvar "osmode" oldsnap)
  168.   (setvar "blipmode" oldblip)
  169.   (setq ssall nil ssrow nil)
  170.   (princ)

  171. );defun

  172. ;;============== SUBROUTINES ====================
  173. ;(defun *error* (msg)
  174. ;  (command)
  175. ;  (command "undo" "end")
  176. ;  (setvar "cmdecho" oldecho)
  177. ;  (setvar "osmode" oldsnap)
  178. ;  (setvar "blipmode" oldblip)
  179. ;  (princ (strcat "\nError: " msg))
  180. ;  );defun

  181. (defun LOFT (r1 r2 r3 s1 s2 s3 / e1 extr highest)
  182.   (command "area" s1 s2 s3 "")
  183.   (if (not (equal (getvar "area") 0.0 0.00000001))
  184.     (progn
  185.       (command "pline" s1 s2 s3 "c")
  186.       (setq highest (max (caddr r1) (caddr r2) (caddr r3)))
  187.       (setq extr (- highest bot))
  188.       (command "extrude" (entlast) "" extr 0.0)
  189.       (command "slice" (entlast) "" "3points" r1 r2 r3 s1)
  190.       (setq e1 (entlast))
  191.       (ssadd e1 ssrow)
  192.       );progn
  193.     );if
  194.   );defun

  195. (princ "M2S loaded.")

m2s Mesh-to-Solid

m2s Mesh-to-Solid
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 8856个

财富等级: 富甲天下

发表于 2016-9-19 06:21:14 | 显示全部楼层
感谢  iLisp  分享程序!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 5600个

财富等级: 富甲天下

发表于 2016-9-19 11:14:25 | 显示全部楼层
谢谢楼主分享程序!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-24 08:29 , Processed in 0.321562 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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