如何在 roblox 上获取模型的尺寸值
How to get Size value of a model on roblox
所以我正在制作一个涉及使用
的游戏
Size
零件的属性。但是,由于模型没有 Size 属性,所以我想知道如何获得模型的 Size 属性。
我想要一个不使用其他部分(例如数字值)来存储它的答案。
谢谢!
正如您所注意到的,Model
s 没有 Size
属性,因为它是从 BasePart
class 继承的——这不是Model
.
的 parent class
如果模型的“大小”是指其边界框的尺寸,则 Model
class 有一个成员函数:GetExtentsSize()
.
您可以找到 here 的 Roblox 参考文章,内容如下:
Returns the size of the smallest bounding box that contains all of the BasePart
s in the Model. If Model.PrimaryPart
exists then the bounding box will be aligned to that part. If a primary part has not been set then the function will chose a part in the model to align the bounding box to. As the the selection of this part is not deterministic it is recommended to set a Model.PrimaryPart
to get consistent results with this function.
Note this function only returns the size of the smallest bounding box, and the developer must employ their own method to obtain the position of the bounding box.
如本说明所述,为没有主要零件的模型调用此函数可能会产生不一致的结果。在 Roblox Studio 中编辑某些内容时,您可能选择并复制了一个模型,并看到副本的边界框与原始边界框发生了变化。我想这就是文章所指的那种不一致。
还有 Model
class 成员函数 GetBoundingBox()
,其中 returns 一个描述包含模型所有部分的体积的元组。不过请注意,我是在快速谷歌搜索后发现此功能的,但我还没有时间了解它是如何工作的。
所以我正在制作一个涉及使用
的游戏Size
零件的属性。但是,由于模型没有 Size 属性,所以我想知道如何获得模型的 Size 属性。 我想要一个不使用其他部分(例如数字值)来存储它的答案。 谢谢!
正如您所注意到的,Model
s 没有 Size
属性,因为它是从 BasePart
class 继承的——这不是Model
.
如果模型的“大小”是指其边界框的尺寸,则 Model
class 有一个成员函数:GetExtentsSize()
.
您可以找到 here 的 Roblox 参考文章,内容如下:
Returns the size of the smallest bounding box that contains all of the
BasePart
s in the Model. IfModel.PrimaryPart
exists then the bounding box will be aligned to that part. If a primary part has not been set then the function will chose a part in the model to align the bounding box to. As the the selection of this part is not deterministic it is recommended to set aModel.PrimaryPart
to get consistent results with this function.
Note this function only returns the size of the smallest bounding box, and the developer must employ their own method to obtain the position of the bounding box.
如本说明所述,为没有主要零件的模型调用此函数可能会产生不一致的结果。在 Roblox Studio 中编辑某些内容时,您可能选择并复制了一个模型,并看到副本的边界框与原始边界框发生了变化。我想这就是文章所指的那种不一致。
还有 Model
class 成员函数 GetBoundingBox()
,其中 returns 一个描述包含模型所有部分的体积的元组。不过请注意,我是在快速谷歌搜索后发现此功能的,但我还没有时间了解它是如何工作的。