Classe de moteur
EditableMesh
*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.
Résumé
Méthodes
Membres hérités
6 hérité du Object
Référence API
Propriétés
Méthodes
AddBone
Paramètres
Retours
AddColor
AddTriangle
Destroy
EditableMesh:Destroy():()
Retours
()
FindClosestPointOnSurface
FindClosestVertex
FindVerticesWithinSphere
GetAdjacentFaces
GetAdjacentVertices
GetBoneByName
GetBoneIsVirtual
GetColorAlpha
GetFacesWithAttribute
GetFacesWithColor
GetFacesWithNormal
GetFacsCorrectivePose
GetFacsPose
Paramètres
Retours
GetVertexBones
GetVertexBoneWeights
GetVertexColors
GetVertexFaceColor
GetVertexFaceNormal
GetVertexFaces
GetVertexFaceUV
GetVertexNormals
GetVerticesWithAttribute
GetVerticesWithColor
GetVerticesWithNormal
MergeVertices
RaycastLocal
Retours
Échantillons de code
EditableMesh:RaycastLocal()
local AssetService = game:GetService("AssetService")
local Workspace = game:GetService("Workspace")
-- Initialiser EditableMesh dans l'espace
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
-- Fonction qui va lancer un rayon depuis le point donné, retournant le point mondial du coup et la coordonnée UV
local function castRayFromCamera(meshPart: MeshPart, editableMesh: EditableMesh, viewportPoint: Vector3)
if not meshPart then
return
end
-- Calculer combien l'objet est redimensionné dans chaque dimension
local renderScale = meshPart.Size / meshPart.MeshSize
-- Créer un rayon de la caméra dans la direction d'un point cliqué
local ray = Workspace.CurrentCamera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y)
-- Convertir en espace objet pour utiliser avec 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
-- N'a pas touché à des faces
return
end
-- Calculer le point d'impact dans l'espace mondial
local worldHitPoint = meshPart.CFrame:PointToWorldSpace(point * renderScale)
-- Obtenir les UV sur la face
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)
-- Interpoler les UVs dans la face en fonction de la coordonnée barycentrique
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
Paramètres
Retours
()
SetFacsCorrectivePose
SetFacsPose
Paramètres
Retours
()
SetNormal
SetPosition
SetVertexBones
SetVertexBoneWeights
SetVertexFaceColor
SetVertexFaceNormal
SetVertexFaceUV
Triangulate
EditableMesh:Triangulate():()
Retours
()