Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Please limit one question/topic per post.
Please provide the following details depending on types of question

▼ For question regarding Editor, please provide:
- Live2D Software Version: (e.g. Cubism Editor 3.1.02, Euclid Editor 1.2.02)
- OS & Version: (e.g. Windows 10, macOS HighSierra)
- PC Model: (e.g. MacBookPro 2017)
- Graphics Specifications: (e.g. GeForce GTX 950M)
- Memory: (e.g. 8GB)
- Illustration Software used: (e.g. Photoshop, ClipStudio, SAI)
- Attach screenshot or capture video to show your problem:
---------------------------
▼ For question regarding SDK, please provide:
- For us to reproduce the issue you wish to inquire about, please provide either a minimum project file which has the issue. or specific instructions on how to reproduce the issue.
- Types and version of Cubism SDK you are using.
---------------------------
▼ For question regarding Cubism Software License,
For issues related to purchasing, your order, license key, and subscription, please contact us via contact form:
https://www.live2d.com/en/contact/contact_form

How do I change the model's expressions during gameplay?

edited February 2016 in Help
I have checked the live2D Manual at "Cubism SDK > platform > Unity", and I haven't found a clear way to change a model's expressions or animations through code.

What I'm trying to do is a function I can call, for example "ShowHappyCharacter();" and "ShowSadCharacter();" that I can use to change the expressions during gameplay.

Comments

  • Hi, CBeam .

    I think change of model's expressions is a code only to SampleApp1 project of Live2D Unity SDK.
    It has change of model's expressions in LAppModel.cs .

    [SampleApp1/Assets/Scripts/sample/LAppModel.cs]

    public void Init(String modelJson)
    {
    	・
    	・
    	// Expression .json Load
    	if (modelSetting.GetExpressionNum() != 0)
    	{
    		var len = modelSetting.GetExpressionNum();
    		for (int i = 0; i < len; i++)
    		{
    			loadExpression(modelSetting.GetExpressionName(i), modelHomeDir + modelSetting.GetExpressionFile(i));
    		}
    	}
    	・
    	・
    }
    
    public void Update()
    {
    	・
    	・
    	// Expression parameter update
    	if (expressionManager != null) expressionManager.updateParam(live2DModel);
    	・
    	・
    	
    	// parameter update
    	live2DModel.update();
    }
    
    Good luck !
  • :'( I really wish I could help you with this CBeam, but I know nothing about Unity. I hope naotaro answered your question. He/She is awesome. Good luck!!
  • edited December 2015
    Ah, it's ok Wai, thank you though.

    Naotaro, I think I have not explained my situation properly, but I am thankful for your response. What I want to do is to have the live2d model's emotion to change during gameplay, so I think that a function that uses "Input" during the "Update()" is required, but I don't know which.

    For example, when I press "A", the emotion changes to "Confident Smile", and when I press "B", it changes to "Laughing".

    Finding a function that changes the expression during "Update()" depending on a variable would also solve my issue.

    image
  • edited December 2015
    My Acquaintance is creating a simple script . Please wait a little .
  • Hi, CBeam.

    You can switch facial expression by changing /sample/Simple/simpleModel.cs of Live2D SDK like below:
    using UnityEngine;
    using live2d;
    using live2d.framework; //
    
    [ExecuteInEditMode]
    public class SimpleModel : MonoBehaviour 
    {
    	public TextAsset mocFile ;
    	public Texture2D[] textureFiles ;
    	
    	private Live2DModelUnity live2DModel;
        private Matrix4x4 live2DCanvasPos;
    
        // expression
        public TextAsset expJsonA, expJsonB; //Please Drag & Drop .exp.json to expJsonA and expJsonB in the Inspector of the Unity Editor.
        AMotion expressionMotionA, expressionMotionB;
        MotionQueueManager expressionMgr;
    	
    	void Start ()
        {
            if (live2DModel != null) return;
            Live2D.init();
    
            live2DModel = Live2DModelUnity.loadModel(mocFile.bytes);
            for (int i = 0; i < textureFiles.Length; i++)
            {
                live2DModel.setTexture(i, textureFiles[i]);
            }
    
            float modelWidth = live2DModel.getCanvasWidth();
            live2DCanvasPos = Matrix4x4.Ortho(0, modelWidth, modelWidth, 0, -50.0f, 50.0f);
    
            // load .exp.json
            expressionMotionA = L2DExpressionMotion.loadJson(expJsonA.bytes);
            expressionMotionB = L2DExpressionMotion.loadJson(expJsonB.bytes);
    
            expressionMgr = new MotionQueueManager();
        }
    	
        void Update()
        {
            if (live2DModel == null) return;
            live2DModel.setMatrix(transform.localToWorldMatrix * live2DCanvasPos);
    
            if (!Application.isPlaying)
            {
                live2DModel.update();
                return;
            }
            
    
            // Change Expression.
            if (Input.GetKeyDown(KeyCode.A))
            {// pressed "A" key.
                expressionMgr.startMotion(expressionMotionA);
            }
            else if (Input.GetKeyDown(KeyCode.B))
            {// pressed "B" key.
                expressionMgr.startMotion(expressionMotionB);
            }
    
            // update change of expression to Live2D model.
            expressionMgr.updateParam(live2DModel);
            
            live2DModel.update();
        }
    	
    	void OnRenderObject()
    	{
            if (live2DModel == null) return;
            live2DModel.draw();
        }
    }

    Add L2DExpressionMotion.cs to the project because L2DExpressionMotion is used to load exp.json.
    L2DExpressionMotion is in /framework folder of Live2D SDK.

    I hope this will answer your question.
  • edited December 2015
    I have followed your instructions and used expression 6 and 8. It works!

    Thank you very much naotaro for your help and y_a_s_ for the code!

    image
Sign In or Register to comment.