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):()

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

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

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

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

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

  • MoveTo(position : Vector3):()

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

  • RemovePersistentPlayer(playerInstance : Player):()

    指定されたプレイヤーのために、このモデルを永続しないようにします。ModelStreamingMode は、削除の結果として動作が変更されるために PersistentPerPlayer に設定する必要があります。

  • ScaleTo(newScaleFactor : number):()

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

  • TranslateBy(delta : Vector3):()

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

PVInstance から継承した 方法

方法

プロパティ

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

ModelStreamingMode

並列読み取り

PrimaryPart

並列読み取り

コードサンプル

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

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

WorldPivot

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

コードサンプル

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
既定値: ""

戻り値

()

GetBoundingBox


戻り値

GetExtentsSize


戻り値

コードサンプル

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

戻り値

Instances

GetScale


戻り値

コードサンプル

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

()

パラメータ

position: Vector3
既定値: ""

戻り値

()

コードサンプル

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
既定値: ""

戻り値

()

ScaleTo

()

パラメータ

newScaleFactor: number
既定値: ""

戻り値

()

TranslateBy

()

パラメータ

delta: Vector3
既定値: ""

戻り値

()

コードサンプル

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)

イベント