我正在尝试用physijs开发一个项目。我遇到过这种类型的错误(来自mozilla firefox控制台):
我试图解决它但没有结果。这是我在physijs设置上的代码片段:
<script src="build/three.js"></script>
<script src="js/libs/physi.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script src="js/Detector.js"></script>
<script>
'use strict';
Physijs.scripts.worker = 'js/libs/physijs_worker.js';
Physijs.scripts.ammo = 'js/libs/ammo.js';
所有javascript文件都在js目录中,但Three.js构建文件(在build目录中)除外。我不知道我的代码中有什么问题,我只创建灯光,地面(遵循Physijs规则的复合形状)和一个包(我想要应用锥形扭曲的constaint但是由于以前的原因并不是工作)。
我甚至添加了用于初始化场景的代码(如果有错误的话):
function createScene() {
var container = document.getElementById( 'container' );
//stats = new Stats();
//container.appendChild( stats.dom );
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.x = 0;
camera.position.z = 17;
camera.position.y = 12;
//scene = new THREE.Scene();
scene = new Physijs.Scene;
scene.setGravity(new THREE.Vector3( 0, -10, 0 ));
renderer = new THREE.WebGLRenderer();
renderer.physicallyCorrectLights = true;
//renderer.gammaInput = true;
//renderer.gammaOutput = true;
renderer.shadowMap.enabled = true;
//renderer.shadowMapType = THREE.PCFSoftShadowMap;
//renderer.toneMapping = THREE.ReinhardToneMapping;
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
var controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.target.set( 0, 0, 0 );
controls.noPan = true; //disable panning of orbit control
controls.noKeys = true; //disable arrow keys of orbit control
controls.update();
window.addEventListener( 'resize', onWindowResize, false );
window.addEventListener( 'keydown', onKeyDown, false );
window.addEventListener( 'keyup', onKeyUp, false );
}
如何解决此问题并正确导入Physi.js?
答案 0 :(得分:0)
已解决我使用了本地网络服务器(Three.js's reference)并对此进行了更改:
Physijs.scripts.worker = 'js/libs/physijs_worker.js';
Physijs.scripts.ammo = 'ammo.js';