Physijs对象通过concaveMesh

时间:2013-12-27 12:49:16

标签: three.js physijs

我有一个似乎已知的问题:我的“边界”对象不会与“地板”的凹面碰撞。

我已经读过这个问题可能是因为将fuzzyMesh与模型一起缩放时出错,所以我根据需要导出了我的地板模型缩放,并在我应用了凹面网格后(如下所示),但它不起作用

我重申了这个问题:https://github.com/chandlerprall/Physijs/issues/102以及关于这个主题的许多其他事情(Physijs Load model three.js collisions don't work和类似的事情)我制作了以下代码但无事可做:(

我真的不明白为什么“限制”会在场上发挥作用。

这是我的代码:

Physijs.scripts.worker = './libs/chandlerprall-Physijs-7e3837b/physijs_worker.js';
Physijs.scripts.ammo = './examples/js/ammo.js';
var gravityVector = new THREE.Vector3( 0, -100, 0 );
//renderer
var renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setClearColor(0xffffff, 0);
renderer.setSize( window.innerWidth, window.innerHeight );
//canvas
var canvas = renderer.domElement;
canvas.setAttribute("width",  window.innerWidth);
canvas.setAttribute("height",  window.innerHeight);
document.body.appendChild( canvas );
var perspectiveCamera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight, 1, 200000);
//scene
var rttScene = new Physijs.Scene();

var bounding = new Physijs.SphereMesh(new THREE.SphereGeometry(100, 100, 100),
    Physijs.createMaterial(
        new THREE.MeshBasicMaterial({color: '#ff0000'}),
        1.0, // friction
        0.0 // restitution
        ),50 //mass
    );

bounding.position.set(200,1200,-5000);

loader.load("http://0.0.0.0:8000/Models/Isola/pavimento.js", function( geometry, materials){
    var groundMaterial = Physijs.createMaterial(new THREE.MeshFaceMaterial(materials),
        0.8, // friction
        0.2 // restitution
            );
    floor = new Physijs.ConcaveMesh(geometry,groundMaterial,0);
    floor.name = "pavimento";
    rttScene.add(floor);
    initScene();
    render();
 });

function initScene() {
    rttScene.setGravity(gravityVector);
    rttScene.add(envModel);
    rttScene.add(bounding);
    bounding.setAngularFactor(new THREE.Vector3(0, 0, 0));
    bounding.setCcdMotionThreshold( 0.1 );
    bounding.setCcdSweptSphereRadius( 1 );

    var ambientLight =  new THREE.AmbientLight(0xD9B775 ); 
    rttScene.add(ambientLight);

    var directionalLight = new THREE.DirectionalLight(0xc7af81);
    directionalLight.target.position.copy( rttScene.position );
    directionalLight.position.set(-550,1950,1950).normalize(); 
    directionalLight.intensity = 0.7;
    rttScene.add(directionalLight);

    perspectiveCamera.position.set(200,1200,-3000);
    perspectiveCamera.lookAt(bounding.position);
}

function render() {
    requestAnimationFrame(render);
    renderer.clear();
    rttScene.simulate();

    renderer.render(rttScene, perspectiveCamera);
    }

我也试过这个到render()函数:

var originPoint = bounding.position.clone();
var ray = new THREE.Raycaster(originPoint, new THREE.Vector3(0, -1, 0));
var collisionResults = ray.intersectObjects(rttScene.children)
if (collisionResults.length > 0) {
    console.log(collisionResults[0].distance);
}

在控制台中我可以读取“边界”和“地板”之间的距离。这应该意味着地板作为对撞机存在,但它不会停止下降。为什么呢?

0 个答案:

没有答案