Help with :DrawImageProjected(). (Crashing)

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)
1 Like
local as = game:GetService("AssetService")
local meshPart = workspace:WaitForChild("1")
local TDP = workspace:WaitForChild("TextureDisplayPart")

local imageSize = Vector2.new(1024, 1024)
local editableImage: EditableImage = as:CreateEditableImage({Size = imageSize})
print("editableImage created:", editableImage ~= nil)

local decalImage: EditableImage = as:CreateEditableImageAsync(Content.fromAssetId(75802053454071), {Size = Vector2.new(512, 512)})
decalImage.Loaded:Wait()
print("decalImage created and loaded:", decalImage ~= nil)

local targetMesh: EditableMesh = as:CreateEditableMeshAsync(meshPart.MeshContent)
targetMesh.Loaded:Wait()
print("targetMesh created and loaded:", targetMesh ~= nil)

local mp = as:CreateMeshPartAsync(Content.fromObject(targetMesh))
mp.TextureContent = Content.fromObject(editableImage)
meshPart:ApplyMesh(mp)

TDP:WaitForChild("SurfaceGui"):WaitForChild("ImageLabel").ImageContent = Content.fromObject(editableImage)

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()
    print("Mouse button 1 down!")
    local ray = mouse.UnitRay
    local hit, position, normal = workspace:FindPartOnRay(ray, mp)

    if hit == mp then
        local relativePos = mp.CFrame:PointToObjectSpace(position)
        local direction = mp.CFrame:VectorToObjectSpace(-ray.Direction)
        local upVector = mp.CFrame:VectorToObjectSpace(normal)

        print("Relative Position:", relativePos)
        print("Direction (Object Space):", direction)
        print("Up Vector (Object Space):", upVector)

        local projectionParams: ProjectionParams = {
            Direction = direction,
            Position = relativePos,
            Size = Vector3.new(20, 20, 20),
            Up = upVector,
        }

        local localBrushConfig: BrushConfig = {
            Decal = decalImage,
            ColorBlendType = Enum.ImageCombineType.BlendSourceOver,
            AlphaBlendType = Enum.ImageAlphaType.Default,
            BlendIntensity = 1,
            FadeAngle = 90.0
        }

        pcall(function()
            editableImage:DrawImageProjected(targetMesh, projectionParams, localBrushConfig)
            print("DrawImageProjected called successfully!")
        end)
    else
        print("Did not click on the target mesh part.")
    end
end)

And why you divide the local imageSize = Vector2.new(1024/2, 1024/2) ?
Try this!

To adjust that make it local imageSize = Vector2.new(512, 512)

Im clicking on the meshpart but it’s not detecting it, It’s printing the (“Did not click on the target mesh”)

1 Like

I’m pretty sure that :FindPartOnRay is a deprecated method.

1 Like

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

1 Like

I can’t test the code where the issues was. But heres the fixes that i only know:

  1. Create the EditableImage instance only once, outside of the mouse button click event handler.

  2. Add a check to see if the DrawImageProjected() method has already been called before making the current call.

  3. 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:

  1. You’re creating a new EditableImage instance every time the mouse button is clicked, which can lead to memory leaks and performance issues.

  2. 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.

  3. 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.

1 Like

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.

1 Like