본문 바로가기
Three.js

Three.js-collision and bullet engine, ammo -part5

by ses jeon 2019. 11. 5.

As the last part of the conflict handling, let's look at how to handle some additional events in the event of a crash.

The java wrapper handles contact related to it by redefining each motion state. However, ammo.js is not supported so far, and the function provided on the homepage is difficult to handle the contact function. That's why there's a related issue that we'll discuss on the next page.

충돌처리의 마지막 부분으로 충돌시에 어떤 추가 이벤트를 처리할수 있는 방법을 보도록 하겠습니다.

 

java wrapper에서는 각 motion state를 재정의함으로써 거기에 contact 관련 처리하였습니다. 하지만 ammo.js에서는 그렇게까지 서포트가 되지 않고, 홈페이지에 제공하는 기능은 contact 처리 기능을 하기 힘듭니다. 그래서 그에 관련된 이슈 제기가 되어있는데 다음 페이지에서 논의하고 있습니다.

https://github.com/kripken/ammo.js/pull/251

 

Global Contact Callback Support by MackeyK24 · Pull Request #251 · kripken/ammo.js

Add support for global contact callback functions: gContactAddedCallback gContactProcessedCallback gContactDestroyedCallback Original Issue Explain Contact Callback Support #82 gContactAddedCallb...

github.com

Added a modified ammo.js for that. Named ammo_contact.js But this version is outdated. Please direct your attention to ammo.js. (I don't know everything)

Anyway, it's an older version, but it works fine. Now let's handle the contact.

그에 관한 수정된 ammo.js를 추가하였습니다. ammo_contact.js 로 이름지었습니다. 그런데 이 버전은 구형 버전입니다. ammo.js 관련된 부분은 직접 파보시길 부탁드립니다. (저도 내용을 전부 알순 없어서)

 

아무튼 구형 버전이지만, 동작은 문제없이 됩니다. 이제 contact 처리를 해보도록 하겠습니다.

 

 

I indexed the creation instance as follows:

And add the following code under dynamicWorld

다음처럼 생성 인스턴스에 index를 주었습니다.

 

그리고 다음 코드를 dynamicWorld 아래에 추가합니다.

The following code is the criteria for handling contacts. The first colObj0 and colObj1 are both objects when a collision occurs.
Number 2 is an object that retrieves information about the collision location at the time of the collision, that is, the collision itself.
3 is the index value of the collision 2 times. This allows the user to manage the conflict by keeping it unique, and then deletes the conflict itself after the fifth conflict.
6 registers this crash handling process.

Let's print the output through 4.

다음같은 코드가 contact 처리 기준이 됩니다. 1번의 colObj0, colObj1 는 충돌이 일어났을때의 양 객체입니다.

2번은 그 충돌시의 충돌 위치등을 알수 있는 정보를 가져오는 객체입니다, 다시 말해서 충돌 그자체라고 볼수 있습니다.

3번은 2번의 그 충돌의 index값입니다. 이걸 사용자가 고유로 두어서 충돌을 관리하고, 그리고 5번의 충돌이 끝날때 그 충돌 자체를 삭제시켜주는것입니다.

6번은 이 충돌 처리 process를 등록시킨겁니다.

 

일단 4번을 통해서 출력을 시켜봅시다.

You can see that the spherical and hexahedral indices 100 and 200 are printed as follows. Then every time this index comes out, you can do a unique process.

When a collision occurs, we will change the sphere color and print the collision point.

다음과 같이 구형과 육면체의 인덱스인 100과 200이 출력되는것을 볼수 있습니다. 그렇다면 이 인덱스가 나올때마다 고유처리를 해주면 될것 같습니다.

 

충돌이 일어날때 구형 색상을 바꾸고, 충돌 포인트를 출력하도록 하겠습니다.

 

You may use your own method of implementation.

구현시 본인만의 방법을 써도 될것입니다.

Then, it puts in a routine to delete cp information when the contact drops.

그리고, 접촉이 떨어질때 cp 정보를 삭제하기 위한 루틴을 집어넣는다.

 

basicStructure5.zip
5.34MB

 

 

 

 

댓글