I seem to be having trouble visualizing the object within Three.js

Recently, I've been working on creating a portfolio using three.js. However, I'm facing an issue where the object is not appearing on the page and I can't figure out what's causing the problem in my code. Here's the project link: https://codepen.io/BernardoOlisan/pen/vYJmpVZ. Can someone help me identify the issue?

<h1>Three.js</h1>
<canvas id="bg"></canvas>

CSS

canvas {
  position: relative;
  width: 100%;
  top: 200px;
}

JS

// Main js for Three.js section work
import * as THREE from "https://cdn.skypack.dev/three";

const scene = new THREE.Scene();

const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

const renderer = new THREE.WebGLRenderer({
  canvas: document.querySelector('#bg'),
});

renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
camera.position.setZ(30);

renderer.render(scene, camera)

const geometry = new THREE.TorusGeometry(10, 3, 16, 100)
const material = new THREE.MeshBasicMaterial({ color: 0xFF6347 });
const torus = new THREE.Mesh(geometry, material);

scene.add(torus)

function animate() {
  requestAnimationFrame(animate);
  renderer.render(scene, camera);
}

animate()

Answer №1

There's a small mistake with window.ineerWidth

let camera = new THREE.PerspectiveCamera( 75, window.ineerWidth / window.innerHeight, 0.1, 1000 );

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 the reason behind the failure of Google Place API integration?

When I try to access the JSON data from the provided link, it works fine. However, when I integrate it into our project, there seems to be an issue. Link to JSON Data ...

What is causing the dysfunction of angular2 form when used with the HTML <form> tag?

Can someone explain the strange behavior of the <form> element in ng2 to me? I have noticed something odd and need some clarification :) To demonstrate, I have created a simple Plunker example at this link: https://plnkr.co/edit/vdrHJBNdd26y6YhPXTHD ...

Remove the JSON object by comparing IDs between two JSON objects in JavaScript or Node.js, deleting it if the ID is not found

let data = fetchData(); let anotherData = getAnotherData(); let result = data.reduce((accumulator, current) => { if (!accumulator[current.system.name]) { accumulator[current.system.name] = {}; } let detailsObject = {}; Object.keys(current. ...

What is the reasoning behind npm modules such as material-ui exporting both es6 and es5 files?

When installing several npm modules, such as @material-ui/core, I noticed that there are three different ways to import the same React component: import { AppBar } from '@material-ui/core' import AppBar from '@material-ui/core/AppBar/AppBar ...

How to integrate Microsoft Maps module with AngularJS

Incorporating the Microsoft.Maps.loadModule function within a directive for AutoSuggest functionality has posed an issue as the script loads asynchronously and my directive fires before the script is fully loaded. I am seeking assistance on how to effectiv ...

Executing a post request using axios

Having some trouble with a post request using axios and it's refusing to cooperate. Here is the specific request I need to make. This is what I attempted: await axios.post( 'https://api.searchads.apple.com/api/v4/campaigns/XXXX/adgroups/targ ...

Determining if an Object is Positioned at the Camera's Center Using ThreeJs

Is there a way to determine if a cylinder is positioned closer to the center of the camera in order to trigger an interaction? The cylinder essentially acts as a button. My initial thought was to use the frustum for this purpose, but I'm unsure how to ...

Discovering the key by its corresponding value in a JavaScript object

I am working with the following code snippet: const searchValue = 'XYZ'; const FIELD_MAP = { 'key1': [ 'SOME', 'THING' ], 'key2': [ 'ANOTHER_VALUE', &a ...

Difficulty arises in AngularJS Material when attempting to access the same object value using ng-model and ng-change

I'm working with angular-material and facing an issue with an md-switch element. The model of the switch is determined by a value in a JavaScript object. However, I want to avoid directly changing the object value when the user toggles the switch. Ins ...

Tips for deactivating dates in the jquery datepicker that correspond to entries in a MySQL database

Is there a way to disable dates directly from a MySQL database in jQuery Datepicker? It seems tedious to constantly update dates in JavaScript, so I'm exploring the option of storing future disable dates in the MySQL database and displaying them in th ...

Ensure that all input fields on the webpage are validated when clicked using jquery

Having just embarked on my journey with jquery, I am giving it my all. Within my asp.net mvc project, there is a page filled with x-editable inputs. I decided to create a simple button: <input type="button" class="btn btn-info" id=& ...

Promise not resolving when image onload event is not being triggered

Hello, I've encountered an issue while working with a promise and recursion within a loop. The problem is that the onload event never triggers, causing the promise not to resolve as expected. Could someone please review my code and point out any mist ...

Navigating through Ajax load selector

I am attempting to implement an 'infinite scroll' feature using Ajax (specifically utilizing Jquery's .load function). The function triggers successfully, but in cases where it works, it generates a large number of articles. To address this ...

Utilizing TranslateHttpLoader with a service URL in ngx-translate: A step-by-step guide

My goal is to retrieve translated text from a content management system by using a service URL. While using a JSON file has been successful, I am unsure of how to utilize a service URL for this purpose. The code below is what I have tried without success: ...

Concentrate on implementing Cross-domain Ajax functionality in Opera browser

For a unique and interesting browsing experience, try using Opera 9.62 to explore the nuances of cross-sub-domain JavaScript calls with Ajax. To understand this better, follow these instructions by placing three simple files on appropriate domains. foo.ht ...

Customizing date colors in JavaScript: A step-by-step guide

var active_dates1 = ["2017-04-02 00:00:00","2014-04-03 00:00:00","2014-04-01 00:00:00"]; $('.datePick', this.$el).datepicker( beforeShowDay: function (date) { for(let date1 of active_dates1){ if (date.getTime( ...

"Resizing issue with multiple Highcharts not being resolved after selecting a new option from

Is there a way to resize multiple Highcharts on a webpage by clicking a button? When attempting to update the last chart using a dropdown menu and then clicking the resize button, an error message stating Uncaught TypeError: Cannot read property 'refl ...

What is the best way to add a key to a JavaScript array while keeping it reactive in Vue.js?

If there's an array in the state: state: { users: [] }, Containing objects like: { id: 1, name: "some cool name" } To add them to the store using a mutator like users.push(user);, how can we ensure that instead of 0:{...}, it uses the ...

What steps should I take to resolve this unexpected issue with svelte?

Whenever I attempt to execute the application, an error is consistently displayed to me. Here is a screenshot of the error: https://i.sstatic.net/jfo3X.png This issue always arises on the initial import type line, regardless of the content or arrangement ...

Inside the Promise.then() function, iterate through the values using a for loop

I am curious about the behavior of promise.then() within a for loop in node.js. Consider the following code snippet: const arrayObject = [ { id: 1234, toto: 'abc' }, { id: 5678, toto: 'def' }, { id: 910, ...