g_dist が固定になってるけどボーンの長さが一定とは限らないので、ヘルパー生成時に各ボーンの長さを配列に保存し、それを計算に使うようにできないかな
- User
g_dist が固定になってるけどボーンの長さが一定とは限らないので、ヘルパー生成時に各ボーンの長さを配列に保存し、それを計算に使うようにできないかな
Assistant
以下のようにスクリプトを改良することで、各ボーンの実際の長さを保存し、それを平行四辺形制約の計算に使用できます。
改修ポイント
- 骨長保存用配列の追加
maxscriptglobal g_dists -- 各ボーンの長さを保存する2D配列- collectFKChainsFromScene関数の改良
maxscriptfn collectFKChainsFromScene = ( local allBones = for o in selection where classOf o == BoneGeometry collect o local roots = for b in allBones where (b.parent == undefined or classOf b.parent != BoneGeometry) collect b g_fkChains = #() g_dists = #() -- 骨長保存用配列を初期化 for r in roots do ( local chain = #() local dists = #() local cur = r while cur != undefined and classOf cur == BoneGeometry do ( append chain cur -- 骨長を計算(親ボーンとの距離) if cur.parent != undefined and classOf cur.parent == BoneGeometry then ( append dists (length (cur.transform.pos - cur.parent.transform.pos)) ) else ( append dists g_dist -- ルートボーンはデフォルト値を使用 ) local childrenBones = for c in cur.children where classOf c == BoneGeometry collect c cur = if childrenBones.count > 0 then childrenBones[1] else undefined ) append g_fkChains chain append g_dists dists -- 骨長配列を保存 ) g_rows = g_fkChains.count g_cols = arrayMax (for ch in g_fkChains collect ch.count) )- maintainParallelogram関数の改良
maxscript
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.