SDK 『ON_SquishParameters』程式範例

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

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

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.

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.

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

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

Hi,

等 Dale 回覆,謝謝。

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協助,謝謝

以下是 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

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

看來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);

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

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

好的,謝謝