Error in three.js library: "Undefined variable 'v' causing a TypeError" while creating a custom geometry

I am attempting to create my own custom geometry using three.js. However, I encounter an error when trying to define it with the following code:

geometry = new THREE.FreeWallGeometry( 3, 5 );

The error message "TypeError: v is undefined" originates from the function addSelf at line 714 in the three.js library.

How can I identify what is causing this error?

Below is the current implementation of my homemade geometry:

define(
    [   "libs/three.js/build/three",
    ],
    function (
        three
        ) {

        console.log("setting up makeControls. regards, makeControls");

        //THREE.FreeWallGeometry = function ( length, height, depth, segmentsWidth, segmentsHeight, segmentsDepth, materials, sides ) {

        // X = length, Y = height, Z = depth,
        THREE.FreeWallGeometry = function ( noOfSegments, segmentLength ) {

            THREE.Geometry.call( this );

            var t1, t2,
            normal = new THREE.Vector3( 0, 0, 1);
            freePlane;

            var freePlane = function ( self, parametricPlane_X, parametricPlane_Y, parametricPlane_Z, equidistantSampler_T1, equidistantSampler_T2 ) {

                for ( t2 = 0; t2 < noOfSegments; t2 ++ ) {

                    for ( t1 = 0; t1 < noOfSegments; t1 ++ ) {

                        console.log("free: t1, t2 ", t1, t2);
                        //var x = t1 * segmentT1_length - length_half;
                        //var y = t2 * segmentT2_length - height_half;
                        var x = parametricPlane_X ( t1, t2 );
                        var y = parametricPlane_Y ( t1, t2 );
                        var z = parametricPlane_Z ( t1, t2 );

                        console.log("free: x, y z ", x, y, z);

                        self.vertices.push( new THREE.Vector3( x, - y, z ) );

                    }

                }

                for ( t2 = 0; t2 < noOfSegments; t2 ++ ) {

                    for ( t1 = 0; t1 < noOfSegments; t1 ++ ) {

                        var a = t1 + noOfSegments * t2;
                        var b = t1 + noOfSegments * ( t2 + 1 );
                        var c = ( t1 + 1 ) + noOfSegments * ( t2 + 1 );
                        var d = ( t1 + 1 ) + noOfSegments * t2;



                        //console.log ("free: a, b, c, d ", a, b, c, d);

                        var face = new THREE.Face4( a, b, c, d );

                        if (!self.vertices[face.a]) {
                            console.log("this face.a can't index vertices: ", face.a);
                        }

                        if (!self.vertices[face.b]) {
                            console.log("this face.b can't index vertices: ", face.b);
                        }

                        if (!self.vertices[face.c]) {
                            console.log("this face.c can't index vertices: ", face.c);
                        }

                        if (!self.vertices[face.d]) {
                            console.log("this face.d can't index vertices: ", face.d);
                        }

                        face.normal.copy( normal );
                        face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone(), normal.clone() );

                        self.faces.push( face );
                        self.faceVertexUvs[ 0 ].push( [
                            new THREE.UV( t1 / noOfSegments, 1 - t2 / noOfSegments ),
                            new THREE.UV( t1 / noOfSegments, 1 - ( t2 + 1 ) / noOfSegments ),
                            new THREE.UV( ( t1 + 1 ) / noOfSegments, 1 - ( t2 + 1 ) / noOfSegments ),
                            new THREE.UV( ( t1 + 1 ) / noOfSegments, 1 - t2 / noOfSegments )
                        ] );

                    }

                }

            }


            var parametricPlane_X = function ( t1, t2 ) {
                x = t1;
                return x;
            };

            var parametricPlane_Y = function ( t1, t2 ) {
                y = t1;
                return y;
            };

            var parametricPlane_Z = function ( t1, t2 ) {
                z = t1 * t2;
                return z;
            };

            var equidistantSampler_T1 = function ( t1 ) {
                t1 = Math.sqrt(t1);
                return t1;
            };

            var equidistantSampler_T2 = function ( t2 ) {
                t2 = t2;
                return t2;
            };

            freePlane(this, parametricPlane_X, parametricPlane_Y, parametricPlane_Z, equidistantSampler_T1, equidistantSampler_T2);


            this.computeCentroids();

        };

        THREE.FreeWallGeometry.prototype = Object.create( THREE.Geometry.prototype );

    }
);

Answer №1

To uncover the sequence of calls leading up to a crash, utilize Firebugs' console.trace().

A scenario specific to your situation is when using console.trace(), it will reveal that just before the call to addSelf, the function computeCentroids located around line 4939 in three.js was invoked.

In the mentioned function, the vertices-array (which your custom geometry populates with vertices upon definition) is accessed via indexes face.a, face.b, face.c, and face.d.

These indexes are sourced from the faces array within your geometry (also defined by you), and mismatches can lead to indexing issues causing some faces to reference vertices outside the bounds of your array resulting in null values instead of actual vertices at

vertices[face.outOfBoundVerticeIndex]
.

As an additional note, consider implementing conditional checks on calls to console.trace based on whether v is undefined to prevent overwhelming Firefox with trace logs, potentially slowing down the browser significantly.

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

Using Ajax/jQuery in combination with Mongodb

My experience with Ajax/jQuery is fairly new. I am currently working on creating a sample HTML page using Ajax/jQuery to retrieve all customers and search for a customer by ID. Each customer has three variables: ID, firstName, and lastName. I am looking t ...

Transforming precise military time using Angular and Javascript filtering

There are a few times where I find myself liking 01:45 //and 15:00 I believe this time format is HH:MM in military time? While I have come across some advanced functions that can parse sentences and even include seconds like HH:MM:SS, I am looking for a ...

The issue of JQuery and document ready being triggered multiple times while loading data into a control

Ever since implementing the load function to load content into a DIV upon document ready, I've noticed that all associated functions are firing multiple times (often twice, and sometimes endlessly). The scripts included in the head tag of all pages a ...

AngularJs FileList Drag and Drop Feature

Being brand new to front-end development, I decided it would be a fun challenge to implement drag and drop functionality on an existing upload page. However, as I began integrating ng-flow (a directive that helps with drag and drop), I encountered difficul ...

The screen is cloaked in a dark veil, rendering it completely inaccessible with no clickable

Utilizing Bootstraps modals, here is my current layout. Within the site's header, there exists a "settings" button that triggers a modal containing various options. These options are not tied to the question at hand. The button responsible for displ ...

Learn how to seamlessly update broken images on a webpage with a placeholder error image using the MooTools 1.2 framework

Currently working on a project with PHP, MySQL and utilizing Mootools 1.2 as the JavaScript framework. I am trying to find a way for all broken images to automatically be replaced with a designated error image. Any suggestions on how I can achieve this? ...

Having trouble accessing properties of an undefined object when trying to read 'credentials' in Firebase Auth within ReactJS

I need to verify the user's password again before allowing them to change it. Currently, my Firebase Auth setup is defined in Firebase.js and exported correctly //appConfig = ...(all the configurations here) const app = firebase.initializeApp(appConf ...

The element's height appears to be fluctuating unexpectedly when I attempt to adjust it using percentage values within a narrow range

I'm utilizing React and Bootstrap in this project. Here's an overview of my code: I have an element with height set to 0, in rem. My goal is to make the height of this element increase as I scroll down the page, creating the illusion that it is ...

Using onchange within an onchange event will not function as intended

When I am in the process of creating 2 dropdown menus filled from a database, the issue arises when the second dropdown is generated after selecting a value from the first one. Upon choosing an option from the second dropdown, my ajax function is triggered ...

"Is it possible to rearrange the parent div's position when hovering over a child image with jquery sortable

Can you assist me with a task? I have two text boxes with an equal sign image, and I want the user to be able to move the div only when hovering over the equal sign. This means that the user should be able to drag the div using the equal sign. Can you hel ...

Rejuvenate your Bootstrap Accordion with these Settings

Using bootstrap documentation, I have implemented an accordion in my web application with the following code: <div class="accordion" id="accordion2"> <div class="accordion-group"> <div class="accordion-heading"> <a class=" ...

Is there a way to determine the position of the highlighted text within a textarea?

Is there a simple way to calculate the position of the selected text within a textarea using vanilla JavaScript or Angular (possibly with a directive)? This is important in order to display a div with a popup above the selected text. Coordinates are need ...

The Fixed Navbar is causing sections to be slightly off from their intended positions

Utilizing a bootstrap navigation menu on my website with a fixed position. When clicking a menu item, it takes me to the designated section but slightly above the desired position. How can I ensure that it goes to the exact position upon clicking the men ...

XMLHttpRequest request shows blank result

Issue: After clicking the submit button on my HTML form, a JavaScript function is called with an Ajax request. The request returns successfully, but the result disappears quickly. I'm curious if I may be overlooking something here (besides jQuery, w ...

Preserve the Browser Scroll Position when navigating to another page

Currently tackling a challenge with JS, JQuery, and PHP where I'm attempting to resolve an infinite scroll issue. The specific problem arises when scrolling down the page extensively while loading more pages via ajax, then navigating to a different pa ...

Executing a series of functions in succession using jQuery

I am trying to iterate through an object that contains functions which need to execute consecutively. Ideally, I would like these functions to be chained together in a way where one function waits for the previous one to finish before executing (e.g., func ...

The information returned to the callback function in Angular comes back null

In my Node.js application, I have set up an endpoint like this: usersRoute.get('/get', function(req, res) { //If no date was passed in - just use today's date var date = req.query.date || dateFormat(new Date(), 'yyyy-mm-dd&ap ...

No assets detected in sails.js

Recently, I began a new sails project using 'sails new project --linker'. Initially, everything was functioning correctly but today I encountered a problem. Every time I start the server with 'sails lift', I now receive a 404 error for ...

Issue-free AJAX call to Neo4j database on local server with no 'Access-Control-Allow-Origin' problem

I'm currently working on a basic JavaScript AJAX request to connect from a MAMP server running at localhost:8888 to a Neo4j database running on localhost:7474. The issue I'm encountering is the following error message: XMLHttpRequest cannot l ...

Angular 10 and Typescript: Variables assigned within the change event become undefined

In my code, I initialize an Algolia input and set an onchange event to it. This initialization takes place in a service. algolia_data; random_var; this.http.post<any>('APIENDPOINT', formData).subscribe(data => { instance = places({ ...