How can I modify the material and color of the result in Three.js CSG?

Upon creating a union of two meshes, I want to apply MeshLambertMaterial specifically on the object named 'result':

var lathe = new THREE.Mesh(latheGeometry);
var cube_bsp = new ThreeBSP( lathe );

var box = new THREE.BoxGeometry( 2,30,3);

var sub = new THREE.Mesh( box );
sub.position = new THREE.Vector3(0,0,19);
var substract_bsp  = new ThreeBSP( sub );
var subtract_bsp  = cube_bsp.union( substract_bsp );

var result = subtract_bsp.toMesh(); 
    result.rotation.x = Math.PI * -0.5;
    scene.add(result);

Currently, the resulting object has a plain random color after the union operation. However, I aim to achieve a white-colored object with LambertMaterial instead.

Images: https://i.sstatic.net/cJzUC.jpg

Answer №1

When utilizing the content, remember to include it during the ThreeBSP.toMesh() function:

subtract_bsp.toMesh( new THREE.MeshLambertMaterial( {color:0xFFFFFF} ) );

Alternatively, you can apply it after generating the mesh:

result.material = new THREE.MeshLambertMaterial( {color:0xFFFFFF} ) );

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

Shader utilizing alpha channel to conceal neighboring objects

I'm experimenting with a simple shadow shader that involves using a plane with a radial gradient shader for colors and alpha. Underneath this shadow, there is another plane with a linear shader. The overall background consists of a linear gradient fro ...

Is there a way to retrieve an array generated within a JavaScript loop?

I've been working on retrieving column values from a database and storing them in an array, but I keep getting an empty array as the result. function FetchData(query, db) { var resultArray = new Array(); db.transaction(function(tx) { tx.executeSq ...

What is the best way to correlate two arrays of strings with one another?

I am working with two sets of data: First Set: let training = [ "Z1,1545 John Doe,P1", "Z2,2415 Shane Yu,P2" ]; Second Set: let skill = [ "P1, Shooting", "P2, Passing", ]; I need to combine both arrays bas ...

Transform Array into JSON using AngularJS

My array consists of three elements var data = []; data["username"]=$scope.username; data["phoneNo"]=$scope.phoneNo; data["altPhoneNo"]=$scope.altPhoneNo; I need to send this data to the server in JSON format, so I used var jsonData = JSON.str ...

Ways to utilize this node.js module within a specific file

This is the third party node-js module I have created: var knox = require('knox') , Resource = require('deployd/lib/resource') , httpUtil = require('deployd/lib/util/http') , formidable = require('formidable') ...

Creating a universal function to handle setTimeout and setInterval globally, inclusive of clearTimeout and clearInterval for all functions

Is it possible to create a universal setTimeout and setInterval function with corresponding clearTimeout and clearInterval for all functions while passing values to them? The situation is as follows: 1. More than 8 functions utilizing setInterval for act ...

utilize jQuery to load webpage with an HTML dropdown element

Querying the Campaigns: // Getting the campaigns $campaigns = $wpdb->get_results( "SELECT * FROM tbl_campaigns ORDER BY campaignID DESC", OBJECT_K ); // Displaying the Cam ...

Unable to view Chart.js on the second tab

I'm currently working on two different charts for a project - a bar chart and a line chart. The bar chart is displayed on the first tab, while the line chart is on the second tab. Interestingly, the bar chart functions properly, and when I point the l ...

Tips for implementing lazy loading for a section of a template in Angular 2

I have an Angular 2 component that has several sub-components within it. Some of these sub-components are expensive to load and may not always be necessary, especially if the user doesn't scroll far enough down the page. Although I am familiar with l ...

The Typescript loop appears to be stuck and not moving through the

I have encountered a problem while trying to iterate through my array using foreach and forloop in an angular 8 application. Despite having 250 objects in the array, it is not iterating through any elements. I am unable to figure out what the issue could b ...

JavaScript - continuously update the image marked as "active"

I have a collection of 4 pictures that I want to rotate through in my web application. Each picture should have the "active" class applied to it, similar to when you hover over an image. .active, .pic:hover{ position: absolute; border: 1px solid ...

What is the best way to sort and organize this JSON data?

There is an array of JSON objects named events that contains fields such as eventId, eventName, and the date of the event. [{event1}, {event2}, {event3}]; The goal is to iterate through this array and filter out events that occur on the same day. The des ...

Javascript program to validate if the user input matches a single value in an array

Currently, I am working with an array: var something = ["1","2","3","4"] ; My plan is to prompt the user to select a number. If the chosen number matches any value in the array, I want to trigger a specific action. Here's my dilemma: How can I veri ...

Encountering a problem while trying to run npm publish with public access, error code E

I've encountered an issue when attempting to publish a scoped package on npm, where I consistently receive this error via the CLI: npm ERR! code E403 npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/@username%2fdynamic-ui-elements - Forbidd ...

Troubleshooting Nested jQuery Plugin Selector Problems

I'm looking to have the ability to nest one plugin inside another. However, my selectors seem too broad and are capturing elements within the nested plugin as well. For instance, consider the following HTML structure: <div class="my-plugin"> ...

Is client-side JavaScript executed prior to server-side JavaScript in AJAX?

I'm curious about how client-side code interacts with server-side responses. I have a lengthy and complex piece of code that triggers a function which in turn executes some server-side code using a HTTPRequest Object, returning a string to the calling ...

Whenever the state of a React component is modified, it does not automatically trigger a re

Currently, I am utilizing the React Infinite Scroller library to display a list of posts. Interestingly, my load more results function seems to be triggered three times, resulting in the update occurring thrice (verified through console.log). For renderi ...

Cannot retrieve Global variables when using chrome.tabs.executescript in Chrome 55

After recently updating Chrome to version 55.0.2883.75, I encountered an issue with my self-developed Chrome Plugin used for parsing HTML files. In the plugin, I utilize chrome.tabs.executescript to retrieve data from a background HTML page. Previously, I ...

"Need to remove all chosen selections within an ng-repeat loop? Here's how

var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.cars = [{ model: "Ford Mustang", color: "red" }, { model: "Fiat 500", color: "white" }, { model: " ...

Refresh State component following fetch using Redux

Greetings everyone, I'm currently in the process of learning React and Redux. I've encountered a challenge where I am unable to update the state of a specific container using Redux without resorting to a setTimeOut function due to the asynchronou ...