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

Encountering a console error: Prop type validation failed for the `Rating` component with the message that the prop `value` is required but is currently `undefined`

I am encountering a proptype error which is causing an issue with the URL display on my Chrome browser. Instead of showing a proper address, I am seeing the URL as undefined like this: http://localhost:3000/order/undefined Instead of undefined, I should h ...

Is it possible to organize and filter a dropdown menu in JQuery based on a secondary value (new attribute)?

Can the drop-down list be sorted by value2? <select id="ddlList"> <option value="3" value2="3">Three</option> <option value="1" value2="1">One</option> <option value="Order_0" value2="0">Zero</option> </sele ...

Refresh database records

I am currently using grails and I am exploring ways to update my database table utility by selecting values from two drop down menus. These drop down menus are populated with values from the database based on user selections from another drop down menu. My ...

Angular 2: Emptying input field value on click event

I am experiencing an issue with resetting my input values. I have a search bar with filter functions. When I enter a value, it displays a list below and I want to add a function to these links. When I click on one of them, it takes me to another component ...

Limiting the style of an input element

How can I mask the input field within an <input type="text" /> tag to restrict the user to a specific format of [].[], with any number of characters allowed between the brackets? For example: "[Analysis].[Analysis]" or another instance: "[Analysi ...

AngularJS $scope variable issue

After searching online, I found this code snippet that I tried to implement, but unfortunately, it's not displaying any data. Below is the HTML code: <html data-ng-app=""> <head> <title>Example 4: Using AngularJS Directives an ...

What are the steps to modify or remove a node in react-sortable-tree?

I am currently working on implementing a drag and drop tree view using react-sortable-tree. Along with that, I also need to incorporate CRUD operations within the tree view. So far, I have been successful in adding, editing, and deleting nodes within the p ...

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 ...

What is the best way to incorporate server-side rendered content from a CMS to hydrate Vue.js?

Consider this scenario: content is managed through a traditional CMS such as Joomla or Drupal content is provided by the CMS as fully rendered HTML and CSS In the Frontend React.js should be utilized for all UI interactions. Despite going over most of R ...

Is there a way to utilize classes in various elements when other jQuery selectors are not functioning properly?

Could someone please clarify or provide an alternative solution to the following situation: The class fruit is present in two different tag elements, and one of these elements has the add class used in a jQuery selector. However, the alert box is not disp ...

Notification pop-up for accepting cookies on a website

I am curious about how to insert a .js code into a button within a bootstrap alert so that when the user clicks 'accept', the alert box does not reappear. Thank you very much. Here is the code I have, but it is not working. Javascript: $(".bt ...

Validation of Numbers and Characters in DevExpress ASP.NET TextBox

When I try to use masking on the textbox for credit card format, I am having trouble entering a hyphen. It seems that the validation does not accept dashes as I only checked for numbers. Any help would be appreciated. Thank you. <script> functio ...

Is it possible to pass parameters in the .env file in Node.js?

I am storing my file users.env inside routes/querys/users.env module.exports = { GET_USERS: "SELECT * FROM users", CREATE_USER: "INSERT INTO users ("id", "first_name", "last_name", "active") VALUES (NULL, '%PARAM1%', '%PARAM2%', & ...

I need to see the image named tree.png

Could someone assist me in identifying the issue with this code that only displays the same image, tree.png, three times? var bankImages = ["troyano", "backup", "tree"]; jQuery.each( bankImages, function( i, val ) { $('#imagesCon ...

Incorporating a new textfield in Codeigniter through a button/link activation

Currently, I am working on designing a request form for my website. I am facing an issue with creating a button that can dynamically add new input fields when clicked. Unfortunately, I am unsure of how to resolve this problem. Picture this: [ button ] A ...

Oops! An error occurred: Uncaught promise rejection - invalid link found for ProductListComponent

I am currently in the process of learning Angular and Ionic, but I am feeling a bit confused as to where my mistake is. I have looked at other questions, but I still can't seem to figure it out. Can anyone provide some assistance? Perhaps someone has ...

What is the best way to store types in a TypeScript-based React/Next application?

I'm currently in the process of setting up a Next.js page in the following manner const Index: NextPage<PageProps> = (props) => { // additional code... Prior to this, I had defined my PageProps as follows: type PageProps = { pictures: pi ...

Can access parent refs when exporting a child component with withStyles by following these steps:

For example: Child Component Code // Assume there is a styles object 's' being used in this component class Child extends Component { render() { return ( <h1 ref={(ref)=>{this.ref = ref}}>Hello</h1> ); } } export defau ...

Is there a reason why the Chrome browser doesn't trigger a popstate event when using the back

JavaScript: $(document).ready(function() { window.history.replaceState({some JSON}, "tittle", aHref); $(window).bind("popstate", function(){ alert("hello~"); }); }); Upon the initial loading of the www.example.com page, the above JavaScript code is ex ...

Utilizing the Google Translate API within an ASP MVC framework to translate a div's content from English to Arabic

Currently, I am working on a small project that involves two divs: one for English and another for Arabic. Despite creating the project, I am encountering an issue with getting the translation from English to Arabic. Below is the code I have attempted, but ...