The cool way of loading models

Requirements to load any model into a roblox game

  1. A lua script that i run outside roblox to serialize the .obj file;
  2. A script in a place to mesh the model that you stored pasting the encoded string inside a ModuleScript.


Teddy bear model overview:

  • Has ~1500 vertexes and 3000+ triangles.
  • This encoded model is 55kb heavy and takes 0.7s to load(99% of the time is spent in decoding).
  • This unencoded model is 44kb heavy and takes 0.003s to load.

I find it pretty cool.
Also, EditableMesh has an 20k triangle limit but it’s easy fixed if you use many meshes to distribute the triangle count.

1 Like

Before any uneducated hoomans freaks out, editable mesh requires you to verify your id and they’re quite strict about the uses

2 Likes

You know you can use wedges for that right? A bit unoptimized but you can make ur own wedge model and use it to actually create NSFW models.

Thats what NSFW artists has been doing before editable meshes, they can use adornments (gizmo-like), wedges, etc

Or just upload half meshes at a time and piece it all together…

bb-but cooler way to do just that

Ye i know. All the modules i got here from roblox forum to mesh it with triangles had math operations that just broken all the wedges CFrames. Using EditableMesh was way faster and easier than trying to fix them, also idk if it runs smooth meshing even low triangle counts like 20k.

The code is 70 lines btw.

I dont really care about the rendereing part i just wanna do the faster possible loading & smallest possible size with serializing externally and deserializing the model internally fr.

You aren’t wrong… And I am sure most NSFW artists will take the hard path because those people are determined to put their filth everywhere they go. They are like slugs that leave a trail wherever they go.

To OP’s responses:

Then there is nothing better than using editable meshes. They are easy, reliable, and performant.

I do wonder how you decoded the data though. :thinking:

1 Like

Thats the roblox script, but a version that uses a crappy base64 module so it gets really slow compared to just doing an http-get on github with the serialized model(no base64 encoding).

local Base64 = require(script.Parent.Base64)
local positionFormat = "fff"
local verticesFormat = "III"
local verticeCountFormat = "I"
local dataLenghtFormat = "I2"
local function UnserializeModel(
	model: string,
	processVertice: (number, number, number) -> (),
	processFace: (number, number, number) -> ()
)	
	model = Base64.base64Decode(model)
	
	local verticeCountHeaderLenght = string.byte(model:sub(1,1))
	local verticeCountHeaderEnd = 2 + verticeCountHeaderLenght
	local verticeCount = string.unpack(verticeCountFormat, model:sub(2, verticeCountHeaderEnd))
	
	local i = verticeCountHeaderEnd
	local stepCount = 0
	local verticeDataEnd = verticeCountHeaderEnd + verticeCount
	repeat
		local valueLenght = string.byte(model:sub(i, i))
		
		i += 1
		local valueEnd = i + valueLenght
		processVertice(string.unpack(positionFormat, model:sub(i, valueEnd)))
		
		i = valueEnd
		stepCount += 1
	until stepCount >= verticeCount
	
	repeat
		local valueLenght = string.byte(model:sub(i, i))

		i += 1
		local valueEnd = i + valueLenght
		processFace(string.unpack(verticesFormat, model:sub(i, valueEnd)))

		i = valueEnd
	until i >= #model
end

local AssetService = game:GetService("AssetService")
local editableMesh = AssetService:CreateEditableMesh()

local vertices: {Vector3} = {}
local vertexMap = {}
UnserializeModel(
	require(script.Parent.Teddy),
	function(x, y, z)
		vertexMap[#vertexMap + 1] = editableMesh:AddVertex(Vector3.new(x, y, z))
	end,
	function(a, b, c)
		editableMesh:AddTriangle(
			vertexMap[a], 
			vertexMap[b],
			vertexMap[c]
		)
	end
)

-- Creating MeshPart linked to our EditableMesh
local meshPart = AssetService:CreateMeshPartAsync(Content.fromObject(editableMesh), {
	CollisionFidelity = Enum.CollisionFidelity.Box,
	RenderFidelity = Enum.RenderFidelity.Precise
})
meshPart.Material = Enum.Material.SmoothPlastic
meshPart.Anchored = true
meshPart.Parent = workspace

The Teddy bear serialized & encoded model:
Hastebin