Skip to content
Advertisement

my three.js scene is not rendering. not sure why

my main.js file contains :-

JavaScript

and my index.html :-

JavaScript

All that appears on my screen is :- [what displays on my browser][1] [1]: https://i.stack.imgur.com/PQmJu.png

I checked and my main.js file is definitely executing, but nothing is rendering on the screen

Advertisement

Answer

You have a few issues.

JavaScript

This would select elements with the class canvas, but your DOM has no such element. It does have an element with the type canvas and the ID globe, so that line should be one of the following:

JavaScript

Next,

JavaScript

As @Mugen87 points out, this should be

JavaScript

As you’ve written it, the renderer’s width is being set to the quotient, and its height (the missing second parameter) is being set to undefined, a situation that three.js has no handling for.

And,

JavaScript

rotateOnAxis is a function that takes a vector (the axis of rotation) and a scalar (the rotation angle) as its parameters. By assigning +0.01 to it, you’re simply replacing the function itself, not calling the function. If, for example, you want to rotate around the globe’s y-axis, you could use

JavaScript

Finally, the second call to renderer.render(...) (the one outside the animate() function) is unnecessary.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement