# Help getting the actual position of a vertices in a buffer geometry!

**URL:** <https://discourse.threejs.org/t/help-getting-the-actual-position-of-a-vertices-in-a-buffer-geometry/29649>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [September 6, 2021, 7:06pm UTC](https://discourse.threejs.org/t/help-getting-the-actual-position-of-a-vertices-in-a-buffer-geometry/29649 "2021-09-06T19:06:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeThAL\_LAD](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lethal_lad/32/20748_2.png) [@LeThAL\_LAD](https://discourse.threejs.org/u/LeThAL_LAD)\
**Post date:** [September 6, 2021, 7:06pm UTC](https://discourse.threejs.org/t/help-getting-the-actual-position-of-a-vertices-in-a-buffer-geometry/29649/1 "2021-09-06T19:06:50Z")

</div>

My code is simplish, just takes the position and feeds it through some noise to create a releastic looking terrain, except

```javascript
  const vertex = new Vector3();
  vertex.fromBufferAttribute(positionAttribute, i);

```

doesn’t return the vertices position in the world which is a pain, it seems to return the local position, sorry I am very new, the full code is below. You can see i am using a odd system to try get around this which works until I try and place trees at the same real world position and its the wrong height.

```javascript
export function generateTerrainChunk(seed, Position, gain, divisor) {
    //------------[MAIN FUNCTION VARIABLES]------------\\
    //const simplex = new SimplexNoise(seed);
    let geometry = new PlaneBufferGeometry(500, 500, 30, 30);
    let colours = [];
    const fbm = new FBM({
        seed: seed,
        scale: 0.007,
        octaves: 6,
        persistance: 0.5,
        lacunarity: 2,
        redistribution: 2,
        height: 40,
    });

    const simplex = new Perlin(seed)

    //------------[Create Material]------------\\
    var material = new MeshPhongMaterial({
        vertexColors: colours,
        reflectivity: 0,
        flatShading: true,
        blending: false
    });

    //------------[Create Mesh]------------\\
    var plane2 = new Mesh(geometry, material);
    plane2.receiveShadow = true;
    plane2.castShadow = true;
    plane2.position.set(Position.x, -3, Position.y);
    plane2.rotateX(Math.PI / 2 + Math.PI);

    const positionAttribute = geometry.getAttribute("position");
    //------------[Edit the Geomtry Accordingly]------------\\
    for (var i = 0, l = geometry.attributes.position.array.length / 3; i < l; i++) {
        // Get Data position
        const vertex = new Vector3();
        vertex.fromBufferAttribute(positionAttribute, i);

        plane2.localToWorld(vertex)

        // Check Height from Perlin Noise Generator

        let location = new Vector2(
            (vertex.x + (Position.x)) * divisor, 
            (vertex.y - (Position.y)) * divisor
        )

        let height = fbm.get2(location) * gain * 4
        // Set the height accordingly

        console.log(location)

        if (location.x >= 25 && location.y >= 25) {
            height = 500
        }

        geometry.attributes.position.array[i * 3 + 2] = height;

        // Update Vertice colours accordinly
        if (height > 100) {
            colours.push(1, 1, 1);
        } else if (height > 50) {
            colours.push(0.56, 0.54, 0.48);
        } else if (height < 2) {
            let heightSecondary = simplex.get2(new Vector2((vertex.x + (Position.x)) * divisor, (vertex.y - (Position.y)) * divisor)) * 0.75
            geometry.attributes.position.array[i * 3 + 2] = heightSecondary;
            colours.push(0, randomIntFromInterval(400, 500) / 1000, randomIntFromInterval(700, 800) / 1000)
        } else {
            colours.push(0.56, 0.68, 0.166);
        }
    }

    //------------[Edit colour attribute]------------\\
    geometry.setAttribute(
        "color",
        new BufferAttribute(new Float32Array(colours), 3)
    );

    //------------[Add to Base Scene]------------\\
    currentTerrain = plane2;
    plane2.name = `Terrain_Chunk_${Position.x}:${Position.y}`;
    return plane2;
}

```

Many Thanks,  
Harvey

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [September 6, 2021, 7:50pm UTC](https://discourse.threejs.org/t/help-getting-the-actual-position-of-a-vertices-in-a-buffer-geometry/29649/2 "2021-09-06T19:50:43Z")

</div>

Hi!

> [@LeThAL\_LAD](#):
>
> ```javascript
> plane2.position.set(Position.x, -3, Position.y);
> plane2.rotateX(Math.PI / 2 + Math.PI);
> 
> ```

Right after these lines, try to add `plane2.updateMatrixWorld();`

---

<div class="post-metadata">

**Author:** ![LeThAL\_LAD](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lethal_lad/32/20748_2.png) [@LeThAL\_LAD](https://discourse.threejs.org/u/LeThAL_LAD)\
**Post date:** [September 6, 2021, 8:10pm UTC](https://discourse.threejs.org/t/help-getting-the-actual-position-of-a-vertices-in-a-buffer-geometry/29649/3 "2021-09-06T20:10:30Z")

</div>

> [@prisoner849](#):
>
> plane2.updateMatrixWorld();

Thanks so much been starring and my screen ready to punch my desk for hours!!!

P.S. It works!

---

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [September 6, 2021, 8:47pm UTC](https://discourse.threejs.org/t/help-getting-the-actual-position-of-a-vertices-in-a-buffer-geometry/29649/4 "2021-09-06T20:47:03Z")

</div>

@LeThAL_LAD You’re welcome 🍻

You can create tiled noise surfaces, using uv and size of tile.  
An option, just from the scratch: [https://jsfiddle.net/prisoner849/cxwkhgdL/](https://jsfiddle.net/prisoner849/cxwkhgdL/)

 ![изображение](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/1/b/1ba3eb4a7cedbc31351255e12867dd650738dc14.png)

---

<div class="post-metadata">

**Author:** ![hofk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/hofk/32/44944_2.png) [@hofk](https://discourse.threejs.org/u/hofk)\
**Post date:** [September 7, 2021, 6:35pm UTC](https://discourse.threejs.org/t/help-getting-the-actual-position-of-a-vertices-in-a-buffer-geometry/29649/5 "2021-09-07T18:35:01Z")

</div>

Again a nice example. 👍

The example is also interesting because of the **quads**. 🟩 🔷 ◽ 🔲

Other applications with quads are in the [Collection of examples from discourse.threejs.org](https://discourse.threejs.org/t/collection-of-examples-from-discourse-threejs-org/4315)

[WireframeOfQuads](https://hofk.de/main/discourse.threejs/2020/WireframeOfQuads/WireframeOfQuads.html)

[SphereWithoutDiagonals](https://hofk.de/main/discourse.threejs/2021/SphereWithoutDiagonals/SphereWithoutDiagonals.html)

With my [Addon. Produces almost infinite many time-varying geometries with functions](https://discourse.threejs.org/t/addon-produces-almost-infinite-many-time-varying-geometries-with-functions/262) you can create similar quads as lines.

[THREEf geometries](https://hofk.de/main/threejs/sandboxthreef/)

 ![2021-09-07 20.22.00](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/e/8/e8f936f2edacbe4ec08b6de1024629476f7f3892.png)
