2D软体:Gelly和可塑? [英] 2D soft bodies: Gelly and moldable?

查看:155
本文介绍了2D软体:Gelly和可塑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Matter.js物理来创建柔体。我能够创建这样的主体:





但是我不确定这是否是我想要的软体。确实,这个身体并不是完全僵硬的,并且当它碰撞并被拖拽时具有那种有弹性的感觉。我正在寻找一个与凝胶有相似之处的身体。这个图像可能在视觉上帮助解释这个概念:





<我想知道如何制作这些类型的身体。它与as matter.js软体相同,但具有非常特殊的属性类型吗?我只能让身体变得僵硬,而不是像我希望的那样可塑造和圆形。



我也很有兴趣操纵物理身体与游戏中的相互作用会增加或减少物理体的大小,这再次让我得出结论,我想要的身体类型必须是相当可塑的。



可以问.js处理这个还是我必须改变物理引擎?有什么方法可以解决这个问题吗?



注意:我使用Phaser.js作为一些游戏内组件,但是物理操作的物理因素是物理操作,因为我相信Phaser集成物理学可以不要模拟这种复杂的身体。



谢谢



编辑:它非常类似于 Box2d:滚动软体球。我想我只需要使用js引擎。有没有?

解决方案

正如我在评论中所提到的,我不熟悉移相器或者你如何实际实现这一点一个Javascript框架。我的目标是给你一些关于不同方法的想法,所以希望你会发现这个答案很有用。






我将尝试回答这个问题:


我想知道如何制作这些类型的物体。 ......我只能让身体变得僵硬,而不是像我希望的那样可塑造和圆形。


对于这句话,你不一定清楚你想要什么。正如我在评论中所指出的那样,我认为你正在寻找可塑性,我将描述一种方法,你可以用一些简单的工具欺骗。



目前你用来形容你的身体运动。这个身体确实不是完全僵硬的,并且当它碰撞并获得时有这种弹性的感觉拖动。。目前你的模型是这样的:


  1. 一个点连接到网格中给出的所有其他点。

  2. 每一步,计算每对之间的力。关节(或点)上的总力是所有这些配对力的总和。

  3. 每个关节都与身体的一部分相关(即它有一些质量 m )并使用 acceleration = force / m 计算其加速度。从那里我们计算速度,最后位置

上述步骤中最有趣的部分是nr 2,因为这将极大地影响整个身体的运动。一种非常常见的实现方式是弹性潜力,对于两点之间的某个距离,会给出一些 force 。像这样:

  function elasticPotential(p1,p2){
//给定两个位置p1和p2我们计算一个他们之间的力量
距离= sqrt(pow(p1.x - p2.x,2)+ pow(p1.y - p2.y,2)+ pow(p1.z - p2.z,2)) ;
force = force_given_distance(distance); //这里一个受欢迎的选择是弹簧力
返回力;
}

现在,您已经在框架中内置了上述功能,所以你不必实现它。我之所以这么说是因为了解我们如何创造可塑性至关重要。上面的问题是没有什么能保持变形 ---弹性潜力的本质是它有一些休息配置(很可能是你的第一个配置)它总会试着回到那个形状。我们希望形状记住它是如何形状错误的。这就是可塑性。



简单的可塑性



首先请注意可塑性问题是一个很大的研究课题,在很多情况下都是微不足道的。我的想法如下:如果两个连接点之间的距离大于某个阈值,重新映射当前配置中的点。也就是说,

 每对(p1,p2):
如果距离(p1,p2)>阈值:
recalculate_connection(p1,p2)

正如你所看到的,这是一个非常简单的塑性模型,很可能不是物理上正确的。但是,应该可以通过重新拼写以及您选择的弹性潜力来获得有趣的行为。



如果你向我提供更多详细信息,我可以进一步讨论这个问题,但是现在我觉得这个答案已经比它应该更长了。






TL; DR:
通过在变形过程中重新拍摄身体来创建可塑形状。获得精确的理想物理行为可能很棘手,但应该可以创建看起来像凝胶状的东西。


I am using Matter.js physics in an attempt to create soft bodies. I was able to create a body like this:

However I am not sure if this is the "soft body" I want. It is true that this body is not entirely rigid and has that bouncy feel when it collides and gets dragged. I was looking for a body that shares similarities with a gelly. This image might visually help explaining the concept:

I was wondering how these type of bodies can be made. Is it the same as the as matter.js soft body but with a very specific type of properties? I can only get the body to be kind of rigid-squared and not as moldable and circular as I would like it to be.

I am also interesting in manipulating the physics body with in-game interactions which would increase or decrease the physics body size which leads me once more to the conclusion that the type of body that I want must be quite moldable.

Can matter.js handle this or do I have to change the physics engine? Any solutions to approach this?

NOTE: I am using Phaser.js for some in-game components but matter.js physics for physics manipulation because I believe Phaser integrated Physics can't simulate this type of complex body.

Thanks

EDIT: It is very similar to this Box2d :roll soft body ball. I just need to do that with a js engine I guess. Is there any?

解决方案

As I mentioned in the comments, I am not familiar with phaser or how you would actually implement this within a Javascript framework. My goal here is maybe to give you some ideas on different ways to proceed, so hopefully you'll find this answer useful.


I will try to answer this:

I was wondering how these type of bodies can be made. ... I can only get the body to be kind of rigid-squared and not as moldable and circular as I would like it to be.

It is not necessarily clear what you want given this sentence. As I noted in comments, what I think you are looking for is plasticity, and I will describe a way which you could possible "cheat" that look with somewhat simple tools.

At the moment you describe the motion of your body by "It is true that this body is not entirely rigid and has that bouncy feel when it collides and gets dragged.". Currently your model works as such:

  1. A point is connected to all other points as given in your mesh.
  2. Every time step, a force is calculated between each pair. The total force on a joint (or point) is the sum of all these pair wise forces.
  3. Each joint is associated with a part of the body (i.e. it has some mass m) and you calculate its acceleration with acceleration = force/m. From there on we calculate velocity and finally position.

The most interesting part of the steps above is nr 2, as that will greatly influence the motion of the whole body. A very common way to implement it is as an elastic potential that for a certain distance between two points gives some force. Like so:

function elasticPotential(p1, p2) {
    // Given two positions p1 and p2 we calculate a force between them
    distance = sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2) + pow(p1.z - p2.z, 2));
    force = force_given_distance(distance); // A popular choice here is for example a spring force
    return force;
}

Now, you already have the function described above built in in your framework, so you don't have to implement it. The reason I'm describing this is because it is essential to understanding how we can create plasticity. The problem with the above is that nothing will retain deformation---the nature of the elastic potential is that it has some rest configuration (most likely your first configuration) and it will always try to get back to that shape. We want the shape to remember how it was mis-shaped. This is what plasticity is.

Simple plasticity

Note first here that the problem of plasticity is a big research topic and in many cases far from trivial. My idea is as follows: if the distance between two connected points are larger than some threshold, remesh the points in the current configuration. That is,

for each pair(p1, p2):
    if distance(p1, p2) > threshold:
        recalculate_connection(p1, p2)

As you can see this is a very simple model for plasticity, and most likely not physically correct. However, it should be possible to get interesting behaviours my playing with the remeshing together with what elastic potential you choose.

If you provide me with more details I might be able to discuss the problem further, but right now I feel this answer is already longer than it should be.


TL;DR: Create a "moldable" shape by remeshing your body during deformation. It might be tricky to get an exact desired physical behaviour, but it should be possible to create something that looks "gelly-like".

这篇关于2D软体:Gelly和可塑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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