Issues with applying texture mapping to Particle materials in three.js

I am currently working on creating a space warp particle effect using Three.js, but I encountered an issue. The particles that are being created appear cubical in shape, however, I want them to be spherical. I tried loading a circle png and mapping it to the particle material, but it didn't produce the desired result.

function init() {

  const renderer = new THREE.WebGLRenderer({
    antialias: true,
  });
  renderer.setSize(innerWidth, innerHeight);
  const app = document.getElementById("app");
  app.appendChild(renderer.domElement);

  // set up camera
  const camera = new THREE.PerspectiveCamera(
    60,
    innerWidth / innerHeight,
    1,
    1000
  );
  camera.position.set(0, 0, 1);
  camera.rotation.x = Math.PI / 2;

  const scene = new THREE.Scene();

  const starGeo = new THREE.BufferGeometry();
  const starCount = 6000;
  const vertices = new window.Float32Array(starCount * 3);
  starGeo.setAttribute("position", new THREE.BufferAttribute(vertices, 3));
  const starsArr = [];

  for (let i = 0; i < starCount * 3; i += 3) {
    vertices[i] = Math.random() * 600 - 300;
    vertices[i + 1] = Math.random() * 600 - 300;
    vertices[i + 2] = Math.random() * 600 - 300;
    if (i % 3 === 0) {
      starsArr.push({
        velocity: 0,
        acceleration: 0.02,
      });
    }
  }

  starGeo.attributes.position.stars = starsArr;


// link to yellow circle 
const starTexture = new THREE.TextureLoader().load("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRHU59FFoWzbzpl_37EPznha05psUWXZJqeXDK_57OXhRCuB6IYMamNujWbewVL4CAYuMM&usqp=CAU"); 
  
// using white circle does nothing, gives blank screen, even while using local image
/* const starTexture = new THREE.TextureLoader().load("https://toppng.com/uploads/preview/white-circle-png-new-moon-phase-drawi-11563654400bdrw3yigxk.png");*/
  
  
  const material = new THREE.PointsMaterial({
    size: 5,
    map: starTexture,
    transparent: true,
  });

  const stars = new THREE.Points(starGeo, material);

  scene.add(stars);

  window.addEventListener("resize", () => {
    renderer.setSize(innerWidth, innerHeight);
    camera.aspect = innerWidth / innerHeight;
     camera.updateProjectionMatrix()
  });

  animate();

  function update() {
    const position = starGeo.getAttribute("position");
    const { array } = position;

    for (let i = 1; i < array.length; i += 3) {
      const _i = parseInt(i);
      const j = Math.floor((_i - 1) / 3);

      position.stars[j].velocity += position.stars[j].acceleration;
      array[i] -= position.stars[j].velocity;
      if (array[i] < -200) {
        array[i] = 200;
        position.stars[j].velocity = 0;
      }
    }

    stars.rotation.y += 0.01;
  }

  function animate() {
    requestAnimationFrame(animate);
    renderer.render(scene, camera);
   // update();

    starGeo.getAttribute("position").needsUpdate = true;
  }
}

init();
*{
 box-sizing: border-box;
}

body{
  margin: 0;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="favicon.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
  </body>
</html>

I have also shared the codepen related to this issue here > https://codepen.io/exxnnonymous/pen/rNJyYwx

Answer №1

The photo file you have selected is labeled as image/jpeg, which means the texture cannot be utilized as planned. It's crucial to opt for PNG (which supports an alpha channel) in this case.

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

How come I am unable to scroll beyond my parallax section unless I move the mouse first?

Currently, I am working on a webpage that includes a Parallax landing image. In order for the Parallax effect to function properly, the image has a greater height, requiring users to scroll down. This leads to the appearance of a second scrollbar specifica ...

New post: "Exploring the latest features in Angular

Looking for help with integrating Angular and SpringREST to fetch data from the backend? Here's my situation: I need to retrieve a JSON string from the backend using a POST request, send it to my site's hosted link, and display it on the user int ...

Is it possible to work with a database file using JavaScript?

Can HTML5 and JavaScript be used to import a .db file from a local machine for CRUD operations using SQL and then export the edited file back to the local machine? Is it possible to use indexedDB in JavaScript to load data from a file and save it back onc ...

Trigger the onClick event of an element only if it was not clicked on specific child elements

<div onClick={()=>do_stuff()}> <div classname="div-1"></div> <div classname="div-2"></div> <div classname="div-3"></div> <div classname="div-4"></div> ...

What is the best way to retrieve content from a different website using javascript in an asp.net environment?

Currently working on a web application in asp.net where I want to provide users with a JavaScript code that allows them to fetch content from my website and display it on their own website. To handle user requests on my website, I have implemented a gener ...

Angular 2: Troubleshooting Issues with Observable Data Display

Looking to implement a RESTful call with Angular 2 that constantly updates whenever there are changes in the API. In my service, I've included an Observable to fetch data from the API: getData(): Observable<any[]> { return this.http.get(url) ...

Choosing an ID along with a numerical value in jQuery

Being new to both stackoverflow and jQuery, I'm facing a challenge in creating a basic function. In my website, there are multiple links with IDs such as "filtro1", "filtro2", and so on. My goal is to write a single piece of code that will be trigger ...

Calculating the sum of all textboxes with jQuery

I'm encountering an issue when trying to add the values of textboxes on blur call. Specifically, after entering a number in one of the textboxes, it throws NaN when attempting to sum up the values from other textboxes. Below is the code snippet causi ...

Searching for a point within a specified range using Sequelize

I have a model called Location with a field named coordinates of type geometry. I'm looking to create a function that takes in latitude, longitude, and radius as parameters, and returns all locations within that radius (in meters). I attempted to foll ...

Issues related to the performance of React, Redux, and three.js

UPDATE: After identifying the issue, I have narrowed it down to this small gist and this jsfiddle. In my real-time 3D game based on three.js, I intended to utilize Redux for state management. Despite creating a simple prototype for testing purposes, even ...

What is the best way to mark a specific photo as a favorite in an array of Photo objects?

I am working with a basic array of photo categories that follows this structure: [ { category: 1001, photos: [ { id: 100101, url: 'url.com/100101', favorite: false}, { id: 100102, url: 'url.com/100102', favorite: ...

Default Data Configuration for Mongoose

Exploring the realm of node.js and the MEAN stack, I am venturing into the creation of an application. Within this application, there exists a need for default data in the database. My goal is to ensure that this data is populated automatically upon the ap ...

Adding a simulated $state object to an angular unit test

I'm facing some challenges with Angular unit testing as I am not very proficient in it. Specifically, I am struggling to set up a simple unit test. Here is my Class: class CampaignController { constructor($state) { this.$state = $state; ...

Creating plugin-based applications using HTML5

I am new to developing web applications and want to create an HTML5 cross-platform application that resembles the startup page of Windows 8, displaying multiple windows for users to choose from. I need guidance on how to start this project. I would like ...

There seems to be an issue with the AJAX REST call failing to transmit data

Whenever I attempt to submit the form, the page refreshes and nothing gets saved in the database. The code in subforum.js $(document).on('click','#submit',function(e) { var user = JSON.parse(sessionStorage.getItem("ulogovan")); consol ...

NextJS getStaticProps failing to pass fetched data to the page component

Struggling with passing props from getStaticProps function into template pages in NextJS. Below is the code for the dynamic page template that I am using. // src/pages/blog/[slug].js import React from 'react'; import matter from 'gray-matte ...

jQuery UI tabs loaded with Ajax causing Javascript to malfunction

It appears that Javascript is disabled in jQuery UI tabs when loaded through ajax. Testing with jQuery tooltips and .click() alerts shows that Javascript functions properly in tabs not loaded through ajax (IDs present on the page). Below is the method use ...

Transform incoming AJAX response into Backbone model

Is there a way to transform the success callback data into a Backbone model? Here is what I currently have: App.Models.Image = Backbone.Model.extend({ idAttribute : 'image_id' }); App.Collections.Image = Backbone.Collection.extend({ model : ...

I am trying to locate the XPath for the NG repeat element with the following code snippet: ng-repeat="thread in threads | orderBy:'-last_ts' | filter : globalSearch track by $index" Can you assist

<div ng-click="changeChatThread(thread, true)" class="item ui three column grid thread_item ng-scope active-thread" ng-class="{'active-thread' : selectedThread === thread.chat_id}" ng-repeat="thread in threads | orderBy:'-last_ts' | ...

The React component is experiencing a delay in its updates

I've been experiencing delayed updates when using React.useEffect(). Can anyone shed some light on why this might be happening? function Process(props) { const [results, setResults] = React.useState({ number: "", f: {} }); let ...