/**
 * Copyright(c) Live2D Inc. All rights reserved.
 *
 * Use of this source code is governed by the Live2D Open Software license
 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
 */ import { CubismBreath } from '../effect/cubismbreath' ; import { CubismEyeBlink } from '../effect/cubismeyeblink' ; import { CubismPose } from '../effect/cubismpose' ; import { CubismIdHandle } from '../id/cubismid' ; import { Constant } from '../live2dcubismframework' ; import { CubismModelMatrix } from '../math/cubismmodelmatrix' ; import { CubismTargetPoint } from '../math/cubismtargetpoint' ; import { ACubismMotion , FinishedMotionCallback } from '../motion/acubismmotion' ; import { CubismExpressionMotion } from '../motion/cubismexpressionmotion' ; import { CubismMotion } from '../motion/cubismmotion' ; import { CubismMotionManager } from '../motion/cubismmotionmanager' ; import { CubismMotionQueueManager } from '../motion/cubismmotionqueuemanager' ; import { CubismPhysics } from '../physics/cubismphysics' ; import { CubismRenderer_WebGL } from '../rendering/cubismrenderer_webgl' ; import { csmString } from '../type/csmstring' ; import { CubismLogError , CubismLogInfo } from '../utils/cubismdebug' ; import { CubismMoc } from './cubismmoc' ; import { CubismModel } from './cubismmodel' ; import { CubismModelUserData } from './cubismmodeluserdata' ; /**
 * ユーザーが実際に使用するモデル
 *
 * ユーザーが実際に使用するモデルの基底クラス。これを継承してユーザーが実装する。
 */ export class CubismUserModel { return return public isInitialized ( ) { return this . _initialized ; } param v public setInitialized ( v ) { this . _initialized = v ; } return return public isUpdating ( ) { return this . _updating ; } param v public setUpdating ( v ) { this . _updating = v ; } param ドラッグしているカーソルのX位置 param ドラッグしているカーソルのY位置 public setDragging ( x , y ) { this . _dragManager . set ( x , y ) ; } param x param y param z public setAcceleration ( x , y , z ) { this . _accelerationX = x ; this . _accelerationY = y ; this . _accelerationZ = z ; } return public getModelMatrix ( ) { return this . _modelMatrix ; } param a public setOpacity ( a ) { this . _opacity = a ; } return public getOpacity ( ) { return this . _opacity ; } param buffer public loadModel ( buffer ) { this . _moc = CubismMoc . create ( buffer ) ; this . _model = this . _moc . createModel ( ) ; this . _model . saveParameters ( ) ; if ( this . _moc == null || this . _model == null ) { CubismLogError ( 'Failed to CreateModel().' ) ; return ; } this . _modelMatrix = new CubismModelMatrix ( this . _model . getCanvasWidth ( ) , this . _model . getCanvasHeight ( ) ) ; } param buffer param size param name param onFinishedMotionHandler return public loadMotion = ( buffer , size , name , onFinishedMotionHandler ? ) => CubismMotion . create ( buffer , size , onFinishedMotionHandler ) ; param buffer param size param name public loadExpression ( buffer , size , name ) { return CubismExpressionMotion . create ( buffer , size ) ; } param buffer param size public loadPose ( buffer , size ) { this . _pose = CubismPose . create ( buffer , size ) ; } param buffer param size public loadUserData ( buffer , size ) { this . _modelUserData = CubismModelUserData . create ( buffer , size ) ; } param buffer param size public loadPhysics ( buffer , size ) { this . _physics = CubismPhysics . create ( buffer , size ) ; } param drawableId param pointX param pointY return return public isHit ( drawableId , pointX , pointY ) { const drawIndex = this . _model . getDrawableIndex ( drawableId ) ; if ( drawIndex < 0 ) { return false ; } const count = this . _model . getDrawableVertexCount ( drawIndex ) ; const vertices = this . _model . getDrawableVertices ( drawIndex ) ; let left = vertices [ 0 ] ; let right = vertices [ 0 ] ; let top = vertices [ 1 ] ; let bottom = vertices [ 1 ] ; for ( let j = 1 ; j < count ; ++ j ) { const x = vertices [ Constant . vertexOffset + j * Constant . vertexStep ] ; const y = vertices [ Constant . vertexOffset + j * Constant . vertexStep + 1 ] ; if ( x < left ) { left = x ; } if ( x > right ) { right = x ; } if ( y < top ) { top = y ; } if ( y > bottom ) { bottom = y ; } } const tx = this . _modelMatrix . invertTransformX ( pointX ) ; const ty = this . _modelMatrix . invertTransformY ( pointY ) ; return left <= tx && tx <= right && top <= ty && ty <= bottom ; } return public getModel ( ) { return this . _model ; } return public getRenderer ( ) { return this . _renderer ; } /**
     * レンダラを作成して初期化を実行する
     */ public createRenderer ( ) { if ( this . _renderer ) { this . deleteRenderer ( ) ; } this . _renderer = new CubismRenderer_WebGL ( ) ; this . _renderer . initialize ( this . _model ) ; } /**
     * レンダラの解放
     */ public deleteRenderer ( ) { if ( this . _renderer != null ) { this . _renderer . release ( ) ; this . _renderer = null ; } } param eventValue public motionEventFired ( eventValue ) { CubismLogInfo ( '{0}' , eventValue . s ) ; } param caller param eventValue param customData public static cubismDefaultMotionEventCallback ( caller , eventValue , customData ) { const model = customData ; if ( model != null ) { model . motionEventFired ( eventValue ) ; } } /**
     * コンストラクタ
     */ public constructor ( ) { this . _moc = null ; this . _model = null ; this . _motionManager = null ; this . _expressionManager = null ; this . _eyeBlink = null ; this . _breath = null ; this . _modelMatrix = null ; this . _pose = null ; this . _dragManager = null ; this . _physics = null ; this . _modelUserData = null ; this . _initialized = false ; this . _updating = false ; this . _opacity = 1.0 ; this . _lipsync = true ; this . _lastLipSyncValue = 0.0 ; this . _dragX = 0.0 ; this . _dragY = 0.0 ; this . _accelerationX = 0.0 ; this . _accelerationY = 0.0 ; this . _accelerationZ = 0.0 ; this . _debugMode = false ; this . _renderer = null ; this . _motionManager = new CubismMotionManager ( ) ; this . _motionManager . setEventCallback ( CubismUserModel . cubismDefaultMotionEventCallback , this ) ; this . _expressionManager = new CubismMotionManager ( ) ; this . _dragManager = new CubismTargetPoint ( ) ; } /**
     * デストラクタに相当する処理
     */ public release ( ) { if ( this . _motionManager != null ) { this . _motionManager . release ( ) ; this . _motionManager = null ; } if ( this . _expressionManager != null ) { this . _expressionManager . release ( ) ; this . _expressionManager = null ; } if ( this . _moc != null ) { this . _moc . deleteModel ( this . _model ) ; this . _moc . release ( ) ; this . _moc = null ; } this . _modelMatrix = null ; CubismPose . delete ( this . _pose ) ; CubismEyeBlink . delete ( this . _eyeBlink ) ; CubismBreath . delete ( this . _breath ) ; this . _dragManager = null ; CubismPhysics . delete ( this . _physics ) ; CubismModelUserData . delete ( this . _modelUserData ) ; this . deleteRenderer ( ) ; } protected _moc : CubismMoc ; protected _model : CubismModel ; protected _motionManager : CubismMotionManager ; protected _expressionManager : CubismMotionManager ; protected _eyeBlink : CubismEyeBlink ; protected _breath : CubismBreath ; protected _modelMatrix : CubismModelMatrix ; protected _pose : CubismPose ; protected _dragManager : CubismTargetPoint ; protected _physics : CubismPhysics ; protected _modelUserData : CubismModelUserData ; protected _initialized : boolean ; protected _updating : boolean ; protected _opacity : number ; protected _lipsync : boolean ; protected _lastLipSyncValue : number ; protected _dragX : number ; protected _dragY : number ; protected _accelerationX : number ; protected _accelerationY : number ; protected _accelerationZ : number ; protected _debugMode : boolean ; private _renderer : CubismRenderer_WebGL ; } import * as $ from './cubismusermodel' ; export namespace Live2DCubismFramework { export const CubismUserModel = $ . CubismUserModel ; export type CubismUserModel = $ . CubismUserModel ; }