Issue with Phong material not responding to area light in a three.js.obj model

Trying to incorporate both a phong material and a shader area light onto my .obj model has proven to be problematic. I attempted using an array within Meshface material to load both materials, but the model vanishes completely when both are applied simultaneously.

The situation works fine when either one is used individually, but combining them seems to cause the issue. Is there any workaround for this problem?

Check out the DEMO here:

CODE:

// Area Light
var lightColor = 0xffffff;
var lightIntensity = 1;

var geometry = new THREE.PlaneGeometry(100, 50);

var material = new THREE.MeshBasicMaterial({
    color: lightColor,
    transparent: true,
    opacity: 0.7,
    side: THREE.FrontSide
});

areaLight = new THREE.Mesh(geometry, material);

// More code follows...

// The main problematic section of the code

var mats = [];
mats.push(new THREE.MeshPhongMaterial({
    color: 0x000000
}));
mats.push(material);
var faceMaterial = new THREE.MeshFaceMaterial(mats);



object4.traverse(function(child) {
    if (child instanceof THREE.Mesh) {
        if (child.material.name == "chandelier_Outside") {

            child.material = Black; // Using faceMaterial here causes the object to disappear
            child.castShadow = true;
            child.receiveShadow = true;
        }


    }
});
scene.add(object4);
});

// More code continues...

Area light reference:http://jsfiddle.net/hh74z2ft/1/

The desired outcome is similar to the image provided in the link below, where the chandelier should also be illuminated similarly to the torusknot while maintaining the phong characteristics (phongness).

[]2

Answer №1

Regrettably, it seems that the solution you suggested may not be feasible.

A material, among other things, dictates how a specific portion of a triangle will be shaded. Each triangle can only have one material assigned to it. Although there is the option of face-material for rendering different faces with different materials, ultimately each triangle still has only one material applied to it.

In three.js, there exists a concept called multiMaterial (refer to

THREE.SceneUtils.createMultiMaterialObject()
). However, this simply generates multiple meshes with identical geometry but different materials, resulting in each triangle being rendered twice - once for each material.

The issue arises when trying to integrate the AreaLight implementation with phong-material. The representation of light through shader-uniforms by AreaLight contrasts greatly with how phong-material functions. Even if you were to attach a phong-material to the object to achieve specular reflections, the phong-material wouldn't be able to interact with the area-light source as it lacks awareness of any lighting present in the scene.

To achieve the desired outcome, incorporating a specular term (the formula for calculating surface specular reflections) into the fragment-shader along with relevant uniforms for control is necessary. This is a complex task, especially concerning area-lights (if it were simple, three.js would already have included it).

However, ongoing advancements based on recent research are addressing this issue. You may find further insights by exploring this matter and viewing the associated demonstration. Additionally, a pull-request pertaining to this can be found here.

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

Having issues with importing images in Next.js using the Next Images package

Having trouble with importing images locally from the images folder. Error message: "Module not found: Can't resolve '../images/banner1.jpg'" https://i.stack.imgur.com/Dv90J.png Attempting to access images in ImagesSlider.js file at compo ...

Adjusting Media Queries according to the browser window's zoom level

Is there a way to detect the browser width dynamically? For instance, can I adjust the CSS styling based on zoom adjustments like ctrl + or ctrl -? By "box," I am referring to a perfectly square shape. So, when the browser width is 100%, I want a layout wi ...

Create a custom Angular directive that allows you to replace tags while inserting the template

I have created a custom directive that can take templates based on the attribute provided. Check out the Plnkr example JS var app = angular.module('app', []); app.directive('sample', function($compile){ var template1 = '<d ...

Instructions for utilizing a non-string reference without triggering flow errors

I've noticed that string refs are considered legacy in React. You can read more about it here: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md However, I am encountering a flow error in my component and I&apo ...

What is the best method to extract the URL from an iframe div element using jQuery or JavaScript?

I have a dynamic way of getting my URL source, as shown in the code below. Is it possible to retrieve the URL from within the gettingiframe div, which is located inside an iframe? Below is the code snippet: <div id="gettingiframe"> <iframe sr ...

Sending an AJAX request to a REST service in order to submit the information captured in an HTML form

<html> <body> <form method="POST"> <label>username</lable> <input id="username" name="username" type="text"> <label>emailid</lable> <input id="emailid" ...

A step-by-step guide on inserting a date into a MongoDB database using data from

I have a JSON file that contains an object with a date. How can I ensure that this date field is correctly inserted as a "date" data type in MongoDB? This needs to be achieved using Node.js. { "name": "Jeff Johnson", "email": "<a href="/cdn-cg ...

Generating random images using Javascript

I am facing some challenges while creating my first custom JavaScript function. My goal is to display three random thumbnails on my webpage by selecting images from a pool of options. However, I am encountering issues with duplicated images and handling s ...

Updating a nested object within an array in a ReactJs component

I am struggling with updating a nested object within an array in the state of my React application. My goal is to determine if an item already exists in the state based on its name. Here's what I'm aiming for: Add an item to the cart. If th ...

What are the applications of global variables in node.js?

global.test = "test"; console.log(global.test); //test but I want to accomplish this: console.log(test); //test without using: var test = global.test; Is there a way to achieve this? I am looking for a solution where any module in my project does not ...

Encountered an error when attempting to use 'appendChild' on 'Node': the first parameter is not the correct type. It was able to work with some elements, but not with others

I'm currently working on a script that utilizes fetch to retrieve an external HTML file. The goal is to perform some operations to create two HTMLCollections and then iterate over them to display a div containing one element from each collection. Here ...

Verify whether a div element is styled in a specific manner

Upon initial load of my website, if the page is maximized or in fullscreen mode, the comBrand div will have specific CSS properties applied. However, during a resize event, I use the .css() function to adjust the properties of this element so it doesn&apos ...

Default Value for Null in Angular DataTable DTColumnBuilder

What is the best way to define a default value in case of null? $scope.dtOptions = DTOptionsBuilder .fromSource('api/Restt/List'); $scope.dtColumns = [ DTColumnBuilder.newColumn('modi ...

Creating a row of aligned card components in React

Recently, I began learning React and successfully created a card component using Material UI. However, this time around, I'm attempting to create it using axios and map() methods. I expected the cards to be displayed in the same row horizontally, not ...

Setting the default selected option in Vue for an object

Can the v-model data be different from the default option in this scenario? data: function() { return { user: { usertype: {}, } } <select v-model="user.usertype" class="btn btn-secondary d-flex header-input"> <option v-for= ...

Is there a way to determine if a website is utilizing javascript?

Currently, I am in the process of developing a web scraping tool using beautifulsoup. Some of the websites I am targeting contain JavaScript elements that prevent me from using urllib3 efficiently. As a workaround, I have incorporated selenium into my sc ...

How to resolve undefined callback when passing it to a custom hook in React Native

I'm facing an issue with passing a callback to my custom hook: export default function useScreenshotDetection(onScreenshot) { useEffect(() => { ... onScreenshot(); ... }, []); } Strangely, the callback is not being detected ...

How can I create automated tests for a Vue.js Tailwind CSS application using Cypress?

As I review the Cypress.io docs, I notice that the examples on how to write tests heavily rely on class selectors. However, my TailwindCSS application consists of numerous small classes rather than the specific ones mentioned in the examples, making it cha ...

Scroll with Angular to Move Elements

Is there a way to convert this Jquery Code into an angularJs directive? http://jsfiddle.net/MMZ2h/4/ var lastScrollTop = 0; $("div").scroll(function (event) { var st = $(this).scrollTop(); if (st > lastScrollTop) { $('img').a ...

Tips for positioning a div relative to another div while controlling its z-index

Hey there, take a look at the image below https://i.sstatic.net/zYiaY.png The issue I'm facing is quite common - I have div 1 and div 2 visible in a loop, but divs 3 are hidden. When div 2 is clicked on, everything is great so far. However, what I wa ...