The visibility of MeshPhongMaterial is currently not displaying

As a beginner in the world of THREE.js, I am attempting to create a sphere that will serve as the foundation for a globe with texture. However, I have hit a roadblock while trying to implement MeshPhongMaterial, as nothing seems to appear on the screen. On the contrary, when using MeshBasicMaterial, everything functions properly.

Below is the code snippet:

var mainScene, camera, aspect, renderer;

mainScene = new THREE.Scene();
aspect = window.innerWidth / window.innerHeight;

camera = new THREE.PerspectiveCamera(40, aspect, 0.1, 100);

renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);

var canvasContainer = document.getElementById("canvasContainer");
canvasContainer.appendChild(renderer.domElement);

var mesh = new THREE.Mesh(
  new THREE.SphereGeometry(0.5,32,32),
  new THREE.MeshPhongMaterial({
    color: 0x00ff00,
    wireframe: true
  })
);

mainScene.add( mesh );

camera.position.z = 5;

var render = function(){

        requestAnimationFrame(render);
    renderer.render(mainScene, camera);

        }

render();

I am uncertain about what may be causing this issue within the code and whether or not MeshPhongMaterial is the appropriate approach. Any guidance would be greatly appreciated.

Thank you

Answer №1

To use the MeshPhongMaterial, make sure you have scene lights set up.

One approach is shown below, but it's recommended to check out the examples provided in three.js.

// Set ambient light
scene.add(new THREE.AmbientLight(0xffffff, 0.1));

// Add a point light
var light = new THREE.PointLight(0xffffff, 1);
camera.add(light);

// Make sure to add the camera to the scene as well
scene.add(camera); // This is necessary because the camera has a child 

Using three.js version r.84

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

What could be causing the delay in Handlebars.js binding process after the initial run?

I'm facing a puzzling issue with my Handlebars.js template. Initially, it efficiently renders data into a table without any hiccups. However, subsequent runs take an unexpectedly long time (even with the same data!) and sometimes result in browser cra ...

Retrieving an array using the $.post() method

I am utilizing the following code: $.post('fromDB.php', function(data) { eval(data); console.log(data); updateTimer(); }); In order to retrieve arrays from PHP. This is what PHP returns: var todayTimeMinutes = [0, 45, 35, 25, 40, 0 ...

Guide on configuring the development environment with Node.js and AngularJS

Having trouble configuring AngularJS view in my Express JS build environment. Can anyone help me resolve this issue? 1: var express = require('express'); var http = require('http'); var path = require('path'); var favicon ...

Does the organization of files and directories (such as modular programming) impact the speed at which AngularJS loads?

Can breaking code into smaller modules help decrease loading time? Exploring ways to modularize AngularJS applications can lead to a well-structured approach for developing large apps. This approach aims to streamline the development process by organizing ...

What is the best way to bring a "subdependency" into ES6?

I am dealing with a situation where I have a package called react-router, which relies on another package called path-to-regexp. The challenge is that react-router does not provide its own import of path-to-regexp. So, I am wondering how I can import the e ...

Encountered unexpected character error while parsing JSON data

I am encountering the following error message: JSON.parse: unexpected character when I execute this code in firebug: JSON.parse({"balance":0,"count":0,"time":1323973673061,"firstname":"howard","userId":5383,"localid":1,"freeExpiration":0,"status":fals ...

Understanding the Use of Normal Maps in THREE.js

I've been struggling to implement normal maps in three.js without success. Despite finding related questions like Three.js Normal Mapping forcing mesh to not render and How to make a normal map in THREE.js correctly?, they haven't been helpful du ...

Using CSS3 keyframe animations to stop and remain on the final frame

I'm having trouble getting a CSS3 keyframe animation to stick at the last frame after it has completed. I thought setting animation-fill-mode to forwards would work, but it doesn't seem to be doing anything. .animatedSprite { .animation-nam ...

Angular 2 - Module 'ng-factory' not found

I am encountering an issue when trying to launch my clean UI theme using 'ng serve'. This is my first time working with Angular and I'm struggling to resolve this problem. Any assistance would be greatly appreciated. I have attempted re-inst ...

A Study on Particle Systems using THREE.js

While working on my particle System in THREE.js with SPARK.js, I have completed the necessary code for the system. However, I am facing an issue where nothing related to the Particle System is being displayed on the screen. Currently, I am trying to creat ...

When you switch to a different URL within the same tab, the session storage will be automatically cleared

My current web application is experiencing an issue with session storage. Whenever I navigate to a different URL within the same tab, it seems like the session storage is being cleared. Let me walk you through the situation: I initially store some data ...

AngularJS right-click menu

I need a context-menu directive that can provide information on the clicked element for proper reaction. Although I experimented with this module, I'm facing an issue in uniquely identifying the clicked element. This is hindering my ability to apply ...

Mysterious jQuery feature: Transform your top slider to slide in from the right side

My expertise lies in web design using Photoshop, while other programmers bring my designs to life. However, I've been considering taking on the coding part myself for a change with jQuery being outside of my comfort zone. This is my first project in w ...

Recording the $index value of dynamically included inputs

Check out my Plunker demo: http://plnkr.co/edit/sm3r4waKZkhd6Wvh0JdB?p=preview I have a dynamic set of form elements that users can add and remove. I am looking to include an 'id' property for each object in the form elements, corresponding to ...

Filtering data using Mongoose to send specific information

Having a bit of code here // Script for retrieving pokedex data app.get("/pokedex", function (req, res) { Pokemon.find(function (err, pokemon) { if (err) { console.log(err); } else { console.log(pokemon ...

Mastering the Art of Manipulating SkinnedMesh Bones in THREE.JS

Currently, I am immersed in a 3D project utilizing THREE.JS and endeavoring to animate a straightforward character reminiscent of Minecraft. To achieve this, I have exported the character from Blender (including bones) and then displayed it using THREE.JS ...

Gaussian blurring with react-three-fiber

I have been experimenting with adding Gaussian blur to a scene using GLSL shader code: uniform sampler2D tDiffuse; uniform int uKernel; uniform float uSigma; uniform vec2 uDirection; uniform float uStrength; uniform float uDirectionalResolution; varying ve ...

Deciphering JavaScript's Minus Equals Operator: What's the Significance?

Can you explain the significance of the minus equals symbol -= in the following code snippet? $('#wrapper').animate({ backgroundPosition: '-=2px' })(); Appreciate your help! ...

Are you initiating several Ajax requests simultaneously?

What is the best approach to updating multiple sections of a page using Ajax? I am working with two divs and two PHP files. My goal is to use jQuery Ajax to populate one div with data received from one PHP file and the other div with data from the second ...

Generating distinct identifiers for selected elements within the document - Mongoose

I'm working on a project using mongoose, and I'm having trouble generating unique IDs for specific elements within the document. Here's an example of what I'm struggling with: Document { _id: ObjectId(...), title: "Post Title" ...