본문 바로가기
Three.js

Three.js-collision, bullet engine, ammo -part3

by ses jeon 2019. 10. 22.

Continues from the previous chapter.

이전 장에서 이어집니다.

========================================================================

basicStructure5.zip
4.95MB

Before we go in, let's make a new definition.

들어가기 앞서서 하나 정의를 새로 하겠습니다.

amendedThree.js

This adds batch conversion of Vector3 and Quaternion variables to the set function.
There are no such functions in three.js at this time. This way, you can customize the three.js engine to suit your needs.

Now go back to the PrimitiveModel.

The role of the PrimitiveModel is to assemble the previously created CollisionElements. In our example, we only use one shape, but if you have a complex model of a human, an animal, a car, etc. In that case, you need to combine several basic shapes.

Similar to CollisionElement, it is also implemented by the static method make.

이는 Vector3와 Quaternion 변수를 set함수로 일괄변환하는 것을 추가합니다.

지금 three.js에는 이런 함수는 없기에 추가한 것입니다. 이 방식으로 three.js 엔진을 본인에 맞춰 수정하실수 있습니다.

 

이제 다시 PrimitiveModel로 넘어옵니다.

 

PrimitiveModel의 역할은 이전에 만든 CollisionElement들을 조합해서 모으는 것입니다. 지금 예제에서는 하나의 모양만 쓰지만, 만약 인간이나 동물, 자동차 등의 복잡한 모델이라면 충돌모양을 하나로 만들기가 힘들것입니다. 그럴때는 기본 모양을 여러개 합쳐야 합니다.

 

역시 CollisionElement와 비슷하게 static 형태의 메서드 make로 구현합니다.

make 구현

1. Bullet variable for transformation, similar to matrix in threejs
2. Skeleton Model for Visual Implementation
3. collision shape object- btCompoundShape can have multiple collision shapes.
After that, we added the previously added model.
Number 4 implements the CollisionElement we implemented earlier.
5 translates the rotation / rotation / size of the returned CollisionElement.

I marked the unit in blue as 1 unit. If your model now has more than one collision shape, you can add one more.

Next, let's see how to handle bounding / compound_shape.

1. 변환을 위한 bullet 변수, threejs로 치자면 메트릭스와 비슷한 역할이다

2. 시각구현을 위한 뼈대 모델

3. collision shape object- btCompoundShape는 여러 collision shape를 가질수 있습니다.

그다음에는 이전의 추가한 모델을 그대로 추가했습니다.

4번은 앞서 구현한 CollisionElement를 구현합니다.

5는 리턴받는 CollisionElement의 이동/회전/크기 변환을 합니다.

 

파란색으로 표시한 부분을 1unit으로 표기했는데요. 만약 지금 모델이 2개 이상의 충돌shape를 가진다면 똑같이 하나더 추가를 하면 됩니다.

 

다음은 이렇게 받은 bounding/compound_shape를 어떻게 처리하는지 봅시다.

 

make 구현 2

Since bounding is already complete, we add it to the returned model.

At the bottom is the shape setup for the dynamic world. This section explains what I said at the beginning of this unit.

bounding은 이미 완결되었으므로 그대로 리턴되는 모델에 추가시킵니다.

 

그 하단은 dynamic world를 위한 shape 설정부분입니다. 이부분에 대한 설명은 이 단원을 시작할때 말했던 

https://xoppa.github.io/blog/using-the-libgdx-3d-physics-bullet-wrapper-part1/

 

Using the libGDX 3D physics Bullet wrapper - part1 | blog.xoppa.com

Many 3D games require some sort of collision detection between 3D objects. Sometimes it's possible to do this with some basic math and bounding boxes and...

xoppa.github.io

Described here. In short, it sets the inertia, or inertia, to the set mass (m) and sets the motionState that tells us when there is a transformation.

By default, the Ammo implementation implements the dynamic world directly, not the collision world.

이곳에 설명되어있습니다. 간단히 설명하면 설정된 질량(m)으로 inertia 즉 관성을 설정하고, 또 변환이 있을때 알려주는 motionState라는것을 설정하는 내용입니다.

 

기본적으로 Ammo 구현은 collision world는 아니고 dynamic world를 바로 구현합니다.

 

========================================================================

 

Let's fix mainPage to see if it's set up right away.

이 상태에서 바로 설정이 되었는지 mainPage를 고쳐봅시다.

mainPage

You will see that we added a skeleton to know the shape of the collision.

충돌모양을 알기위한 뼈대를 추가한것이 보일것입니다.

You can see that it is well implemented.

In the next chapter, we will check to see if the conflict actually works.

잘 구현된것을 알수 있습니다.

 

다음 장에서는 실제로 충돌이 잘 이뤄지는지 확인해 보도록 하겠습니다.

 

 

 

 

 

 

댓글