Texturing a sphere using Three.js is not compatible with smartphones

I've encountered some difficulties using Three.js. My goal is to add a texture to a sphere (an image). The code I have works flawlessly... until I attempt to run it on a smartphone. I attempted to debug the issue with Firefox and its remote debugger, but unfortunately, I couldn't pinpoint the problem. Here's my current code:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title>Test</title>
        <meta name="viewport" content="initial-scale=1.0" />
        <script src="./three.min.js"></script>
        <script src="./sphere.js"></script>
        <style>
            html, body, #container {
                margin: 0;
                overflow: hidden;
            }
        </style>
    </head>

    <body>
        <div id="container" style="width: 300px; height: 200px;"></div>

        <script>
            init();
        </script>
    </body>

</html>

and :

var renderer, scene, camera, mesh;

function init() {
    var container = document.getElementById('container');
    var width = container.offsetWidth;
    var height = container.offsetHeight;

    renderer = new THREE.WebGLRenderer();
    renderer.setSize(width, height);
    container.appendChild(renderer.domElement);

    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera(90, width/height, 1, 1000);
    camera.position.set(0, 0, 300);
    scene.add(camera);

    var geometry = new THREE.SphereGeometry(200, 16, 16);

    var texture = new THREE.Texture();
    var loader = new THREE.ImageLoader();
    var f = function(img) {
        texture.needsUpdate = true;
        texture.image = img;

        var material = new THREE.MeshBasicMaterial({map: texture, overdraw: true});
        mesh = new THREE.Mesh(geometry, material);
        scene.add(mesh);
        render();
        animate();
    }
    loader.load('sphere.jpg', f);
}

function animate() {
    requestAnimationFrame(animate);
    mesh.rotation.y += 0.003;
    render();
}

function render() {
    renderer.render(scene, camera);
}

Could you help me identify where I might be going wrong?

If you're interested in observing the code in action, feel free to visit this link. It's worth mentioning that the issue persists with both WebGLRenderer and CanvasRenderer.

Answer №1

By leveraging the strength of power of two texture sizes, the issue has been successfully resolved through a repost.

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

Using jQuery to dynamically pass variables to an HTML document

In my JavaScript file, I have the value 'testValue' stored. The code snippet below retrieves this value using a REST service and displays it in an input box: $('#testValue').val(RestServices.getValueCovid(response, 'TESTVALUE' ...

I'm having trouble with my Rock Paper Scissors script. The console is showing an error message: "Uncaught SyntaxError: Identifier 'playerSelection' has already been declared."

Currently delving into the world of JavaScript, I've embarked on a project to create a console-based Rock Paper Scissors game. Here's the code snippet that I've come up with: <!DOCTYPE html> <html> <body> <script> ...

Attempting to assign a value to the Progress Circle

Can I modify the code to incorporate a hardcoded number instead of displaying "Goals completed:" and still have the progress bar reflect the percentage? I want to hide the prompt for users to input a number and handle all updates behind the scenes. Essent ...

Extract data from an array in MongoDB by organizing it into sections based on dates

As a beginner in the world of MongoDB, I'm trying to figure out how to extract data from an array in separate sections. { "name":"User name", "messages":[ { "message":"Message 1", ...

AngularJS - Using filters to extract specific options from multiple <select> components

There are N "select" components generated based on JSON data, with the "options" populated by an external API. I am trying to implement a custom filter that ensures when an option is selected in one "select" component, it should not appear in the other com ...

Troubles with IE7 regarding jQuery [clicking and changing events]

My code snippets are designed to loop through cached JSON data on the 1st click function and display any values that exist for a specific id. The 2nd change function captures when elements' values change (e.g., from yes to no). Since these elements a ...

Incorporate a fresh attribute to the JSON data in an Angular API response

I'm currently working on updating my JSON response by adding a new object property. Below is an example of my initial JSON response: { "products": [{ "id": 1, "name": "xyz" }] } My goal is to include a new object property ca ...

Convert your Node.js server URL hosted on AWS Elastic Beanstalk to HTTPS

Struggling to deploy my React JS app using AWS S3 bucket as I am new to the platform. The app communicates with a Node/Express server hosted on an Elastic Beanstalk environment. Encountered the error: Mixed Content: The page at 'https://myReactApp.s3. ...

Using module.exports and require() in JavaScript for front-end development

Recently, I've been exploring the possibility of utilizing a library like SVGO to clean up SVG code submitted by users directly on the front end. SVGO is primarily designed for node.js on the back end, so wrapping my head around the process of sending ...

Utilizing props and state within a function declaration in a class component: a guide

I am facing an issue with a class component that contains a function called printData(). I need to utilize the states and props variables of the class within this function. How can I achieve this? Here is a snippet of my code - class ReadData extends Comp ...

standalone visuals generated interactively with matplotlib

While I appreciate the plots generated by matplotlib and the ability to save them as SVG, there is a feature missing that I would like to see added... I am looking for a way to save the figure as an SVG file with embedded JavaScript code to add interactiv ...

Tips on preventing right-click actions in jqGrid

While utilizing onSelectRow in a jqGrid, I have noticed that it functions properly when clicking with the left mouse button. However, when right-clicking, it still triggers the function. My aim is for the right-click to perform its usual action (such as di ...

Ways to direct to dashboard if a user is logged in using AngularJS

As a newcomer to AngularJS, I am facing an issue with redirecting my page to the dashboard once the user has logged in. I receive an access token after login, which I save in cookies. Despite trying solutions from Stack Overflow, I have not been able to re ...

Utilizing dual identifiers in a Jquery plugin

I am currently working with a jQuery plugin and I need to apply the same functionality to two different IDs. How can I achieve this? It involves a next and previous functionality where clicking on the next button automatically scrolls both divs. The issu ...

What are the drawbacks of calling async/await within a fresh Promise() constructor?

I have implemented the async.eachLimit function to manage the maximum number of operations concurrently. const { eachLimit } = require("async"); function myFunction() { return new Promise(async (resolve, reject) => { eachLimit((await getAsyncArray ...

A function designed to detect errors based on the parameters supplied as arguments

In order to ensure secure access to my restful API, I am looking to implement an authentication function called "access". I would like the function to have the following structure whenever a user interacts with the server: access(id , token ,function(err) ...

Move the dropdown elements to align directly beneath the dropdown control for better organization

I have a dropdown control that is populated from a table. Here is the code: <tr> <td> <asp:Label ID="Label23" runat="server" Text="Escalation Reason"></asp:Label> </td> <td& ...

Binding in Angular JS seems to be having some issues

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap 101 Template ...

Can information be saved to a JSON file without using a server-side language?

Previously, I've come across questions where the recommended solution involves using a server-side language. However, since I don't have knowledge of a server-side language yet, I was curious to know if it's possible to achieve this with my ...

Revealing or Concealing a column with a Checkbox Toggle

Showing and Hiding Columns with Checkbox Selection DISCLAIMER: I have exhausted all available solutions before posting this question, as none of them have worked for me so far. I joined specifically because the existing solutions did not meet my needs. T ...