Animation in Three.JS not visible in Chrome version 61 on Mac OS X Sierra

I've been going through some beginner tutorials for three.js and I'm facing an issue where I only see a red background when I try to run the code I created in Atom on Chrome (Version 62.0.3202.75 (Official Build) (64-bit)), Mac OS X (macOS Sierra, Intel Iris Plus Graphics 640 1536 MB). However, when I download and run the exact same code from a tutorial located in

Downloads>threes_js_basic>index.html
, it works fine. It's confusing because the code seems correct as I can see it using "View Page Source" in Chrome.

I have tried running the code through a local server following advice from this link without success. I made sure that WebGL is enabled and even installed a cross-origin resource sharing extension.

The code snippet below is directly copied from the tutorial that I downloaded and pasted into Atom. You can find the original tutorial link here: Tutorial Link

<html>
<head>
<title>threejs - basic</title>
<style>
    body{
        margin: 0;
        overflow: hidden;
    }

    canvas{
        background: red;
    }

</style>
</head>
<body>

<canvas id="myCanvas"></canvas>

<script src="three.js"></script>
<script>

    //RENDERER
    var renderer = new THREE.WebGLRenderer({canvas: document.getElementById('myCanvas'), antialias: true});
    renderer.setClearColor(0x00ff00);
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setSize(window.innerWidth, window.innerHeight);

    //CAMERA
    var camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 3000);
    // var camera = new THREE.OrthographicCamera(window.innerWidth / -2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / -2, 0.1, 3000);

    //SCENE
    var scene = new THREE.Scene();

    //LIGHTS
    var light = new THREE.AmbientLight(0xffffff, 0.5);
    scene.add(light);

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

    //OBJECT
    var geometry = new THREE.CubeGeometry(100, 100, 100);
    var material = new THREE.MeshLambertMaterial({color: 0xF3FFE2});
    var mesh = new THREE.Mesh(geometry, material);
    mesh.position.set(0, 0, -1000);

    scene.add(mesh);


    //RENDER LOOP
    requestAnimationFrame(render);

    function render() {
        mesh.rotation.x += 0.01;
        mesh.rotation.y += 0.01;
        renderer.render(scene, camera);
        requestAnimationFrame(render);
    }
</script>

Answer №1

An issue arose due to the absence of including this code in <head>:

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.min.js"></script>

I didn't come across this specific link in any other tutorials, so it might have been downloaded before recording or mentioned elsewhere in the tutorial and I overlooked it.

Credit to @2pha for suggesting that I check the console - I wasn't aware of this feature in Chrome. Much appreciated!

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

Tips for preserving scroll location on Angular components (not the window) when navigating

My current layout setup is like this: https://i.sstatic.net/hOTbe.png In essence <navbar/> <router-outlet/> The issue I'm facing is that the router-outlet has overflow: scroll, making it scrollable (just the outlet section, not the ent ...

Creating a dynamic JSON array with a single key as an array

After converting data from an excel sheet into a json array, here is the structure: [{ 'booktitle': 'Leading', 'bookid': '56353', 'bookauthor': 'Sir Alex Ferguson' }, { 'booktitle&ap ...

Add a click event listener to the body element using a button click, without causing it to trigger

What is the current situation: A button is clicked by the user The menu opens (list items display = block) The function to close the menu is connected to the <body> The function to close the menu is immediately triggered, causing the menu to close ...

Ensuring User Input Integrity with JavaScript Prompt Validation

I need help with validating input from a Javascript prompt() in an external js file using HTML code. I know how to call the Javascript function and write the validation logic, but I'm unsure how to handle the prompt and user input in HTML. Do I need ...

Validating date and time picker pairs using JavaScript

I am looking to implement start and end date validation using datetimepicker. My current code is not functioning as expected. I need the end date to be greater than or equal to the start date, and vice versa. If anyone has a solution for this issue, plea ...

Trigger the restart of a jQuery function once the condition within it is satisfied

I have a payment page with various payment options displayed. If the selected payment option is 10, a list of banks that support that payment option is shown. When a bank is clicked from the dropdown list, I generate a button with the corresponding paymen ...

Guide on activating an event when a slider image is updated using jquery

I am working on a project that includes a slider. I have been trying to trigger an event when the slider image changes, but so far using the classChange Event has not been successful. Here is the link to my code: [1] https://codepen.io/anon/pen/gzLYaO ...

Error: Unexpected syntax error encountered in the form of T_FOR

I'm currently working on building an HTML form that includes a dropdown menu. Check out the code snippet I have below: $output[]='<td><select name="qty'.$name.'">' for($count=1;$count<=$total;$count+=1) { &apo ...

Creating a default homepage across various HTML files using Google Apps Script and deploying it as a WebApp

Is there a way to set a default main page on multiple HTML and GS files in Google AppScript? I plan to publish it as a Web App. Have you attempted using the doGet function? ...

Discover the hidden truth: Unveiling the enigma of React

I'm currently learning React and I've been working on some apps to enhance my skills and deepen my understanding. Right now, I am facing a challenge where I need to incorporate the logged user information into the Redux state. However, whenever I ...

Keeping the header fixed on a sticky div (tocbot)

While working on my website, I decided to implement a Table of Contents section using tocbot. However, I encountered an issue where the Title I added above the table doesn't stay fixed when scrolling. https://i.stack.imgur.com/vCm1K.gif Here's ...

What steps should I follow to create a Lunr search functionality for Markdown MD files?

Currently, I am in search of a suitable lunr search implementation for my MD (Markdown) documents spread throughout my React/NextJS website. Our website contains a plethora of Markdown docs within both blog and regular "docs" sections, necessitating a robu ...

The sub-menu positioning feature functions properly in Chrome and Safari, but is not compatible with Internet Explorer and Firefox

Working on a website for a gaming community, known as http://www.quad-gaming.com/. All is running smoothly except for the dropdown menu under "Login" on the right side of the navigation bar. It behaves properly in Chrome and Safari, but in IE and Firefox, ...

"Utilizing JSON data to generate a visual representation through a chart

I am attempting to generate a graph in chart.js by utilizing data extracted from an SQL database using python. My current approach involves creating a JSON file in python and then loading it in javascript (although I am uncertain if this is the most optima ...

The el-dialog is functioning properly, however, I am looking to add CSS that will animate it to open

I've set up a dialog to open on button click, and it's functioning correctly. My goal is to have the dialog open from the bottom with a height of 300px, show the contents inside it, and then hide when I click outside or inside any element. Here ...

The encoding for double quotation marks vanishes when used in the form action

I am attempting to pass a URL in the following format: my_url = '"query"'; when a user clicks on a form. I have experimented with encodeURI and encodeURIComponent functions as well as using alerts to confirm that I receive either "query" or %2 ...

Setting the width of a div element dynamically according to its height

Here is a snippet of my HTML code: <div class="persoonal"> <div class="left"></div> <div class="rigth"></div> </div> This is the CSS code I have written: .profile { width: 100%;} .left { width: 50%; float: le ...

What are the steps for creating a new npm package based on an existing one?

I'm a newcomer to the node ecosystem and the npm package system. In my redux/react web app, I currently make use of the photoswipe package alongside react-photoswipe. Recently, I decided to extend the functionality of the photoswipe package by making ...

"Effortlessly create a disappearing effect for your Bootstrap modal: Fade in upon opening, and instantly

When it comes to Bootstrap 3 modals, I have a question regarding the fade effect. On my outer modal div, I am using class="modal fade" to achieve the default fade in/out effect. However, what I really want is for the modal to fade in when opened, but disap ...

how to assign a value to a field automatically in PHP

Is it possible to send values such as name, email, and contact number from one URL like to another URL at ? I would like these values to be automatically displayed on the form of the target URL (http://www.otherurl.com/test.php). I do not have access to ...