G
G
greenline1112020-11-19 15:54:35
three.js
greenline111, 2020-11-19 15:54:35

Threejs not working locally?

On LAN, when opening index, nothing is a white screen, everything is fine on the host.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir, 2020-11-19
@Casufi

Works

V
Vladimir Korotenko, 2020-11-19
@firedragon

You need to understand that your script most likely receives data from somewhere, if you launched the page, then the console clearly wrote to you why you can’t use local files. So everything works, but you have an error. The node has a local server for these purposes.

A
Alexey P, 2020-11-19
@ruddy22

greenline111
The essence of your mistake: the browser does not understand your js.
You have a choice, though not much:
1. Include Webpack, Gulp + Babel, Browserify + Babel or something else that builds your project correctly.
2. Change your code like this:

<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
    <canvas id="app"></canvas>
    <script src="src/three.js"></script>
    <script src="src/index.js"></script>
  </body>
</html>

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

const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

It is better, of course, to go through the tutorial on the project website and deal with Webpack (or Roll-up ).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question