I’m currently doing wave function collapse for large scale chunk operations a simple solution was using the zone entry points to generate the next region so that they encompass the currently explored region and execute with a ordered delay. I’ve watched a few videos about it on youtube. Currently I’m using a seed based on the position of the chunk and reloading the closest chunk and the position where the player left off. Compressing objects not in view to a reference to their source object in the games library.
But I was looking at this code and was wondering if you could help with getting and output of RGB values for the triangle using the surface appearance. I have some low poly assets that are one piece with a texture and I could not use it because the current implementation lacks support.
if meshPart then
local surfaceAppearance = meshPart:FindFirstChildWhichIsA("SurfaceAppearance",true)
local textureID = meshPart.TextureID
if textureID == "" then
textureID = nil
end
if textureID then
if not textureID:match("%d") then
textureID = nil
end
end
if surfaceAppearance then
if not textureID then
textureID = surfaceAppearance.ColorMap
if textureID == "" then
textureID = nil
end
end
end
if textureID then
CanLoadTexture:set(false)
LoadingImage:set(true)
local promise = RobloxImage.fromAsset(textureID)
promise:andThen(function(fileType,width,height,imgData)
local idNum = textureID:match("%d+")
LoadedImageName:set(string.format("%s.%s",idNum,fileType))
LoadedImage:set{
width = width,
height = height,
imgData = imgData
}
LoadedImageID:set(textureID)
end):catch(function()
print("Failed to load image")
end)
promise:finally(function()
CanLoadTexture:set(true)
LoadingImage:set()
end)
return
end
end
LoadingImage:set(true)
local file = StudioService:PromptImportFile({"jpg","png","bmp"})
if file then
LoadingImage:set(true)
local promise = RobloxImage.fromBin(file:GetBinaryContents())
promise:andThen(function(fileType,width,height,imgData)
if fileType then
LoadedImageID:set(file:GetTemporaryId())
LoadingImage:set()
LoadedImageName:set(file.Name)
LoadedImage:set{
width = width,
height = height,
imgData = imgData
}
end
end):catch(function()
print("Failed to load image")
end)
promise:finally(function()
CanLoadTexture:set(true)
LoadingImage:set()
end)
else
CanLoadTexture:set(true)
LoadingImage:set()
end
end,
--[[ Generation function, takes in a table of MeshParts, not asynchronous ]]
local function Generate(meshParts,fmaterial,surfacem,jobsover)
if fmaterial==nil then fmaterial=fillMaterial end
if surfacem==nil then surfacem=surfaceMaterial end
local objDatas = {}
local numMeshes = #meshParts
local promises = {}
--Decode a cached job
--if jobsover~=nil then
-- print("using module")
-- for _,job in jobsover do
-- for i,v in job[2] do
-- for t,o in job[2][i] do
-- if t~=4 then
-- --if string.upper(job[2][i][t])==job[2][i][t] then -- check if is a word
-- job[2][i][t]=Vector3.new(job[2][i][t])
-- end
-- end
-- end
-- TerrainGen:DoJobs({{unpack(job)}})
-- end
-- return true
--end
local fail
for i,meshPart in meshParts do
local promise = RobloxMesh.fromAsset(meshPart.MeshId)
table.insert(promises,promise)
promise:andThen(function(meshData)
local objData = {Verts = meshData.Verts,Tris = meshData.LODs[1]}
table.insert(objDatas,{meshPart=meshPart,objData=objData})
end)
promise:catch(function()
fail = true
end)
end
task.spawn(function()
repeat task.wait() until #objDatas == numMeshes or fail
if fail then
print("Generating from multiple failed")
for _,promise in promises do
promise:cancel()
end
else
local jobs = {}
--[[ Generating ]]
for i,data in objDatas do
local meshPart = data.meshPart
local objData = data.objData
local tris = objData.Tris
local meshCFrame,meshSize = CalculateMeshBounds(objData,tris)
local stampSize,meshSize,stampCF,scale = GetGenerationData(meshPart,objData,meshSize)
stampCF *= CFrame.new(generationOffset)
scale *= generationScale
local triangles = {}
local matTarget = surfacem
for _,tri in tris do
local v1 = objData.Verts[tri[1]]
local v2 = objData.Verts[tri[2]]
local v3 = objData.Verts[tri[3]]
local a = stampCF * (meshCFrame:PointToObjectSpace(v1.Position) * scale)
local b = stampCF * (meshCFrame:PointToObjectSpace(v2.Position) * scale)
local c = stampCF * (meshCFrame:PointToObjectSpace(v3.Position) * scale)
local triangleMaterial = matTarget
table.insert(triangles,{a,b,c,triangleMaterial})
end
table.insert(jobs,{replaceVoxels,triangles,fmaterial,generationFloorStuds,generationSurfaceThickness})
end
for _,job in jobs do
TerrainGen:DoJobs({{unpack(job)}})
end
--return jobs
end
end)
end
Also included a commented section which demonstrates simple encoding and decoding of a cached job to reduce API usage but is restricted to a static position. It would be good to implement if I have any issues with performance when implementing the library. I would have to just bake the model at position 0,0,0 and adjust them based on their new CFrame.
Also, I’ve gotten pretty good performance benchmarks and almost double the speed using the baked mesh into a module method I explained above. Beyond that I didn’t edit anything beyond mainly using optimized low poly assets.
This was my much anticipated project with this module so thanks for your help! I’ve gotten a lot done with this am done for now.