ShadowCamera is absent in Three.js

I'm currently exploring the world of Three.js and experimenting with this demo code:

function init(){
  var scene = new THREE.Scene();
  var camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, .1, 500);
  var renderer = new THREE.WebGLRenderer();

  renderer.setClearColor(0xdddddd);
  renderer.setSize(window.innerWidth, window.innerHeight);
  renderer.shadowMap.enabled = true;
  renderer.shadowMapSoft = true;

  //Enable orbit controls
  controls = new THREE.OrbitControls(camera, renderer.domElement);
  controls.addEventListener('change', render);

  var axis = new THREE.AxisHelper(10);
  scene.add(axis);

  var grid = new THREE.GridHelper(50, 5);
  var color = new THREE.Color("rgb(255,0,0)");
  grid.setColors(color, 0x000000);
  scene.add(grid);

  var cubeGeometry = new THREE.BoxGeometry(5, 5, 5);
  var cubeMaterial = new THREE.MeshLambertMaterial({color:0xff3300});
  var cube = new THREE.Mesh(cubeGeometry, cubeMaterial);

  cube.position.x = 2.5;
  cube.position.y = 4;
  cube.position.z = 2.5;
  cube.castShadow = true;
  scene.add(cube);

  camera.position.x = 40;
  camera.position.y = 40;
  camera.position.z = 40;

  camera.lookAt(scene.position);

  var planeGeometry = new THREE.PlaneGeometry(30, 30, 30);
  var planeMaterial = new THREE.MeshLambertMaterial({color:0xffffff});
  var plane = new THREE.Mesh(planeGeometry, planeMaterial);

  plane.rotation.x = -.5*Math.PI;
  plane.recieveShadow = true;
  scene.add(plane);

  var guiControls = new function(){
    this.rotationX = 0.01;
    this.rotationY = 0.01;
    this.rotationZ = 0.01;

    ...
  
  

I'm having trouble getting the shadow camera to show up in my project. The light source is visible and functional, but the cube isn't casting any shadows onto the plane below it...

If you have any insights or suggestions on what I might be missing here, please let me know!

Thanks for your help!

Answer №1

It's always satisfying when a solution is already found, but frustrating when it's not marked as solved! :-)

I'll share the fix that resolved the issue – it turned out to be a typo in plane.receiveShadow = true;.

This piece of code seems to be inspired by a reference from this specific example (where the spelling is correct), which could be useful for anyone looking to understand lighting concepts.

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 does the "done" callback function entail in Node.js?

Many npm packages commonly utilize a "done" callback function in their code. I find it challenging to grasp its purpose. For instance: passport.serializeUser(function(user, done) { done(null, user.id); }); From what I can gather: The "done" function a ...

A common challenge in React is aligning the button and input line on the same level

I'm currently working on a React page where I have an input field and a button. My goal is to align the bottom edge of the button with the bottom line of the input. Here's the code snippet I have: `<form className='button-container'& ...

Node.js Error: The requested URL cannot be found

I have encountered an issue in my Node project where I am getting a 'Cannot GET/' error when trying to open localhost on port 8081. I suspect that the problem lies in correctly reading the HTML file, but I'm not entirely sure. var express = ...

What is the best way to display multiple quotes from my generator at once?

I'm seeking assistance with my quote generator. It functions correctly in JS Bin, generating the specified number of quotes when output to the console log. However, once integrated into an HTML page, it only generates one quote regardless of user inpu ...

Retrieve the list of users playing certain games using the start.gg API

Is there a way to retrieve all users from Smash Ultimate using the start.gg API? I couldn't find any information about fetching all users, only details about tournaments or specific player sets. You can access the API here: Thank you in advance for ...

How to properly structure an array in JSON format for utilizing in the Google Charts API?

Noticed that integer values need to be integers in the json, however I am using strings. The original array structure is as follows: '[{"sctr":"Asset Managers","amount":"1586500"},{"sctr":"Auto Parts","amount":"1618000"},{"sctr":"Business Su ...

IE page refresh causing jQuery blur to malfunction

Our website features a textbox with a watermark that appears and disappears based on focus and blur events in jQuery. However, we have encountered a unique issue with Internet Explorer browsers. Whenever a user clicks on the textbox, the watermark disapp ...

retrieving a URL with the help of $.getJSON and effectively parsing its contents

I seem to be struggling with a coding issue and I can't quite figure out what's wrong. My code fetches a URL that returns JSON, but the function is not returning the expected string: function getit() { var ws_url = 'example.com/test.js&ap ...

Determine the position of a relative element using jQuery and CSS, then adjust the position of the tooltip

I designed a map that displays different locations, and when you hover over each location, a tooltip appears next to the cursor with information about that specific spot. The map is used as a background image for the main ul element with an id of "map". E ...

Adjusting the background color of <tr> depending on the number of <tr> elements in the HTML using CSS

When working on my HTML page, I have utilized multiple <tr> tags with different bgcolor values such as: <tr bgcolor="#000000"> <tr bgcolor="#E5F1CC"> <tr bgcolor="#D30A0A"> <tr bgcolor="#656766"> I am aiming to assign unique ...

Having difficulty iterating through a JSON object in NodeJS

My NODEJS program utilizes xml2js to convert an XML file into JSON and parse it. However, when attempting to loop through the JSON object to display the ID and LastReportTime for each entry, I receive an output stating 'undefined'. Output 2015- ...

Locate and retrieve user data from MongoDB

Let me provide some context. I am transmitting a post along with the username and what he shared with me is shown in the log. console.log(req.body.username); // 'username' My question is, how can I utilize mongodb to locate and display a user w ...

What is the reason behind JavaScript's restriction on using double comparison operators?

What is the reason behind javaScript not supporting double comparison? For example, in 64 < str.charCodeAt(i) && str.charCodeAt(i)<=77, why is it not possible to simplify it to 64 < str.charCodeAt(i)<=77? ...

Executing PHP script simultaneously in the background with jQuery

I have a PHP script that performs time-consuming tasks in the background. All I want is to display a simple message to the user: "Command executed. Invites pending." The rest of the processing will happen behind the scenes in my .php file. I'm consid ...

Extract particular information from the JSON reply

When working with a JSON response in JavaScript, I use the following code to convert it to a string: var myObject = JSON.stringify(data); Although this code successfully prints out the results, I am having trouble extracting specific data such as myObjec ...

Exploring the dynamic duo of Django and DataTables: a guide on incorporating

Have you cautiously attempted to fetch data using AJAX, and displaying it in a datatable works seamlessly, but the issue arises when attempting to search or sort within the table. It seems that upon doing so, the data is lost, necessitating a page reload. ...

Common problems with handling foreign characters in Javascript JSON parsing

I am having an issue with parsing a valid JSON string containing Japanese characters. Every time I try to parse it, the process gets stuck on a specific character which is flagged as invalid. Below is the problematic string causing the error. Attempting t ...

D3 group of legendary elements

Is there a way to group both the circle and text elements for each legend item together? I'm currently facing a challenge with the enter/exit methods. While I can create the groups (g), I'm unable to append the text and circle elements. li.sel ...

Accessing new information seamlessly without the need for page refresh

For optimal mobile viewing of my website, I am considering implementing a select element. Here are the available options: HTML: <select name="select-choice-8" id="select-choice-nc"> <optgroup label="News"> & ...

Three.js: position the object at the center of the viewport

After successfully loading a 3D model using OBJLoader, I encountered an issue with the model's positioning. The model was originally created with a three-dimensional modeling software and converted to .obj format. Due to its absolute positioning, the ...