Engine Class
EditableMesh
Summary
Methods
Inherited Members
6 inherited from Object
API Reference
Properties
Methods
AddBone
Parameters
Returns
AddColor
AddTriangle
Destroy
EditableMesh:Destroy():()
Returns
()
FindClosestPointOnSurface
FindClosestVertex
FindVerticesWithinSphere
GetAdjacentFaces
GetAdjacentVertices
GetBoneByName
GetBoneIsVirtual
GetColorAlpha
GetFacesWithAttribute
GetFacesWithColor
GetFacesWithNormal
GetFacsCorrectivePose
GetFacsPose
Parameters
Returns
GetVertexBones
GetVertexBoneWeights
GetVertexColors
GetVertexFaceColor
GetVertexFaceNormal
GetVertexFaces
GetVertexFaceUV
GetVertexNormals
GetVerticesWithAttribute
GetVerticesWithColor
GetVerticesWithNormal
MergeVertices
RaycastLocal
Returns
Code Samples
EditableMesh:RaycastLocal()
local AssetService = game:GetService("AssetService")
local Workspace = game:GetService("Workspace")
-- Initialize EditableMesh in space
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
-- Function that will cast a ray from the given point, returning the world point of the hit and the UV coordinate
local function castRayFromCamera(meshPart: MeshPart, editableMesh: EditableMesh, viewportPoint: Vector3)
if not meshPart then
return
end
-- Calculate how much the object is being scaled in each dimension
local renderScale = meshPart.Size / meshPart.MeshSize
-- Create ray from camera along the direction of a clicked point
local ray = Workspace.CurrentCamera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y)
-- Convert to object space to use with 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
-- Didn't hit any faces
return
end
-- Compute the hit point in world space
local worldHitPoint = meshPart.CFrame:PointToWorldSpace(point * renderScale)
-- Get the UVs on the 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)
-- Interpolate UVs within the face based on the barycentric coordinate
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
Parameters
Returns
()
SetFacsCorrectivePose
SetFacsPose
Parameters
Returns
()
SetNormal
SetPosition
SetVertexBones
SetVertexBoneWeights
SetVertexFaceColor
SetVertexFaceNormal
SetVertexFaceUV
Triangulate
EditableMesh:Triangulate():()
Returns
()