Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I optimize my 3D perlin noise script?

Asked by 5 years ago
Edited 5 years ago

A few days ago I've started researching 2D perlin noise and I've finally got that down, but in the process I've learned of 3D perlin noise generation, and after eventually getting a working script I've found it's very ill optimized

https://imgur.com/a/zZhx6dk

Here is an image of my 3D perlin noise

My problem is that I'm not sure how to remove the parts that wouldn't normally be seen by the player. How do I remove the parts within and make a shell like structure so my generated object isn't tens of thousands of parts?

Edit:

https://i.imgur.com/hpO30Ax.jpg

Here is an image I found of someone who has gotten the shell like effect I want

Another Edit: Here is the script I'd like some help on, nothing super fancy or never seen before.

local resolution = 50
local frequency = 10
local power = 20
local Seed = math.random(1, 500)
local MaxDensity = -1

local Block = Instance.new("Part")              
Block.Anchored = true
Block.Size = Vector3.new(2,2,2)

for x = 2, resolution do
    for y = 2, resolution do
        for z = 2, resolution do
            local X = math.noise((y/frequency),(z/frequency),Seed)*power
            local Y = math.noise((x/frequency),(z/frequency),Seed)*power
            local Z = math.noise((y/frequency),(x/frequency),Seed)*power
            local Density = X + Y + Z
            if Density < MaxDensity then
                local Blocka = Block:Clone()
                Blocka.Parent = game.Workspace
                Blocka.CFrame = CFrame.new(x*2,y*2,z*2)
                Blocka.Color = Color3.new(Blocka.Position.X*2,Blocka.Position.Y*2,Blocka.Position.Z*2)
            end
        end
    end
end
0
If you want us to help you with your script, you're going to have to provide the script... SteamG00B 1633 — 5y
0
Currently, the filled in areas would be represented by the influence vectors so use a unit vector to save a slice of the influence vector, and just don't fill in the rest. This would limit blocks to the blocks visible to players, including any caves and such. rens321 1 — 5y
0
How would I go about doing that rens321? I'm still pretty new to Lua. MasterMan917 10 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Okay I figured it out with just a bit of testing, it is really quite simple.

First I added IntValues to all of the blocks. The IntValue reflected each block's density.

Then I went through lots of blocks until I found the density value of each block that would be visible to the normal player, the density's numbers ranged from the MaxDensity(-1) down to -7

After finding the lowest number visible to the player I went back into the script and added this:

if Density > -7 then
    local Blocka = Block:Clone()
    Blocka.Parent = game.Workspace
    Blocka.CFrame = CFrame.new(x*2,y*2,z*2)
    Blocka.Color = Color3.new(Blocka.Position.X*2,Blocka.Position.Y*2,Blocka.Position.Z*2)
end

The end result was EXACTLY what I was looking for:

https://imgur.com/b8Q6UhG

Thank you to anyone who commented on the question.

Ad

Answer this question