Selecting either "THREE.NearestFilter" or "THREE.LinearFilter" will result in the black plane

During my experimentation with the THREE.js library, I encountered a notification stating:

THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.

To address this issue, I made the following adjustment:

var groundGeometry = new THREE.PlaneBufferGeometry( 5000, 5000, 96, 96 );
var grassTexture = THREE.ImageUtils.loadTexture("images/grass.jpg");
grassTexture.minFilter = THREE.LinearFilter;//applying the filter here
var groundMaterial = new THREE.MeshBasicMaterial( {map: grassTexture, side: THREE.DoubleSide} );
var groundPlane = new THREE.Mesh(groundGeometry, groundMaterial);
scene.add( groundPlane );

Despite attempting another approach, all I ended up with was a black plane:

var groundGeometry = new THREE.PlaneBufferGeometry( 5000, 5000, 96, 96 );
var groundMaterial = new THREE.MeshBasicMaterial( {map: THREE.ImageUtils.loadTexture({image: "images/grass.jpg", minFilter: THREE.LinearFilter}), side: THREE.DoubleSide} );
var groundPlane = new THREE.Mesh(groundGeometry, groundMaterial);
scene.add( groundPlane );

Answer №1

The reason you are seeing a black plane in the second scenario is due to incorrect arguments being passed to THREE.ImageUtils.loadTexture(). Instead of passing an empty object {}, you should be using code similar to this:

var groundMaterial = new THREE.MeshBasicMaterial( { 
    map: THREE.ImageUtils.loadTexture( "images/grass.jpg" ),
    side: THREE.DoubleSide
} );
groundMaterial.map.minFilter = THREE.LinearFilter;

Although texture loading is asynchronous, it's unclear if that's the problem without reviewing more of your code.

Additionally, consider reducing the number of faces in your PlaneBufferGeometry. You can try something like this:

groundGeometry = new THREE.PlaneBufferGeometry( 5000, 5000, 1, 1 );

This advice applies to three.js r.71 version.

Answer №2

The download and availability of the texture for use may not align with your expectations.

In one scenario, the request for loading the texture happens asynchronously before later being assigned to a variable. This process might work by chance rather than design.

Alternatively, in another case, both downloading and assigning the texture occur simultaneously within a single statement, leaving little time for the texture to finish downloading.

To handle textures properly, it is recommended to follow this approach (adapted from )

var groundMaterial;
...
// initiate a loader
var loader = new THREE.ImageLoader();

// load an image resource
loader.load(
    // resource URL
    'images/grass.jpg',

    // Action upon successful loading of the resource
    function ( image ) {
        // By using this method, you ensure that the texture has finished downloading before utilizing it.
        groundMaterial = new THREE.MeshBasicMaterial( {map: image, side: THREE.DoubleSide} );
} );

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

Sending text content using AJAX

Recently, I've delved into the world of AJAX and JavaScript while working on a project in JSP. My goal is to submit text entered in a textarea using a JavaScript button. The first submit button worked fine initially, but upon posting, I ended up with ...

How can I use XPATH to target a div after choosing a nested element?

I had the task of creating a universal identifier to locate a dropdown menu following a label. There are 10 different forms, each with a unique structure but consistent format, which means I cannot rely on specific IDs or names. Instead, my approach was to ...

Ways to examine the origin of an image based on the attributes of a React component that I have passed as a prop?

I'm facing an issue where I can't use the component's prop to set the src of an image that I imported from a file path in my component's JavaScript file. I have tried different syntaxes but none seem to be working. Here are the formats ...

Generating separators in every third row using an array of card elements

https://i.stack.imgur.com/PIMR2.png Hey everyone, I'm working on creating a Divider for every row of 3 items. Currently, my setup only handles two sets of rows, but there could be an unlimited amount of rows that need this divider. I am using slice t ...

What is the best way to retrieve the length of a string from an element once it has been bound with Angular

I am currently working on a task that involves counting the number of characters within an element. However, the element contains bindings (e.g. {{data.username}}) and I need to determine the string length after the binding has been resolved. My initial a ...

Transferring user-selected values from JavaScript to a PHP file

When sending values from JavaScript to a PHP file, everything works smoothly when all the values are collected. Step1 functions perfectly as both fields are mandatory. However, in Step2, values are only sent when all the fields are selected. There are co ...

What is the process for reverting back to a previous version using n (Node Version Manager)?

After installing n(tj/n) to manage my node versions, I installed Node version 14.6 which automatically became the active version. When I tried to switch back using the n command, it only displayed the version I installed with n. Is there a way to switch b ...

Issue: The provider "tProvider" is not recognized in the Rails application using angularJS

Having trouble with AngularJS? I encountered an error when minifying my javascript that reads "Error: Unknown provider: tProvider <- t". Interestingly, disabling the minification fixes the issue. I've followed all the tips provided in http://docs.a ...

Function "Contains" not Present in Object

Upon executing the code provided below, I encounter the following error message. An issue has arisen: Cannot find function contains in object Is Patient Fasting?/# of Hours->Yes; 12 hours. Here is the snippet of my code: var i = 0; var tempF ...

AngularJS error: Cannot find provider for $scopeProvider due to $scope not being injected in the service

I've come across a puzzling issue while working with AngularJS and dependency injection that seems to be common among many developers. When I attempt to inject a service into a controller in my AngularJS app, I encounter an error stating: Unknown prov ...

Tips for recalling the display and concealment of a div element using cookies

My HTML code looks like this: <div id='mainleft-content'>content is visible</div> <div id="expand-hidden">Button Expand +</div> To show/hide the divs, I am using JQuery as shown below: $(document).ready(function () { ...

Issue encountered while attempting to start npm: Error code from NPM

I keep encountering the npm ENOENT error every time I attempt to execute npm start. I am unsure of what steps to take in order to resolve this issue. I have made efforts to adjust folder permissions. bryantcaruthers-> npm start npm ERR! code ENOENT npm ...

Troubleshooting problems with AJAX in WordPress

I have been attempting to transfer an array from PHP to JavaScript in order to display search results from a database. After converting the array into JSON format, I am facing difficulties in retrieving it. Despite having colleagues experienced in AJAX, we ...

Harnessing the power of lazysizes with WebP

I've been working on optimizing our site through the Google Lighthouse audit, and it's clear that images are a major focus. Right now, my main goal is to address the issue of 'Deter offscreen images' highlighted in the audit. To tackle ...

JavaScript still displaying empty values despite correct syntax being used

Here is the HTML form I have created: <form accept-charset="utf-8" onsubmit="return validateForm()"> <input placeholder="Enter Username" type="text" id="user"> <input placeholder="Enter Your Password" type="password" id="pass"> ...

What is the syntax for replacing specific letters within a JavaScript string using JavaScript?

When I print data from an external JSON file, I am seeing strange characters like "Ã Å, Ã ¤, Ã ¶" instead of "Å, Ä, Ö". The file seems to have the wrong encoding, but unfortunately, I cannot change it since it is from an API. Is there a simple s ...

Concentrate on the disappeared div element following the AJAX request

Encountering an unusual issue here that has me a bit puzzled. In one of my DIV elements, I have included several links which trigger an AJAX call (using jQuery) upon being clicked. The server (Controller) then responds with HTML content, specifically a JS ...

Material selection through span in three.js is not functional

Initially, the span element was functioning properly for me. However, after setting up materialsLib and initMaterialSelectionMenus based on the documentation and examples, the span stopped working and now the model is not visible. Any assistance would be g ...

Having trouble interacting with buttons using HtmlUnitDriver, but no issues clicking buttons with FirefoxDriver

I am currently facing an issue with my code that utilizes Selenium HtmlUnitDriver. While I am able to access the website and click on the "except cookies" button, I am encountering difficulties in clicking the "play demo" button. This is puzzling because I ...

The Arabic characters are not rendering correctly

As a beginner in html programming, I am looking to include Arabic text in my html file. I have added the following line containing Arabic text: <h1 dir="rtl">نص تجريبي لاختبار</h1> However, when I view the output, I am seeing u ...