# SDK 『ON\_SquishParameters』程式範例

**URL:** <https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469>\
**Category:** Rhino Windows 版\
**Created:** [2014年十一月27日 00:28 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469 "2014-11-27T00:28:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![tielsc](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/tielsc/32/1480_2.png) [@tielsc](https://cn.discourse.mcneel.com/u/tielsc)\
**Post date:** [2014年十一月27日 00:28 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/1 "2014-11-27T00:28:43Z")

</div>

你好，Rhino裡面有Squish指令，可以將曲面展平成平面。我找了SDK help上面有『ON\_SquishParameters』函式，是否有相關的程式範例可以參考(VC++)？謝謝

補充：  
我有個曲面A，展平成平面B，然後想開發一個工具可以讓user在平面B上面畫線，然後即時更新到曲面A上面。

---

<div class="post-metadata">

**Author:** ![KelvinC](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/kelvinc/32/3391_2.png) [@KelvinC](https://cn.discourse.mcneel.com/u/KelvinC)\
**Post date:** [2014年十一月28日 01:33 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/2 "2014-11-28T01:33:50Z")

</div>

Hi @dale, is there a VC++ sample code for ON\_SquishParameters?

@tielsc wants to develop something that allows you to draw curves on the flattened surface, the curves apply to the 3d surface in real time.

---

<div class="post-metadata">

**Author:** ![KelvinC](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/kelvinc/32/3391_2.png) [@KelvinC](https://cn.discourse.mcneel.com/u/KelvinC)\
**Post date:** [2014年十二月1日 03:39 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/3 "2014-12-01T03:39:02Z")

</div>

Hi,

以下是 Dale 的回答：

ON\_SquishParameters isn’t used anywhere in Rhino. Probably a place holder for future development. There is no squish SDK function, as all this code resides in the Squish plug-in.

---

<div class="post-metadata">

**Author:** ![tielsc](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/tielsc/32/1480_2.png) [@tielsc](https://cn.discourse.mcneel.com/u/tielsc)\
**Post date:** [2014年十二月1日 06:33 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/4 "2014-12-01T06:33:07Z")

</div>

> [@KelvinC](#):
>
> Probably a place holder for future development. There is no squish SDK function, as all this code resides in the Squish plug-in

hi Kelvin:  
我後來在SDK找到ON\_SquishMesh()這函式，也成功的可將一個3D曲面squish成2D平面網格，不過效果不如Rhino的Squish指令(結果會扭曲)，我自己也還在測試。但要如何將2D平面上的線條如同Rhino SquishBack指令能將2D curve mapping回去3D，我還找不到方法。

---

<div class="post-metadata">

**Author:** ![tielsc](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/tielsc/32/1480_2.png) [@tielsc](https://cn.discourse.mcneel.com/u/tielsc)\
**Post date:** [2014年十二月2日 05:32 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/5 "2014-12-02T05:32:53Z")

</div>

hi Kelven:  
我測試後已經可以跟Rhino Squish指令差不多，不過我現在遇到的困難則是要如何用ON\_SquishMesh()把3D曲面上的曲線能mapping到2D上，以及2D網格上的曲線mapping回3D曲面，是否有其他的函式或參數能達成?謝謝

![](https://sea3.discourse-cdn.com/mcneel/uploads/mcneel_cn/502/2626a23db9a60995.jpg)

---

<div class="post-metadata">

**Author:** ![KelvinC](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/kelvinc/32/3391_2.png) [@KelvinC](https://cn.discourse.mcneel.com/u/KelvinC)\
**Post date:** [2014年十二月2日 06:42 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/6 "2014-12-02T06:42:49Z")

</div>

Hi,

等 Dale 回覆，謝謝。

---

<div class="post-metadata">

**Author:** ![tielsc](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/tielsc/32/1480_2.png) [@tielsc](https://cn.discourse.mcneel.com/u/tielsc)\
**Post date:** [2014年十二月2日 23:51 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/7 "2014-12-02T23:51:31Z")

</div>

hi Kelvin:  
我所使用的ON\_SquishMesh()函式裡面有用到ON\_SquishParameters，查了SDK Help文件上ON\_SquishParameters 裡面有一個member: m\_bSaveMapping，上面說明了：『If m\_bEnableMapBack is true, then ON\_SquishMesh() will save extra information on the squished mesh …』，不過我遍尋SDK Help文件都找不到m\_bEnableMapBack這個member說明，是否也能請Dale協助，謝謝

---

<div class="post-metadata">

**Author:** ![KelvinC](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/kelvinc/32/3391_2.png) [@KelvinC](https://cn.discourse.mcneel.com/u/KelvinC)\
**Post date:** [2014年十二月4日 04:20 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/8 "2014-12-04T04:20:31Z")

</div>

以下是 Dale 之前的回覆：

The openNURBS toolkit does define an ON\_SquishMesh() function which will flatten a mesh. This function is not used in core Rhino. Nor it is used by the Squish command (found in the Squish plug-in included with Rhino).

And, the code behind the Squish command is not exposed in the Rhino SDK. Nor is the code behind the SquishBack command. Thus, only way to use the functionality of the Squish and SquishBack commands from a plug-in is to script the commands

他的回覆和你看到的情形有衝突嗎?

---

<div class="post-metadata">

**Author:** ![tielsc](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/tielsc/32/1480_2.png) [@tielsc](https://cn.discourse.mcneel.com/u/tielsc)\
**Post date:** [2014年十二月5日 02:18 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/9 "2014-12-05T02:18:09Z")

</div>

看來Squish和SquishBack核心並沒有放在 SDK，不過沒關係。那麼我是想瞭解ON\_SquishMesh()的用法，就SDK文件上的敘述：  
ON\_DECL ON\_Mesh\* ON\_SquishMesh(const ON\_Mesh\* mesh, const ON\_SquishParameters\* squish\_parameters, const ON\_SquishConstraints\* squish\_constraints, ON\_Mesh\* squished\_mesh);

1. 函式input的第四個參數『squished\_mesh』跟函式產出的ON\_Mesh的差別是什麼？
2. 函式第二個參數使用Class ON\_SquishParameters，此Class內的m\_bSaveMapping變數於SDK Help內的說明為『If **m\_bEnableMapBack** is true, then ON\_SquishMesh() will **save extra information on the squished mesh** so 3d points and curves near the input mesh can be mapped to the squished mesh and 2d points and curves on the squished mesh can be mapped back to the 3d mesh.』這邊衍生兩個小問題：  
(a) **m\_bEnableMapBack** 此變數在SDK help裡面找不到。  
(b)看說明似乎是說input 3D mesh附近的3D curve & point會被map到squished mesh 上的2D curve & point, 之後可被map回3D mesh上。 **而這個map回3D mesh動作是否有範例參考？**

PS：以下是我測試的code，可以把3D surface squish成2D mesh，但在2D mesh上並不會出現3D surface上的curve（上述第二點(b)有提到)。

ON\_SquishParameters \*sp = new ON\_SquishParameters();  
sp-\>SetSpringConstants(1.0, 1.0);  
sp-\>m\_bSaveMapping=true;  
sp-\>m\_bAreaPreprocess=true;  
sp-\>m\_material=1;

ON\_SquishConstraints \*sc = new ON\_SquishConstraints();  
Srf0-\>CreateMesh(mp, m\_meshAry);  
ON\_Mesh \*outMesh1 = new ON\_Mesh();  
ON\_Mesh \*outMesh2 = new ON\_Mesh();

outMesh1 = ON\_SquishMesh(m\_meshAry[0], sp, sc, outMesh2);  
context.m\_doc.AddMeshObject(\*outMesh1);

---

<div class="post-metadata">

**Author:** ![KelvinC](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/kelvinc/32/3391_2.png) [@KelvinC](https://cn.discourse.mcneel.com/u/KelvinC)\
**Post date:** [2014年十二月5日 14:25 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/10 "2014-12-05T14:25:26Z")

</div>

要翻譯這麼長的問題，對於不會程式設計的我有點一個頭兩個大… 😉

如果你可以用英文描述你的問題，可否請到 [http://discourse.mcneel.com/c/rhino-developer](http://discourse.mcneel.com/c/rhino-developer) 與 Dale Fugier 直接溝通? 他如果看不懂你對問題的描述會再來找我翻譯。

---

<div class="post-metadata">

**Author:** ![tielsc](https://sea3.discourse-cdn.com/mcneel/user_avatar/cn.discourse.mcneel.com/tielsc/32/1480_2.png) [@tielsc](https://cn.discourse.mcneel.com/u/tielsc)\
**Post date:** [2014年十二月8日 00:28 UTC](https://cn.discourse.mcneel.com/t/sdk-on-squishparameters/469/11 "2014-12-08T00:28:29Z")

</div>

好的，謝謝
