从THREE.Mesh或THREE.Geometry创建CANNON.RigidBody [英] Create CANNON.RigidBody from THREE.Mesh or THREE.Geometry

查看:64
本文介绍了从THREE.Mesh或THREE.Geometry创建CANNON.RigidBody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 THREE.JSONLoader 对象创建 THREE.Mesh 对象,如下所示:

I am creating a THREE.Mesh object using a THREE.JSONLoader object like so:

// Create castle.
loader.load('/Meshes/CastleTower.js', function(geometry, materials) {
    var tmp_material = new THREE.MeshLambertMaterial();
    THREE.ColorUtils.adjustHSV(tmp_material.color, 0, 0, 0.9);

    var castle = new THREE.Mesh(geometry, tmp_material);
    castle.scale.set(0.2, 0.2, 0.2);
    castle.rotation.setX(-Math.PI/2);
    scene.add(castle);
});

是否可以创建 CANNON.RigidBody 来自 THREE.Mesh var castle )或 THREE.Geometry var geometry )对象? 你可以读到的另一种方法是:你如何制作任何自定义 THREE.Mesh solid?

Is it possible to create a CANNON.RigidBody from the THREE.Mesh (var castle) or THREE.Geometry (var geometry) object? Another way you could read this is: How do you make any custom THREE.Mesh "solid"?

我使用Blender,从盒子中创建了一个新城堡,导出它为Three.js格式。如果将质量设置为 0 CANNON.Body ,它将保持静态。 这个非常完美......

I used Blender, created a new castle from boxes, and exported it to the Three.js format. If you set the mass to 0 of a CANNON.Body, it remains static. This worked out perfectly...

推荐答案

这取决于你的模型的物理代表应该有多精确。我对cannon.js不是很熟悉,但这里有一些我知道的选项:

Well it depends on how exact the physical representatin of your model should be. I'm not very familiar with cannon.js, but here are some options I know:


  • 使用computeBoundingBox并在你的塔上创建一个带有这些边界的cannon.js框

  • 以类似的方式使用computeBoundingSphere

  • 将物理学用于凹面(即任意)网格。这是性能最耗的方式。 Cannon.js在这里有一个例子: http://schteppe.github.io/cannon .js / demos / bunny.html

  • use "computeBoundingBox" and on your tower and create a cannon.js box with those bounds
  • use "computeBoundingSphere" in a similar way
  • use physics for a concave (i.e. arbitrary) mesh. This is the most performance consuming way. Cannon.js has an example here: http://schteppe.github.io/cannon.js/demos/bunny.html

非cannon.js相关方法将是例如使用重播。 Recast会为您加载.obj文件,并根据您的设置为您创建导航网格。然后你可以在那里走动(如果你有像游戏一样的RTS鸟瞰图,或者跑来跑去的机器人,那就太棒了)。可以在此处找到重铸javascript端口: https://github.com/vincent/recast.js

A non cannon.js related approach would be to e.g. use Recast. Recast would load your .obj file for you and create a navigation mesh for you according to your settings. Then you could walk around there (absolutely great if you have a RTS birdview like game, or bots running around). A recast javascript port can be found here: https://github.com/vincent/recast.js

希望这会有所帮助!

这篇关于从THREE.Mesh或THREE.Geometry创建CANNON.RigidBody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆