2
내 자신의 스타일로 Physi.js 예제 중 하나를 다시 작성하려고했지만 실제로 사용할 수없는 것처럼 보입니다. 중량. 렌더링 루프가 끊임없이 실행되고 있지만 그래도 바뀌지는 않습니다.Three.js + Physi.js - 중력을 시작할 수 없습니다.
내가 여기서 무엇을 업로드 한 : http://kemp59f.info/up/down/index.htm
이것은 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();
});