EditableMesh

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

无法创建

EditableMesh 将应用的视觉网格更改为连接到 MeshPart 时,允许在 Studio 和体验中查询和修改网格。

一个 EditableMesh 可以从现有的 ContentMeshPart 或网格 ID 使用 AssetService:CreateEditableMeshAsync() 或空白 EditableMesh 创建,或使用 AssetService:CreateEditableMesh() 可以创建一个空白 。然后可以显示、修改和更新其碰撞模型。不是所有步骤都是必要的;例如,你可能想创建一个 EditableMesh 仅用于射线投射,而不显示它。

当它链接到新的 EditableMesh 时,将显示一个 MeshPart ,通过 AssetService:CreateMeshPartAsync() 。您可以创建更多 引用相同 的实例,或通过 链接到现有的 。

要重新计算编辑后的碰撞和流体几何图形,您可以再次调用 AssetService:CreateMeshPartAsync()MeshPart:ApplyMesh() 来更新现有的 MeshPart 。一般建议在概念编辑结束后执行此操作,而不是在调用个别方法来操作几何图形之后。网格的视觉变化始终会立即反映在引擎上,无需调用 AssetService:CreateMeshPartAsync()

启用可编辑的网格对已发布的体验

为了安全目的,默认情况下,使用 EditableMesh 对发布的体验失败。要启用使用,EditableMesh,你必须年满 13 岁并身份验证通过。验证通过后,打开 Studio 的 游戏设置,选择 安全 ,启用 允许网格和图像 API 切换。请记住,在启用切换之前,查看使用条款

权限

为了防止滥用,AssetService:CreateEditableMeshAsync() 只允许您加载和编辑网格资产:

  • 这些是由体验的创建者拥有的(如果体验由个人拥有)。
  • 这些是由群组拥有的(如果体验由群组拥有)。
  • 这些是由登录的 Studio 用户拥有的(如果地点文件尚未保存或发布到 Roblox)。

如果使用 API 来加载不满足上述条件的资产,它们将抛出错误。

固定尺寸网格

当从现有网格资产中创建一个 EditableMesh 时(通过 AssetService:CreateEditableMeshAsync() ),结果的可编辑网格默认为固定尺寸。固定尺寸的网格在内存方面更高效,但您无法更改边顶点、面或属性的数量。只能编辑顶点属性和位置的值。

稳定的垂直/面 ID

许多 EditableMesh 方法使用 vertex , normal , UV , colorface ID。这些在 Luau 中被视为整数,但需要一些特殊处理。主要区别是,ID 是稳定的,即使其他部分的网格发生变化,它们也是相同的。例如,如果一个 EditableMesh 有五个边顶 {1, 2, 3, 4, 5} ,如果你移除边顶 4 ,那么新的边顶将是 {1, 2, 3, 5}

请注意,ID 不保证是按顺序排列的,因此,当遍历垂直或面时,您应该遍历由 GetVertices()GetFaces() 返回的表。

分割垂直面属性

一个 边角 是面的角落,并且可以将面连接在一起。顶点可以有几个属性:位置、正常、UV坐标、颜色和透明度。

有时对于所有接触顶点的面都有用使用相同的属性值,但有时你会想让不同的面使用不同的属性值在同一顶点上。例如,在光滑的球体上,每个边点只有一个正常。相反,在立方体的角落,顶点将有 3 个不同的正常(每个邻近面都有一个)。您还可以在 UV 坐标或顶点颜色上有缝隙或锋利的变化。

当创建面时,每个vertex默认会拥有每个属性中的一个:一个正常值、一个UV坐标和一个颜色/透明度。如果你想创建缝合,你应该创建新属性并将它们设置在面上。例如,这段代码会创建一个锋利的立方体:


local AssetService = game:GetService("AssetService")
-- 给出 4 个顶点 ID,添加新的正常和 2 个三角形,制作锋利的四角
local function addSharpQuad(eMesh, vid0, vid1, vid2, vid3)
local nid = eMesh:AddNormal() -- 这会创建一个正常 ID,它会自动计算
local fid1 = eMesh:AddTriangle(vid0, vid1, vid2)
eMesh:SetFaceNormals(fid1, {nid, nid, nid})
local fid2 = eMesh:AddTriangle(vid0, vid2, vid3)
eMesh:SetFaceNormals(fid2, {nid, nid, nid})
end
-- 使6边之间的边缘增加的立方体
local function makeSharpCube()
local eMesh = AssetService:CreateEditableMesh()
local v1 = eMesh:AddVertex(Vector3.new(0, 0, 0))
local v2 = eMesh:AddVertex(Vector3.new(1, 0, 0))
local v3 = eMesh:AddVertex(Vector3.new(0, 1, 0))
local v4 = eMesh:AddVertex(Vector3.new(1, 1, 0))
local v5 = eMesh:AddVertex(Vector3.new(0, 0, 1))
local v6 = eMesh:AddVertex(Vector3.new(1, 0, 1))
local v7 = eMesh:AddVertex(Vector3.new(0, 1, 1))
local v8 = eMesh:AddVertex(Vector3.new(1, 1, 1))
addSharpQuad(eMesh, v5, v6, v8, v7) -- 前
addSharpQuad(eMesh, v1, v3, v4, v2) -- 返回
addSharpQuad(eMesh, v1, v5, v7, v3) -- 左
addSharpQuad(eMesh, v2, v4, v8, v6) -- 右侧
addSharpQuad(eMesh, v1, v2, v6, v5) -- 底部
addSharpQuad(eMesh, v3, v7, v8, v4) -- 顶部
eMesh:RemoveUnused()
return eMesh
end
卷线

网格面有前面和后面。当绘制网格时,默认情况下只绘制面的前部,尽管您可以通过设置网格的 DoubleSided 属性为 true 来更改此情况。

面周围的边缘点的顺序决定你是否正在查看前部或后返回。当垂直向前时,面的前部可见,当垂直向后时,面的后部可见。

Order of the vertices around the face
限制

EditableMesh 目前有 60,000 个边和 20,000 个三角形的限制。尝试添加太多边或三角形会导致错误。

概要

属性

方法

属性

FixedSize

只读
未复制
Roblox 安全性
读取并联

固定大小的网格允许更改边点属性的值,但不允许添加或删除边点和三角形。

SkinningEnabled

读取并联

方法

AddBone

参数

boneProperties: Dictionary
默认值:""

返回

AddColor

添加新颜色到几何图形,并返回稳定的颜色 ID。

参数

color: Color3

新的颜色。

默认值:""
alpha: number

颜色 alpha(透明度)。

默认值:""

返回

新颜色的稳定颜色 ID。

AddNormal

添加新的正常值到几何图形,并返回稳定的正常 ID。如果未指定正常值,正常将自动计算。

参数

normal: Vector3

普通矢量力。如果未指定普通值,普通将自动计算。

默认值:""

返回

新常态的稳定普通 ID。

AddTriangle

添加新的三角形到网格并返回稳定的面 ID。

参数

vertexId0: number

三角形的第一个顶点的 ID。

默认值:""
vertexId1: number

三角形第二个顶点的 ID。

默认值:""
vertexId2: number

三角形的第三个顶点的 ID。

默认值:""

返回

新脸部的稳定面 ID。

AddUV

添加新的 UV 到几何体并返回稳定的 UV ID。

参数

新的 UV 坐标。

默认值:""

返回

新的 UV 的稳定 UV ID。

AddVertex

添加新的vertex到几何图形中,并返回稳定的vertex ID。

参数

在网格的本地对象空间中的位置。

默认值:""

返回

新边缘的稳定vertex ID。

Destroy

()

摧毁网格内容,立即回收使用的内存。


返回

()

FindClosestPointOnSurface

找到网格表面上最接近的点。返回面部ID,指向本地对象空间的网格,以及面部内部位置的坐标。见 RaycastLocal() 获取更多关于椭圆坐标的信息。

参数

point: Vector3

网格的本地对象空间中的点位置。

默认值:""

返回

面 ID tuple、在本地对象空间上的网格点以及脸部内的位置坐标。

FindClosestVertex

找到空间中最接近特定点的vertex并返回稳定的vertex ID。

参数

toThisPoint: Vector3

网格的本地对象空间中的点位置。

默认值:""

返回

最接近稳定顶点 ID 到指定空间点。

FindVerticesWithinSphere

查找特定球体内的所有边点并返回一列稳定边点ID列表。

参数

center: Vector3

网格本地对象空间中球体的中心。

默认值:""
radius: number

球体的半径。

默认值:""

返回

请求球体内稳定边界ID列表。

GetAdjacentFaces

给出稳定的面 ID,返回邻近面的列表。

Adjacent faces indicated around requested face

参数

faceId: number
默认值:""

返回

与给定面邻近的面 ID 列表。

GetAdjacentVertices

给出稳定的顶点 ID,返回邻近顶点列表。

Adjacent vertices indicated around requested vertex

参数

vertexId: number

绕着哪个垂直 ID 获得邻近垂直。

默认值:""

返回

给定垂直ID周围的邻近边缘的ID列表。

GetBoneByName

参数

boneName: string
默认值:""

返回

GetBoneCFrame

参数

boneId: number
默认值:""

返回

GetBoneIsVirtual

参数

boneId: number
默认值:""

返回

GetBoneName

参数

boneId: number
默认值:""

返回

GetBoneParent

参数

boneId: number
默认值:""

返回

GetBones


返回

GetCenter


返回

EditableMesh 的边界盒中心。

GetColor

返回给定颜色ID的颜色。

参数

colorId: number

获取颜色的颜色ID。

默认值:""

返回

要求的稳定颜色 ID 的颜色。

GetColorAlpha

返回指定稳定颜色 ID 的颜色 alpha(透明度)。

参数

colorId: number

获取Alpha的颜色ID。

默认值:""

返回

颜色 alpha 在请求稳定颜色 ID。

GetColors

返回网格的所有颜色为稳定颜色ID列表。


返回

稳定颜色 ID 列表。

GetFaceColors

返回面的颜色 ID,用于面上的边顶点。

参数

faceId: number

用于获取颜色ID的面部ID。

默认值:""

返回

用于指定面上的顶点的颜色 ID 列表。

GetFaceNormals

返回面的正常 ID,用于面上的边顶点。

参数

faceId: number

用于获取普通ID的面部ID。

默认值:""

返回

用于给定面上的顶点的普通ID列表。

GetFaceUVs

返回面的 UV ID,用于面上的边顶点。

参数

faceId: number

用于获取 UV ID 的面部识别。

默认值:""

返回

用于指定面上的顶点的 UV ID 列表。

GetFaceVertices

返回面的顶点 ID。

参数

faceId: number
默认值:""

返回

给定面周围的vertex ID列表。

GetFaces

返回网格的所有面为一列稳定的面 ID。


返回

稳定面 ID 列表。

GetFacesWithColor

参数

colorId: number
默认值:""

返回

GetFacesWithNormal

参数

normalId: number
默认值:""

返回

GetFacesWithUV

参数

uvId: number
默认值:""

返回

GetFacsCorrectivePose

参数

actions: Array
默认值:""

返回

GetFacsCorrectivePoses


返回

GetFacsPose

参数

默认值:""

返回

GetFacsPoses


返回

GetNormal

返回给定普通ID的普通向量。

参数

normalId: number

正常ID用于获取正常向矢量力。

默认值:""

返回

在请求的正常 ID 上的普通向量。

GetNormals

返回网格的所有正常值为一列稳定的正常ID。


返回

稳定的普通 ID 列表。

GetPosition

获取网格本地对象空间中vertex的位置。

参数

vertexId: number

稳定的垂直 ID,用于获取位置。

默认值:""

返回

在网格本地对象空间中的顶点位置。

GetSize


返回

EditableMesh 的大小。

GetUV

返回指定的 UV ID 的 UV 坐标。

参数

uvId: number

用于获取紫外坐标的 UV ID。

默认值:""

返回

在请求的 UV ID 上的 UV 坐标。

GetUVs

返回网格的所有 UV 作为一个列表稳定的 UV ID。


返回

稳定的 UV ID 列表。

GetVertexBoneWeights

参数

vertexId: number
默认值:""

返回

GetVertexBones

参数

vertexId: number
默认值:""

返回

GetVertexColors

参数

vertexId: number
默认值:""

返回

GetVertexFaceColor

参数

vertexId: number
默认值:""
faceId: number
默认值:""

返回

GetVertexFaceNormal

参数

vertexId: number
默认值:""
faceId: number
默认值:""

返回

GetVertexFaceUV

参数

vertexId: number
默认值:""
faceId: number
默认值:""

返回

GetVertexFaces

参数

vertexId: number
默认值:""

返回

GetVertexNormals

参数

vertexId: number
默认值:""

返回

GetVertexUVs

参数

vertexId: number
默认值:""

返回

GetVertices

返回所有顶点为一列稳定顶点 ID 列表。


返回

稳定边界ID列表。

GetVerticesWithColor

参数

colorId: number
默认值:""

返回

GetVerticesWithNormal

参数

normalId: number
默认值:""

返回

GetVerticesWithUV

参数

uvId: number
默认值:""

返回

IdDebugString

返回描述稳定ID的字符串,用于调试目的,如 f17v12 ,包含类输入、ID号和版本。

参数

id: number

用于返回调试信息字符串的ID。

默认值:""

返回

描述ID以人阅读可读格式的字符串。

MergeVertices

Map

合并触碰在一起的边点,使用单个边点 ID,但保留其他原始属性 ID。

参数

mergeTolerance: number

在那里,边顶被认为相互接触的距离。

默认值:""

返回

Map

将旧的vertex ID映射到新的vertex ID以融合已合并的垂直,

RaycastLocal

投射射线并返回交叉点、面 ID 和球心坐标。该方法的输入和输出位于网格的本地对象空间。

一个 椭圆坐标 是指将面内的一个点指定为面的 3 个边缘的权重组合的方式。这有助于作为一般方法来融合vertex特性。看这个方法的代码示例作为说明。

参数

origin: Vector3

网格本地对象空间中射线的起源。

默认值:""
direction: Vector3

射线的方向。

默认值:""

返回

交叉点、面 ID 和楔形坐标的 tuple。

代码示例

This code finds the position and UV coordinates of the closest point on an EditableMesh to the input point.

EditableMesh:RaycastLocal()

local AssetService = game:GetService("AssetService")
-- Initialize EditableMesh in space
local editableMesh = nil
local success, errorMsg = pcall(function()
editableMesh = AssetService:CreateEditableMeshAsync(Content.fromUri("rbxassetid://ASSET_ID"))
end)
local meshPart = nil
if success and editableMesh then
meshPart = AssetService:CreateMeshPartAsync(
Content.fromObject(editableMesh),
{ CollisionFidelity = Enum.CollisionFidelity.Hull }
)
meshPart.Parent = workspace
else
print(errorMsg)
end
local function castRayFromCamera(position)
if not meshPart then
return
end
-- Create ray from camera along the direction of a clicked point
local camera = workspace.CurrentCamera
local ray = camera:ScreenPointToRay(position.X, position.Y)
-- Convert to object space to use with RaycastLocal()
local relativeOrigin = meshPart.CFrame:PointToObjectSpace(ray.Origin)
local relativeDirection = meshPart.CFrame:VectorToObjectSpace(ray.Direction)
local triangleId, point, barycentricCoordinate
triangleId, point, barycentricCoordinate = editableMesh:RaycastLocal(relativeOrigin, relativeDirection * 100)
if not triangleId then
-- Didn't hit any triangles
return
end
-- Interpolate UVs within the triangle
local vert1, vert2, vert3 = editableMesh:GetTriangleVertices(triangleId)
local uv0 = editableMesh:GetUV(vert1)
local uv1 = editableMesh:GetUV(vert2)
local uv2 = editableMesh:GetUV(vert3)
local u = (barycentricCoordinate.x * uv0.x) + (barycentricCoordinate.y * uv1.x) + (barycentricCoordinate.z * uv2.x)
local v = (barycentricCoordinate.x * uv0.y) + (barycentricCoordinate.y * uv1.y) + (barycentricCoordinate.z * uv2.y)
return Vector2.new(u, v)
end

RemoveBone

()

参数

boneId: number
默认值:""

返回

()

RemoveFace

()

使用稳定的面 ID 去除一个面。

参数

faceId: number
默认值:""

返回

()

RemoveUnused

移除所有不在任何面中使用的边、正常、UV和颜色,并返回移除的ID。


返回

所有删除的稳定 ID。

ResetNormal

()

将此普通 ID 重置为自动计算,基于网格形状而不是手动设置。

参数

normalId: number

稳定的普通 ID 进行重置。

默认值:""

返回

()

SetBoneCFrame

()

参数

boneId: number
默认值:""
cframe: CFrame
默认值:""

返回

()

SetBoneIsVirtual

()

参数

boneId: number
默认值:""
virtual: boolean
默认值:""

返回

()

SetBoneName

()

参数

boneId: number
默认值:""
name: string
默认值:""

返回

()

SetBoneParent

()

参数

boneId: number
默认值:""
parentBoneId: number
默认值:""

返回

()

SetColor

()

设置颜色为颜色 ID。

参数

colorId: number

稳定的颜色 ID,用于设置颜色。

默认值:""
color: Color3

要设置的颜色。

默认值:""

返回

()

SetColorAlpha

()

设置颜色 alpha(透明度)为颜色 ID。

参数

colorId: number

稳定的颜色 ID,用于设置颜色 alpha。

默认值:""
alpha: number

Alpha 设置。

默认值:""

返回

()

SetFaceColors

()

将面的顶点颜色设置为新的颜色 ID。

参数

faceId: number

用于更新顶点颜色的面部ID。

默认值:""
ids: Array

用于指定面的顶点的新稳定颜色 ID 列表。

默认值:""

返回

()

SetFaceNormals

()

将面的顶点正常设置为新的正常 ID。

参数

faceId: number

用于更新顶点正常的面 ID。

默认值:""
ids: Array

用于给定面的顶点的新稳定常规 ID 列表。

默认值:""

返回

()

SetFaceUVs

()

将面的顶点 UV 设置为新的 UV ID。

参数

faceId: number

用于更新顶点 UV 的面 ID。

默认值:""
ids: Array

用于指定面的顶点的新稳定 UV ID 列表。

默认值:""

返回

()

SetFaceVertices

()

将面的顶点设置为新的顶点 ID。

参数

faceId: number

用于更新边点的面部ID。

默认值:""
ids: Array

用于指定面的新稳定边界ID列表。

默认值:""

返回

()

SetFacsBonePose

()

参数

默认值:""
boneId: number
默认值:""
cframe: CFrame
默认值:""

返回

()

SetFacsCorrectivePose

()

参数

actions: Array
默认值:""
boneIds: Array
默认值:""
cframes: Array
默认值:""

返回

()

SetFacsPose

()

参数

默认值:""
boneIds: Array
默认值:""
cframes: Array
默认值:""

返回

()

SetNormal

()

设置一个正常ID的正常值。这将更改每个使用正常ID的面向的顶点的正常值。

参数

normalId: number

稳定的普通 ID,用于设置普通向矢量力。

默认值:""
normal: Vector3

普通向量以设置。

默认值:""

返回

()

SetPosition

()

在网格的本地对象空间中设置一个vertex位置。

参数

vertexId: number

稳定垂直 ID 的垂直到位置。

默认值:""

在网格的本地对象空间中的位置。

默认值:""

返回

()

SetUV

()

设置 UV 坐标为 UV ID。

参数

uvId: number

用于设置UV坐标的UV ID。

默认值:""

UV坐标。

默认值:""

返回

()

SetVertexBoneWeights

()

参数

vertexId: number
默认值:""
boneWeights: Array
默认值:""

返回

()

SetVertexBones

()

参数

vertexId: number
默认值:""
boneIDs: Array
默认值:""

返回

()

SetVertexFaceColor

()

参数

vertexId: number
默认值:""
faceId: number
默认值:""
colorId: number
默认值:""

返回

()

SetVertexFaceNormal

()

参数

vertexId: number
默认值:""
faceId: number
默认值:""
normalId: number
默认值:""

返回

()

SetVertexFaceUV

()

参数

vertexId: number
默认值:""
faceId: number
默认值:""
uvId: number
默认值:""

返回

()

Triangulate

()

将网格上的所有面分为三角形目前,由于只能创建三角形,因此无需做任何操作,但如果您的代码依赖于三角形,建议您在调用 AssetService:CreateEditableMeshAsync() 之后调用此方法。


返回

()

活动