Is it possible to change the background color of a TextGeometry object in Three.js?

I am working with a THREE.js TextGeometry in my scene:

const loader = new THREE.FontLoader();
const linkToFont ='link-to-font';
let textGeo;
const self = this;
loader.load(linkToFont, function (font) {
  textGeo = new THREE.TextGeometry('Hello three.js!', {
    font,
    size: 0.3,
    height: 0.01,
  });
  textGeo.computeBoundingBox();
  const textMaterial = new THREE.MeshBasicMaterial({ color: 0xff0000 });
  const textMesh = new THREE.Mesh(textGeo, textMaterial);
  textMesh.position.set(-100, 0, 0);
  textMesh.updateMatrixWorld();
  self.addToScene(textMesh);
});

This code displays the text in red on the scene. I am interested in adding a solid "background color" to the area behind the text. Is there a way to accomplish this?

Answer №1

You are presented with 2 different choices:

  1. To paint the entire canvas one solid color, utilize scene.background to cover the entire canvas with the desired color using
    scene.background = new THREE.Color(0x9900ff)
    .
  2. If you prefer a more customized approach, create a plane behind the text with the specific background color using MeshBasicMaterial.

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

Why is the checkmark still displaying red when it should be showing as green?

Are you struggling with password strength on your website? I faced a similar issue where the checkmarks remained red despite my attempts to turn them green. If you want to change the checkmark color, here is some code that may help: document.getElementBy ...

When running npm install -g, the package is being installed into a global directory on

For a considerable amount of time, I have been working with node and npm. Now, as I embark on a more extensive project using these tools, I've encountered an issue. Whenever I execute 'sudo npm install -g', the installation is directed to &a ...

Limit the category to a specific subset of strings

Looking for a way to implement literal type restrictions without using type aliases: const foo = (a: 'string', b: 'string') => { } foo("123", "abc") // should fail foo("123" as 'string', "abc" as 'string') I pr ...

Prevent tooltip text from appearing when a button is disabled in an angular application

As a beginner in UI development, I have a requirement for my Angular application. I need to enable and disable a button based on certain conditions. The tricky part is that I want to display a tooltip only when the button is enabled. I have managed to chan ...

Issue with AngularJS $http not responding to ng-click after first call

My landing controller uses a service that initiates the $http call by default when the App loads. However, I need to pass parameters based on click events, so I implemented an ajax call on ng-click. The issue is that I keep receiving the same data on ng-c ...

Obtaining results from several observable requests within a function

A function is currently operational, functioning by setting a value in the component when called (user.userImage). getLoggedInUserPhoto() { this.adalService.acquireToken('https://graph.microsoft.com') .subscribe(token => { let header = ...

Using JSON to import categorical data from SQL into C3.js

I am currently working on creating dynamic column graphs in MVC by utilizing C3 Charts. Although I have successfully retrieved data from the database using AJAX/JSON, I am facing challenges in binding the X-Axis categories along with the Y-Axis coordinates ...

I need help figuring out how to increase the HTML h4 tag within an AJAX call. Whenever I try to debug, I keep getting values like h

<script> var pageUrl = "http://localhost:12152/Product.aspx"; window.onload = function () { var ncount = 0; ncount++; $("#callproceed").click(function () { alert("working"); $.ajax({ type: "POST", ...

Utilizing a function as an express middleware in a specific route

I've encountered an issue with my route where I have some messy code that I want to transform into middleware. However, the documentation provided by Express is a bit unclear and as a result, my code keeps throwing a 404 error. Is there a way for me ...

Determine the data type of a string without needing to convert it

Can you determine if a value is numeric without casting it? For example, how can you differentiate between 'abc' and '123' without converting them to a specific data type? While visually apparent that 'abc' is not numeric, t ...

The functionality of Bootstrap "tabs" and "navbar" seems to be malfunctioning within the electron environment

Bootstrap is being loaded using the following code: <script> let $ = require('jquery') ; </script> <script src="./bower_components/bootstrap/dist/js/bootstrap.min.js"></script> <script> ...

Guide on using javascript to alter a json structure

Recently, I discovered a method to manipulate a JSON file using JavaScript. Although I don't have any formal training in JavaScript, I understand that it is primarily utilized on web browsers. Can someone guide me on how to execute this script? I cons ...

Can items be conveniently stored in an MVC Controller?

Forgive me if this question seems trivial, but I am curious about the functionality and best practices involved. If the HomeController has a list as a field and one user adds to it, will that user see the updated list or will it remain empty? Furthermore, ...

I encountered an issue while trying to integrate react-alert into my React application. An Uncaught Error was thrown, stating that objects are not valid as a React

I encountered the following error: react-dom.development.js:14748 Uncaught Error: Objects are not valid as a React child (found: object with keys {$$typeof, render}). If you meant to render a collection of children, use an array instead. in Unknown (c ...

HighStocks should show categories instead of dates

The zoom function in HighCharts is what drew me to it initially. Everything was working perfectly until I encountered an issue that I can't seem to resolve. Here's my code snippet: http://jsfiddle.net/ma50685a/16/ $(function() { // Crea ...

Unable to access specific data from the JSON string retrieved from the backend, as it is returning a value of undefined

After receiving a JSON string from the backend, my frontend is encountering issues when trying to index it post using JSON.parse(). The indexed value keeps returning as undefined, even though it's a JSON object literal and not within an array. For th ...

The animation of a cube rotating to a different face is not functioning properly when using three.js

Why is my cube not animating when rotating to another face with the code below? How can I resolve this issue? new Vue({ el: '#app', data () { return { camera: null, scene: null, renderer: null, mesh: null, ...

Troubleshooting issue with jQuery validation functionality not functioning properly with select dropdown

My default validator settings include displaying a red error message when validation fails. However, it works on Input and textareas, but not on select. $.validator.setDefaults({ ignore: "", errorPlacement: function(error, element) { ...

Can you provide guidance on implementing structured data jsonLD in a Next.js 13 application's router?

I have been struggling to implement structured data in my Next.js 13 (app router) application and have not been able to find the correct method. The next-seo package is also throwing errors for me. When I tried using next-seo, I encountered this error: ...

Guide on merging paths in distinct modules within an Angular project

I am looking to merge two sets of routes from different modules in my application. The first module is located at: ./app-routing.module.ts import {NgModule} from '@angular/core'; import {Routes, RouterModule} from '@angular/router'; i ...