Model

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

モデルはコンテナオブジェクトであり、オブジェクトをグループ化します。彼らは BaseParts のコレクションを保持するのに最適で、機能を拡張する複数の機能があります。

モデルは 幾何学的 グループを表すことを目的としています。グループ化に幾何学的な解釈がない場合、たとえば Scripts のコレクション、代わりに Folder を使用します。

構成部品がジョイントで結合されているモデル (物理シミュレーションで移動したり、破壊されたりできる) は通常、PrimaryPart セットを持っています。モデルが移動すると、ピボットとバインディングボックスが "モデルにフォローう" 部分を指定します。1つの場所に留まる静的モデ設定するは、プライマリパーツセットを持つことで恩恵を受けません。

モデルには、Roblox プレイヤーキャラクターを含む幅広い適用範囲があります。また、留意すべき多くのユニークな動作があります:

  • モデルの下で HumanoidPart と呼ばれる名前の が親になると、モデルの上に名前/健康 GUIが表示されます;詳細は キャラクター名/健康表示 を参照してください
  • パーツの Y 軸の位置が Workspace.FallenPartsDestroyHeight 値に達し、それが Model 内の最後のオブジェクトだった場合、モデルも破壊されます。
  • Workspace.StreamingEnabled を trueに設定した場所で使用すると、モデルとその子孫がクライアントから複製されたり削除されたりする方法の周りのさまざまな動作が値 ModelStreamingMode によって制御されます。さらに、LevelOfDetail の値はモデルのレンダリングに影響します。

すべての Instance タイプと同様、親 Model がクライアントにレプリケートされることは、すべての子がレプリケートされることを保証しません。これは、特に、これらのインスタンスがクライアント上で実行されるコードによってアクセスされている場合、例えば LocalScript です。親モデルがクライアント上に存在する場合、またはアトミック性が必要でない場合は、 といった値を使用して、モデル全体とすべての子モデルが存在するようにすることができます。

コードサンプル

The following sample includes a basic function that takes a table of objects and parents them into a new Model, returning that Model.

Basic Model Instantiation

local function groupObjects(objectTable)
local model = Instance.new("Model")
for _, object in pairs(objectTable) do
object.Parent = model
end
return model
end
local objects = {
Instance.new("Part"),
Instance.new("Part"),
}
groupObjects(objects)

概要

プロパティ

  • プラグインのセキュリティ
    並列読み取り

    インスタンスストリーミングを有効にしたエクスペリエンスのモデルの詳細レベルを設定します。

  • インスタンスストリーミングが有効になっているときに、モデルストリーミングの動作を制御します Models

  • 並列読み取り

    The primary part of the Model 、または nil が明示的に設定する定されていない場合

  • 複製されていません
    スクリプト作成できません
    並列読み取り

    モデルの周りにスケールを拡大するために使用される編集者専用のプロパティ。このプロパティを設定すると、スケールが Model/ScaleTo を呼び出したように移動します。

  • 複製されていません
    並列読み取り

    どこに Modelしない を持つピボットが位置するかを決定します。Determines where the pivot of a > which does not have a set Model.PrimaryPart is located.

PVInstance から継承した プロパティ
  • 複製されていません
    スクリプト作成できません
    並列読み取り
  • 複製されていません
    スクリプト作成できません
    並列読み取り

方法

  • AddPersistentPlayer(playerInstance : Player):()

    指定されたプレイヤーのために、このモデルを永続するように設定します。Model.ModelStreamingMode は、追加により変更されるため、 PersistentPerPlayer に設定する必要があります。

  • モデルのすべての部分を含むボリュームの説明を返します。

  • 返すのは、BaseParts すべてを含む最小のバインディングボックスのサイズ、そして Model に沿って設定されている場合、Model.PrimaryPart と一致します。

  • このモデルオブジェクトが持続するすべての Player オブジェクトを返します。動作は、このメソッドが Script または LocalScript から呼ばれるかどうかによって異なります。

  • モデルの正規スケールを返し、新しく作成されたモデルにはデフォルトで 1 が割り当てられ、Model/ScaleTo を介してスケールすると変更されます。

  • MoveTo(position : Vector3):()

    PrimaryPart を指定された位置に移動します。プライマリパーツが指定されていない場合、モデルのルートパーツが使用されます。

  • RemovePersistentPlayer(playerInstance : Player):()

    指定されたプレイヤーに対して、このモデルを永続しなくする。Model.ModelStreamingMode は、削除により変更されるため、 PersistentPerPlayer に設定する必要があります。

  • ScaleTo(newScaleFactor : number):()

    モデルのスケール因子を設定し、すべての子インスタンスのサイズと場所を調整して、スケール因子が 1 のときと比較して、そのスケール因子が初期のサイズと場所に関連しているようにします。

  • TranslateBy(delta : Vector3):()

    指定された オフセットによってシフトし、モデルの向きを保持します。新しい位置に別の BasePart または Terrain がすでに存在する場合、Model はそのオブジェクトをオーバーライドします。

PVInstance から継承した 方法

プロパティ

プラグインのセキュリティ
並列読み取り

インスタンス ストリーミング を有効にしたエクスペリエンスのモデルの詳細レベルを設定します。

StreamingMesh に設定すると、解像度の低い「インポスター」メッシュ(モデルのすべての子部品を包む粗いカラーメッシュ)がストリーミング範囲外にレンダリングされます。

Disabled または Automatic に設定すると、解像度の低いメッシュが表示されなくなります。

ModelStreamingMode

並列読み取り

インスタンスが ストリーミング を有効にしたときに、Models がどのようにストリームされ入出しされるかを制御します。動作は選択された枚数に依存します。ストリーミングが有効になっていない場合、効果はありません。

このプロパティは、ストリーミングが有効になっているときに Studio の プロパティ ウィンドウを通じて変更する必要があり、または Scripts で、決して LocalScripts (そうすると未定義の動作が発生する可能性があります)ではありません。

PrimaryPart

並列読み取り

Model の主要な部分にポイントします。主な部分は、モデルのピボットの物理参照として機能する BasePart です。つまり、モデル内のパーツが物理シミュレーションまたは他の手段により移動すると、ピボットは主要なパーツと同期して移動します。

注: Models はデフォルトで PrimaryPart が設定されていません。物理によって実行する必要があるモデルを作成している場合、Studio またはスクリプト内でこのプロパティを手動で設定する必要があります。メインパーツが ではなく 設定されている場合、モデル内のパーツが移動されても、ピボットは世界空間の同じ場所に残ります。

このプロパティを設定するときは、モデルの子孫である BasePart が必須であることに注意してください。モデルの子孫ではない を に設定しようとすると、モデルの子孫ではない が設定されますが、次のシミュレーションステップでリセットされます—これは、モデルの子孫ではない を一時的に設定できると仮定するスクリプトをサポートするためのレガシー動作です。

モデルの一般的なルールは次のとおりです:

  • モデルのパーツが WeldConstraints または Motor6Ds のような物理ジョイントで結合されているモデルは、プライマリパーツが割り当てられる必要があります。たとえば、Roblox キャラクターモデルは、デフォルトで Model.PrimaryPartHumanoidRootPart に設定します。
  • スクリプトが明示的に移動しない限り、1か所に留まる静的 (通常 Anchored ) モデルは、Model.PrimaryPart が必要ない傾向があり、1設定するのセットを持つことの恩恵を受けない。

コードサンプル

This code sample creates and throws a dice model, then outputs whether it landed with the blue side facing up. If Model.PrimaryPart was not set, the pivot / bounding box of the dice would rotate, as the parts inside of it are physically simulated during the roll.

Throwing Dice

-- Create a dice model with two halves and attach them together
local diceModel = Instance.new("Model")
diceModel.Name = "ChanceCube"
local diceTop = Instance.new("Part")
diceTop.Size = Vector3.new(4, 2, 4)
diceTop.Position = Vector3.new(0, 1, 0)
diceTop.Color = Color3.new(0, 0, 1)
diceTop.Parent = diceModel
local diceBottom = diceTop:Clone()
diceBottom.Position = Vector3.new(0, -1, 0)
diceBottom.Color = Color3.new(1, 0, 0)
diceBottom.Parent = diceModel
local weld = Instance.new("WeldConstraint")
weld.Part0 = diceTop
weld.Part1 = diceBottom
weld.Parent = diceModel
-- Put the dice up in the air above the workspace origin (does not require a primary part)
diceModel.Parent = workspace
diceModel:PivotTo(CFrame.new(0, 10, 0))
-- Assign the primary part before physical simulation
-- Without this line, the script will always output the same thing and the bounding box of the model will not change orientation
diceModel.PrimaryPart = diceTop
-- Wait a bit before rolling the dice (let it settle onto the floor)
for i = 5, 1, -1 do
print("Rolling dice in...", i)
task.wait(1)
end
diceTop:ApplyAngularImpulse(Vector3.new(15000, 1000, 5000))
diceTop:ApplyImpulse(Vector3.new(0, 3000, 0))
task.wait(1)
-- Wait for the roll to complete
while diceTop.AssemblyLinearVelocity.Magnitude > 0.1 or diceTop.AssemblyAngularVelocity.Magnitude > 0.1 do
task.wait()
end
-- Get the dice orientation, impacted by the primary part
local orientation = diceModel:GetBoundingBox()
if orientation.YVector.Y > 0.5 then
print("It's the boy!")
else
print("It's his mother!")
end

Scale

複製されていません
スクリプト作成できません
並列読み取り

プロパティウィンドウでこのプロパティを設定すると、Model/ScaleTo が呼び出されたようにモデルがスケールするため、マテリアル、画像、および部品の 3D ジオメトリなどのすべての後続インスタンスがモデルにスケールされ、モデルが原始サイズに対して指定されたスケール因子を持つようになります。

このプロパティはスタジオでのみ利用可能であり、Script または LocalScript で使用するとエラーが発生します。Model/ScaleToModel/GetScale は、スクリプトから使用する必要があります。

WorldPivot

複製されていません
並列読み取り

このプロパティは、Model持っていない ピボットの場所を決定します。これは、Model.PrimaryPart が設定されている場所です。If the Model doesPrimaryPart がある場合、Model のピボットは、代わりにその主要部分のピボットと同等であり、この WorldPivot プロパティは無視されます。

新しく作成された Model には、 最初の時点Model.WorldPivot プロパティが設定されるまで、そのピボットはそのコンテンツのバインディングボックスの中心として扱います。世界軸が初めて設定されたら、この最初の動作を復元することは不可能です。

一般的に、Studio ツールまたはモデル移動機能 (PVInstance:PivotTo()Model:MoveTo() など) を使用してモデルを移動すると、ワールドの軸が設定され、この新しいモデル動作が終了します。

この振る舞いの目的は、Luau コードが新しいモデルを作成し、それに親を付けることによって単純に意味のあるピボットを取得できるようにすることで、コードでモデルを作成するたびに Model.WorldPivot を明示的に設定する必要を避けることです。


local Workspace = game:GetService("Workspace")
local model = Instance.new("Model")
Workspace.BluePart.Parent = model
Workspace.RedPart.Parent = model
model.Parent = Workspace
print(model:GetPivot()) -- Currently equal to the center of the bounding box containing "BluePart" and "RedPart"
model:PivotTo(CFrame.new(0, 10, 0)) -- This works without needing to explicitly set "model.WorldPivot"

コードサンプル

This code sample shows a custom function for resetting the pivot of a model back to the center of that model's bounding box.

Reset Pivot

local function resetPivot(model)
local boundsCFrame = model:GetBoundingBox()
if model.PrimaryPart then
model.PrimaryPart.PivotOffset = model.PrimaryPart.CFrame:ToObjectSpace(boundsCFrame)
else
model.WorldPivot = boundsCFrame
end
end
resetPivot(script.Parent)

方法

AddPersistentPlayer

()

パラメータ

playerInstance: Player
既定値: "nil"

戻り値

()

GetBoundingBox

この関数は、BasePart 内のすべての子供を含むボリュームの説明を返します。この Model 内。ボリュームの向きは、PrimaryPart の向きに基づいており、モデルが選択されたときにStudioでレンダリングされた選択ボックスと一致します。Terrain:FillBlock() の動作をミラーリングし、そのバインディングボックスの中心を表す CFrame と、サイズを表す Vector3 を返します。

モデルに PrimaryPart がない場合、バインディングボックスは世界軸に沿われます。


local Workspace = game:GetService("Workspace")
local model = Workspace.Model
local part = Workspace.Part
local orientation, size = model:GetBoundingBox()
-- モデルのバインディングボックスと同じ大きさと位置のパーツを再設定する
part.Size = size
part.CFrame = orientation

戻り値

A CFrame がボリュームの向きを表し、続いてボリュームのサイズを表す Vector3

GetExtentsSize

すべての を含む最小のバインディングボックスのサイズを返します。Model.PrimaryPart が存在する場合、バインディングボックスはその部分に沿われます。主要なパーツが設定されていない場合、機能はモデル内のパーツを選択してバインディングボックスを揃えます。この部分の選択は決定的ではないので、この機能と一貫した結果を得るために Model.PrimaryPart を設定することをお勧めします。

この関数は、最小のバインディングボックスのサイズのみを返し、開発者はバインディングボックスの位置を取得するために独自のメソッドを使用する必要があります。


戻り値

The Vector3 拡張サイズ of the Model .

コードサンプル

The code sample below demonstrates how Model.GetExtentsSize can be used to get the size of the bounding box containing the parts.

Model GetExtentsSize

local model = Instance.new("Model")
model.Parent = workspace
local RNG = Random.new()
for _ = 1, 5 do
local part = Instance.new("Part")
part.Anchored = true
part.Size = Vector3.new(RNG:NextNumber(0.05, 5), RNG:NextNumber(0.05, 5), RNG:NextNumber(0.05, 5))
part.Parent = model
end
print(model:GetExtentsSize())

GetPersistentPlayers

Instances

このメソッドが Script から呼び出されると、このモデルが持続するすべての Player オブジェクトが返されます。LocalScript から呼び出されると、このメソッドは、このモデルが LocalPlayer に永続するかどうかのみをチェックします。


戻り値

Instances

このモデルオブジェクトが持続するすべての Player オブジェクトを含むテーブル。

GetScale

モデルには、新しく作成されたモデルから 1 で始まる永続的なカノニカルスケールファクターが含まれており、モデルが Model/ScaleTo を呼び出すと変更されます。この関数は、モデルの現在の標準スケール因子を返します。

現在のスケールファクターは、直接 モデルの下のインスタンスのサイズに影響しません。モデルが元のサイズに対してどのようにスケーリングされたかを記憶するために、コンテンツ作成およびスクリプト用途に使用されます。

指定されたセッション内で、モデルは最初の Model/ScaleTo 呼び出しの後、子孫インスタンスの正確なオリジナルサイズ情報をキャッシュします。これは、ScaleTo(x) に続いて ScaleTo(1) を呼び出すと、浮動小数点ドリフトなしでモデルのオリジナル構成を正確に取り戻すことを意味します。浮動小数点ドリフトを避けることは、スケール 機能の代わりにスケール 機能を持つ動機です。

スケールファクターは、1つの方法でエンジンの動作に影響します:モデルのスケールファクターが、そのモデルの下で 演奏された共同オフセットに適用され、アニメーテッドリグがスケーリングされているときでも正しくアニメーションが再生されます。


戻り値

モデルの現在の標準スケール因子。

コードサンプル

This code sample demonstrates substituting in a replacement for all the copies of a tree model using PivotTo and ScaleTo. The pivot and scale of the models are used as a reference ensuring that the relative sizes and locations of the replacement models match those of the originals.

Substituting in a replacement model using PivotTo and ScaleTo

local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- Find all the models with the tag we want to replace
local items = CollectionService:GetTagged("Tree")
local newModel = ReplicatedStorage.FancyTreeReplacementModel
for _, item in items do
-- Make the new item and scale / position it where the old one was
local newItem = newModel:Clone()
newItem:ScaleTo(item:GetScale())
newItem:PivotTo(item:GetPivot())
-- Add the same tag to the replacement
CollectionService:AddTag(newItem, "Tree")
-- Delete the old item and parent the new one
newItem.Parent = item.Parent
item:Destroy()
end

MoveTo

()

PrimaryPart を指定された位置に移動します。主要なパーツが指定されていない場合、モデルのルートパーツが使用されますが、ルートパーツは決定的ではなく、MoveTo() を使用するときに常に主要なパーツを設定することをお勧めします。

モデルを移動する障害がある場合、例えば Terrain またはその他の BaseParts がある場合、モデルは通路に何もないまで上向きに移動されます。この動作は望ましくない場合は、PVInstance:PivotTo() 代わりに使用する必要があります。

モデルを移動するときに MoveTo() で回転が保存されないことに注意してください。現在のモデルの回転が保存される必要がある場合は、TranslateBy() または PVInstance:PivotTo() を使用することをお勧めします。

パラメータ

position: Vector3

移動されるのは、Vector3Model です。

既定値: ""

戻り値

()

コードサンプル

This sample demonstrates how Model:MoveTo avoids collisions.

A simple two part Model is created, and its PrimaryPart is set. An large obstruction part is placed next to it.

After 5 seconds Model:MoveTo is used to direct the model to move inside the obstruction part. However, as MoveTo will not move a model inside of an obstruction the Model is moved up on the Y axis and placed above the obstruction.

Model MoveTo

local START_POSITION = Vector3.new(-20, 10, 0)
local END_POSITION = Vector3.new(0, 10, 0)
local model = Instance.new("Model")
model.Parent = workspace
local part1 = Instance.new("Part")
part1.Size = Vector3.new(4, 4, 4)
part1.Position = START_POSITION
part1.Anchored = true
part1.BrickColor = BrickColor.new("Bright yellow")
part1.Parent = model
local part2 = Instance.new("Part")
part2.Size = Vector3.new(2, 2, 2)
part2.Position = START_POSITION + Vector3.new(0, 3, 0)
part2.Anchored = true
part2.BrickColor = BrickColor.new("Bright blue")
part2.Parent = model
model.PrimaryPart = part1
model.Parent = workspace
local obstruction = Instance.new("Part")
obstruction.Name = "Obstruction"
obstruction.Size = Vector3.new(10, 10, 10)
obstruction.Position = Vector3.new(0, 10, 0)
obstruction.Anchored = true
obstruction.BrickColor = BrickColor.new("Bright green")
obstruction.Parent = workspace
task.wait(3)
model:MoveTo(END_POSITION)

RemovePersistentPlayer

()

パラメータ

playerInstance: Player
既定値: "nil"

戻り値

()

ScaleTo

()

モデルには、新しく作成されたモデルで 1 から始まる永続的なカノニカルスケールファクターが含まれています。この関数は、ピボットロケーションの周りでモデルをスケールし、スケール因子 1 で見えるようにします。これを達成するには、2つのことを行います:

  • モデルの現在のスケール因子を指定された値に設定する
  • すべての子インスタンスを適切に再サイズ化して再配置する

場所のスケーリングは、ピボットロケーションの周りで行われます。

子インスタンスのすべての「幾何学的」プロパティがスケールされます。それは明らかにパーツのサイズを含みますが、次にいくつかのスケールされたプロパティの他の例があります:

  • WeldConstraintsClass.Rope|Ropes のような接続の長さ
  • 物理速度や力のような Hinge.MaxServoTorque
  • パーティクルエミッターのサイズなどの視覚的プロパティ
  • Sound.RollOffMinDistance などの他の長さプロパティ

パラメータ

newScaleFactor: number
既定値: ""

戻り値

()

TranslateBy

()

指定された オフセットによってシフトし、モデルの向きを保持します。新しい位置に別の BasePart または Terrain がすでに存在する場合、Model はそのオブジェクトをオーバーライドします。

翻訳はオブジェクトスペースではなくワールドスペースに適用され、モデルのパーツが異なる向きに向いていても、標準の軸に沿って移動し続けます。

パラメータ

delta: Vector3

The Vector3 によって、Model を翻訳する。

既定値: ""

戻り値

()

コードサンプル

This sample demonstrates how Model:TranslateBy ignores collisions and respects the orientation of the model.

A simple two part Model is created, rotated 45 degrees on the Y axis, and its PrimaryPart is set. An large obstruction part is placed next to it.

After 5 seconds Model:TranslateBy is used to direct the model to move inside the obstruction part. The model will move inside of the obstruction and maintain it's current orientation.

Model TranslateBy

local START_POSITION = Vector3.new(-20, 10, 0)
local END_POSITION = Vector3.new(0, 10, 0)
local model = Instance.new("Model")
local part1 = Instance.new("Part")
part1.Size = Vector3.new(4, 4, 4)
part1.CFrame = CFrame.new(START_POSITION) * CFrame.Angles(0, math.rad(45), 0)
part1.Anchored = true
part1.BrickColor = BrickColor.new("Bright yellow")
part1.Parent = model
local part2 = Instance.new("Part")
part2.Size = Vector3.new(2, 2, 2)
part2.CFrame = part1.CFrame * CFrame.new(0, 3, 0)
part2.Anchored = true
part2.BrickColor = BrickColor.new("Bright blue")
part2.Parent = model
model.PrimaryPart = part1
model.Parent = workspace
local obstruction = Instance.new("Part")
obstruction.Name = "Obstruction"
obstruction.Size = Vector3.new(10, 10, 10)
obstruction.Position = Vector3.new(0, 10, 0)
obstruction.Transparency = 0.5
obstruction.Anchored = true
obstruction.BrickColor = BrickColor.new("Bright green")
obstruction.Parent = workspace
task.wait(3)
-- use TranslateBy to shift the model into the obstruction
model:TranslateBy(END_POSITION - START_POSITION)

イベント