Implementing two-dimensional orientation on particles in three.js

My first attempt at using three.js involves a basic particle animation with 4 different textures mapped onto them. Everything is working smoothly so far, except for one issue - I can't seem to rotate the particles randomly for different orientations (upside down, sideways, etc.). Can anyone provide guidance on how to achieve this? Any help would be greatly appreciated!

You can view my current progress here:

Below is the relevant code snippet:

            sprite1 = THREE.ImageUtils.loadTexture( "sprite1.png" );
            sprite2 = THREE.ImageUtils.loadTexture( "sprite2.png" );
            sprite3 = THREE.ImageUtils.loadTexture( "sprite3.png" );
            sprite4 = THREE.ImageUtils.loadTexture( "sprite4.png" );

            parameters = [ sprite1, sprite2, sprite3, sprite4];

            for ( i = 0; i < parameters.length; i ++ ) {

                sprite = parameters[i];

                materials[i] = new THREE.PointCloudMaterial( { size: 45, map: sprite, depthTest: false, transparent : true} );


                particles = new THREE.PointCloud( geometry, materials[i] );

                particles.rotation.x = Math.random() * 60;
                particles.rotation.y = Math.random() * 60;
                particles.rotation.z = Math.random() * 60;

                scene.add( particles );

            }

Utilizing three.js r71

Answer №1

From what I understand, the PointCloud/PointCloudMaterial particle system in three.js uses gl.POINTS to render the points, which comes with certain limitations.

  1. Rotation of the points is not possible.

    Even if you create a custom shader to rotate the UV coordinates in the fragment shader, it won't be effective if the image fills the point completely because rotating a square texture inside a square will result in clipped corners as it rotates.

  2. The size of the points cannot exceed the maximum point side supported by the GPU/Driver being used.

    WebGL specifies a maximum size of 1.0, meaning there are GPUs/Drivers that only support points of 1 pixel in size.

    According to webglstats.com, the percentage of machines supporting points larger than 1 pixel has decreased, but around 5% still only allow points 63 pixels or smaller, which may pose an issue when navigating a field of points.

  3. Only square points are allowed.

    It's not possible to have rectangular points, limiting options for shapes like long and thin sparks, for instance.

One workaround is to create a custom particle system using quads, allowing for rotation and scaling of vertices in multiple directions. This example operates entirely on the GPU, although it's not based on three.js.

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

Prevent animations on child elements with Vue.js

I am dealing with a scenario where I want to remove the fade transition on a child div within a <transition> component. The reason for nesting it is to prevent layout flickering, which can be demonstrated in a fiddle if necessary. In the fiddle belo ...

React - Parent Component not successfully passing Ajax data to Child Component

I have a parent component and a child component. I am using the fetch method within the componentDidMount() callback to retrieve data from an API and then set the state with key items to that data. The intention is for this data to be passed down to the ch ...

Is it possible to observe the website functionalities and execute them directly from the console?

Question about JavaScript: Is it safe for a script tag to be visible in the body of the developer console and for functions to be run directly on the website? It raises security concerns, and there should be measures in place to prevent this kind of displa ...

Functionality in Three.js that involves selecting nearby objects with an event handler and ensuring that the self object is

I have spent countless hours today diving deep into the documentation, tutorials, and stackoverflow questions in pursuit of a solution to this issue. I am pleading for your assistance – please take pity on me and help! The problem at hand involves a wat ...

Error: JSON key data not present in rendering

Here is a JSON string I am working with: {"{\"nodeName\":\"abc\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]," {\"nodeName\":\"pqr\"}":[{"url":"abc","status":true},{"url":"abc","status":true}]} ...

Activate or deactivate a button depending on the input value of a TextField in React.js

I am currently designing a form similar to the one displayed in this image. I want the "Add" button to become active as soon as the user starts typing in the "Tags" input field. For this project, I am using material-ui and I have created an Input compone ...

Having two menus displayed simultaneously on the screen is not feasible

Achieving the Desired Screen Layout To create a screen layout with two menus, one being the burger menu generated using createDrawerNavigator from react-navigation (located in the top left corner) and the other menu as a bottom button created by createBot ...

The .get function is functioning properly during development, but encountering issues in the production environment

Here is the scenario: while running my server on node.js locally, the client code successfully retrieves data from the server. However, upon pushing the code to the live server, the client receives a /getSettings 500 (Internal Server Error). The main index ...

Create a function that adds a new div element with a one-of-a-kind identification when

I am currently developing a web application on www.firstusadata.com/cash_flow_test/. The functionality involves two buttons that add products and vendors dynamically. However, the issue I'm facing is that the appended divs do not have unique IDs, maki ...

Guidelines for integrating deep links into a ReactJS Ionic Android application

I have recently converted my ReactJS project into an android project following a tutorial. Now, I have successfully created an APK file and would like to configure the app to open when a specific URL is clicked on a mobile browser. Any guidance on how to a ...

Update JSON data in ng-blur event using AngularJS

Could you offer some guidance on how to push the content from a text box into JSON when I click outside of the box? Below is the code for my text box: <input type="text" name="treatmentCost" class="form-control" ng-model="addTemplate" /> And here i ...

Determining the victorious player in a game of Blackjack

After the player clicks "stand" in my blackjack game, my program checks for a winner. I am using AJAX to determine if there is a winner. If there is a winner, an alert will display their name. Otherwise, the dealer will proceed with making their move. Any ...

What is the process to retrieve a variable from a Node.js file in an HTML document?

What is the best way to showcase a variable from a node.js route in an HTML File? I have a node.js route structure as follows: router.post("/login", async (req,res) => { try { const formData = req.body const name = formData.name ...

Troubles with deploying on Heroku

Every time I try to run my application on Heroku, all I see is: Heroku | Welcome to your new app! Refer to the documentation if you need help deploying. Because of this, I attempted to deploy my app to Heroku using this command: git push heroku master Ho ...

What is the method for developing a Typescript-connected High-Order React Component with Redux?

I am looking to develop a React Higher-Order Component that can safeguard routes within my application from unauthorized users without an access token. I aim to use this HOC to wrap a Component like so in the parent component: <Route exact path ...

ReactJS: Unable to navigate to a new page when moving from a page with automatic refresh

Every 5 seconds, I automatically refresh a page (Page1) using setTimeout and a callback function. However, every time I navigate to a new page (Page2), it quickly redirects back to Page1 after a few moments. I have tried using window beforeunload event l ...

Distinguishing between a video or image when uploading files in JavaScript

I've been researching whether JavaScript can determine if a file is a video or an image. However, most of the information I found only shows how to accept these types using the input tag. What I really need is for JS to identify the file type and the ...

Peer-to-peer Ajax image sharing

Currently, I'm utilizing Ajax to fetch images from a remote server. Initially, I attempted this by directly using the URL of the remote server - resulting in the returned image being a string (given that's how Ajax communicates). To rectify this, ...

JavaScript Selenium code encountering an "Element not interactable" error with input textbox element

Currently, I am attempting to utilize Selenium in order to automate inputting a location into the search bar on weather.com. Initially, I wrote the code in Python and it seems to be functioning properly: // this works driver = webdriver.Chrome(ChromeDriver ...