Error message: Cannot generate Three.js mesh due to undefined buffer attribute in BufferAttribute.copyVector3sArray vector

During runtime, I am constructing the mesh of a sphere for later use in supershape generation, which is why I am not using SphereGeometry. The current vector placements appear to be functioning correctly, as confirmed by placing spheres at the corresponding coordinates. However, when attempting to create the mesh from these coordinates, I am encountering the following error:

three.min.js:532
THREE.BufferAttribute.copyVector3sArray(): vector is undefined 0
copyVector3sArray   @   three.min.js:532
fromDirectGeometry  @   three.min.js:548
fromGeometry    @   three.min.js:547
setFromObject   @   three.min.js:544
get @   three.min.js:67
update  @   three.min.js:76
k   @   three.min.js:155
k   @   three.min.js:156
Wd.render   @   three.min.js:190
render  @   threedVisuals.js:520
superShapes @   threedVisuals.js:512
visualise   @   app.js:155
(anonymous) @   app.js:87

Upon using Chrome’s debugger, it seems that the vertices and faces are correctly being assigned to the mesh. However, the error occurs when the mesh is passed into the render cycle. The functions involved in this process are:

function calcSphere(radius, detailLevel) {
  var globePoints = [];

  for (var i = 0; i < detailLevel; i++) { //latitude
    var lat = map_range(i, 0, detailLevel, -Math.PI / 2, Math.PI / 2);

    var latPoints = [];
    for (var j = 0; j < detailLevel; j++) { //longitude
      var long = map_range(j, 0, detailLevel, -Math.PI, Math.PI);

      // convert lat and long to cartesian coords
      var x = radius * Math.sin(long) * Math.cos(lat);
      var y = radius * Math.sin(long) * Math.sin(lat);
      var z = radius * Math.cos(long);

      latPoints.push({
        x,
        y,
        z
      });
    }
    globePoints.push(latPoints);
  }
  drawSphere(globePoints);
}

function drawSphere(globePoints) {

  var sphereGeo = new THREE.Geometry();

  for (var i = 0; i < globePoints.length - 1; i++) {
    for (var j = 0; j < globePoints[i].length - 1; j++) {

      var curIndex = sphereGeo.vertices.length; //used for tracking cur location in vertices array

      var v1 = globePoints[i][j];
      sphereGeo.vertices.push(new THREE.Vector3(v1.x, v1.y, v1.z));
      var v2 = globePoints[i + 1][j];
      sphereGeo.vertices.push(new THREE.Vector3(v2.x, v2.y, v2.z));
      var v3 = globePoints[i][j + 1];
      sphereGeo.vertices.push(new THREE.Vector3(v3.x, v3.y, v3.z));
      var v4 = globePoints[i + 1][j + 1];
      sphereGeo.vertices.push(new THREE.Vector3(v4.x, v4.y, v4.z));


      var f1 = new THREE.Face3(
        sphereGeo.vertices[curIndex + 0],
        sphereGeo.vertices[curIndex + 1],
        sphereGeo.vertices[curIndex + 2]);
      var f2 = new THREE.Face3(
        sphereGeo.vertices[curIndex + 1],
        sphereGeo.vertices[curIndex + 2],
        sphereGeo.vertices[curIndex + 3]);

      sphereGeo.faces.push(f1);
      sphereGeo.faces.push(f2);
    }
  }

  // sphereGeo.computeFaceNormals();
  // sphereGeo.computeVertexNormals();
  var sphereMat = new THREE.MeshBasicMaterial();
  var sphereMesh = new THREE.Mesh(sphereGeo, sphereMat);
  scene.add(sphereMesh);
}

Could someone provide insight into why this issue is happening? I have not been able to find any similar problems, and attempted solutions such as computing normals are also failing (

three.min.js:326 - Uncaught TypeError: Cannot read property 'x' of undefined
).

Thank you in advance!

Answer №1

Big thanks to @prisoner849 for pointing out my silly mistake.

Here is the corrected code block:

  var f1 = new THREE.Face3(
    sphereGeo.vertices[curIndex + 0],
    sphereGeo.vertices[curIndex + 1],
    sphereGeo.vertices[curIndex + 2]);
  var f2 = new THREE.Face3(
    sphereGeo.vertices[curIndex + 1],
    sphereGeo.vertices[curIndex + 2],
    sphereGeo.vertices[curIndex + 3]);

The simplified version should look like this:

        var f1 = new THREE.Face3(
          curIndex+0,
          curIndex+1,
          curIndex+2);
        var f2 = new THREE.Face3(
          curIndex+1,
          curIndex+2,
          curIndex+3);

There is no need to directly reference the vertices in this case.

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

Despite successfully connecting to my webservice, the ajax function encounters an error

<script type='text/javascript'> $(document).ready(function () { $("#submit").click(function (e) { e.preventDefault(); var userName = $("#username").val(); var pwd = $("#password").val(); authenticate(use ...

What is the correct way to utilize Array.reduce with Typescript?

My current approach looks something like this: [].reduce<GenericType>( (acc, { value, status, time }) => { if (time) { return { ...acc, bestValue: valu ...

Include a clickable hyperlink within a column in JQGrid that, when clicked, triggers a specific Jquery function

I am dealing with a JQgrid that only has 5 columns. Below is the code I have attempted: jQuery("#grdAnn6InvstDetails").jqGrid({ url: RootUrl + 'FDIAS/Ann6InvDtlsGridData', datatype: 'json', mtype: 'POST&ap ...

Fading Out with JQuery

My page contains about 30 same-sized divs with different classes, such as: .mosaic-block, .events, .exhibitions, .gallery, .sponsors, .hospitality, .workshops, .lectures { background:rgba(0, 0, 0, .30); float:left; position:relative; overf ...

Encountering a hitch while attempting to integrate a framework in Angular JS 1

Having experience with Angular JS 1 in my projects, I have always found it to work well. However, I recently encountered a project that uses Python and Django, with some pages incorporating Angular. The specific page I needed to work on did not have any An ...

Jquery is not working as expected

I am having trouble implementing a jQuery function to show and hide select components. It doesn't seem to be working correctly. Can someone help me identify the issue? <html> <head> <meta charset='UTF-8' /> <script ...

What is the process for generating an HTTP response that results in a pipe error being thrown

In my NestJS application, I have created a custom pipe that validates if a given value is a valid URL. If the URL is invalid, an error is thrown. This pipe is utilized in a controller to save an item into the database. Recently, I discovered that the pipe ...

Step-by-step guide on how to change the appearance of a <DIV> using data from a database (JSON

After retrieving data from a database as a JSON file, I have written code to loop through an item (portOn) and determine if certain ports are present in the array. If a port is found in the array, its corresponding variable is set to true. var portG01,port ...

When I utilize $router.push() to navigate to a different page, the back button will take me back to the previous page

Within my Vue project, there is an HTML page that I am working on. Here is the link to the page: https://i.sstatic.net/cbtqM.png Whenever I click on the "+"" button, it redirects me to this specific page: https://i.sstatic.net/0rmMD.png This page funct ...

Next.js configuration: Redirecting / to the basePath

Whenever a user accesses the path /, I need it to redirect to the basePath that has been previously set. Below is my configuration in next.config.js: module.exports = { basePath: '/docs', } This means that whenever the path / is visited, it s ...

Transferring files to Django using AJAX

I am struggling with the process of uploading files to django using ajax. The upload is done within a modal window. The Form <div class="modal fade bs-example-modal-lg" id="fileUploadModal" role="dialog" aria-hidden="true"> <div class="modal ...

`Is there a way to dynamically update a nested field object in Mongoose without updating the entire object?`

const userProfile = new Schema({ name: { type: String, default: null }, contacts: { mobileNumber: { countryCode: { type: String, default: null }, digits: { type: String, default: null } }, email: { type: String, default: null }, facebook: { ...

The Johnny-Five stepper initiates movement within a for-loop

I am new to using node.js and johnny-five. I want to move a stepper motor 5 times with 1000 steps each. Here is what I have tried: do 1000 Steps in cw ; console.log('ready); do 1000 steps; console.log('ready') ... It woul ...

Implement responsive data tables by setting a specific class for hiding columns

Having trouble assigning a specific class name to individual columns in datatables? It seems that when columns are hidden using the responsive extension, the desired class is not applied. Looking for a solution or workaround. Check out this example from D ...

Tips for adding an svg element to an existing svg using d3.js

Can another SVG be appended to an existing SVG parent using d3.js? I have tried using the 'svg:image' attribute, but unfortunately, I lose full control over the inner SVG child. The DOM node is created by d3, but it is not rendered, resulting i ...

jQuery and ajax method are failing to insert data into the database

I am having trouble inserting data into the database using jQuery and Ajax. Can someone please assist me in figuring out if I'm doing something wrong? Here is the code snippet: form.html <!DOCTYPE html> <html> <head> & ...

What steps should I take to execute a task during input checkout?

Check out my code below: $(document).on('checkout', 'input', function(){ alert('input is not focused anymore'); }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <i ...

Integrate CSS and Javascript Plugins into your Ruby on Rails application

I am utilizing an HTML, CSS, and JS template to design the interface for my Rails application. Within this template, there are several plug-ins that are required in both CSS and JS formats. I have stored these plug-ins within the "/assets/plugins/" directo ...

Guide to retrieve the file name into a text box upon selection (Avoid displaying as c:/fake path/)

I am trying to achieve the functionality where after choosing a file in a file input, the file name is automatically displayed in a text box named file_name without needing to click or submit any button. Unfortunately, I have been unable to find the correc ...

Utilize Three.js to dynamically rotate objects within a moving Object3D element, ensuring they constantly face the camera

As someone who is relatively new to Threejs, I am curious about how to ensure that a moving mesh always faces the camera in a scene. Within a container Object3D, there are 100 meshes, and I am rotating this container on the x and y axis. Is there a method ...