Hi,
I don’t understand why it doesn’t works…
Here my files :
// classes/player.js
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);
scene.add(this.mesh)
}
}
export default PLAYER;
and my main.js
import * as THREE from "https://threejs.org/build/three.module.js";
import
{
OrbitControls
} from "https://threejs.org/examples/jsm/controls/OrbitControls.js";
import
{
CSM
} from "https://threejs.org/examples/jsm/csm/CSM.js";
import
{
TWEEN
} from 'https://unpkg.com/three@0.125.2/examples//jsm/libs/tween.module.min'
import
{
PLAYER
} from "./classes/player.js"
console.clear();
const params = {
color_cube: 0xacaaad,
};
let m = {} // materials
let g = {} // geometry
let o = {} // objects
let s = {} // sounds
let startX, startY, my_latest_tap;
let scene, camera, renderer, container, controls; // what to see
let csm, csmHelper; // plugin to have shadows on huge scene
// // // TOUCH ACTIONS
function init_app()
{
init()
//CHANGE KEY TOGGLES
animate()
///////////////////////////////////////////////////////////////////////////////////////////
function init()
{
// init_minimal(this)
const random = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
scene = new THREE.Scene();
// pour avoir une couleur de fond dans le ciel
scene.background = new THREE.Color(0xf6ffb9);
scene.fog = new THREE.Fog(params.color_fog, 0, params.distance_fog);
// camera = new THREE.PerspectiveCamera(55, window.innerWidth / window.innerHeight, 0.01, 2000);
camera = new THREE.PerspectiveCamera(55, window.innerWidth / window.innerHeight, 2, 2000);
// for camera with mouse
// camera.position.set(10, 1, 10);
// for camera with controls
camera.position.set(40, 13, 40);
camera.rotation.order = "YXZ";
camera.rotation.y = -Math.PI / 2;
o.direction = new THREE.Vector3(0, 0, 0);
console.log(o.direction)
camera.getWorldDirection(o.direction);
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// document.getElementById("canvas").appendChild(renderer.domElement);
//Shadows
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
// ORBIT
controls = new OrbitControls(camera, renderer.domElement);
// controls.target.y = 5
// LIGHTS
var ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
g.cube = new THREE.BoxGeometry(2, 2, 2);
m.cube = new THREE.MeshPhongMaterial({
color: params.color_cube,
shininess: 100,
});
///////////////////////////////////////////////////////////////////////////////////////////
o.cube = new THREE.Mesh(g.cube, m.cube);
o.cube.castShadow = true
o.cube.receiveShadow = true
o.cube.outside = true
scene.add(o.cube);
let pl = new Player()
}
function animate()
{
requestAnimationFrame(animate);
///////////////////////////////////////////////////////////////////////////////////////////
camera.updateMatrixWorld();
renderer.render(scene, camera);
}
}
init_app()
my error is :
Uncaught SyntaxError: The requested module ‘./classes/player.js’ does not provide an export named ‘PLAYER’
Why ?