Challenges encountered with transferring BufferGeometry in three.js

I am relatively new to the world of three.js and I'm attempting to modify some scripts I stumbled upon online to address my own issue. Initially, I had a functional 3D view with one of my components but I required some additional features that are only available in newer releases. Starting from r66, I aimed to upgrade to r71, but I encountered some glDrawArray errors along the way. I suspect there might be an issue with my BufferGeometry within the create_component function. Here are snippets of the relevant code:

//main file
init();
animate();

function init() 
{
    if ( !Detector.webgl ) Detector.addGetWebGLMessage();

    renderer = new THREE.WebGLRenderer({antialias: true});
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);
    renderer.setClearColor(0xFFFFFF, 1);

    camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 2843.14990,  12217.65039);
    camera.position.x = 0.00000;
    camera.position.y = 0.00000;
    camera.position.z = 5897.56250;
    camera.up = new THREE.Vector3(0, 1, 0);
    var target = new THREE.Vector3(0.00000, 0.00000, 0.00000);
    camera.lookAt(target);

    controls = new THREE.TrackballControls(camera);
    controls.addEventListener('change', render);

    scene = new THREE.Scene();


    var light_ambient = new THREE.AmbientLight(0x000000);
    scene.add(light_ambient);

    light = new THREE.PointLight(0x999999);
    light.position.set(2843.14941, -3790.86621, 5686.29980);
    scene.add(light);
    light = new THREE.PointLight(0x4C4C4C);
    light.position.set(-3790.86621, -3790.86621, 2843.14990);
    scene.add(light);
    light = new THREE.PointLight(0x4C4C4C);
    light.position.set(0.00000, 3790.86646, 3790.86621);
    scene.add(light);

    create_component(scene);

    window.addEventListener('resize', onWindowResize, false);
}

function onWindowResize() 
{
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();

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

    controls.handleResize();
    render();
}

function animate()
{
    requestAnimationFrame(animate);
    renderer.render(scene, camera);
    controls.update();
}

function render()
{
    renderer.render(scene, camera);
}


//second file  
function create_component(scene)
{
    var mesh;
    var material;
    var geometry;

    geometry = new THREE.BufferGeometry();
    geometry.attributes = {
        position: {
            itemSize: 3,
            array: new Float32Array([
                // Insert your float32array values here
            ])
        },
        normal: {
            itemSize: 3,
            array: new Float32Array([
               // Insert your float32array values here
            ])
        }
    };

    material = new THREE.MeshPhongMaterial({
        color: 0x505050,
        shininess: 2.00000,
        ambient: 0x505050,
        side: THREE.DoubleSide,
        specular: 0x000000
    });

    mesh = new THREE.Mesh(geometry, material);
    scene.add(mesh);
}

Excluding the file containing the float32arrays resolves the issues I'm facing. Any guidance on how to overcome this challenge would be greatly appreciated as I lack expertise in webGL programming.

Thank you!

Answer №1

To generate your BufferGeometry, simply adhere to this pattern:

var points = new Float32Array( [
        439.22070, 1088.16528, 57.26282,
        . . .
        1465.75195, -1791.83447, 57.26282
        ] );

var normals = new Float32Array( [
        0.00000, 0.00000, 1.00000,
        . . .
        0.00000, 0.00000, 1.00000
        ] );

geometry = new THREE.BufferGeometry();

geometry.addAttribute( 'position', new THREE.BufferAttribute( points, 3 ) );
geometry.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );

Operating on three.js version r.71

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

Ways to determine if your code is written in ES6

After completing a lot of Javascript coding, I just learned about the existence of various JS 'versions' such as ES5 and ES6. My project is now up on Github, and someone advised me to convert my ES6 code to ES5 using Babel. The problem is, I&ap ...

Reveal the hidden div by sliding it up from the bottom

I have a container with brown branches resembling the image, and I'm looking to hide it. When a button is clicked, I want it to reveal from the bottom to the top, almost like it's being unmasked. I've ruled out a typical bottom-up slide anim ...

Variable within a JSON response encapsulated in a JavaScript object

I am attempting to include a PHP variable within a JavaScript script that is stored in a result variable and will be processed with JSON, but I am struggling to make it work. I believe the issue lies with the use of double and single quotes, but I cannot d ...

developed a regular expression to disregard .goutputstream documents

After successfully creating a watcher with chokidar, I encountered an issue when trying to ignore certain files using regex. I am struggling to figure out what went wrong in my code or regex implementation. Below is the snippet of the code: const watcher ...

Activate a single button to reveal hidden buttons

My HTML page is filled with numerous buttons, each designed to expand specific information upon clicking. To enhance usability, I am seeking a way to use one main button to expand all the others. Initially, I attempted to display only one button alongsid ...

How can you identify changes in localstorage and then trigger the activation of a new boot file or reallocate a value using Vue.js or JavaScript?

When users log in, they have the option to choose from 3 domains: dev, demo, and sandbox. The configuration for these domains is set in the Boot.js file using Axios. The boot file is triggered prior to the firing of the Vue instance. Below is the content o ...

UI-Router: What is the best way to access a page within my project without adding it as a State?

Currently in the process of learning Angular and UI-Router. Initially, I followed the advice of many and chose to utilize UI-Router. In my original setup, the login page was included in all States. However, I decided it would be best to keep it as a separ ...

relocate items originally placed at the starting point to move in the direction specified by a vector

Explore the code snippet on this JSFiddle link Is there a way to reposition objects that originate at the center point and make them align with a specific vector direction? In my demonstration, I have a sphere containing evenly spaced sprites. Additional ...

Node-archiver: A tool for dynamically compressing PDF files

I am currently working on a project that involves generating multiple PDF files using pdfkit. I have an array of users, and for each user, I create a report using the createTable() function. The function returns a Buffer, which is then passed to archiver t ...

Error Encountered: Angular JS Throwing Unhandled Injection Error

I am having trouble validating the fields in my index.html and js files. I keep seeing errors, even after trying different versions of angular-route.min.js and angular.js. AngularJs | Basic Login Form <body ng-app="myApp"> ...

Retrieve the parent's current state by accessing it through a callback function in React

My callback function onRestore is only logging the history until the id of the clicked snapshot. Why is it showing incorrect state? I've exhausted all options, so any help would be appreciated. import React, { useState, useEffect, useRef } from "re ...

Is it possible to eliminate the dedupe feature in npm?

By mistake, I accidentally ran the command npm dedupe and now all of my node_modules directories are flattened. While this reduces file size, it's making it more difficult to find things. Is there a way to reverse this and return to the hierarchical f ...

Tips on adding up polygon values in mapbox

After providing detailed information about my issue, I was criticized for seeking help, so I will be more general in my explanation. I am trying to calculate the sum of values for each location within a polygon drawn on Mapbox. I have the code to insert th ...

Modify the values of an object by utilizing the setter function

How can I utilize the setter method to update existing values of an object and perform mathematical operations? var obj = { set model(object) { //method's logic } }; obj = {x:10, y: 20, p: 15}; obj = { x:10, y: 20, p: 15 set mod ...

Importing multiple modules in Typescript is a common practice

I need to include the 'express' module in my app. According to Mozilla's documentation, we should use the following code: import { Application }, * as Express from 'express' However, when using it in TypeScript and VSCode, I enc ...

Is it advisable to incorporate await within Promise.all?

Currently, I am developing express middleware to conduct two asynchronous calls to the database in order to verify whether a username or email is already being used. The functions return promises without a catch block as I aim to keep the database logic se ...

Challenges arise when building a package while importing all modules on external servers

While exploring Three.js within a React application, I have created an example that functions properly when tested locally; however, it fails to load when accessed remotely from static hosts like GitHub or Amazon S3. When I run my GitHub project locally, ...

Vue.js is displaying one less item

Recently I started working with Vuejs and encountered an unexpected issue in my application. The purpose of my app is to search for channels using the YouTube API and then display those channels in a list. However, when I try to render the list of subscri ...

What steps can I take to fix the problem of Expo Go crashing on my Android device?

For the past 3 days, the Expo Go Android app version 2.28.4 has been crashing every time I try to start it. This issue is preventing me from testing my Expo apps on physical devices, as they work fine on simulators. Even the app that I published on Expo ...

Utilizing AngularJS to invoke REST API calls within a for loop and efficiently manage priority for the visible content area

Currently, I am dealing with an array containing over 400 data IDs related to different fruits. My goal is to make API calls in a for loop to retrieve relevant information about each fruit. While this works fine for smaller lists, it fails when dealing wit ...