Just for clarification: This runtime error happens since your import three.js
as an ES6 module. That means the resulting THREE
namespace is not available in the global space (and hence not in your Player
class). Try the following:
- Implement your
Player
class as an ES6 module like so:
import * as THREE from "https://threejs.org/build/three.module.js";
class Player{
constructor()
{
this.geom = new THREE.BoxGeometry(2,2,2);
this.mat = new THREE.MeshPhongMaterial({
color: 0xfffff,
});
this.mesh = new THREE.Mesh(this.geom, this.mat);
}
}
export default Player;
- Import the
Player
class inmain.js
like so:
import Player from `./classes/player.js`;
- Remove the obsolete import in your
index.html
:
<script src="js/classes/player.js"></script>