- Home /
Perlin noise continuous through different objects
I want to use a Perlin noise function that acts continuously through different objects (planes in this case), wich means, with no gaps between vertices of different meshes. I've attached the script that applies the Perlin noise in a parent game object (an empty game object). The script runs the Perlin noise function once and search for the childrens (the planes), applying the noise to each vertex of each plane.
It worked when the noise is applyied only in one direction, but it doesn't when two or more directions are used. This question seems to use the same idea I have here, but I've tried many things suggested by the answers and comments provided there and could not come to a solution (Actually, I didn't understand some of the code provided there, I'm not a experienced programmer).
Here are some screenshots of when it works and when it doesn't, and the code (JS). The script is a simplified version of the one found in the Unity's Procedural Examples, and the Perlin Noise function can be found there too.
EDIT: CODE UPDATED, NOW WORKING, SEE UPDATE BELOW
var scale : float = 1.0;
var recalculateNormals = true;
private var perlin : Perlin = new Perlin();
function Start ()
{
for(var childPlane : Transform in transform)
MakePerlin(childPlane);
}
function MakePerlin(childPlane : Transform){
var baseVertices : Vector3[];
var mesh : Mesh = childPlane.GetComponent(MeshFilter).mesh;
if (baseVertices == null)
baseVertices = mesh.vertices;
var vertices = new Vector3[baseVertices.Length];
for (var i = 0; i < vertices.Length; i++)
{
var vertex = baseVertices[i];
var worldPosition : Vector3 = childPlane.transform.TransformPoint(baseVertices[i]);
vertex.y += perlin.Noise(worldPosition.x + 0.1, worldPosition.z + 0.1) * scale;
vertices[i] = vertex;
}
mesh.vertices = vertices;
if (recalculateNormals)
mesh.RecalculateNormals();
mesh.RecalculateBounds();
childPlane.GetComponent(MeshCollider).sharedMesh = null;
childPlane.GetComponent(MeshCollider).sharedMesh = mesh;
}
I don't know if my logic is flawed, but it seems to be almost there. Thanks in advance.
EDIT: SOLVED.
Solved. It was very simple: it was just a matter of converting each vertex coordinate (by default, in local space) to world space. Once we know each vertex world coordinates, the Perlin noise function can be applied to world space coordinates, so every vertex that shares that world space coordinate will have the same noise. Below, an image showing it. And the code has been updated too.
Just posted it so that if anyone comes across this question, it may be useful.
Answer by Saitodepaula · Aug 10, 2012 at 05:30 PM
I don't know if I can answer my own question but I've come to a solution and just wanted to mark it as solved (look at the edits in the question itself).
Sure. but usually, put the answer IN and answer. Glad you got it working.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075402im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Basics of Perlin Noise? 1 Answer
easy c# Simplex Noise script code 1 Answer
Using noise as texture 2 Answers
Optimize perlin code 1 Answer
Why does Perlin-generated Texture lose gradient when with colour? 1 Answer