Using Three.js allows for the addition of multiple geometries simulataneously

Hey there, I'm new to Three.js and I'm facing an issue where my second geometry is not showing up. I've added the first geometry with all its materials to the scene successfully, but the second one seems to be missing. Any assistance would be greatly appreciated. Thanks in advance!!

// Setting up the Scene and Camera
var scene = new THREE.Scene(); 
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000);

// Renderer Initialization
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

// Adding the First Geometry with Material to the Scene
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
var cube = new THREE.Mesh(geometry, material);
scene.add( cube );

// Adding the Second Geometry with Material to the Scene
var mysphere = new THREE.SphereGeometry(5, 32, 32);
var color = new THREE.Color('#ee7800');
var hex = color.getHex;
var sphereMaterial = new THREE.MeshLambertMaterial( { color: hex } );
var sphere = new THREE.Mesh(mysphere, sphereMaterial);
sphere.position.y = 10; // Position adjustment
scene.add( sphere );

// Adjusting the Camera Position
camera.position.z = 5;

// Rendering and Animating the Cube
function render() {
  requestAnimationFrame( render );

  cube.rotation.x += 0.03;
  cube.rotation.y += 0.01;

  renderer.render( scene, camera);
};

render();

Answer №1

Could you please check if there are any error messages appearing in your console log?

var hexValue = color.getHex();

Remember, getHex() is a method that should be called accordingly.

Another approach could be:

var sphereMaterial = new THREE.MeshLambertMaterial( { color: 0xee7800} );

It seems like the constructor of Color doesn't match the standard format. It should look more like this:

var color = new THREE.Color( 0xee7800 );

Answer №2

The sphere is currently located at y=10, while the camera is positioned at y=0;z=5, causing the view of the sphere to be slightly from underneath. This results in the sphere being offscreen. Adjust the camera positioning by setting camera.position.z=30 to bring the sphere into the field-of-view.

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

Creating variable assignments based on object properties

I am facing a dilemma with a simple object that contains constants. { KEY1: "value1", KEY2: "value2" } I am looking for a way to make these constants accessible globally. Currently, I have to use Config.KEY1 to access the values globally, but I w ...

Unable to assign a scroll event delegation by using the "on" method

When attempting to delegate a scroll event in order for my element to maintain the same handler after being returned by an ajax call, I utilized the on method for delegation. $('body').on({ scroll:function(){ alert('scrolling&ap ...

What could be the reason for the malfunction of Twitter Bootstrap's typeahead feature in this case?

Struggling to implement typeahead.js into my current project. Despite having bootstrap loaded, the source code does not mention anything about typeahead. As a result, I included the standalone js file with hopes of making it work. Upon implementation, the ...

What is the best way to control the number of fetch calls sent to an endpoint service ensuring that only a maximum of 10 calls are made every second?

Is there a way to prevent the browser from encountering the "Error 429 Too Many Requests" by adjusting the code below to ensure that no more than 10 calls per second are made? Please note that the rate limit of 10 calls per second is set by a 3rd-party AP ...

Extracting the month and year from a datetime string: A simple guide

I am working with a JSON object that includes a field called Month with a string datetime value- { Month : "31-Jan-2022 12:00 AM (EST)" .... .... } Is there a way to extract the Month Name and Year from this string using JavaScript's dat ...

We encountered a problem while trying to create the route "/": Minification of HTML failed in Nuxt js

After successfully developing a Nuxt app that runs perfectly with "npm run dev," I encountered an error when generating the site using "npx nuxt generate." Despite my efforts, I cannot locate the source of the error. Any assistance would be greatly appre ...

The Google Maps API has been successfully initialized, however, it is experiencing difficulties being displayed on the webpage

I have been successfully using a custom Google API on various web pages. However, I encountered an issue where the map API loads successfully but is not displaying on a specific web page. Below are the relevant code snippets: <html> <head> &l ...

Send information from a web page's elements to PHP with the help of AJAX

My goal is to integrate AJAX, HTML, and PHP to create a seamless user experience. I am currently facing difficulty in passing variables to the PHP form. The method I've employed seems a bit complex, especially since this is my first attempt at using A ...

Tips for using NodeJS with a MySQL database

Hello everyone, I'm new to this community so please bear with me if my question seems too simplistic. I've been tasked with a basic web project for one of my courses and will be using NodeJS+MySQL along with VS Code which has caught my eye. Howe ...

Adding a character sequence to a parsed JSON object results in a literal string outcome

I have saved some currency information in the state manager of my app and here is how I am accessing it: For example, to retrieve the value of Euro against the dollar, I use the following code: JSON.parse(this.$store.state.clientSide.currencyrates).rates. ...

When a form is submitted in JQuery, it creates a fresh form on the

My current setup involves a JQuery script that sends user input to a PHP script within the same file. The PHP script processes this input and displays the results successfully. However, I have encountered a peculiar issue where upon submission, the JQuery ...

What is the best way to link a dynamic property with a bootstrap popover within a nested v-for loop?

After spending several days searching for an example to guide me without success, I am turning to SO with my specific use case. I am currently working on a Bootstrap Vue layout where I need to load dates into 12 buttons corresponding to months and display ...

A different approach for dynamically displaying React components sourced from an API

As I develop a website using Next.js/React that pulls in content from Strapi CMS, my goal is to create a dynamic page template for news articles. The aim is to empower content editors by giving them the flexibility to choose the type of content they wish t ...

Vue.js: Redundant CSS classes (CSS components) are created when importing the same CSS file

I am currently developing an App using Vue.js and CSS Components. Within my Vue components, I have noticed that some share similar styling. In my Hello.vue component: <template> <div :class="$style.title">Hello, World</div> </templ ...

What is the reason for the lack of user data being saved in studio3t?

I'm struggling to identify the issue in my app development process. I'm creating an application that collects user email and password, storing them in a database. The problem lies in the fact that while user passwords are successfully stored, the ...

Aggregate information from an array containing multiple nested arrays

With regards to marking this as answered by another question, please take note that this is not a flat array but an array of arrays. Additionally, the numbers provided are just examples for visual representation. I am attempting to iterate through an arra ...

Look through the contents of each child within a div to locate specific text, then conceal any that do not include it

I want to dynamically hide divs that do not contain the text I specify. Here is the code I have tried: var $searchBox = $('#search-weeazer'); $searchBox.on('input', function() { var scope = this; var $userDivs = $('.infor ...

Having trouble parsing bytes from a protobuf message in JavaScript

In my current project, I am faced with the task of encoding and decoding bytes within a protobuf message using Javascript. It seems that working with strings is functional, but once I introduce bytes in the message definition, retrieving the data becomes a ...

Is there a way to iterate through documents in Mongoose using NodeJS?

Two collections are being used here - Let's call them the main and sub collections. The main collection is structured as follows: { "_id" : "xxxxx", "subId" : "1234" } The sub collection has a different structure: { "_id" : "1234", "name" : ...

You have attempted to make an invalid hook call in the react chat app. Hooks can only be called within the body of a function component

Encountering problems like manifest.json:1 Manifest: Line: 1, column: 1, Syntax error. **Important Error Message/User Notification:** react-dom.development.js:20085 The above error occurred in the <WithStyles(ForwardRef(AppBar))> component: Arrange ...