Creating personalized features on Three.js models: Geometry's custom attributes

I have been grappling with an issue while using Three.js. I am trying to pass a custom attribute to my shader, which needs frequent updates. The shader is set as a ShaderMaterial for my mesh. However, the problem I am facing is that Three.js has recently changed how it handles attributes. Instead of being in the material, they are now linked to the geometry. Unfortunately, it seems that a standard geometry cannot accommodate custom attributes, leaving me in a bit of a predicament as I had been relying on its convenience. While attempting to use BufferGeometry, I encountered confusion and frustration when trying to correctly map my constantly updating UVs. Is there an alternative approach to BufferGeometry for implementing custom attributes? Or perhaps a less preferable method to accurately apply my UVs? And why can't a regular geometry support custom attributes?

Answer №1

If you convert your geometry to a buffer geometry, you can easily set custom attributes while still benefitting from the advantages of both options. This approach will eliminate any hassle of dealing with buffergeometry uvs, as it seems to be what you are inquiring about. The uvs can simply be passed over.

For example:


var bufferGeometry = new THREE.BufferGeometry().fromGeometry( originalGeometry );

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

Getting parameter names (or retrieving arguments as an object) within a method decorator in TypeScript: What you need to know

I am currently working on creating a method decorator that logs the method name, its arguments, and result after execution. However, I want to implement a filter that allows me to choose which parameters are logged. Since the number and names of parameter ...

What is the best way to store JSON data in the state of a ReactJS application?

I need assistance with a data format related issue. The current format of the data is being set by someone else in the backend of the application. When the data is empty, it looks like this: "opening_time":{"Mon":[["0"],["0"]], "Tue":[["0"],["0"]], "Wed" ...

Jquery failing to append existing values into the DOM

I'm currently attempting to enhance an existing jQuery table structure with the following code snippet: function GetViewData(data) { $.ajax({ type: "GET", url: "/Services/Configuration/ViewServices. ...

tips for choosing an element using getByTestId that matches a particular value in react-testing-library

When working with React, I have a scenario where I am mapping out elements from an array. For instance: {options.map((option)=>{ return <div data-testid="option">{option}</div> }) In some cases, I need to select an option withou ...

Concealing a message within a section that has been minimized to a width of 0

Recently, I've encountered a challenge in attempting to set the width of a section to 0 and have all its contents also disappear. Despite changing the section's width to 0px, the text inside continues to be displayed and even shifts off to the si ...

Is there a way to automatically populate an AngularJS input field?

Attempting to automate filling out a website using JavaScript. The script below: document.getElementsByClassName('form-control')[1].value = "MYNAME"; The input text changes, but upon clicking the submit button it displays as empty. Any as ...

Checking for valid zip code using a regular expression in JavaScript

Thank you for the suggestions, everyone. I have made some modifications to the script based on your advice and it appears to be functioning correctly now. <script src="jquery-1.4.2.min.js" type="text/javascript"></script> <script> $ ...

Guide on organizing an array of objects by the sub-part of their property values

Is there a way to order the elements in the given array based on a custom criteria related to the last 3 letters of 'prop2' in descending order? The specific order should be 'ABR', 'FDE', 'ZFR'. Another array needs t ...

The JSON data rendered by Angular is causing disturbance

I am trying to create JSON from a multi-array in the following format: var qus ={ { "qus" :"what is your name?", "option1" : {"ans" : Alex, "cor:"false"}, "option2" : {"ans" : Hervy, "cor:"false"}, "option3" : {"ans" : Rico, "cor:"true"}, "option4" : {" ...

Error in Angular Universal: KeyboardEvent is not defined

I have inserted the word "domino" into the server.ts file and updated the webpack.server.config.js as follows: module: { rules: [ { test: /\.(ts|js)$/, loader: 'regexp-replace-loader', options: { match: { pattern: '&bs ...

Guide to incorporating a jade file into a node.js application after executing an Ajax request

While working on my node.js application, I encountered an issue with loading a new HTML file using Ajax on a button click. Despite everything else working perfectly, the new HTML file was not being loaded. This is how I am making the ajax call in my main. ...

Should code in Vuejs be spread out among multiple components or consolidated into a single component?

After spending a significant amount of time working with Vue, I find myself facing a dilemma now that my app has grown in size. Organizing it efficiently has become a challenge. I grasp the concept of components and their usefulness in scenarios where the ...

Exploring JS Pattern Matching across Two Distinct Data Sources

In my database, I have two tables (and more can be added in the future) with rows structured like this: <table> <tr> <th>name</th> <th>salary</th> </tr> <tr> <td>a</td> &l ...

Using the ng-repeat directive along with the string replace expression allows for dynamically

Struggling to find a way to remove a substring within an angular expression while using the ng-repeat directive. The controller resides in an external JavaScript file, and here is the corresponding HTML code snippet. function myController($scope, $http ...

Meteor: Incorporating New Fields when Creating an Account

Currently, I am experimenting with the Meteor Roles package found at https://github.com/alanning/meteor-roles in order to add a new field to the user model. The user creation process goes smoothly without any issues, however, the 'roles' field t ...

I am unsure of the timestamp format for the value 1522899000000. Can it be used in both Ionic and AngularJS? And how would one go

While parsing a JSON from an external URL, I came across a timestamp with the value starttime: 1522899000000 (on 4/5/2018 -> 5th April 2018). The value seemed like a Unix timestamp, but when I tried to convert it, it displayed the year 1912. What kind o ...

Building a Loading Bar with Two Images Using JavaScript and CSS

I am currently experimenting with creating a progress bar using two images: one in greyscale and the other colored. My goal is to place these two divs next to each other and then adjust their x-position and width dynamically. However, I'm having troub ...

I encountered a NextJS error while trying to implement getStaticProps(). Can someone help identify the issue at hand?

I'm encountering an issue while using getStaticProps(). I am working with nextjs and passing the returned value as props to a component. Despite trying various methods such as await and JSON.stringify(), nothing seems to be effective in resolving the ...

The Lightgallery plugin is creating three duplicates of the slides

I am currently facing an issue with a gallery that loads images from an API and displays them using the lightgallery plugin. Upon implementing the lightbox in the correct location (view question here), I discovered that the plugin is generating three slid ...

Searching with jQuery UI Autocomplete

I am interested in implementing jQuery UI autocomplete to allow users to search for items on my website. I have a list of products that I want to convert into JSON data (or just include them directly in JavaScript like the jQuery UI demo does), but I&apos ...