/**
 * 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 { ICubismModelSetting } from './icubismmodelsetting' ; import { CubismIdHandle } from './id/cubismid' ; import { CubismFramework } from './live2dcubismframework' ; import { csmMap , iterator } from './type/csmmap' ; import { csmVector } from './type/csmvector' ; import { CubismJson , Value } from './utils/cubismjson' ; /**
 * Model3Jsonのキー文字列
 */ const Version = 'Version' ; const FileReferences = 'FileReferences' ; const Groups = 'Groups' ; const Layout = 'Layout' ; const HitAreas = 'HitAreas' ; const Moc = 'Moc' ; const Textures = 'Textures' ; const Physics = 'Physics' ; const Pose = 'Pose' ; const Expressions = 'Expressions' ; const Motions = 'Motions' ; const UserData = 'UserData' ; const Name = 'Name' ; const FilePath = 'File' ; const Id = 'Id' ; const Ids = 'Ids' ; const Target = 'Target' ; const Idle = 'Idle' ; const TapBody = 'TapBody' ; const PinchIn = 'PinchIn' ; const PinchOut = 'PinchOut' ; const Shake = 'Shake' ; const FlickHead = 'FlickHead' ; const Parameter = 'Parameter' ; const SoundPath = 'Sound' ; const FadeInTime = 'FadeInTime' ; const FadeOutTime = 'FadeOutTime' ; const CenterX = 'CenterX' ; const CenterY = 'CenterY' ; const X = 'X' ; const Y = 'Y' ; const Width = 'Width' ; const Height = 'Height' ; const LipSync = 'LipSync' ; const EyeBlink = 'EyeBlink' ; const InitParameter = 'init_param' ; const InitPartsVisible = 'init_parts_visible' ; const Val = 'val' ; enum FrequestNode { FrequestNode_Groups , FrequestNode_Moc , FrequestNode_Motions , FrequestNode_Expressions , FrequestNode_Textures , FrequestNode_Physics , FrequestNode_Pose , FrequestNode_HitAreas } /**
 * Model3Jsonパーサー
 *
 * model3.jsonファイルをパースして値を取得する
 */ export class CubismModelSettingJson extends ICubismModelSetting { param buffer param size public constructor ( buffer , size ) { super ( ) ; this . _json = CubismJson . create ( buffer , size ) ; if ( this . _json ) { this . _jsonValue = new csmVector < Value > ( ) ; this . _jsonValue . pushBack ( this . _json . getRoot ( ) . getValueByString ( Groups ) ) ; this . _jsonValue . pushBack ( this . _json . getRoot ( ) . getValueByString ( FileReferences ) . getValueByString ( Moc ) ) ; this . _jsonValue . pushBack ( this . _json . getRoot ( ) . getValueByString ( FileReferences ) . getValueByString ( Motions ) ) ; this . _jsonValue . pushBack ( this . _json . getRoot ( ) . getValueByString ( FileReferences ) . getValueByString ( Expressions ) ) ; this . _jsonValue . pushBack ( this . _json . getRoot ( ) . getValueByString ( FileReferences ) . getValueByString ( Textures ) ) ; this . _jsonValue . pushBack ( this . _json . getRoot ( ) . getValueByString ( FileReferences ) . getValueByString ( Physics ) ) ; this . _jsonValue . pushBack ( this . _json . getRoot ( ) . getValueByString ( FileReferences ) . getValueByString ( Pose ) ) ; this . _jsonValue . pushBack ( this . _json . getRoot ( ) . getValueByString ( HitAreas ) ) ; } } /**
     * デストラクタ相当の処理
     */ public release ( ) { CubismJson . delete ( this . _json ) ; this . _jsonValue = null ; } return public GetJson ( ) { return this . _json ; } return public getModelFileName ( ) { if ( ! this . isExistModelFile ( ) ) { return '' ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Moc ) . getRawString ( ) ; } /**
     * モデルが使用するテクスチャの数を取得する
     * テクスチャの数
     */ public getTextureCount ( ) { if ( ! this . isExistTextureFiles ( ) ) { return 0 ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Textures ) . getSize ( ) ; } return public getTextureDirectory ( ) { return this . _jsonValue . at ( FrequestNode . FrequestNode_Textures ) . getRawString ( ) ; } param index return public getTextureFileName ( index ) { return this . _jsonValue . at ( FrequestNode . FrequestNode_Textures ) . getValueByIndex ( index ) . getRawString ( ) ; } return public getHitAreasCount ( ) { if ( ! this . isExistHitAreas ( ) ) { return 0 ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_HitAreas ) . getSize ( ) ; } param index return public getHitAreaId ( index ) { return CubismFramework . getIdManager ( ) . getId ( this . _jsonValue . at ( FrequestNode . FrequestNode_HitAreas ) . getValueByIndex ( index ) . getValueByString ( Id ) . getRawString ( ) ) ; } param index return public getHitAreaName ( index ) { return this . _jsonValue . at ( FrequestNode . FrequestNode_HitAreas ) . getValueByIndex ( index ) . getValueByString ( Name ) . getRawString ( ) ; } return public getPhysicsFileName ( ) { if ( ! this . isExistPhysicsFile ( ) ) { return '' ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Physics ) . getRawString ( ) ; } return public getPoseFileName ( ) { if ( ! this . isExistPoseFile ( ) ) { return '' ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Pose ) . getRawString ( ) ; } return public getExpressionCount ( ) { if ( ! this . isExistExpressionFile ( ) ) { return 0 ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Expressions ) . getSize ( ) ; } param index return public getExpressionName ( index ) { return this . _jsonValue . at ( FrequestNode . FrequestNode_Expressions ) . getValueByIndex ( index ) . getValueByString ( Name ) . getRawString ( ) ; } param index return public getExpressionFileName ( index ) { return this . _jsonValue . at ( FrequestNode . FrequestNode_Expressions ) . getValueByIndex ( index ) . getValueByString ( FilePath ) . getRawString ( ) ; } return public getMotionGroupCount ( ) { if ( ! this . isExistMotionGroups ( ) ) { return 0 ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getKeys ( ) . getSize ( ) ; } param index return public getMotionGroupName ( index ) { if ( ! this . isExistMotionGroups ( ) ) { return null ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getKeys ( ) . at ( index ) ; } param groupName return public getMotionCount ( groupName ) { if ( ! this . isExistMotionGroupName ( groupName ) ) { return 0 ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getValueByString ( groupName ) . getSize ( ) ; } param groupName param index return public getMotionFileName ( groupName , index ) { if ( ! this . isExistMotionGroupName ( groupName ) ) { return '' ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getValueByString ( groupName ) . getValueByIndex ( index ) . getValueByString ( FilePath ) . getRawString ( ) ; } param groupName param index return public getMotionSoundFileName ( groupName , index ) { if ( ! this . isExistMotionSoundFile ( groupName , index ) ) { return '' ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getValueByString ( groupName ) . getValueByIndex ( index ) . getValueByString ( SoundPath ) . getRawString ( ) ; } param groupName param index return public getMotionFadeInTimeValue ( groupName , index ) { if ( ! this . isExistMotionFadeIn ( groupName , index ) ) { return - 1.0 ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getValueByString ( groupName ) . getValueByIndex ( index ) . getValueByString ( FadeInTime ) . toFloat ( ) ; } param groupName param index return public getMotionFadeOutTimeValue ( groupName , index ) { if ( ! this . isExistMotionFadeOut ( groupName , index ) ) { return - 1.0 ; } return this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getValueByString ( groupName ) . getValueByIndex ( index ) . getValueByString ( FadeOutTime ) . toFloat ( ) ; } return public getUserDataFile ( ) { if ( ! this . isExistUserDataFile ( ) ) { return '' ; } return this . _json . getRoot ( ) . getValueByString ( FileReferences ) . getValueByString ( UserData ) . getRawString ( ) ; } param outLayoutMap return return public getLayoutMap ( outLayoutMap ) { const map = this . _json . getRoot ( ) . getValueByString ( Layout ) . getMap ( ) ; if ( map == null ) { return false ; } let ret = false ; for ( const ite = map . begin ( ) ; ite . notEqual ( map . end ( ) ) ; ite . preIncrement ( ) ) { outLayoutMap . setValue ( ite . ptr ( ) . first , ite . ptr ( ) . second . toFloat ( ) ) ; ret = true ; } return ret ; } return public getEyeBlinkParameterCount ( ) { if ( ! this . isExistEyeBlinkParameters ( ) ) { return 0 ; } let num = 0 ; for ( let i = 0 ; i < this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getSize ( ) ; i ++ ) { const refI = this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getValueByIndex ( i ) ; if ( refI . isNull ( ) || refI . isError ( ) ) { continue ; } if ( refI . getValueByString ( Name ) . getRawString ( ) == EyeBlink ) { num = refI . getValueByString ( Ids ) . getVector ( ) . getSize ( ) ; break ; } } return num ; } param index return public getEyeBlinkParameterId ( index ) { if ( ! this . isExistEyeBlinkParameters ( ) ) { return null ; } for ( let i = 0 ; i < this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getSize ( ) ; i ++ ) { const refI = this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getValueByIndex ( i ) ; if ( refI . isNull ( ) || refI . isError ( ) ) { continue ; } if ( refI . getValueByString ( Name ) . getRawString ( ) == EyeBlink ) { return CubismFramework . getIdManager ( ) . getId ( refI . getValueByString ( Ids ) . getValueByIndex ( index ) . getRawString ( ) ) ; } } return null ; } return public getLipSyncParameterCount ( ) { if ( ! this . isExistLipSyncParameters ( ) ) { return 0 ; } let num = 0 ; for ( let i = 0 ; i < this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getSize ( ) ; i ++ ) { const refI = this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getValueByIndex ( i ) ; if ( refI . isNull ( ) || refI . isError ( ) ) { continue ; } if ( refI . getValueByString ( Name ) . getRawString ( ) == LipSync ) { num = refI . getValueByString ( Ids ) . getVector ( ) . getSize ( ) ; break ; } } return num ; } param index return public getLipSyncParameterId ( index ) { if ( ! this . isExistLipSyncParameters ( ) ) { return null ; } for ( let i = 0 ; i < this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getSize ( ) ; i ++ ) { const refI = this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getValueByIndex ( i ) ; if ( refI . isNull ( ) || refI . isError ( ) ) { continue ; } if ( refI . getValueByString ( Name ) . getRawString ( ) == LipSync ) { return CubismFramework . getIdManager ( ) . getId ( refI . getValueByString ( Ids ) . getValueByIndex ( index ) . getRawString ( ) ) ; } } return null ; } return return private isExistModelFile ( ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Moc ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } return return private isExistTextureFiles ( ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Textures ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } return return private isExistHitAreas ( ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_HitAreas ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } return return private isExistPhysicsFile ( ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Physics ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } return return private isExistPoseFile ( ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Pose ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } return return private isExistExpressionFile ( ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Expressions ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } return return private isExistMotionGroups ( ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } param groupName return return private isExistMotionGroupName ( groupName ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getValueByString ( groupName ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } param groupName param index return return private isExistMotionSoundFile ( groupName , index ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getValueByString ( groupName ) . getValueByIndex ( index ) . getValueByString ( SoundPath ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } param groupName param index return return private isExistMotionFadeIn ( groupName , index ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getValueByString ( groupName ) . getValueByIndex ( index ) . getValueByString ( FadeInTime ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } param groupName param index return return private isExistMotionFadeOut ( groupName , index ) { const node = this . _jsonValue . at ( FrequestNode . FrequestNode_Motions ) . getValueByString ( groupName ) . getValueByIndex ( index ) . getValueByString ( FadeOutTime ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } return return private isExistUserDataFile ( ) { const node = this . _json . getRoot ( ) . getValueByString ( FileReferences ) . getValueByString ( UserData ) ; return ! node . isNull ( ) && ! node . isError ( ) ; } return return private isExistEyeBlinkParameters ( ) { if ( this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . isNull ( ) || this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . isError ( ) ) { return false ; } for ( let i = 0 ; i < this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getSize ( ) ; ++ i ) { if ( this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getValueByIndex ( i ) . getValueByString ( Name ) . getRawString ( ) == EyeBlink ) { return true ; } } return false ; } return return private isExistLipSyncParameters ( ) { if ( this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . isNull ( ) || this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . isError ( ) ) { return false ; } for ( let i = 0 ; i < this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getSize ( ) ; ++ i ) { if ( this . _jsonValue . at ( FrequestNode . FrequestNode_Groups ) . getValueByIndex ( i ) . getValueByString ( Name ) . getRawString ( ) == LipSync ) { return true ; } } return false ; } private _json : CubismJson ; private _jsonValue : csmVector < Value > ; } import * as $ from './cubismmodelsettingjson' ; export namespace Live2DCubismFramework { export const CubismModelSettingJson = $ . CubismModelSettingJson ; export type CubismModelSettingJson = $ . CubismModelSettingJson ; }