11package dev .eatgrapes .live2d ;
22
3+ import java .util .function .Consumer ;
4+
35public class CubismUserModel extends Native {
4-
6+ private Consumer <String > motionFinishedCallback ;
7+
58 public CubismUserModel () {
69 super (createNative ());
710 }
811
912 private static native long createNative ();
1013
11- public void loadModel (byte [] buffer ) {
12- loadModelNative (_ptr , buffer );
13- }
14-
14+ public void loadModel (byte [] buffer ) { loadModelNative (_ptr , buffer ); }
1515 private static native void loadModelNative (long ptr , byte [] buffer );
1616
17- public void loadPhysics (byte [] buffer ) {
18- loadPhysicsNative (_ptr , buffer );
19- }
20-
17+ public void loadPhysics (byte [] buffer ) { loadPhysicsNative (_ptr , buffer ); }
2118 private static native void loadPhysicsNative (long ptr , byte [] buffer );
2219
23- public void loadPose (byte [] buffer ) {
24- loadPoseNative (_ptr , buffer );
25- }
26-
20+ public void loadPose (byte [] buffer ) { loadPoseNative (_ptr , buffer ); }
2721 private static native void loadPoseNative (long ptr , byte [] buffer );
2822
29- public void loadExpression (byte [] buffer , String name ) {
30- loadExpressionNative (_ptr , buffer , name );
31- }
32-
23+ public void loadExpression (byte [] buffer , String name ) { loadExpressionNative (_ptr , buffer , name ); }
3324 private static native void loadExpressionNative (long ptr , byte [] buffer , String name );
3425
35- public void createRenderer () {
36- createRendererNative (_ptr );
37- }
38-
26+ public void createRenderer () { createRendererNative (_ptr ); }
3927 private static native void createRendererNative (long ptr );
4028
41- public void update (float deltaTime ) {
42- updateNative (_ptr , deltaTime );
43- }
29+ public void registerTexture (int index , int textureId ) { registerTextureNative (_ptr , index , textureId ); }
30+ private static native void registerTextureNative (long ptr , int index , int textureId );
4431
45- private static native void updateNative (long ptr , float deltaTime );
32+ // Eye Tracking / Dragging
33+ public void setDragging (float x , float y ) { setDraggingNative (_ptr , x , y ); }
34+ private static native void setDraggingNative (long ptr , float x , float y );
4635
47- public void registerTexture ( int index , int textureId ) {
48- registerTextureNative (_ptr , index , textureId );
49- }
36+ // Hit Detection
37+ public boolean isHit ( String drawableId , float x , float y ) { return isHitNative (_ptr , drawableId , x , y ); }
38+ private static native boolean isHitNative ( long ptr , String drawableId , float x , float y );
5039
51- private static native void registerTextureNative (long ptr , int index , int textureId );
40+ // Motion Playback
41+ public void startMotion (byte [] buffer , int priority , Consumer <String > onFinished ) {
42+ this .motionFinishedCallback = onFinished ;
43+ startMotionNative (_ptr , buffer , priority );
44+ }
45+ private static native void startMotionNative (long ptr , byte [] buffer , int priority );
5246
53- public void setParameterValue (String id , float value ) {
54- setParameterValueNative (_ptr , id , value );
47+ // Called from JNI
48+ private void onMotionFinished (String name ) {
49+ if (motionFinishedCallback != null ) {
50+ motionFinishedCallback .accept (name );
51+ }
5552 }
5653
57- private static native void setParameterValueNative (long ptr , String id , float value );
54+ public void update (float deltaTime ) { updateNative (_ptr , deltaTime ); }
55+ private static native void updateNative (long ptr , float deltaTime );
5856
59- public float getCanvasWidth () {
60- return getCanvasWidthNative (_ptr );
61- }
57+ public void setParameterValue (String id , float value ) { setParameterValueNative (_ptr , id , value ); }
58+ private static native void setParameterValueNative (long ptr , String id , float value );
6259
60+ public float getCanvasWidth () { return getCanvasWidthNative (_ptr ); }
6361 private static native float getCanvasWidthNative (long ptr );
6462
65- public float getCanvasHeight () {
66- return getCanvasHeightNative (_ptr );
67- }
68-
63+ public float getCanvasHeight () { return getCanvasHeightNative (_ptr ); }
6964 private static native float getCanvasHeightNative (long ptr );
7065
71- public void draw (float [] mvpMatrix ) {
72- drawNative (_ptr , mvpMatrix );
73- }
74-
66+ public void draw (float [] mvpMatrix ) { drawNative (_ptr , mvpMatrix ); }
7567 private static native void drawNative (long ptr , float [] mvpMatrix );
7668
7769 @ Override
78- public void close () {
79- deleteNative (_ptr );
80- }
81-
70+ public void close () { deleteNative (_ptr ); }
8271 private static native void deleteNative (long ptr );
83- }
72+ }
0 commit comments