Model

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

모델은 컨테이너 개체로, 개체를 함께 그룹화합니다.그들은 BaseParts의 컬렉션을 보관하는 데 가장 적합하며, 기능을 확장하는 여러 기능이 있습니다.

모델은 기하학적 그룹화 를 나타내기 위한 것입니다.그룹화에 기하학적 해석이 없는 경우, 예를 들어 Scripts 의 컬렉션, Folder 대신 사용하십시오.

구성 부품이 조인트로 결합되어 이동하거나 물리 시뮬레이션을 통해 파괴되는 모델의 경우 일반적으로 PrimaryPart 설정있으며, 모델이 이동할 때 피벗 및 바인딩 상자가 "팔로우" 부품을 지정합니다.한 곳에 머무르는 정적 모델은 기본 부품 설정있는 것으로 이득을 얻지 못합니다.

모델에는 Roblox 플레이어 캐릭터를 포함하여 다양한 응용 프로그램이 있습니다.또한 기억해야 할 많은 독특한 행동이 있습니다:

모든 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에서 모델 스트리밍 행동을 제어합니다.

  • 병렬 읽기

    기본 부분의 Model 또는 nil 명시적으로 설정되지 않은 경우.

  • 복제되지 않음
    스크립팅할 수 없음
    병렬 읽기

    편집기에만 사용되는 속성으로, 피벗 주위에 모델을 확장하는 데 사용됩니다. 이 속성을 설정하면 피벗에서 Model/ScaleTo가 호출된 것처럼 규모가 이동됩니다.

  • 복제되지 않음
    병렬 읽기

    어떤 Model가지고 있지 않은 피벗의 위치를 결정합니다. where the pivot of a which does not have a set Model.PrimaryPart 는.

속성PVInstance에서 상속되었습니다

메서드

  • AddPersistentPlayer(playerInstance : Player):()

    지정된 플레이어에 대해 이 모델을 영구적으로 유지하도록 설정합니다.Model.ModelStreamingMode 는 추가로 인해 변경된 동작을 위해 PersistentPerPlayer 로 설정해야 합니다.

  • 모델의 모든 부분을 포함하는 볼륨의 설명을 반환합니다.

  • 설정되면 의 모든 것을 포함하는 가장 작은 바인딩 상자의 크기를 반환합니다.Returns the size of the smallest bounding box that contains all of the in the , aligned with the if it is set.

  • 이 모델 개체가 영구적으로 유지하는 모든 Player 개체를 반환합니다.이 메서드가 Script 또는 LocalScript 호출되는지에 따라 동작이 달라집니다.

  • 새로 생성된 모델에 기본값이 1인 모델의 캐논 규모를 반환하며, Model/ScaleTo를 통해 크기가 조정될 때 변경됩니다.

  • MoveTo(position : Vector3):()

    PrimaryPart를 지정된 위치로 이동합니다. 기본 부품이 지정되지 않았으면 모델의 루트 부품이 사용됩니다.

  • RemovePersistentPlayer(playerInstance : Player):()

    지정된 플레이어에 대해 이 모델을 더 이상 영구적으로 유지하지 않습니다.Model.ModelStreamingMode 는 제거로 인해 변경된 동작을 위해 PersistentPerPlayer 로 설정해야 합니다.

  • ScaleTo(newScaleFactor : number):()

    모델의 규모 요소를 설정하여 모든 하위 인스턴스의 크기와 위치를 조정하여 규모 요소가 1일 때 초기 크기와 위치와 관련하여 그 규모 요소가 있도록 합니다.

  • TranslateBy(delta : Vector3):()

    모델의 방향을 유지하면서 주어진 오프셋 Model에 의해 이동하여 Vector3로 전환합니다.새 위치에 이미 다른 BasePart 또는 Terrain 가 있으면 해당 Model 가 해당 개체를 겹치게 합니다.

메서드PVInstance에서 상속되었습니다

속성

플러그인 보안
병렬 읽기

인스턴스 스트리밍 활성화된 경험에 대한 모델의 세부 수준을 설정합니다.

StreamingMesh 로 설정되면 해상도가 더 낮은 "침입자" 메쉬(모델의 모든 자식 부품을 감싸는 색상, 거친 메쉬)가 스트리밍 범위 밖에서 렌더링됩니다.

Disabled 또는 Automatic 로 설정하면 해상도가 낮은 메쉬가 표시되지 않습니다.

ModelStreamingMode

병렬 읽기

인스턴스가 Models 활성화되었을 때 컨트롤이 스트림에 어떻게 투입되고 투출되는지 제어합니다.동작은 선택한 열거형에 따라 달라집니다.스트리밍이 활성화되지 않은 경우 효과가 없습니다.

이 속성은 스트리밍이 활성화된 경우 스튜디오의 속성 창을 통해서만 변경되어야 하며, 또는 Scripts , 하지만 결코 LocalScripts (그렇게 하면 정의되지 않은 동작이 발생할 수 있음)에서는 절대로 변경되어서는 안됩니다(그렇게 하면 정의되지 않은 동작이 발생할 수 있음).

PrimaryPart

병렬 읽기

Model의 주요 부분으로 포인트합니다.주요 부분은 모델의 피벗에 대한 물리적 참조로 작용하는 BasePart입니다.즉, 물리적 시뮬레이션이나 다른 수단으로 인해 모델 내의 부품이 이동되면 피벗은 주 부품과 동기화하여 이동합니다.

참고로 Models는 기본적으로 PrimaryPart가 설정되어 있지 않습니다.물리학에 의해 작동해야 하는 모델을 생성하는 경우 Studio 또는 스크립트 내에서 이 속성을 수동으로 설정해야 합니다.기본 부품이 가 아님 으로 설정되면 모델 내의 부품이 이동되더라도 피벗은 세계 공간에서 동일한 위치에 유지됩니다.

또한 이 속성을 설정할 때 모델의 하위인 BasePart 이어야 한다는 점에 유의하십시오.모델의 후손이 아닌 을 으로 설정하려고 시도하면 다음 시뮬레이션 단계 동안 해당 부분으로 설정되지만 재설정됩니다(이는 모델의 후손이 아닌 스크립트를 지원하기 위한 레거시 동작입니다.스크립트가 모델의 주요 부분을 일시적으로 설정할 수 있다고 가정하는 것은 아닙니다).

모델에 대한 일반 규칙은 다음과 같습니다:

  • WeldConstraints 또는 Motor6Ds와 같은 물리적 조인을 통해 부품이 결합된 모델은 기본 부품이 할당되어야 합니다.예를 들어 Roblox 캐릭터 모델은 기본적으로 Model.PrimaryPartHumanoidRootPart 로 설정합니다.
  • 스크립트가 명시적으로 이동하지 않으면 한 곳에 머무르는 정적(일반적으로 Anchored ) 모델은 Model.PrimaryPart 가 필요하지 않으며 한 설정갖는 것으로 이득을 보지 않습니다.

코드 샘플

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 기하 등 모델의 모든 하위 인스턴스를 확장하여 모델이 원래 크기에 비해 지정된 확장 요소 비율을 갖게 됩니다.

이 속성은 Studio에서만 사용할 수 있으며 Script 또는 LocalScript에서 사용하면 오류가 발생합니다.Model/ScaleToModel/GetScale 는 스크립트에서 사용해야 합니다.

WorldPivot

복제되지 않음
병렬 읽기

이 속성은 설정이 없는 의 피벗이 위치한 곳을 결정합니다. This property determines where the pivot of a which does not have a set is located.Model 에 있는 PrimaryPart 가 있으면, 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 자식이 포함된 볼륨에 대한 설명을 반환합니다.This function returns a description of a volume that contains all children within a 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()
-- 모델의 바인딩 상자와 같은 크기와 위치의 부품 조정 Resize and position part equal to bounding box of model
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 호출 후 하위 인스턴스의 정확한 원래 크기 정보를 캐시합니다.즉, 를 호출하고 에 따라 원래 모델의 정확한 구성을 되찾으면 부동 소수점 드리프트가 없습니다.부동 소수점 드리프트를 피하는 것은 규모 에서 함수 대신 규모 에서 함수를 사용하는 동기입니다.

규모 요소는 엔진 동작에 영향을 미치는 한 가지 방법으로 작동합니다: 모델의 규모 요소가 해당 모델 아래에서 재생되는 의 공동 오프셋에 적용되어 애니메이션을 올바르게 재생하지만 크기가 조정되더라도 애니메이션이 올바르게 재생됩니다.


반환

모델의 현재 캐논 규모 요소.

코드 샘플

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

이동할 Vector3 이동할 Model 이동할 대상입니다.

기본값: ""

반환

()

코드 샘플

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의 저울 요소로 보일 것과 비교합니다.이를 달성하기 위해 두 가지를 수행합니다:

  • 모델의 현재 규모 요소를 지정된 값으로 설정합니다
  • 모든 하위 인스턴스를 적절하게 재설정하고 재배치합니다

위치의 크기 조정은 피벗 위치 주변에서 수행됩니다.

하위 인스턴스의 모든 "기하학적" 속성이 크기가 조정됩니다.분명히 부품 크기가 포함되지만, 다음은 크기가 조정된 속성의 몇 가지 다른 예입니다:

  • WeldConstraintsClass.Rope|Ropes와 같은 조인의 길이
  • 물리적 속도와 힘, 예를 들어 Hinge.MaxServoTorque
  • 입자 방출기의 크기와 같은 시각적 속성
  • Sound.RollOffMinDistance와 같은 다른 길이 속성

매개 변수

newScaleFactor: number
기본값: ""

반환

()

TranslateBy

()

모델의 방향을 유지하면서 주어진 오프셋 Model에 의해 이동하여 Vector3로 전환합니다.새 위치에 이미 다른 BasePart 또는 Terrain 가 있으면 해당 Model 가 해당 개체를 겹치게 합니다.

번역은 개체 공간이 아닌 세계 공간에 적용되므로 모델의 부품이 서로 다르게 향하더라도 여전히 표준 축을 따라 이동합니다.

매개 변수

delta: Vector3

번역할 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)

이벤트