Lớp công cụ
EditableMesh
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Phương Pháp
Thành viên kế thừa
6 thành viên kế thừa từ Object
Tài Liệu Tham Khảo API
Thuộc Tính
Phương Pháp
AddBone
Tham Số
Lợi Nhuận
AddColor
AddTriangle
Destroy
EditableMesh:Destroy():()
Lợi Nhuận
()
FindClosestPointOnSurface
FindClosestVertex
FindVerticesWithinSphere
GetAdjacentFaces
GetAdjacentVertices
GetBoneByName
GetBoneIsVirtual
GetColorAlpha
GetFacesWithAttribute
GetFacesWithColor
GetFacesWithNormal
GetFacsCorrectivePose
GetFacsPose
Tham Số
Lợi Nhuận
GetVertexBones
GetVertexBoneWeights
GetVertexColors
GetVertexFaceColor
GetVertexFaceNormal
GetVertexFaces
GetVertexFaceUV
GetVertexNormals
GetVerticesWithAttribute
GetVerticesWithColor
GetVerticesWithNormal
MergeVertices
RaycastLocal
Lợi Nhuận
Mẫu mã
EditableMesh:RaycastLocal()
local AssetService = game:GetService("AssetService")
local Workspace = game:GetService("Workspace")
-- Khởi tạo EditableMesh trong không gian
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
-- Hàm sẽ phát tia từ điểm đã cho, trả về điểm thế giới của va chạm và tọa độ UV
local function castRayFromCamera(meshPart: MeshPart, editableMesh: EditableMesh, viewportPoint: Vector3)
if not meshPart then
return
end
-- Tính toán mức độ mà đối tượng đang được phóng đại trong mỗi kích thước
local renderScale = meshPart.Size / meshPart.MeshSize
-- Tạo một tia từ camera theo hướng của điểm được nhấp
local ray = Workspace.CurrentCamera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y)
-- Chuyển đổi sang không gian đối tượng để sử dụng với 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
-- Không va chạm với bất kỳ mặt nào
return
end
-- Tính toán điểm va chạm trong không gian thế giới
local worldHitPoint = meshPart.CFrame:PointToWorldSpace(point * renderScale)
-- Lấy các UV trên mặt
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)
-- Nội suy UV trong mặt dựa trên tọa độ barycentric
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
SetBoneName
SetBoneParent
SetColor
SetColorAlpha
SetFaceColors
SetFaceNormals
SetFaceUVs
SetFaceVertices
SetFacsBonePose
Tham Số
Lợi Nhuận
()
SetFacsCorrectivePose
SetFacsPose
Tham Số
Lợi Nhuận
()
SetNormal
SetPosition
SetVertexBones
SetVertexBoneWeights
SetVertexFaceColor
SetVertexFaceNormal
SetVertexFaceUV
Triangulate
EditableMesh:Triangulate():()
Lợi Nhuận
()