Experiencing difficulties when trying to upload images onto the inner surface of a spherical object using Three.js

I am new to working with Three.js and this is my first major project. Despite its simplicity, I have been struggling for the past two weeks trying to resolve an issue. My goal is to create a model of the Earth in Three.js along with a star field, but I can't seem to get any image other than the Earth itself to work on the second sphere.

Here's the image I'm using for the Earth:

And here are some images I've tried for the star field:

<script>

        //pre stuff
        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 );
        var loader = new THREE.ImageLoader();
        camera.position.z = 5;

        const canvas = document.querySelector('#c');
        var renderer = new THREE.WebGLRenderer({canvas});
        renderer.setSize( window.innerWidth, window.innerHeight );
        document.body.appendChild( renderer.domElement );

        var ambient = new THREE.AmbientLight( 0xF6FBFF );
        scene.add( ambient );

        // main code

        var geometry = new THREE.SphereGeometry(2,72,72);
        var texture = THREE.ImageUtils.loadTexture('Earth.jpg');
        var material = new THREE.MeshPhongMaterial({map: texture});
        var sphere = new THREE.Mesh( geometry, material );
        sphere.rotateX( .4 );
        scene.add( sphere );

        var geometry2 = new THREE.SphereGeometry(10,72,72);
        var material2 = new THREE.MeshBasicMaterial();
        material2.map   = THREE.ImageUtils.loadTexture('star-map.jpg')
        material2.side  = THREE.BackSide
        var StarMap = new THREE.Mesh( geometry2, material2 );
        scene.add( StarMap );

  //animations

        var animate = function () {
            requestAnimationFrame( animate );

            sphere.rotation.y -= 0.002;

            renderer.render( scene, camera );
        };

        animate();

Answer №1

After some experimentation, I was able to successfully resolve the problem. However, I must admit that I am not entirely sure why my solution worked. It involved making adjustments to the image using Photoshop, which led me to suspect that the issue may have been related to the size of the photo.

What started as a mere comment has now evolved into a full-fledged answer. It seems that people took notice - perhaps because of my lack of experience with Stack Overflow.

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

Ensure that only a single onmouseover event is triggered when hovering over multiple elements

I want to create a simple code snippet like the one below: <span onmouseover="alert('hi')">Hello, <span onmouseover="alert('hello')">this</span> is a test</span> However, I need to ensure that when hovering ove ...

The Significance of Server-Side JavaScript

How common is the use of server-side JavaScript? What are the advantages of using it over other server-side scripting languages? Can you point out specific use cases where it outperforms other options? I'm also unsure about how to start experimenting ...

Show a malfunction with the `show_message` function

How can I show the die() message in if($allowed) in the same location as the move_uploaded_file result? <?php $destination_path = $_SERVER['DOCUMENT_ROOT'].'/uploads/'; $allowed[] = 'image/gif'; $allowed[] = ' ...

Unable to detect POST action in Firebug or Chrome browser

When I check Firebug or Chrome's development tool, I can't seem to detect a POST ajax request being made. The strange thing is that while I can't see the output of console.log(data) inside the success in Firebug, it does show up in Chrome. ...

What is the best way to incorporate an HTML element using JavaScript?

My attempt to generate a chip when a checkbox is checked by adding an event listener function to the checkbox seems to be failing. It appears that the element is not being inserted into the HTML. Below is the code snippet: let ChoosenFiltercontainer = docu ...

Is it possible for an AngularJS directive to compile a fresh element that has a second directive assigned to it?

UPDATE: All directives listed below will now require ng-model bindings to be applied in the elements they generate, targeting the controller assigned to the page. The code has been modified to reflect this. I am exploring the creation of dynamic HTML usin ...

Understanding the document.domain feature in Javascript

I have a website called foo.com hosted on server bar. Within this website, I have created a subdomain called api.foo.com. To connect the subdomain with Google Apps, I have set up a CNAME entry pointing to ghs.google.com. Now, I am facing an issue when att ...

Pass an array of links from the parent component to the child component in Vue in order to generate a dynamic

I am currently working on building a menu using vue.js. My setup includes 2 components - Navigation and NavLink. To populate the menu, I have created an array of links in the App.vue file and passed it as props to the Navigation component. Within the Navig ...

Switching between ThreeJS geometry formats 3 and 4 can be a challenge, especially when it comes to

I'm currently facing an issue with the migration process from ThreeJS geometry format 3 to 4. Specifically, I am trying to manually create a surface in the model.json file but have been unable to make it work. In geometry format 3, the code snippet b ...

Troubleshooting problems with dataTransfer and the file input type in JavaScript

Working on a project, I'm currently exploring the idea of implementing a JavaScript drag-and-drop feature. Typically, when using drag and drop, one would pass the event.dataTransfer.files to an ajax call for uploading the file to an external PHP file ...

Utilizing the path.join() method to incorporate tabs and line breaks in Node.js

Within this scenario, the variable filePath is experiencing a discrepancy in its output. While it successfully combines the paths, it includes unnecessary tabs and newlines. https://i.sstatic.net/rUugT.png let folderPath = path.join(__dirname, topicName); ...

What is the proper way to declare a Type for a JSX attribute in Google AMP that utilizes square brackets?

When utilizing AMP's binding feature, you must apply specific attributes that encapsulate an element's property with square brackets and connect it to an expression. An example from AMP is shown below: <p [text]="'Hello ' + foo"> ...

Limit the frequency of rendering JSX elements in React by implementing debouncing techniques

Is there a way to delay the rendering of a jsx element in order to smooth out the animation? I have an expanding panel with content inside, and when the panel is empty, the animation works well. However, if the panel already contains content, the expansion ...

Managing the pressure of numerous ajax requests using RxJS

Looking for a solution using RxJS 5: Imagine I am retrieving a list of categories from a REST API. For each category, I need to fetch subcategories from another endpoint. Then, for each subcategory, I need to retrieve products and their detailed descrip ...

What is the best way to modify an element's state based on the index array?

Here is the current state object: state = { index: 0, routes: [ { key: 'first', title: 'Drop-Off', selected: true }, { key: 'second', title: 'Pick up', selected: false }, ], }; I want to ...

Stop javascript function from automatically invoking itself

I am new to php and javascript and currently working on using a session variable to keep track of a counter. I want the counter to increment on the next button click and decrement on the previous button click. The issue I'm facing is with the JavaScri ...

Error Message: "Unknown Element Encountered: Lazy Loading Angular / Ionic 3 Component AOT"

Having some trouble with Lazy loading my Ionic components. Everything works fine in development, but when I try to compile AOT throws an error. Spent hours trying different solutions and still stuck on the same error. I've checked examples and everyt ...

Is it feasible to create a doughnut chart with curved edges?

My goal is to create a doughnut chart, but my search for reliable CSS/SVG/Canvas solutions has not been successful. https://i.sstatic.net/Rq6Lx.jpg I want each segment to have fully rounded corners, which presents a unique challenge. ...

What is the best way to eliminate a particular element from an array produced using the .map() function in

I am experiencing an issue with my EventCell.tsx component. When a user clicks on the component, an event is created by adding an element to the components state. Subsequently, a list of Event.tsx components is rendered using the .map() method. The problem ...

Unable to display the current state after update in React Native

I am facing an issue where I cannot display the updated state name in the sidedrawer of my app. Even though my functions are working fine and I can see the name printed twice in the console, the actual name value is not showing up on the app screen - it ...