現在、オブジェクトのピボットを任意のマトリックスで変換しようとしています。
これまでのところ、不均一なスケールが適用されていないオブジェクトに対してそれを行うことができましたが、ターゲット オブジェクトに不均一なスケールがあると機能しなくなります。
これが機能するには、これが objectOffset の にアクセスする必要があるという印象を受けましたが、これscalerotationpart
はmaxscriptでは利用できないようです。
これは、 objectOffsetスケールがScaleValue
(スケール ベクトルとクォータニオンを含む、SDK docsを参照) として表現されるため、C++ SDK を使用して実行できます。
明らかな何かが欠けていますか?または、これを機能させるには maxscript プラグイン拡張機能を作成する必要がありますか?
ありがとう、
私の出発点は次の機能でした:
fn AlignPivotTo Obj Trgt =
(
-- http://forums.cgsociety.org/archive/index.php/t-636495.html
--This fails miserably for any objects having a negative or non-uniform scale, but it seems to work well in any other case I have tested:
-- Get matrix from object
if classOf Trgt != matrix3 then Trgt = Trgt.transform
-- Store child transforms
local ChldTms = in coordSys Trgt ( for Chld in Obj.children collect Chld.transform )
-- Current offset transform matrix
local TmScale = scaleMatrix Obj.objectOffsetScale
local TmRot = Obj.objectOffsetRot as matrix3
local TmPos = transMatrix Obj.objectOffsetPos
local TmOffset = TmScale * TmRot * TmPos
-- New offset transform matrix
local deltaTransform = obj.transform * inverse Trgt
TmOffset *= deltaTransform
-- Apply matrix
Obj.transform = Trgt
-- Restore offsets
Obj.objectOffsetPos = TmOffset.translationPart * inverse TmOffset.scalerotationpart
Obj.objectOffsetRot = TmOffset.rotationPart * invers eTmOffset.scalerotationpart
Obj.objectOffsetScale = TmOffset.scalePart
-- Restore child transforms
for i = 1 to Obj.children.count do ( Obj.children[i].transform = ChldTms[i] * inverse Trgt * Obj.transform )
)