Class · inherits Instance
WrapTextureTransfer
WrapTextureTransfer allows a parent Decal to be wrapped around
its parent MeshPart based on the cage of its WrapTarget.
About WrapTextureTransfer
WrapTextureTransfer provides an alternative projection mode for Decal
where this Decal is fit to the parent MeshPart based on it's
CageMesh provided in WrapTarget.
This is useful as it allows fitting of Decals to a wide variety of differently shaped MeshParts that share a similar WrapTarget CageMesh topology. By authoring textures that are in the WrapTarget UV space, these textures can be reused across many different MeshParts with different texture layouts.
- DataModel Structure
A way to visualize how this works is to imagine the Decals textures on the
WrapTarget CageMesh, which is wrapped around the MeshPart. These textures are
then projected from the CageMesh onto the MeshPart surface. Geometry that is
internal to the MeshPart, or that is not covered by the CageMesh, will not
receive any projected decal textures. Segmented regions of the target
MeshPart are used to improve projection quality near holes or
boundaries in the CageMesh.
Properties 3
ReferenceCageMeshContent
: ContentAn optional reference mesh used for pruning and validating the target cage.The reference cage mesh is the cage mesh that the texture was authored for. This target cage mesh defined in
WrapTargetis pruned against thisReferenceCageMeshContent. If the target cage mesh contains vertices or faces that are not present in the reference cage mesh, these vertices and faces are removed from the target cage mesh before performing the texture transfer. If there are no shared UVs betweenReferenceCageMeshContentand cage mesh defined inWrapTarget, the texture transfer fails.When not defined, the cage in
WrapTargetin ancestorMeshPartis used for transfer without any pruning or validation.UVMaxBound
: Vector2Determines the maximum bound of the UV space to include in the transfer.Determines the maximum bound of the UV space to include in the transfer. Areas of the cage mesh with UV values greater than the maximum bound aren't included when applying the texture.
The Decal textures apply to the parent
MeshPartwith the textures scaling linearly between UVMinBound and UVMaxBound.When set to default -inf, the maximum UV value is used from WrapTarget's cage.
UVMinBound
: Vector2Determines the minimum bound of the UV space to include in the transfer.Determines the minimum bound of the UV space to include in the transfer. Areas of the cage mesh with UV values smaller than the minimum bound aren't included when applying the texture.
The Decal textures apply to the parent
MeshPartwith the textures scaling linearly between UVMinBound and UVMaxBound.When set to default inf, uses the minimum UV value from WrapTarget's cage.
Methods 1
PrepareProjectionMeshDataAsync
() → ()YieldsPrepares and caches projection data for using thisWrapTextureTransferwith projectedEditableImageoperations.Prepares this
WrapTextureTransferfor use as theprojectionSourceinEditableImage.DrawImageProjectedandEditableImage.SampleImageProjected. This method takes no parameters, yields until preparation completes, and returns no value.This allows projected texture editing, such as painting makeup on a player's current head, without creating an
EditableMeshfrom the target asset or requiring permission to create one. The prepared data is cached internally; it is not returned to scripts and cannot be inspected, converted toContent, or published.The
WrapTextureTransfermust be parented to aDecalwhose parent is aMeshPartwith mesh content and a validWrapTargetchild. This hierarchy must be in the data model. ConfigureWrapTextureTransfer.ReferenceCageMeshContent,WrapTextureTransfer.UVMinBound, andWrapTextureTransfer.UVMaxBoundas needed before calling this method.The prepared data combines the target mesh's positions, normals, and triangle connectivity within the region covered by the transfer with the transferred UVs computed from the current cage configuration and UV bounds. The geometry is scaled to match the target
MeshPart's currentBasePart.Size. Projection positions and directions use the target MeshPart's local space.Preparation is reused across projected image operations while the data remains valid. Changes to the target mesh or its size, cage configuration, UV bounds, or hierarchy invalidate the cached data. Call this method again after such a change. Both projection methods raise an error if preparation has not completed successfully or the cached data has been invalidated. Passing an
EditableMeshto those methods does not require this preparation.Use
pcall()to handle preparation errors, including invalid hierarchy, unavailable mesh or cage data, failed UV transfer, or inputs changing during preparation. Only perform projected image operations after the call succeeds.For example, with the head, decal, images, reference cage content, UV bounds, and brush configurations already defined:
local projectionTransfer = Instance.new("WrapTextureTransfer") projectionTransfer.ReferenceCageMeshContent = referenceCageContent projectionTransfer.UVMinBound = makeupUVMin projectionTransfer.UVMaxBound = makeupUVMax projectionTransfer.Parent = makeupDecal makeupDecal.Parent = playerHead local success, errorMessage = pcall(function() projectionTransfer:PrepareProjectionMeshDataAsync() end) if not success then warn("Failed to prepare makeup projection: " .. tostring(errorMessage)) return end makeupTexture:DrawImageProjected(projectionTransfer, projection, brushConfig) sampledBrush:SampleImageProjected( projectionTransfer, makeupTexture, projection, sampleBrushConfig )
WrapTextureTransfer also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.