Model hit detection

[Last updated: 11/07/2019]

 

Although the model itself does not have the ability to perform hit detection,

the ability to obtain the vertex information of the ArtMesh can be used to implement the hit detection process.

The “hit judgment” described here

refers to a test to see if the target mesh is at a specified point on the screen.

 

 

Preparing for a hit

ArtMesh is used to determine the hit.
To prepare the ArtMesh for the hit detection in the Editor, see “Setting Up Hit Detection in the Editor”.
After preparing the hit decision, it is necessary to set the hit decision using the Cubism Viewer (for OW) function and incorporate it into the .model3.json file.

When you set up a hit decision on Cubism Viewer (for OW) and output it, the .model3.json file will contain the following description.

 

 

In Cubism Viewer (for OW), only ArtMesh with HitArea~ and ID can be registered, but
you can also set the .model3.json file to hit for ArtMesh other than HitArea~ if you process it directly in a text editor.

Make a hit decision

The Native (C++) CubismUserModel::IsHit function or the Web (TypeScript) CubismUserModel.isHit function can be used to determine the hit.
The first argument specifies the ID of the target drawable, and the second and third arguments specify the X and Y values on the drawing to be inspected.

 

 

Details and notes on the hit decision

The hit detection is a system that scans all the vertices of the ArtMesh, creates a rectangular range from the maximum and minimum XY coordinates of the vertices,
inverts the screen coordinates to be inspected from the model's transformation matrix, and checks whether they fit into a rectangle.
When using this function, the following points should be noted.

• If rotation is entered in the transformed coordinates of the model, it will not be transformed correctly.

• ArtMesh that is close to a rectangle changes size significantly when rotated by a rotational deformer or other means.

© 2010 - 2022 Live2D Inc.