热门搜索 :
考研考公
您的当前位置:首页正文

IFE2017,WebGL-08 物理引擎——使用Physijs

来源:东饰资讯网
  • 加载的外部模型没有物理特性

因为physijs自身没有加载模块,所以加载的时候需要用physijs的方法拷贝外部模型

var objLoader = new THREE.OBJLoader();

objLoader.load('xxx.obj',function(object){
  var model = object;

  for (let x in model.children){
    let material = Physijs.createMaterial(
      model.children[x].material,
      1,
      0
    );
    let mesh = new Physijs.BoxMesh(
      model.children[x].geometry,
      material,
      0
    );
    mesh.castShadow = true;
    mesh.receiveShadow = true;

    scene.add(mesh);
  }
},onProgress,onError);

<br />

  • 不能同时向场景加入多个元素

scene.add(obj1,obj2)
原本three.js是支持这样的做法的,但是physijs中这种写法只会加载第一个元素
<br />

  • 直接改变元素的位置或角度时必须要设置参数

// Change the object's position
mesh.position.set( 0, 0, 0 );
mesh.__dirtyPosition = true;

// Change the object's rotation
mesh.rotation.set(0, 90, 180);
mesh.__dirtyRotation = true;

推荐的做法是给物体一个线速度或者角速度

// use linear velocity to change rotation
mesh.setLinearVelocity(new THREE.Vector3(0, 0, 1));

// use angular velocity to change rotation
mesh.setAngularVelocity(new THREE.Vector3(0, 1, 0));

但是这有个问题,直接改变的做法动画是很流畅的,但是用速度矢量画面会有一顿一顿的情况,暂未能解决。
<br />

  • 直接改变角度无法超过90度

监控物体的rotation可以发现在y在90度附近时rotation的x和z在-PI,0,PI之间反复变动的情况

Top