Perebraco
Perebraco

Reputation: 35

Three.js property length of geometry.vertices is undefined

Hello people of StackOverflow. I'm learning three.js and as a learning project, I chose to make an 80's style retro hills similar to this. Everything was going smoothly but then


script.js:37 Uncaught TypeError: Cannot read property 'length' of undefined
        at init (script.js:37)
        at script.js:6

appeared. I checked everywhere but found no solution. This is my script.js(html is just the default template for head and body). Any help helps!

let renderer;
let scene;
let camera;
let mesh;

init();
animate();

function animate() {

    requestAnimationFrame(animate);

    renderer.render(scene, camera);
}

function init() {

    renderer = new THREE.WebGLRenderer();

    renderer.setSize(window.innerWidth, window.innerHeight);

    document.body.appendChild(renderer.domElement);

    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera(100, window.innerWidth / window.innerHeight, 1, 100);
    camera.position.set(0, 0, 5);
    scene.add(camera);

    var geometry = new THREE.PlaneGeometry(256, 256, 256, 256);
    var material = new THREE.MeshBasicMaterial({ color: 0xc04df9, wireframe: true });
    var floor = new THREE.Mesh(geometry, material);
    floor.rotation.x = 90;
    const verticeXYZ = geometry.vertices;
    //perlin.seed()
    for (let i = 0; i < verticeXYZ.length; i++) {
        verticeXYZ.x = 53;
    }
    scene.add(floor);
}

Error appears at line 37:

for (let i = 0; i < verticeXYZ.length; i++) {
        verticeXYZ.x = 53;
    }

Upvotes: 1

Views: 3537

Answers (2)

adelriosantiago
adelriosantiago

Reputation: 8134

Well, this is more like a pure Javascript error. The constant verticeXYZ is not defined, this means geometry.vertices is not defined as well. This results in "Cannot read property 'length' of undefined" when doing verticeXYZ.length because there is no length property.

Take a look at this example and its code. Here, geometry is well defined. I recommend you using it as your starting point.

Upvotes: 1

Kevin Lin
Kevin Lin

Reputation: 111

Which version are you using? I guess the vertices property no longer exists in the latest versions. I used r70 version and it solved my issue.

Upvotes: 0

Related Questions