I’ve tried to use the :DrawImageProjected() to project an image on an editable mesh with a mouse click, The problem is that There’s no image projecting, instead my studio crashes as soon as I run the projected method. Any ideas what the issue can be? I would be super thankful.
local as = game:GetService("AssetService")
local meshPart = workspace:WaitForChild("1")
local TDP = workspace:WaitForChild("TextureDisplayPart")
local imageSize = Vector2.new(1024/2, 1024/2)
local editableImage: EditableImage = as:CreateEditableImage({Size = imageSize}) -- The result for this projection
local decalImage: EditableImage = as:CreateEditableImageAsync(Content.fromAssetId(75802053454071), {Size = Vector2.new(512/2,512/2)}) -- The decal for projection
local targetMesh: EditableMesh = as:CreateEditableMeshAsync(meshPart.MeshContent) -- This will be the mesh you want to project to
local mp = as:CreateMeshPartAsync(Content.fromObject(targetMesh))
mp.TextureContent = Content.fromObject(editableImage)
TDP:WaitForChild("SurfaceGui"):WaitForChild("ImageLabel").ImageContent = Content.fromObject(editableImage)
meshPart:ApplyMesh(mp)
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local arrow = game:GetService("Workspace"):WaitForChild("Arrow")
workspace:WaitForChild("TextureDisplayPart"):WaitForChild("SurfaceGui"):WaitForChild("ImageLabel").ImageContent = Content.fromObject(editableImage)
mouse.Button1Down:Connect(function()
local relativePos = mp.CFrame:PointToWorldSpace(mouse.Hit.Position)
local direction = (game.Workspace.CurrentCamera.CFrame.Position - relativePos).Unit
local projectionParams: ProjectionParams = {
Direction = mp.CFrame:VectorToObjectSpace(direction),
Position = mp.CFrame:PointToObjectSpace(relativePos),
Size = Vector3.new(1, 1, 1),
Up = mp.CFrame.UpVector,
}
local localBrushConfig: BrushConfig = {
Decal = decalImage,
ColorBlendType = Enum.ImageCombineType.BlendSourceOver,
AlphaBlendType = Enum.ImageAlphaType.Default,
BlendIntensity = 1,
FadeAngle = 90.0
}
editableImage:DrawImageProjected(targetMesh, projectionParams, localBrushConfig)
end)
I did a different kind of raycast. It detects now the problem is that the image is too big that I only see colors. when I try to edit the size category, the image doesn’t appear at all. It’s either too big or non existant
I can’t test the code where the issues was. But heres the fixes that i only know:
Create the EditableImage instance only once, outside of the mouse button click event handler.
Add a check to see if the DrawImageProjected() method has already been called before making the current call.
Handle any potential errors that may occur when calling DrawImageProjected().
Here are a few issues with your code that could be contributing to the problem:
You’re creating a new EditableImage instance every time the mouse button is clicked, which can lead to memory leaks and performance issues.
You’re not checking if the DrawImageProjected() method has already been called before making the current call. This could lead to the method being called multiple times in quick succession, causing the Studio to crash.
You’re not handling any potential errors that may occur when calling DrawImageProjected(). If an error occurs, it could cause the Studio to crash or become unresponsive.
Thanks for the reply. I figured out what the issue was. The mesh was so complicated and the texture multiplies so many times over it, when I draw something on texture the image will be drawn many times that studio wouldn’t handle it.