The length parameter for geometry.vertices in Three.js is not defined

Greetings, fellow members of the StackOverflow community. I have embarked on a journey to learn three.js, and for my learning project, I decided to recreate an 80's style retro hills scene reminiscent of this. Initially, everything was progressing smoothly until


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

made an unexpected appearance. Despite my best efforts, I have been unable to find a solution to this issue. Below is my script.js file (the HTML structure follows the default template for head and body). Any assistance or guidance would be greatly appreciated!

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);
}

The error is specifically at line 37:

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

Answer №1

It seems like there's a specific Javascript error happening here. The variable verticeXYZ hasn't been defined, which means that geometry.vertices is also not defined. This leads to an error saying "Cannot read property 'length' of undefined" when trying to access verticeXYZ.length because the property length doesn't exist.

Check out this example and its code. In this code snippet, the variable geometry is properly defined. I suggest using this as a reference point for your own code.

Answer №2

Can you specify which version you're currently using? Seems like the vertices property has been removed in the most recent updates. Personally, I had success with resolving the issue when using version r70.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Comparing Objects in an Array to Eliminate Duplicates and Make Updates in Javascript

I am working with an array of objects that is structured like this: 0: Object ConsolidatedItem_catalogId: "080808" ConsolidatedItem_catalogItem: "undefined" ConsolidatedItem_cost: "0" ConsolidatedItem_description: "Test Catalog Item" ConsolidatedItem_ima ...

How to achieve padding of strings in JavaScript or jQuery

Does anyone have information on a similar function in jQuery or JavaScript that mimics the prototype toPaddedString method? ...

A guide to organizing elements in Javascript to calculate the Cartesian product in Javascript

I encountered a situation where I have an object structured like this: [ {attributeGroupId:2, attributeId: 11, name: 'Diamond'}, {attributeGroupId:1, attributeId: 9, name: '916'}, {attributeGroupId:1, attributeId: 1, name ...

The timer countdown is encountering an issue where it cannot update the 'textContent' property of a null element

I'm encountering errors with a countdown script that I can't seem to resolve. The error message is generating 1 error every second: Uncaught TypeError: Cannot set property 'textContent' of null at (index):181 (anonymous) @ (index):181 ...

Incorporate ng-click as an attribute in AngularJS

Is there a way to include ng-click as an attribute? For example, imagine I want to add ng-click if my <li> has the class someClass: angular.element(root.querySelector('li.someClass').attr({'ng-click': 'someFunc()'}); ...

Tips for setting unique click functions for each face of a cube using React Three Fiber

Hey there! I have created a basic Cube component using react three fibre. import {useState,useRef} from 'react'; import { useFrame } from '@react-three/fiber'; const Box = ({props}) =>{ const ref = useRef() const [hove ...

Managing various iterations of identical repositories

Currently in the process of constructing a library of unique react components that are being utilized in various downstream applications. To incorporate these components into my downstream applications, I rely on the package.json. Recently, I began ponde ...

Using Multer: Specifying multiple destinations with the destination property

I am facing a situation where I have to store images in multiple directories. To achieve this, I have configured multer as follows: app.use(multer({ dest: path.join(__dirname, '`public/assets/img/profile`'), rename: function (fieldname, ...

Is Highcharts-angular (Highcharts wrapper for Angular) compatible with Angular 4?

I have attempted to install various versions of highcharts-angular, ranging from 2.0.0 to 2.10.0. However, I consistently encounter the same error when running the application. The error message states: Metadata version mismatch for module C:/dev/Angular- ...

What distinguishes v-text from v-load in Vue.js when concealing {{ Mustache }}?

When experiencing the "flash of uncompiled content" in Vue, the brief moment when the page is loading and you see the {{ Mustache }} syntax, developers often use either v-text or v-cloak. According to the documentation, v-text: Updates the element’s t ...

Error message: When accessing react-native camera roll, the message "this.state.photos is not a valid object" appears

Encountering an error while attempting to implement camera roll functionality in my demo app. The error states, "null is not an object (evaluating 'this.state.photos')" View iOS Error Message. I am a beginner developer working on my first react-n ...

New data field is created with AngularFire2 update instead of updating existing field

I am facing an issue with updating a Firestore model in Angular 6. The model consists of a profile name and a list of hashtags. The "name" is stored as the value of a document field, while the "hashtags" are stored as keys in an object. However, every time ...

Slideshow not displaying properly after an Ajax request due to CSS not being applied

My goal is to dynamically load data when reaching the bottom of a page using the onScroll event handler. The data to be loaded mainly consists of slideshows and, behind each one, within a separate div, there is an iframe with embedded vimeo content. Initi ...

Links have a longer transition delay compared to the content

In a unique JavaScript function I've developed, the my-content-section-visible class is removed and replaced with my-content-section-hidden. This change is being made to hide a particular div using a smooth transition effect. The transition itself is ...

SoundCloud and Vimeo have the capability to link their players across separate tabs, and even between tabs and embedded players

I find it intriguing how SoundCloud and Vimeo are synchronized with their tabs, so that when you play something in one tab, the others pause. It's worth noting that this feature only works on SoundCloud when two instances of the website are open, wher ...

What is the method to effectively conduct a testing procedure for JavaScript files that have been exported using

I have a JavaScript file called "sum.js" which contains a simple function: // sum.js function sum(a, b) { return a + b; } export default { sum }; Now I want to write a test for this file using Jest. Here is my "sum.test.js" file in the same folder: // ...

Automatically log users out of Django and update the backend after a period of inactivity without requiring any additional requests

In my Django project, I am working on a simple multiplayer system where I need to update the isCurrentlyActive value in a user-related model automatically and then log them out. I tried using middleware following a solution from this post, which works well ...

Is there a way to assign innerHTML values to table cells using PHP?

I'm currently building a website that relies on a database to store information. I have created an array to hold the values retrieved from the database, and now I need to populate a table with these values. Each cell in the table has a numerical ID ra ...

After refreshing the page, the local storage does not appear

I've been struggling to get it working for hours with no luck. After submitting the form, I create local storage values for name, surname, and email so that they can be automatically filled in the form next time without requiring the user to retype th ...

The shared hosting environment encountered an error during the Next JS build process

When I execute the command "npm run build" on my shared hosting server, it throws an error message: spawn ENOMEM. Interestingly, this command runs perfectly fine on my localhost and has been running smoothly on the hosting server for a few weeks until yest ...