The issue with displaying the initial two objects in three.js

Why are the sphere and box geometries not showing up in my scene even though everything else seems to work fine? I'm new to three.js and suspect that there might be an issue with the render function or animation frame. I've tried adjusting materials, rotation, clear color, etc., but can't figure out why only the plane geometry is visible.

var renderer,
        scene,
        camera,
        myCanvas = document.getElementById('myCanvas');

    //RENDERER
    renderer = new THREE.WebGLRenderer({
      canvas: myCanvas,
      antialias: true,
    });
  renderer.setClearColor(0x000000);
  renderer.setPixelRatio(window.devicePixelRatio);        //device pixel ratio
  renderer.setSize(window.innerWidth, window.innerHeight);                //canvas size

  //CAMERA
  var camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 300, 10000)
  //SCENE
  var scene = new THREE.Scene();
  //LIGHT
  var light = new THREE.AmbientLight(0xffff, 0.5)
  scene.add(light);

  var light1 = new THREE.PointLight(0xffff, 0.5)
  scene.add(light1);

  //MATERIAL

  var material = new THREE.MeshLambertMaterial({
      color: 0xF3FFE2,
      lightMap: null,
      lightMapIntensity: 1,
      emissive: 0x000000,
      emissiveMap: null,
      emissiveIntensity: 1,
      specularMap: null
    });

  //GEOMETRY

  var geometry = new THREE.BoxGeometry(100, 100, 100);
    var mesh = new THREE.Points(geometry, material);
    mesh.position.z = -1000;
    mesh.position.x = -100;
    scene.add(mesh);


  var geometry2 = new THREE.SphereGeometry(50, 20, 20);
    var mesh2 = new THREE.Points(geometry2, material);
    mesh2.position.z = -1000;
    mesh2.position.x = 100;
    scene.add(mesh2);

  var geometry3 =  new THREE.PlaneGeometry(10000, 10000, 100, 100);
    var mesh3 = new THREE.Mesh(geometry3, material);
    mesh3.rotation.x = -90 * Math.PI / 180;
    mesh3.position.y = -100;
    scene.add(mesh3);

  //RENDER LOOP

  render();



      function render() {

        mesh.rotation.x += 0.01;
        mesh.rotation.y += 0.01;



        renderer.render(scene, camera);

        requestAnimationFrame(render);
      }

Answer №1

After testing out your code, I found that everything is working fine, although the two objects need to be designated as THREE.Mesh.

    var geometry = new THREE.BoxGeometry(100, 100, 100);
    var mesh = new THREE.Mesh(geometry, material);
    mesh.position.z = -1000;
    mesh.position.x = -100;
    scene.add(mesh);


    var geometry2 = new THREE.SphereGeometry(50, 20, 20);
    var mesh2 = new THREE.Mesh(geometry2, material);
    mesh2.position.z = -1000;
    mesh2.position.x = 100;
    scene.add(mesh2);

https://i.sstatic.net/T4jQ3.png

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 trouble updating state with useEffect in a React functional component

Currently, I am dealing with a React functional component that is calling an API to fetch data. The response from the API call is confirmed to be received successfully. My aim is to store this data in an array within the component's state so that it c ...

A guide to verifying a user's age using JavaScript by collecting information from 3 separate input fields

On page load, only the year input is required for users to fill in. The user can enter their birth year first without providing the month and day. Currently, I have a function that checks if a person is over 16 years old by comparing their birth year with ...

The latest update to the Server Stats code mistakenly changes the channel to "undefined" instead of displaying the total number

I've been working on a private bot for a specific server that displays server statistics and more. However, I've encountered an issue where every time a user joins or leaves the guild, the bot updates a channel with 'undefined' instead ...

Triggering Jquery event multiple times

I am using a jQuery datatable that gets populated with data from a database through an AJAX call when a user clicks on a load button. The data is displayed based on the date selected by the user in a datepicker. I have also added an export button to allow ...

Removing dropdown lists from input forms can be achieved without using jQuery by utilizing vanilla JavaScript

Looking to build a custom HTML/JavaScript terminal or shell. Interested in utilizing an input box and form to interact with JavaScript functions/commands. Unsure of how to eliminate the drop-down menu that appears after previous inputs. Pictured terminal: ...

Using Electron with Angular 2 and integrating PouchDB

I'm currently exploring the use of Angular2, PouchDB, and Electron for my desktop application. However, I've hit a roadblock when trying to integrate the PouchDB APIs with Angular2. Could anyone provide guidance on how to utilize the PouchDB APIs ...

Uploading files using Ajax in the Laravel framework

I am attempting to utilize ajax to upload a file in Laravel. $("#stepbutton2").click(function(){ var uploadFile = document.getElementById("largeImage"); if( ""==uploadFile.value){ } else{ v ...

Why is my client program not receiving a response from this socket.io server?

Currently, I am in the process of developing a trivia game where two users engage in answering questions with the winner being declared at the end. As part of this project, I have integrated socket.io to facilitate the exchange of answers. However, I have ...

The pre-set value in the search bar of the Google specialized search

Is it possible to pre-fill the search field with text when the Google Custom Search page is loaded using the standard copy and paste code (free with ads)? If yes, how can this be achieved? Below is the code snippet: <div id="cse" style="width: 100%;" ...

Every time I attempt to execute route.js in my API folder, I encounter a persistent 404 error

Project Structure: https://i.stack.imgur.com/qMF6T.png While working on my project, I encountered an issue with a component that is supposed to call an API function. However, it seems like the file is not being found. I have double-checked the directory ...

rearrangement of characters in a string (javascript)

I am currently working on a game where users have to guess a word by selecting the right symbol from the alphabet. When the user guesses correctly, the code is supposed to replace all placeholders with the correct character, but in the wrong order. var se ...

What is the solution to deselecting all other options when selecting one in an <input type='radio'>?

As a newcomer to Vue/Nuxt, I'm currently facing an issue with a group of radio inputs that do not unselect when another option is chosen. After some investigation, it seems like the problem may lie within this specific code snippet below. My focus is ...

Creating users or custom roles in MongoDB on a NodeJS server is not currently possible

I have been attempting to directly create users on my database through our Express server, utilizing MongoDB 3.4 for the backend. Below is the current code snippet from the server: const express = require('express'); const bodyParser = require(& ...

Issue with date comparison operator logic

Here's a simple JavaScript function I have: function checkTime() { var current = new Date(); var target = new Date('April 10, 2017 12:11:00'); if (current < target) { $('#modalnew').modal('show'); } els ...

Unable to assign value to this.name within a $scope function in AngularJS

After developing an AngularJS application using Skinny AngularJS Controllers, everything seems to be functioning correctly. However, I have encountered a problem with the $scope.submit method. I am trying to assign a value to this.name, and then retrieve i ...

JavaScript error occurring when trying to validate Ajax response

I am attempting to create a report using a dynamically generated form. The form loads successfully through XMLHttpRequest, but the validation for the form fields does not seem to be working. I have experimented with using eval() and found that it only work ...

Encountering a Laravel Nova issue where attempting to override a Vue component leads to a Vue warning: Error

Recently, I decided to incorporate a user guide into my nova using the following Vue Shepherd library. To make this work, I made some adjustments in the files within the nova directory. One of these changes involved renaming the file "webpack.mix.js.dist" ...

Troubleshooting Initialization Problem in Three.js Version r71

I encountered an issue: TypeError: undefined is not an object (evaluating 'data.initialized') Any tips on resolving this? I am currently working with three.js (r71), which has addressed the #5831 bug. ...

Ways to emphasize the current tab on the site's navigation bar?

Here's my question: I have a menu with different items, and I want to make sure that the active tab is highlighted when users switch to another page. I noticed that Stack Overflow uses the following CSS: .nav { float: left; font-size: 1 ...

Exporting a function to another class using the default export is a common practice

I'm working with two classes, Orders.js and api.js. In api.js, I need to invoke a function called ShowAlertWithDelay. However, due to the existence of a default export named mapStateToProps, I am unable to declare another export. Below is the code sni ...