# Update old three.js code

**URL:** <https://discourse.threejs.org/t/update-old-three-js-code/35113>\
**Category:** Questions\
**Tags:** migration, geometry\
**Created:** [February 21, 2022, 10:55am UTC](https://discourse.threejs.org/t/update-old-three-js-code/35113 "2022-02-21T10:55:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rebol](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rebol/32/24414_2.png) [@Rebol](https://discourse.threejs.org/u/Rebol)\
**Post date:** [February 21, 2022, 10:55am UTC](https://discourse.threejs.org/t/update-old-three-js-code/35113/1 "2022-02-21T10:55:02Z")

</div>

Hey! I’m trying to use code for an older version of three.js with a new version due to that I need newer functionality in the new three.js versions.

The code below won’t run on newer three.js versions. From what I can understand getting the faces,vertices and the faceVertexUvs works differently in newer versions by using the .getAttribute. But it does not return the same result as the old versions do.

Does anyone have a clue how I could convert the given code below to produce the same result using the latest version of three.js?

For those interested it is from the three-fisheye repo on Github.

```javascript
function createFisheyeMesh(fisheye_texture: THREE.Texture, MESH_N: number): THREE.Mesh {
  const sphere = new THREE.SphereGeometry(1000, MESH_N, MESH_N, Math.PI, Math.PI);
  const {vertices, faces, faceVertexUvs} = sphere;
  const radius = sphere.boundingSphere.radius;
  faces.forEach((face, i)=>{
    const {a, b, c} = face;
    faceVertexUvs[0][i] = [a, b, c].map((id)=>{
      const {x, y, z} = vertices[id]; 
      return new THREE.Vector2(
        (x+radius)/(2*radius),
        (y+radius)/(2*radius));
    });
  });
  const mat = new THREE.MeshBasicMaterial( { color: 0xFFFFFF, map: fisheye_texture, side: THREE.BackSide } );
  const mesh = new THREE.Mesh(sphere, mat);
  mesh.rotation.x = Math.PI*1/2;
  return mesh;
}

```

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [February 21, 2022, 12:11pm UTC](https://discourse.threejs.org/t/update-old-three-js-code/35113/2 "2022-02-21T12:11:55Z")

</div>

`THREE.Geometry`: [Edit fiddle - JSFiddle - Code Playground](https://jsfiddle.net/zg1ce02n/2/)  
`THREE.BufferGeometry`(latest release): [Edit fiddle - JSFiddle - Code Playground](https://jsfiddle.net/38nx4jgq/)

---

<div class="post-metadata">

**Author:** ![Rebol](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rebol/32/24414_2.png) [@Rebol](https://discourse.threejs.org/u/Rebol)\
**Post date:** [February 21, 2022, 12:33pm UTC](https://discourse.threejs.org/t/update-old-three-js-code/35113/3 "2022-02-21T12:33:31Z")

</div>

Thank you, the solution using buffer geometry did it. 😁
