Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Three.js+;Physi.js--can';我没有重力_Javascript_Physics_Three.js - Fatal编程技术网

Javascript Three.js+;Physi.js--can';我没有重力

Javascript Three.js+;Physi.js--can';我没有重力,javascript,physics,three.js,Javascript,Physics,Three.js,我一直试图用自己的风格重写其中一个Physi.js示例,但我似乎无法让它真正使用重力。渲染循环像应该的那样不断触发,但似乎没有任何变化 我已经上传了我在这里的内容: 这是Physi.js示例: 这是我的密码: var ground = {}, box = {}, boxes = [], ground = {}, projector, renderer, scene, light, camera, render, gr

我一直试图用自己的风格重写其中一个Physi.js示例,但我似乎无法让它真正使用重力。渲染循环像应该的那样不断触发,但似乎没有任何变化

我已经上传了我在这里的内容:

这是Physi.js示例:

这是我的密码:

var ground = {},
    box = {},
    boxes = [],
    ground = {},
    projector,
    renderer,
    scene,
    light,
    camera,
    render,
    gravity;

// Set things up for Physijs
Physijs.scripts.worker = 'physi.js_worker.js';
Physijs.scripts.ammo = 'ammo.js';

// Projector
projector = new THREE.Projector;

// Renderer
renderer = new THREE.WebGLRenderer({
    antialias: true
});
renderer.setSize( 1000, 600 );
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;

// Scene
scene = new Physijs.Scene;

// Camera
camera = new THREE.PerspectiveCamera( 35, ( 1000 / 600 ), 1, 1000 );
camera.position.set( 60, 50, 60 );
camera.lookAt( scene.position );

scene.add( camera );

// Light
light = new THREE.DirectionalLight( 0xFFFFFF );
light.position.set( 20, 40, -15 );
light.target.position.copy( scene.position );
light.castShadow = true;
light.shadowCameraLeft = -60;
light.shadowCameraTop = -60;
light.shadowCameraRight = 60;
light.shadowCameraBottom = 60;
light.shadowCameraNear = 20;
light.shadowCameraFar = 200;
light.shadowBias = -0.0001;
light.shadowMapWidth = light.shadowMapHeight = 2048;
light.shadowDarkness = 0.7;

scene.add( light );

// Ground
ground.material = new THREE.MeshLambertMaterial({
    color: 0xDDDDDD
});
ground.material = Physijs.createMaterial( ground.material, 0.8, 0.4 );
ground.geometry = new THREE.CubeGeometry( 100, 1, 100 );
ground.mesh = new Physijs.BoxMesh( ground.geometry, ground.material, 0 );
ground.mesh.receiveShadow = true;

scene.add( ground.mesh );

// Box
box.material = new THREE.MeshLambertMaterial({
    color: 0x00FF00
});
box.material = Physijs.createMaterial( box.material, 0.4, 0.6 );
box.geometry = new THREE.CubeGeometry( 4, 4, 4 );

// Draw 10 boxes
for( var i = 0; i < 10; i++ ){

    var pos = {},
        rot = {};

    pos.x = Math.random() * 50 - 25;
    pos.y = 10 + Math.random() * 5;
    pos.z = Math.random() * 50 - 25;
    rot.x = Math.random() * Math.PI * 2;
    rot.y = Math.random() * Math.PI * 2;
    rot.z = Math.random() * Math.PI * 2;
    box.mesh = new Physijs.BoxMesh( box.geometry, box.material );
    box.mesh.position.set( pos.x, pos.y, pos.z );
    box.mesh.rotation.set( rot.x, rot.y, rot.z );
    box.mesh.castShadow = true;

    scene.add( box.mesh );
    boxes.push( box.mesh );

};

// Render method
render = function(){

    scene.simulate( null, 50 );
    renderer.render( scene, camera );
    requestAnimationFrame( render );

};

// Render this shit
$( function(){

    $('#viewport').append( renderer.domElement );

    render();

});
var地面={},
box={},
框=[],
地面={},
投影仪
渲染器,
场景
轻,,
摄像机,
提供,
重力;
//为Physijs做准备
Physijs.scripts.worker='physi.js_worker.js';
Physijs.scripts.ammo='ammo.js';
//放映机
投影仪=新的三台投影仪;
//渲染器
renderer=new THREE.WebGLRenderer({
反别名:对
});
设置大小(1000600);
renderer.shadowMapEnabled=true;
renderer.shadowMapSoft=true;
//场面
场景=新Physijs.scene;
//摄像机
摄像机=新的三个透视摄像机(35,(1000/600),1100);
摄像机。位置。设置(60,50,60);
摄像机。注视(场景。位置);
场景。添加(摄影机);
//轻的
灯光=新的三个方向灯光(0xFFFFFF);
光。位置。设置(20,40,-15);
灯光、目标、位置、复制(场景、位置);
light.castShadow=true;
light.shadowCameraLeft=-60;
light.shadowCameraTop=-60;
light.shadowCameraRight=60;
light.shadowCameraBottom=60;
light.shadowCameraNear=20;
light.shadowCameraFar=200;
灯光阴影偏差=-0.0001;
light.shadowMapWidth=light.shadowMapHeight=2048;
明暗度=0.7;
场景。添加(灯光);
//地面
ground.material=新的三网格LambertMaterial({
颜色:0xDDDD
});
ground.material=Physijs.createMaterial(ground.material,0.8,0.4);
ground.geometry=新的三立方测量法(100,1100);
ground.mesh=new Physijs.BoxMesh(ground.geometry,ground.material,0);
ground.mesh.receiveShadow=true;
场景.添加(ground.mesh);
//盒子
box.material=新的三网格LambertMaterial({
颜色:0x00FF00
});
box.material=Physijs.createMaterial(box.material,0.4,0.6);
box.geometry=新的三立方测量法(4,4,4);
//画10个盒子
对于(变量i=0;i<10;i++){
var pos={},
rot={};
pos.x=数学随机()*50-25;
位置y=10+数学随机数()*5;
pos.z=Math.random()*50-25;
rot.x=Math.random()*Math.PI*2;
rot.y=Math.random()*Math.PI*2;
rot.z=Math.random()*Math.PI*2;
box.mesh=new Physijs.BoxMesh(box.geometry,box.material);
箱网位置设置(x、y、z位置);
框。网格。旋转。设置(rot.x,rot.y,rot.z);
box.mesh.castShadow=true;
场景。添加(box.mesh);
box.push(box.mesh);
};
//渲染方法
render=function(){
scene.simulate(null,50);
渲染器。渲染(场景、摄影机);
请求动画帧(渲染);
};
//把这狗屎弄出来
$(函数(){
$('#viewport').append(renderer.doElement);
render();
});

您的“physi.js\u worker.js”版本似乎为空。这意味着web worker正在启动,但永远不会响应脚本