Editable Mesh
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ข้อมูลสรุป
วิธีการ
สมาชิกที่ได้รับทอด
สมาชิก 6 คนที่รับทอดมาจาก Object
เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
วิธีการ
Add Bone
พารามิเตอร์
ส่งค่ากลับ
Add Color
Add Triangle
Batch Add
พารามิเตอร์
ส่งค่ากลับ
Batch Get Face Attributes
พารามิเตอร์
ส่งค่ากลับ
Batch Get Vertex Attributes
พารามิเตอร์
ส่งค่ากลับ
Batch Get Vertex Face Attributes
Editable Mesh: Batch Get Vertex Face Attributes(
พารามิเตอร์
ส่งค่ากลับ
Batch Set Face Attributes
Batch Set Values
Batch Set Vertex Face Attributes
Clear
Editable Mesh: Clear():()
ส่งค่ากลับ
()
Destroy
Editable Mesh: Destroy():()
ส่งค่ากลับ
()
Find Closest Point On Surface
Find Closest Vertex
Find Vertices Within Sphere
Get Adjacent Faces
Get Adjacent Vertices
Get Bone By Name
Get Bone C Frame
Get Bone Is Virtual
Get Bone Parent
Get Color Alpha
Get Face Normals
Get Faces With Attribute
Get Faces With Color
Get Faces With Normal
Get Face Vertices
Get Facs Corrective Pose
Get Facs Pose
พารามิเตอร์
ส่งค่ากลับ
Get Normal
Get Position
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 Vertex U Vs
Get Vertices With Attribute
Get Vertices With Color
Get Vertices With Normal
Get Vertices With UV
Merge Vertices
Raycast Local
ส่งค่ากลับ
ตัวอย่างโค้ด
EditableMesh:RaycastLocal()
local AssetService = game:GetService("AssetService")
local Workspace = game:GetService("Workspace")
-- เริ่มต้น EditableMesh ในพื้นที่
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)
-- รับ UVs บนหน้า
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)
-- ทำการอินเตอร์โพล UVs ภายในหน้าตามพิกัด 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
พารามิเตอร์
ส่งค่ากลับ
()
Set Facs Corrective Pose
Set Facs Pose
พารามิเตอร์
ส่งค่ากลับ
()
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():()
ส่งค่ากลับ
()