概要
方法
繼承成員
6 位繼承自「Object」
API 參考
屬性
方法
AddTriangle
Destroy
EditableMesh:Destroy():()
返回
()
FindClosestPointOnSurface
FindClosestVertex
FindVerticesWithinSphere
GetFacesWithAttribute
GetFacsPose
GetVertexBoneWeights
GetVertexFaceColor
GetVertexFaceNormal
GetVertexFaceUV
GetVerticesWithAttribute
GetVerticesWithNormal
RaycastLocal
返回
範例程式碼
可編輯網格:RaycastLocal()
local AssetService = game:GetService("AssetService")
local Workspace = game:GetService("Workspace")
-- 在空間中初始化可編輯網格
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
warn(errorMsg)
end
-- 將從給定點發射光線的函數,返回命中的世界點和UV座標
local function castRayFromCamera(meshPart: MeshPart, editableMesh: EditableMesh, viewportPoint: Vector3)
if not meshPart then
return
end
-- 計算 物件在每個維度上被縮放的程度
local renderScale = meshPart.Size / meshPart.MeshSize
-- 創建從相機到被點擊點方向的光線
local ray = Workspace.CurrentCamera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y)
-- 轉換為物件空間以用於RaycastLocal()
local relativeOrigin = meshPart.CFrame:PointToObjectSpace(ray.Origin) / renderScale
local relativeTarget = meshPart.CFrame:PointToObjectSpace(ray.Origin + ray.Direction * 100) / renderScale
local relativeDirection = relativeTarget - relativeOrigin
local faceId, point, barycentricCoordinate, vertId1, vertId2, vertId3 =
editableMesh:RaycastLocal(relativeOrigin, relativeDirection)
if not faceId then
-- 沒有擊中任何面
return
end
-- 計算在世界空間中的命中點
local worldHitPoint = meshPart.CFrame:PointToWorldSpace(point * renderScale)
-- 獲取面的UV
local uvId1 = editableMesh:GetVertexFaceUV(vertId1, faceId)
local uvId2 = editableMesh:GetVertexFaceUV(vertId2, faceId)
local uvId3 = editableMesh:GetVertexFaceUV(vertId3, faceId)
local uv1 = editableMesh:GetUV(uvId1)
local uv2 = editableMesh:GetUV(uvId2)
local uv3 = editableMesh:GetUV(uvId3)
-- 根據重心坐標在面內插值UV
local u = (barycentricCoordinate.x * uv1.x) + (barycentricCoordinate.y * uv2.x) + (barycentricCoordinate.z * uv3.x)
local v = (barycentricCoordinate.x * uv1.y) + (barycentricCoordinate.y * uv2.y) + (barycentricCoordinate.z * uv3.y)
return worldHitPoint, Vector2.new(u, v)
endSetBoneCFrame
SetBoneIsVirtual
SetBoneParent
SetColorAlpha
SetFaceVertices
SetFacsBonePose
參數
返回
()
SetFacsCorrectivePose
SetFacsPose
參數
返回
()
SetNormal
SetVertexBones
SetVertexBoneWeights
SetVertexFaceColor
SetVertexFaceNormal
SetVertexFaceUV
Triangulate
EditableMesh:Triangulate():()
返回
()