Shiny Exterior using ThreeJS

Trying to achieve a realistic metallic appearance in ThreeJS has been a challenge for me. Despite knowing that I should be using the MeshPhongMaterial material type, I am struggling to configure it properly.

My current implementation only results in a plain black surface:

var material = new THREE.MeshPhongMaterial({ 
    color: 0xBCC6CC, 
    shininess: 30,
    metal: true,
    wrapAround: true,
    shading: THREE.FlatShading
});

If anyone can provide guidance on what each parameter of the MeshPhongMaterial signifies to someone with limited knowledge of 3D graphics, I would greatly appreciate it.

Answer №1

The Phong Shading technique creates a smooth shading effect by interpolating the normal vectors at the vertices of your vector graphics. Each corner has a direction vector pointing to where the surface is facing, and by interpolating these directions, the surface appears "smooth" even if made up of quads or triangles.

For more information on Phong shading, visit this link.

If you are manually constructing geometry, remember to calculate Face Normals for Phong shading using:

geometry.computeFaceNormals();

When building meshes manually, you can also specify normals in the face constructor like:

var face = new THREE.Face3( 0, 1, 2, normal, color, 0 );

To achieve a metallic look with specular reflection, add point lights close to the surface. Learn more about lighting options here: PointLight, SpotLight, DirectionalLight.

Experiment with different parameters such as shininess, metal, and wraparound to control how light interacts with the surface material. Adjusting these values can create various effects on the rendered object.

If you want to dive deeper into the implementation details, check out the source code of the Fragment shader used by WebGL in Three.js: lights_phong_fragment.glsl.

While the documentation focuses on PointLight, SpotLight, and DirectionalLight affecting MeshPhongMaterial, keep in mind that Diffuse and Ambient lights also play a role in determining the final appearance of the surface.

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

The absence of req.body in the app reflects an undefined state

I'm encountering an issue with my app and I believe showing you my code is the best way to explain the problem: var Meetup = require('./models/meetup'); module.exports.create = function (req, res) { var meetup = new Meetup(req.body); c ...

The trim() method in Vue.JS does not properly handle trimming a passed string

I've been attempting to eliminate white space from a property of one of the returned objects using the .trim() function, but it's not working as expected. Even after trying JavaScript functions like .replace(/\s/g,''), the issue p ...

When utilizing CKEditor in conjunction with ExpressJS, HTML tags may be displayed in the browser

Check out my app.js code below: <!DOCTYPE html> <html lang="en> <head> <meta charset="UTF-8> <meta name="viewport" content="width=device-width, initial-scale=1.0> <meta http-equiv="X-UA-Compatible" content="ie= ...

Guide on uploading a file to Pinata directly from a React application

I keep encountering the 'MODULE_NOT_FOUND' console error code. Displayed below is the complete console error: > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f4b4d564b5a4d4d5e4c1251505b5a7f0e110f110f">[email& ...

What is the process for including a scope in an Angular.js HTTP controller?

I am looking to access a $scope variable within this controller in order to utilize Angular functions like ng-click and ng-change in my HTML. Currently, I am only able to use the $http function but unable to execute any Angular methods on it. I am struggli ...

The left and right arrows maintain their visibility even when they are outside of the image

I am a beginner in the world of web development and I am trying to implement left and right navigation for images using arrows. My goal is to have the arrows fade in when the mouse hovers over the image and fade out when it's moved away. However, I am ...

ReactJS modal close event

I am looking for a way to automatically close my modal after a certain period of time. Here is what I have tried so far: import React from 'react'; import IconcloseModal from './../../assets/icon/icon-cerrar-modal.png'; import './ ...

I'm wondering why myDivId.toggle() is functioning properly but myDivClass.toggle() is not working as expected

Using JQuery's toggle() function, I have been able to hide and show some DIVs successfully. Recently, I discovered relationships between certain DIVs that allowed me to group them into a class. I decided to try toggling the entire class rather than ...

Insufficient Resources Error (net::ERR_INSUFFICIENT_RESOURCES) encountered while executing jQuery script with multiple ajax requests for 2 minutes

Upon initially loading the code below, everything seems to be functioning smoothly with the dayofweek and hourofday functions. However, shortly thereafter, the browser (Chrome) freezes up and displays the error message: net::ERR_INSUFFICIENT_RESOURCES. Thi ...

What could be the reason for my Three.js file displaying only a blank white screen on the live server?

I encountered an error in the browser console that reads, --Uncaught TypeError: Failed to resolve module specifier "three". Relative references must start with either "/", "./", or "../".-- As a beginner in threejs, ...

Using AngularJS to Apply a Class with ng-repeat

Using ng-repeat in my markup, I am trying to add text to each li element and also include an additional class (besides the 'fa' class). This is what I have done so far: <ul class='social-icons' ng-repeat="social in myCtrl.socialArr" ...

Turn off auto-suggestion feature on the iPad and iPhone keyboard using JavaScript

I'm facing a challenge where I want to turn off the predictive suggestions and autocorrect feature on the iPad keyboard. This image is just for display purposes and not from my actual project. I need to hide the highlighted suggestion bar, and I am u ...

I've been attempting to relocate a CSS element at my command using a button, but my previous attempts using offset and onclick were unsuccessful

I am trying to dynamically move CSS items based on user input or button clicks. Specifically, I want to increment the position of elements by a specified number of pixels or a percentage of pixels. Currently, I am able to set the starting positions (top a ...

Using AngularJS UI Bootstrap tooltips in conjunction with Bootstrap 4: A complete guide

When using the directive <div uib-tooltip="hello-world" tooltip-is-open="true">hello world</div>, an error occurs: Failed to load template: uib/template/tooltip/tooltip-popup.html This website is utilizing both ui-bootstrap.js and ui-bootstra ...

Executing a function after a subscriber has finished in Angular 8+

Welcome fellow learners! Currently, I am diving into the world of Angular and Firebase. I am facing an interesting challenge where I fetch ticket data from my collection and need to add new properties to it. However, the issue arises when my ordering funct ...

Issues arise when jQuery functions do not execute as expected within an "if" statement following

Recently, I delved into the realm of AJAX and embarked on a journey to learn its intricacies. Prior to seeking assistance here, I diligently scoured through past queries, such as this, but to no avail. Here is an excerpt from my code: $('.del'). ...

Waiting for the forEach loop to complete

One of my express endpoints has a functionality that includes checking the availability of domain names against GoDaddy's API. However, I am struggling with how to properly await the results. My code currently iterates through an array called tlds an ...

Is there a way to apply toggling and styles to only the card that was clicked in Vue.js?

DisplayBooks.vue consists of a single page responsible for showcasing books fetched from a backend API. Each card on the UI features two buttons - ADD TO BAG and ADDED TO BAG. When a user clicks on the ADD TO BAG button of a specific card, it should toggle ...

Develop a regular expression tailored for jQuery validation purposes

I'm working with jQuery validation in my web form and I need to validate a text field with specific criteria: 1. Must contain a number. 2. The letters 'a' or 'A', 'b' or 'B' are allowed after the number. 3. Th ...

Optimizing Style Inclusion Order with Vue SFC, vue-loader, and webpack

My Vue/SFC/webpack/vue-loader application integrates bootstrap using 'import', with component styles directly included in the SFCs. However, vue-loader always places bootstrap after the component styles, preventing proper overwrite/cascade over b ...