The combination of subtracted geometries creates unusual lighting effects

When working with three.js, I have been experimenting with the concept of cutting out a window from a box geometry, which represents a wall. I came across a helpful csg (constructive solid geometry) extension on this GitHub repository.

After successfully cutting out the window, I noticed that the surface of the resulting geometry reflects light in a peculiar manner, as shown below.

var leftWallGeometry = new THREE.BoxGeometry( $scope.wall.width, $scope.room.height, $scope.room.depth);
var leftWallMesh = new THREE.Mesh( leftWallGeometry );

var leftWallBSP = new ThreeBSP( leftWallMesh );

var leftWindowGeometry = new THREE.BoxGeometry($scope.wall.width +10, 100, 100 );
var leftWindowMesh = new THREE.Mesh( leftWindowGeometry)

var leftWindowBSP = new ThreeBSP( leftWindowMesh );

var windowWallBSP = leftWallBSP.subtract( leftWindowBSP );
var result = windowWallBSP.toMesh( wallMaterial );
result.geometry.computeVertexNormals();

result.position.x = $scope.room.width / -2
result.position.y = $scope.room.height / 2
$scope.scene.add( result ); 

The material used for the wall is a MeshPhongMaterial with a repeated texture and bump map applied to it.

var wallTexture = new THREE.ImageUtils.loadTexture('img/wall_diffuse_0.jpg')
// wall bump texture
var wallBumpTexture = new THREE.ImageUtils.loadTexture('img/bump_1.jpg')


// repeate wall texture and wall bump texture
wallTexture.wrapS = wallTexture.wrapT = THREE.RepeatWrapping; 
wallTexture.repeat.set( 10, 10 );

wallBumpTexture.wrapS = wallBumpTexture.wrapT = THREE.RepeatWrapping; 
wallBumpTexture.repeat.set( 10, 10 );

var wallMaterial = new THREE.MeshPhongMaterial( { map: wallTexture, bumpMap: wallBumpTexture, bumpScale: 0.2} );

I am seeking advice on how to resolve this unusual light reflection issue or alternative methods to effectively cut windows from walls/boxes in three.js. Any suggestions would be greatly appreciated.

Answer №1

To achieve a smooth shading effect on the wall, adjust the Material setting to Flat Shading:

wallMaterial.shading = THREE.FlatShading;

Refer to the image below for a visual representation of a properly shaded wall:

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 Angular 2's dependency injection to inject several instances at once

I have developed an "Messages" injectable that serves as a service for fetching a user's messages. This class relies on a "Database" class to log in to the backend using the user's credentials. Now, I aim to create a test scenario where 2 users ...

Is there a way to automatically generate and allocate an identifier to an input field?

I've written the code below, but I'm having trouble figuring out if it's accurate. Specifically, I can't seem to access the text inputs that have been created by their respective id attributes. for (i=0;i<t;i++) { div.innerHTML=div. ...

Understanding the reasoning behind the back button

I am currently working on a project that requires implementing a back button functionality. Unfortunately, I am facing some challenges with it. While I have successfully created a back button that works, the issue arises when the user wants to edit the pre ...

Converting an array of objects into an array of Objects containing both individual objects and arrays

I am dealing with an object const response = { "message": "story records found successfully", "result": [ { "created_AT": "Thu, 13 Jan 2022 17:37:04 GMT", ...

How can we automatically redirect users to an external website based on their responses to a specific question in SurveyJS?

Within my SurveyJS json, I have a radiogroup question that prompts users to make a choice. If they select a specific option, I'd like to redirect them to a different page. Otherwise, I want them to continue with the survey. Is this achievable? (The s ...

Best practices for efficiently updating state in React components

Currently, I am in the process of learning React and trying to grasp its concepts by practicing. One exercise I decided to tackle involves deleting an element from an array when a user clicks on it in the UI. Below is the code snippet that I have been work ...

Incorporate JavaScript .js file into the webpage asynchronously to invoke a web service

JavaScript File: JScript.js function Helloworld() { $(document).ready(function () { $.ajax ({ type: "POST", url: "Default.aspx/Helloworld", contentType: "application/json; charset=utf-8", dataType: "json", a ...

How come my ajax function is not processing when the form is submitted?

Having an issue with validating a form where I need to check if a username is available before submission. Although all functions, including the PHP script for checking the username, are working properly, I'm unable to prevent the form from submitting ...

Using Props with jQuery in React Components: A Comprehensive Guide

I trust you comprehend this straightforward example. I attempted to modify the background color of my HTML element during initial rendering by managing it in a React Component with a touch of jQuery assistance. Here is the code within my React Component ...

React-Collapsible Compilation Error

Currently, I am working on a project that involves Spring and ReactJS. I am still new to front-end development. One of the tasks I am trying to accomplish is creating a simple accordion using "REACT-COLLAPSIBLE". The code I have written is quite straight ...

The selected value from the array in the scope model is not appearing correctly in the UI dropdown menu

I apologize for any linguistic errors in my communication. I have encountered an issue with the UI-Select select box while attempting to display data. Despite using a basic array, the ng-model value is returning as undefined. ...

What is the correct way to implement Axios interceptor in TypeScript?

I have implemented an axios interceptor: instance.interceptors.response.use(async (response) => { return response.data; }, (err) => { return Promise.reject(err); }); This interceptor retrieves the data property from the response. The re ...

Having trouble with the mouse trail code on codepen.io

I am currently attempting to integrate this specific CodePen sample into a Hugo template called Somrat Theme. I'm facing challenges in deciding where to place the HTML file; only the 'no cursor' section should go into style.css, and I need ...

What sets apart `Object.merge(...)` from `Object.append(...)` in MooTools?

This question may seem simple at first glance, but upon further inspection, the MooTools documentation for the 'append' and 'merge' methods appears to be identical. Here is the code snippet provided in the documentation: var firstObj ...

Conflict arises between Angular $scope and the file input type

I have been attempting to convert a file into a byte array using AngularJS. The conversion process is successful and I am able to add the byte code and filename to an array ($scope.FileAttachments). However, there seems to be an issue with ng-repeat not wo ...

Retrieve the selected option value from a dropdown menu when hovering or making a change within the same event

Apologies for my poor English. Is there a way to retrieve the value of a select box when a user either changes the select box or hovers over it with just one event? I attempted the following code snippet but it did not work as expected: jQuery("select[nam ...

"Encountering a problem with global variables in Nightwatch while running a for loop in Node.js

My current project involves using node, nightwatch, and selenium for automation tasks. I recently encountered a specific scenario that I need assistance with: Within my nightwatch setup, I have declared a global array as follows: Dev.js 'checkforLi ...

Generate a JavaScript function on the fly

I am looking for a way to dynamically bind a function to the .click() event of multiple divs in a loop. Once clicked, the function should hide the respective div. Despite my attempts, I have been struggling with losing reference to the div and unsuccessful ...

What is the proper way to utilize the "Long" type when declaring a schema in MongoDB?

Forgive my ignorance, but I am trying to achieve something like this: var mongoose = require('mongoose'); var Long = require("long"); var UserSchema = new mongoose.Schema({ id: Long(), name: String, completed: Long(), ...

Ways to personalize Angular's toaster notifications

I am currently utilizing angular-file-upload for batch file uploads, where I match file names to properties in a database. The structure of the files should follow this format: 01-1998 VRF RD678.pdf VRF represents the pipeline name RD represents the lo ...