Creating a canvas texture on tube geometry with three.js for optimal display on iPad devices

I have a 3D model of a tube geometry with 18000 coordinates on the production side. To simplify, I am selecting every 9th coordinate to plot 9000 coordinates for building the tube geometry using only the CanvasRenderer.

When utilizing vertexColors: THREE.VertexColors in the WebGLRenderer, each face of the model displays a different color. However, switching to the CanvasRenderer results in the entire model turning white, even if changing to vertexColors: THREE.FaceColors.

Please refer to the jsfiddle link and my previous work where support was added by "mrdoob" for

material.vertexColors = THREE.FaceColors
for the CanvasRenderer.

Support for vertex color in canvas rendering

Tube in canvas rendering

Below is an image demonstrating color application based on values.

The image illustrates 12 values at 12 different degrees for each coordinate. A tube with radius segments of 12 has been created and these values are stored in a JSON file. With 2000 plotted points, there is a heavy load due to the large file size, despite only using 2000 out of the total 18000 points. Each segment consists of 12 faces, resulting in 24000 faces on the tube.

Refer to the programming logic below to apply colors based on parameter values:

// Fetching json data of resistivity values at different degrees as shown in the image
var result = getResValue(); 

for(var k=0; k<tube.faces.length; k++){
    // Logic for applying color based on resistance value
}

This current logic takes up too much rendering time and makes the model heavy causing low FPS on Android devices. The ultimate goal is to optimize the model for smooth performance on iPad using the CanvasRenderer exclusively.

How can this model be optimized for smoother performance on iPad? Are there alternative methods to apply colors to each face efficiently considering performance limitations?

Update: After updating the library version to r53, randomly colored faces were achieved by implementing vertexColors: THREE.FaceColors and

face.color.setRGB( Math.random(), Math.random(), Math.random())
for canvas rendering.

The challenge now lies in applying colors as per requirements (via canvas mapping or any other feasible solution) and optimizing the model for light loading and smooth operation on iPad.

Answer №1

Improving performance can be achieved by implementing an automated method to calculate colors for each angle offset and setting the hex color directly:

for ( var i = 0; i < tube.faces.length; i ++ ) {
    tube.faces[ i ].color.setHex( Math.random() * 0xffffff );
}

It's important to note that using canvas textures may impact FPS if too many faces are rendered, as discussed in a previous message about three.js - text next to line.

If attempting to render 24,000 faces on a canvas renderer for optimal display on an iPad, it may not be feasible.

A possible solution could be:

  1. Set the tube to only 1 segment.
  2. Create 12 canvas elements with width matching the tube length.
  3. Divide the canvas length into portions for each of the 2000 segments within each canvas element, assigning calculated colors accordingly.
  4. Apply the colored-bars-canvas-texture to each radius segment.

This approach reduces the number of faces to render, improving performance during initial page load.

To determine which faces to show lines with tag text, simply pick a face (out of 12) based on position coordinates and translate them back to JSON data.

Hopefully, this information is helpful!

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

Tips on increasing the height of an element that is overflowing

When populating my timeline component with dynamically mapped data from an array, I encountered an issue where if I added more data causing the maximum height to be reached, the overflow-y element didn't display all content. Despite trying various sol ...

Learn to leverage JavaScript in Node-RED to dynamically display messages based on selected dropdown options

After reviewing this Node-red flow: https://i.stack.imgur.com/y4aDM.png I am struggling with the implementation in my function. There are 3 options in each dropdown, one for meat type and the other for doneness. Once I select a combination from the drop ...

Ways to incorporate a deserialize function into an abstract class

I'm struggling with understanding how to implement my idea. I've created an abstract class AJsonSerializer where I aim to handle Serialization and Deserialization of classes. public abstract class AJsonSerializer { public string ToJson() { ...

Adjustable value range slider in HTML5 with ng-repeat directive in AngularJs

I am facing a problem with my HTML5 range slider. After setting a value (status) and sending it to the database, when I reload the page the slider's value is always set to '50'. The slider is being generated within an ng-repeat from AngularJ ...

Issue with ng-checked not detecting boolean values retrieved from local storage

I'm working on a code snippet in my controller where I have a checkbox in my HTML with "ng-checked="enterToSend" and "ng-click="enterToSendCheck()" attached to it. $scope.enterToSend = localStorage.getItem('enterToSend'); $scope.enterToSen ...

The HTML document requests information from a JSP file

I am faced with a situation where I have an HTML page stored on my local computer and a JSP file located on a remote server. My current challenge is: How can I showcase the content from the JSP file on the HTML page? The HTML page is strictly HTML-based ...

Issues with connecting to Socket.IO in Cordova app

I'm having troubles setting up my Cordova app to establish a socket.io websocket connection. Despite following the instructions I found, it doesn't seem to connect when running in debug mode. Can anyone help me troubleshoot this issue? Server Si ...

Retrieving a designated set of attributes for elements chosen using an element selector

Is there a way to retrieve specific attributes for the first 10 <p> elements in a document using jQuery? I know I can easily get the first 10 elements with $('p').slice(0,10), but I only need certain attributes like innerText for each eleme ...

Ajax is functional, however the server is not responding

After many attempts to resolve the issue with my website, I am turning to this community in hopes of finding a solution. The problem lies in the fact that while the ajax success function appears to be working and shows a status code of 200 in the network ...

Utilizing a jQuery variable within an .html() method

Can a Jquery if statement be used to display different content inside a div based on a variable? For example, if the variable is set to "cats", the displayed content might say "I like cats", and if it changes to "dogs", it would read "I like dogs". Is this ...

The toggling feature seems to be malfunctioning as the div section fails to display

I'm facing an issue with my Django project while working on a template. I want to toggle the visibility of a div element between hiding and showing, but the function I used isn't working for some reason. I borrowed the function from a different t ...

I'm new to Angular, so could you please explain this to me? I'm trying to understand the concept of `private todoItems: TodoItem[] = []`. I know `TodoItem` is an array that

//This pertains to the todoList class// The property name is todoItems, which is an array of TodoItem objects fetched from the TodoItem file. I am unable to make it private using "private todoItems: TodoItem[] = []," is this because of Dependency Injectio ...

The EJS template on the Express app is encountering an issue: it is unable to find the view "/id" within the views directory located at "/home/USER/Desktop/scholarship-app/views"

When attempting to render the request URL for an ID in my Express app, I encountered the following error: Error: Failed to find view "/id" in views directory "/home/USER/Desktop/scholarship-app/views" Here is a portion of my Express app code: app.get(&a ...

"Triggering the jQuery mouseout event following a resize of an element

I'm currently trying to develop a dynamic shopping cart widget. The concept is to have a box that displays the number of items in your cart, and when you click on it, it expands to show a detailed view of the cart contents. I've successfully man ...

Enhancing Values Across a Timeframe Using JavaScript

Last time, I asked about my code. Here is what I have currently: var secs = 100; setInterval(function() { var $badge = $('#nhb_01'); $badge.text((parseFloat($badge.text())+0.01).toFixed(2)); }, secs); I want the counter to increase by ...

How to deserialize a dictionary into a struct in golang using the unmarshal function

This scenario serves as an example illustrating my dilemma. Although it may seem like a singular struct with a JSON optional parameter would solve this issue, please disregard that notion. Consider the following: { "name": "alice", "ad ...

Collapsing an array within a JSON structure

Looking to flatten a JSON object before exporting it to CSV using the flatten_json module. The JSON input is structured like this: { "responseStatus": "SUCCESS", "responseDetails": { "total": 5754 }, "data": [ { ...

Is there a way to have content update automatically?

After writing this block of code, I discovered that clicking on one of the circles activates it and displays the corresponding content. Now, I am looking for a way to automate this process so that every 5 seconds, a new circle gets activated along with its ...

Deciphering a JSON response from an API using PHP (with a multidimensional array)

I am trying to parse JSON data with PHP within a WordPress environment. Here is my code snippet, but it seems to be encountering some issues: function decode_json(){ $json_data = file_get_contents('https://api.pray.zone/v2/times/today.json?city=j ...

Mocking a Promise-returning dependency for a React Component in Jest

There's a React component I'm working on that has a dependency like so: import { fetchUsers } from '../../api/'; This function is a utility that returns a Promise. My challenge lies in trying to mock this dependency using Jest. I&apo ...