Tips for incorporating numerous visible arrows into your Three.js project by utilizing the THREE.ArrowHelper functionality

edited: specifying the use of ArrowHelper I am looking to create a multitude of arrows on a 2D plane to visually represent a vector field. Typically, there are around 20,000 vectors that need to be displayed.

Although I am currently using THREE.ArrowHelper to achieve this, the process is quite slow. This leads me to believe that there might be a more efficient approach. Is there a way to update the field with a reduced number of vectors when zoomed out, and dynamically add only what the renderer requires?

added: I generate the vectors using the code snippet provided below. This loop creates a 2D vector field on the x,y coordinates of a parametric surface.

// set default color
var hex = 0x00ff00;
var u,v,xx,yy,ii,dir,mag,origin;
// loop through
Geometry[i].vertices.forEach(function(point,j) 
{
  xx = Math.floor((point.x-data[i].x0)/data[i].dx);
  yy = Math.floor((point.y-data[i].y0)/data[i].dy);
  ii = data[i].nx*yy+xx;

  u = data[i].frame[data[i].xvec][ii];
  v = data[i].frame[data[i].yvec][ii];
  mag = Math.pow(u*u+v*v,.5);
  dir = new THREE.Vector3( u, v, 1 );
  origin = new THREE.Vector3( point.x+data[i].dx/2,
                              point.y+data[i].dy/2, 1 );

  data[i].arrowHelper[j] = new THREE.ArrowHelper( dir.normalize(), 
                                                  origin,
                                                  data[i].scale*mag, 
                                                  hex);
  scene.add( data[i].arrowHelper[j] );

});

Running the code on a more powerful machine showed some improvement, but the performance impact is still significant.

While I can smoothly display the parametric surface and even a texture underlying it with 1e06 elements without issues, the slowdown is primarily caused by the ArrowHelpers.

Answer №1

Shoutout to @pailhead for providing the solution to plotting arrows using TWO sets of line calls with THREE.LinePieces. In the original code, the arrow base is then established as follows: The line[i] is recalculated whenever there is a change in the vectors.

// defining default color
var hex = 0x00ff00;
var u,v,xx,yy,ii;
// setting up arrow bases
var lines = new THREE.Geometry();
// iterating through
Geometry[i].vertices.forEach(function(point,j) 
{
    // rescaling
    xx = Math.floor((point.x-data[i].x0)/data[i].dx);
    yy = Math.floor((point.y-data[i].y0)/data[i].dy);
    ii = data[i].nx*yy+xx;
    u = data[i].frame[data[i].xvec][ii]*data[i].scale;
    v = data[i].frame[data[i].yvec][ii]*data[i].scale;
    lines.vertices.push(
      new THREE.Vector3(point.x+data[i].dx/2, point.y+data[i].dy/2,1), 
      new THREE.Vector3(point.x+data[i].dx/2+u, point.y+data[i].dy/2+v,1)
    );

});
var mat = new THREE.LineBasicMaterial({color:hex})
line[i] = new THREE.LineSegments( lines, material);
scene.add(line[i]);

This code is built for three.js version r.73

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

What is the best way to dynamically update a state that is deeply nested?

Is there a way to update the object using key: 1311 and retrieve the updated state while not knowing its exact location but only its key value? state = { iow: [ { key: 1, iow_description: "EARTH WORK", unit: null, rate: nul ...

Why is the jQuery change event only firing when the page loads?

I am experiencing an issue with a .js file. The change event is only triggering when the page loads, rather than when the selection changes as expected. $(document).ready(function(){ $("#dropdown").on("change keyup", colorizeSelect()).change(); }); f ...

Ways to customize weekend colors in v-calendar (distinct colors for Saturdays and Sundays)

Looking to customize the appearance of weekends in your calendar by changing their colors? I have a component for the v-calendar that can help with that. Here's the code: <div id='app'> <v-date-picker title-position="left&quo ...

export module from the express framework

function affirm(){ console.log("yes") } Element={} Element=affirm Element.something="something" Element.nothing="nothing" DEPICTED IN WEB BROWSER: In the code snippet above, if you were to console.log(Element), it would display ...

The Javascript logic on the NewForm for a Sharepoint 2013 on-premise list is failing to trigger

Screen shot linkThere seems to be an issue with the code I have written. The save button should only be enabled if all 5 checkboxes are ticked, but currently, the button is not disabled on form load. I have tried adding the code in both CEWP and SEWP, bu ...

Troubleshooting Error 400 while fetching JSON data using $http.get method in AngularJS

I keep encountering a 400 error when attempting to fetch the JSON data from the following URL using $http.get. $http.get('https://api.spotify.com/v1/search?q=artist:Owl+City+title:On+The+Wing&type=track&limit=1'). success(function(data) ...

What is the best way to extract values from this PHP script?

I recently delved into the d3 javascript library and successfully created a scatter plot chart that pulls random values from an array. Below is the code snippet: <!DOCTYPE html> <meta charset="utf-8"> <head> <script type="text/ja ...

Is there a way to figure out the number of days from the current date using jQuery UI datepicker?

Hello there, I'm currently facing an issue with calculating the number of days from the present to a chosen date after utilizing a jQuery datepicker. It seems that the date formatting is getting altered upon selection, causing discrepancies in the ca ...

Check the validity of your JavaScript files with our convenient online tool!

Is there a website or online tool available to validate the syntax of JavaScript code in a file? I am experiencing problems with Internet Explorer 7 while running JavaScript, so I want to make sure my JavaScript file is valid. ...

Flask-SocketIO: Transmitting data between nodes using Redis adapter

When integrating SocketIO into an application running behind a node-balancer, the documentation recommends using SocketIO-Redis to facilitate event passing between nodes: const io = require('socket.io')(3000); const redis = require('socket.i ...

Customize the filename and Task Bar name for your Electron app when using electron-packager

My application uses electron packager to build the app on Mac. Here is my package.json configuration: { "name": "desktop_v2" "productName": "desktop v2", "version": "1.0.0", "license": "MIT", "scripts": { "build": "node --max_o ...

ASP.NET sending an AJAX request

Hi, I am new to the world of ajax requests and asp.net. I am facing an issue while sending an ajax request to an aspx page. Even though the server side debugging seems fine, I am encountering an error message in the response. I have already tried changing ...

The "loose" mode is not resolving the issue with the lack of support for the experimental syntax 'classProperties' that is currently disabled

Error Message: The experimental syntax 'classProperties' is currently not enabled Even after trying the suggested solutions, I still encounter the error during re-building. Click here for more information on the experimental syntax 'classP ...

Align the center of table headers in JavaScript

I'm currently in the process of creating a table with the following code snippet: const table = document.createElement('table'); table.style.textAlign = 'center'; table.setAttribute('border', '2'); const thead ...

Determine the maximum size of a specified number of square divs that can fit within responsive parent divs

I am working on creating a grid of square divs inside a container with variable height and width. The number of square div's is predetermined. All square divs will have images with the same dimensions (similar to the example). They should align left ...

When running grunt-bower, I am encountering an error stating that _.object is not a function

I am attempting to execute the grunt-bower task in order to copy all of my bower components. Encountered an error while running "bower:dev" (bower) task TypeError: _.object is not a function at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/g ...

I'm a complete programming newbie and I want to start learning JavaScript, jQuery, and other programming languages. Where should I

Coming from a design background with zero programming knowledge, I have recently learned XHTML and CSS. Now, I am eager to expand my skills by mastering JavaScript, jQuery, and more. Where should I begin? This will be my first foray into programming. Whil ...

Gather and consolidate all files into a single file using Node.js / JavaScript

I currently have 3 JSON files located in my project/Folder file1.json { "id":"01", "name":"abc", "subject":[ "subject1":"Maths", "subject2":"Science" ...

Having difficulty utilizing the express.session module in conjunction with HTTPS

I need to implement authentication and session creation on a HTTPS static website using expressjs. Here is the code snippet: app.js: // Set up the https server var express = require('express'); var https = require('https'); var http ...

A guide on implementing a callback function with the iTunes search API

I am having trouble setting up a callback function to effectively utilize the iTunes Store search API. My goal is to achieve the following behavior: const getiTunes = fetch(`https://itunes.apple.com/search?term=${search}&media=movie&limit=200`) ...