Editable Mesh
*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
Add Bone
Tham Số
Lợi Nhuận
Add Color
Add Triangle
Batch Add
Tham Số
Lợi Nhuận
Batch Get Face Attributes
Tham Số
Lợi Nhuận
Batch Get Vertex Attributes
Tham Số
Lợi Nhuận
Batch Get Vertex Face Attributes
Editable Mesh: Batch Get Vertex Face Attributes(
Tham Số
Lợi Nhuận
Batch Set Face Attributes
Batch Set Values
Batch Set Vertex Face Attributes
Clear
Editable Mesh: Clear():()
Lợi Nhuận
()
Destroy
Editable Mesh: Destroy():()
Lợi Nhuận
()
Find Closest Point On Surface
Find Closest Vertex
Find Vertices Within Sphere
Get Adjacent Faces
Get Adjacent Vertices
Get Bone By Name
Get Bone Is Virtual
Get Color Alpha
Get Faces With Attribute
Get Faces With Color
Get Faces With Normal
Get Facs Corrective Pose
Get Facs Pose
Tham Số
Lợi Nhuận
Get Vertex Bones
Get Vertex Bone Weights
Get Vertex Colors
Get Vertex Face Color
Get Vertex Face Normal
Get Vertex Faces
Get Vertex Face UV
Get Vertex Normals
Get Vertices With Attribute
Get Vertices With Color
Get Vertices With Normal
Merge Vertices
Raycast Local
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 ra mộ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 thay đổi kích thước trong mỗi chiều
local renderScale = meshPart.Size / meshPart.MeshSize
-- Tạo tia từ camera theo hướng của điểm đã 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)
end
if meshPart and editableMesh then
local worldHitPoint, uv = castRayFromCamera(meshPart, editableMesh, Vector3.new(400, 300, 0))
print(worldHitPoint, uv)
endSet Bone C Frame
Set Bone Is Virtual
Set Bone Name
Set Bone Parent
Set Color
Set Color Alpha
Set Face Colors
Set Face Normals
Set Face U Vs
Set Face Vertices
Set Facs Bone Pose
Tham Số
Lợi Nhuận
()
Set Facs Corrective Pose
Set Facs Pose
Tham Số
Lợi Nhuận
()
Set Normal
Set Position
Set Vertex Bones
Set Vertex Bone Weights
Set Vertex Face Color
Set Vertex Face Normal
Set Vertex Face UV
Triangulate
Editable Mesh: Triangulate():()
Lợi Nhuận
()