во всех примерах, которые я видел, использовалось «three.min. js» в теге сценария, но для добавления воды и солнечного света мне нужно добавить «three.module. js» с помощью оператора import (могу ли я сделать это без модуля?), но модуль показывает некоторую ошибку всякий раз, когда я заменяю THREE.Scene () на Physi js .Scene, поэтому скажите мне, как с этим бороться, вот код, который я написал
<script type="text/javascript" src="Physijs-master\Physijs-master\examples\js\three.min.js"></script>
<script src="Physijs-master\Physijs-master\physi.js"></script>
<?php header("Access-Control-Allow-Header: *") ?>
<div id="container"></div>
<script type="module">
'use strict';
import * as THREE from "./Javascript/three.module.js"
import Stats from './Javascript/three.js-master/examples/jsm/libs/stats.module.js';
import { GUI } from './Javascript/three.js-master/examples/jsm/libs/dat.gui.module.js';
import { OrbitControls } from './Javascript/three.js-master/examples/jsm/controls/OrbitControls.js';
import { Water } from "./Javascript/three.js-master/examples/jsm/objects/Water.js";
import { Sky } from './Javascript/three.js-master/examples/jsm/objects/Sky.js';
var container, stats;
var camera, scene, renderer, light;
var controls, water, sphere;
init();
animate();
Physijs.scripts.worker = "Physijs-master/Physijs-master/examples/js/ammo.js"
Physijs.scripts.ammo = "Physijs-master/Physijs-master/physijs_worker.js"
function init() {
container = document.getElementById( 'container' );
//
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
//
scene = new THREE.Scene() // if i replace it to Physijs.Scene , Module shows error
//
camera = new THREE.PerspectiveCamera( 55, window.innerWidth / window.innerHeight, 1, 20000 );
camera.position.set( 30, 30, 100 );
//
light = new THREE.DirectionalLight( 0xffffff, 0.8 );
scene.add( light );
// Water
var waterGeometry = new THREE.PlaneBufferGeometry( 10000, 10000 );
water = new Water(
waterGeometry,
{
textureWidth: 512,
textureHeight: 512,
waterNormals: new THREE.TextureLoader().load( 'media/waternormals.jpg', function ( texture ) {
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
} ),
alpha: 1.0,
sunDirection: light.position.clone().normalize(),
sunColor: 0xffffff,
waterColor: 0x001e0f,
distortionScale: 3.7,
fog: scene.fog !== undefined
}
);
water.rotation.x = - Math.PI / 2;
water.scale.x = 1000000
water.scale.y = 100000
scene.add( water );
// Skybox
var sky = new Sky();
var uniforms = sky.material.uniforms;
uniforms[ 'turbidity' ].value = 10;
uniforms[ 'rayleigh' ].value = 2;
uniforms[ 'luminance' ].value = 1;
uniforms[ 'mieCoefficient' ].value = 0.005;
uniforms[ 'mieDirectionalG' ].value = 0.8;
var parameters = {
distance: 400,
inclination: 0.49,
azimuth: 0.205
};
var cubeCamera = new THREE.CubeCamera( 0.1, 1, 512 );
cubeCamera.renderTarget.texture.generateMipmaps = true;
cubeCamera.renderTarget.texture.minFilter = THREE.LinearMipmapLinearFilter;
scene.background = cubeCamera.renderTarget;
function updateSun() {
var theta = Math.PI * ( parameters.inclination - 0.5 );
var phi = 2 * Math.PI * ( parameters.azimuth - 0.5 );
light.position.x = parameters.distance * Math.cos( phi );
light.position.y = parameters.distance * Math.sin( phi ) * Math.sin( theta );
light.position.z = parameters.distance * Math.sin( phi ) * Math.cos( theta );
sky.material.uniforms[ 'sunPosition' ].value = light.position.copy( light.position );
water.material.uniforms[ 'sunDirection' ].value.copy( light.position ).normalize();
cubeCamera.update( renderer, sky );
}
updateSun();
//
//
controls = new OrbitControls( camera, renderer.domElement );
controls.maxPolarAngle = Math.PI * 0.495;
controls.target.set( 0, 10, 0 );
controls.minDistance = 40.0;
controls.maxDistance = 200.0;
controls.update();
//
stats = new Stats();
container.appendChild( stats.dom );
// GUI
var gui = new GUI();
var folder = gui.addFolder( 'Sky' );
folder.add( parameters, 'inclination', 0, 0.5, 0.0001 ).onChange( updateSun );
folder.add( parameters, 'azimuth', 0, 1, 0.0001 ).onChange( updateSun );
folder.open();
var uniforms = water.material.uniforms;
var folder = gui.addFolder( 'Water' );
folder.add( uniforms.distortionScale, 'value', 0, 8, 0.1 ).name( 'distortionScale' );
folder.add( uniforms.size, 'value', 0.1, 10, 0.1 ).name( 'size' );
folder.add( uniforms.alpha, 'value', 0.9, 1, .001 ).name( 'alpha' );
folder.open();
//
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
var time = performance.now() * 0.001;
water.material.uniforms[ 'time' ].value += 1.0 / 60.0;
renderer.render( scene, camera );
}
// A json object to load
var json_load = new THREE.ObjectLoader()
json_load.load("Models/house.js",function(model){
model.scale.set(10,10,10)
scene.add(model)
},
function (xhr) {
console.log('progress : ' + xhr.loaded / xhr.total * 100) + '%'
},
function (err) {
console.log('error')
}
)
И ЭТО ОШИБКА, ПОЛУЧЕННАЯ ::