Issues creating texturable editable meshes

trying to create a flat mesh that can be textured, can’t seem to get the UVs right, and most code available (by official roblox accounts might I add) on EditableMeshes are deprecated or don’t work because EditableMesh / EditableImage is one of the, if not the, most botched updates in roblox history.

bump

1 Like

Changes to the EditableMesh and EditableImage APIs and/or workflows were to be expected during the beta period. Although documentation can sometimes still feel sparse, there’s definitely resources out there (including kindly asking for help on this forum!) that can help you figure out what you’re trying to do.

I couldn’t specifically ascertain what problem you were having or what you were trying to accomplish, but anyways, here’s an example of a dynamically created EditableMesh plane that scrolls a texture using EditableMesh UVs:

The code
-- Creating a simple face mesh

local AssetService = game:GetService("AssetService")

local mesh: EditableMesh = AssetService:CreateEditableMesh()

local v1: number = mesh:AddVertex(Vector3.new(4, 0, -4))
local v2: number = mesh:AddVertex(Vector3.new(-4, 0, -4))
local v3: number = mesh:AddVertex(Vector3.new(-4, 0, 4))
local v4: number = mesh:AddVertex(Vector3.new(4, 0, 4))

--[[
	UV coords are typically in the range [0, 1], for example:
	(0, 0) corresponds to the top left corner of an image
	(1, 0) corresponds to the top right corner of an image
	(0, 1) corresponds to the bottom left corner of an image
	(1, 1) corresponds to the bottom right corner of an image
]]
local u1: number = mesh:AddUV(Vector2.new(1, 0))
local u2: number = mesh:AddUV(Vector2.new(0, 0))
local u3: number = mesh:AddUV(Vector2.new(0, 1))
local u4: number = mesh:AddUV(Vector2.new(1, 1))

local f1: number = mesh:AddTriangle(v1, v2, v3)
local f2: number = mesh:AddTriangle(v3, v4, v1)

mesh:SetFaceUVs(f1, {u1, u2, u3})
mesh:SetFaceUVs(f2, {u3, u4, u1})

local meshPart: MeshPart = AssetService:CreateMeshPartAsync(Content.fromObject(mesh))
meshPart.Anchored = true
meshPart.TextureContent = Content.fromAssetId(83555541734317) --You'll probably need to change this to some asset you own
meshPart.CFrame = CFrame.new(0, 4, 0)
meshPart.Parent = workspace

-- Adding simple texture scrolling

local RunService = game:GetService("RunService")

local SCROLL_PERIOD: number = 4

RunService.Heartbeat:Connect(function()
	
	local tNorm: number = (tick() % SCROLL_PERIOD) / SCROLL_PERIOD
	local v2Offset: Vector2 = Vector2.new(tNorm, 0)
	
	--Here we scroll the UV coords outside the typical range, however the UV coords "wrap"
	--In other words, the UV coords are (automatically) bound to the range [0, 1] using the function: x_output = mod(x_input, 1)
	mesh:SetUV(u1, Vector2.new(1, 0) + v2Offset)
	mesh:SetUV(u2, Vector2.new(0, 0) + v2Offset)
	mesh:SetUV(u3, Vector2.new(0, 1) + v2Offset)
	mesh:SetUV(u4, Vector2.new(1, 1) + v2Offset)
	
end)
1 Like

Thanks for the reply, of course everyone expects changes to beta features, but the reason I called the updated “botched” is because the inconsistency, from instance.new('EditableImage') to AssetService to Content, in addition to keeping deprecated code on topics makes using the API very cumbersome.

there’s definitely resources out there (including kindly asking for help on this forum!) that can help you figure out what you’re trying to do.

Not sure what recourses you could be referring to, I’ve only seen EditableImage resources, not any for EditableMesh. (is asking for help on the forum not what I’m doing currently? lmao)

Anyways I’ve solved the issue prior to this reply, but I was unaware that uv coords typically ranged from 0-1, and not -1, 1, so thanks for that.

This announcement explains why they changed the Instance.new("EditableMesh") workflow to its current (and greatly improved) Content workflow.

By the way, Engine API documentation is open-source so feel free to submit any changes or suggestions you have.

1 Like

Even taking the announcement into consideration, I feel it still doesn’t take away from the other points I made, in addition to the inconsistent feel of it all, and the poor documentation, or lack thereof.

By the way, Engine API documentation is open-source so feel free to submit any changes or suggestions you have.

I doubt they read or take any points into consideration, many have already suggested removing the ID verification requirement for publishing, but Roblox is unlikely to do so, but thanks, I’ll look into the API documentation.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.