オブジェクトのボリュームを計算する方法はありますか。
 
 
 

MAXScript FAQに関する質問と回答 > MAXScript 値の操作 > オブジェクトのボリュームを計算する方法はありますか。

現在、MAXScript から Measure Utility へはアクセスできません。 しかし、次の MAXScript 関数を使用して同じ結果を得ることができます。

スクリプト:

fn CalculateVolumeAndCenterOfMass obj =
(
local Volume= 0.0
local Center= [0.0, 0.0, 0.0]
local theMesh = snapshotasmesh obj
local numFaces = theMesh.numfaces
for i = 1 to numFaces do
(
  local Face= getFace theMesh i
  local vert2 = getVert theMesh Face.z
  local vert1 = getVert theMesh Face.y
  local vert0 = getVert theMesh Face.x
  local dV = Dot (Cross (vert1 - vert0) (vert2 - vert0)) vert0
  Volume+= dV
  Center+= (vert0 + vert1 + vert2) * dV
)
delete theMesh
Volume /= 6
Center /= 24
Center /= Volume
#(Volume,Center)
)
-- ジオメトリ オブジェクトで関数を呼び出します。 この結果、 
-- ローカル スペースのボリュームと重心を含むリストが表示されます。
theVolAndCom = CalculateVolumeAndCenterOfMass $Sphere01
-- ユーティリティと同じように重心のワールド スペースを取得するには、
-- 別の操作が少し必要です。
theComInWorld = theVolAndCom[2] * $Sphere01.objectTransform
関連事項