Example #1
0
    public void Init(String modelJson)
    {
        updating    = true;
        initialized = false;

        modelSetting = new ModelSettingJson(modelJson);

        if (LAppDefine.DEBUG_LOG)
        {
            Debug.Log("Start to load model");
        }

        // Live2D Model
        if (modelSetting.GetModelFile() != null)
        {
            loadModelData(modelHomeDir + modelSetting.GetModelFile());

            var len = modelSetting.GetTextureNum();
            for (int i = 0; i < len; i++)
            {
                loadTexture(i, modelHomeDir + modelSetting.GetTextureFile(i));
            }
        }



        for (int i = 0; i < modelSetting.GetInitParamNum(); i++)
        {
            string id    = modelSetting.GetInitParamID(i);
            float  value = modelSetting.GetInitParamValue(i);
            live2DModel.setParamFloat(id, value);
        }

        for (int i = 0; i < modelSetting.GetInitPartsVisibleNum(); i++)
        {
            string id    = modelSetting.GetInitPartsVisibleID(i);
            float  value = modelSetting.GetInitPartsVisibleValue(i);
            live2DModel.setPartsOpacity(id, value);
        }



        view.SetupView(
            live2DModel.getCanvasWidth(),
            live2DModel.getCanvasHeight());

        updating    = false;
        initialized = true;
    }
Example #2
0
    /*
     * 初始化模型
     * @throws Exception
     */
    public void Init(String modelJson)
    {
        updating    = true;
        initialized = false;

        modelSetting = new ModelSettingJson(modelJson);

        if (LAppDefine.DEBUG_LOG)
        {
            Debug.Log("Start to load model");
        }

        // Live2D Model
        if (modelSetting.GetModelFile() != null)
        {
            loadModelData(modelHomeDir + modelSetting.GetModelFile());

            var len = modelSetting.GetTextureNum();
            Debug.Log(len);
            for (int i = 0; i < len; i++)
            {
                loadTexture(i, modelHomeDir + modelSetting.GetTextureFile(i));
            }
        }

        // Expression
        if (modelSetting.GetExpressionNum() != 0)
        {
            var len = modelSetting.GetExpressionNum();
            for (int i = 0; i < len; i++)
            {
                loadExpression(modelSetting.GetExpressionName(i), modelHomeDir + modelSetting.GetExpressionFile(i));
            }
        }

        // Physics
        if (modelSetting.GetPhysicsFile() != null)
        {
            loadPhysics(modelHomeDir + modelSetting.GetPhysicsFile());
        }

        // Pose
        if (modelSetting.GetPoseFile() != null)
        {
            loadPose(modelHomeDir + modelSetting.GetPoseFile());
        }

        // 由于布局可以在Unity上设置,因此不会从JSON中读取
        //Dictionary<string, float> layout = new Dictionary<string, float>();
        //if (modelSetting.GetLayout(layout))
        //{
        //    if (layout.ContainsKey("width")) modelMatrix.setWidth(layout["width"]);
        //    if (layout.ContainsKey("height")) modelMatrix.setHeight(layout["height"]);
        //    if (layout.ContainsKey("x")) modelMatrix.setX(layout["x"]);
        //    if (layout.ContainsKey("y")) modelMatrix.setY(layout["y"]);
        //    if (layout.ContainsKey("center_x")) modelMatrix.centerX(layout["center_x"]);
        //    if (layout.ContainsKey("center_y")) modelMatrix.centerY(layout["center_y"]);
        //    if (layout.ContainsKey("top")) modelMatrix.top(layout["top"]);
        //    if (layout.ContainsKey("bottom")) modelMatrix.bottom(layout["bottom"]);
        //    if (layout.ContainsKey("left")) modelMatrix.left(layout["left"]);
        //    if (layout.ContainsKey("right")) modelMatrix.right(layout["right"]);
        //}


        // 初始参数
        for (int i = 0; i < modelSetting.GetInitParamNum(); i++)
        {
            string id    = modelSetting.GetInitParamID(i);
            float  value = modelSetting.GetInitParamValue(i);
            live2DModel.setParamFloat(id, value);
        }

        for (int i = 0; i < modelSetting.GetInitPartsVisibleNum(); i++)
        {
            string id    = modelSetting.GetInitPartsVisibleID(i);
            float  value = modelSetting.GetInitPartsVisibleValue(i);
            live2DModel.setPartsOpacity(id, value);
        }

        // 自动捕眼器
        eyeBlink = new L2DEyeBlink();

        view.SetupView(
            live2DModel.getCanvasWidth(),
            live2DModel.getCanvasHeight());

        updating    = false; // 更新状態の完了
        initialized = true;  // 初期化完了
    }
Example #3
0
    public void Init(String modelJson)
    {
        updating = true;
        initialized = false;

        modelSetting = new ModelSettingJson(modelJson);

        if (LAppDefine.DEBUG_LOG) Debug.Log("Start to load model");

        // Live2D Model
        if (modelSetting.GetModelFile() != null)
        {
            loadModelData(modelHomeDir + modelSetting.GetModelFile());

            ((Live2DModelUnity)live2DModel).setRenderMode (Live2D.L2D_RENDER_DRAW_MESH);
            var len = modelSetting.GetTextureNum();
            for (int i = 0; i < len; i++)
            {
                loadTexture(i, modelHomeDir + modelSetting.GetTextureFile(i));
            }
        }

        // Expression
        if (modelSetting.GetExpressionNum() != 0)
        {
            var len = modelSetting.GetExpressionNum();
            for (int i = 0; i < len; i++)
            {
                loadExpression(modelSetting.GetExpressionName(i), modelHomeDir + modelSetting.GetExpressionFile(i));
            }
        }

        // Physics
        if (modelSetting.GetPhysicsFile()!=null)
        {
            loadPhysics(modelHomeDir + modelSetting.GetPhysicsFile());
        }

        // Pose
        if (modelSetting.GetPoseFile()!=null)
        {
            loadPose(modelHomeDir + modelSetting.GetPoseFile());
        }

        //Dictionary<string, float> layout = new Dictionary<string, float>();
        //if (modelSetting.GetLayout(layout))
        //{
        //    if (layout.ContainsKey("width")) modelMatrix.setWidth(layout["width"]);
        //    if (layout.ContainsKey("height")) modelMatrix.setHeight(layout["height"]);
        //    if (layout.ContainsKey("x")) modelMatrix.setX(layout["x"]);
        //    if (layout.ContainsKey("y")) modelMatrix.setY(layout["y"]);
        //    if (layout.ContainsKey("center_x")) modelMatrix.centerX(layout["center_x"]);
        //    if (layout.ContainsKey("center_y")) modelMatrix.centerY(layout["center_y"]);
        //    if (layout.ContainsKey("top")) modelMatrix.top(layout["top"]);
        //    if (layout.ContainsKey("bottom")) modelMatrix.bottom(layout["bottom"]);
        //    if (layout.ContainsKey("left")) modelMatrix.left(layout["left"]);
        //    if (layout.ContainsKey("right")) modelMatrix.right(layout["right"]);
        //}

        for (int i = 0; i < modelSetting.GetInitParamNum(); i++)
        {
            string id = modelSetting.GetInitParamID(i);
            float value = modelSetting.GetInitParamValue(i);
            live2DModel.setParamFloat(id, value);
        }

        for (int i = 0; i < modelSetting.GetInitPartsVisibleNum(); i++)
        {
            string id = modelSetting.GetInitPartsVisibleID(i);
            float value = modelSetting.GetInitPartsVisibleValue(i);
            live2DModel.setPartsOpacity(id, value);
        }

        eyeBlink = new L2DEyeBlink();

        view.SetupView(
            live2DModel.getCanvasWidth(),
            live2DModel.getCanvasHeight());

        updating = false;
        initialized = true;

        GetLive2DModelUnity ().setRenderMode (Live2D.L2D_RENDER_DRAW_MESH);

        //		int max = modelSetting.GetMotionNum ("normal");
        //		for (int i = 0; i < max; ++i) {
        //		}

        //		currentAnimIndex = -1;
        //		StartMotion("normal", currentAnimIndex, LAppDefine.PRIORITY_NORMAL);
    }
Example #4
0
    public void Initialize(L2DModelInfo modelInfo, int modelSlotIdx)
    {
        setUpdating(true);  // 모델 갱신중
        setInitialized(false);

        _IsActivate     = true;
        _modelHomeDir   = FileManager.getDirName(modelInfo._SettingFullPath);
        _modelRenderPos = new Vector3(modelSlotIdx * 5.0f, 60.0f, 0.0f);

        GameObject proxyObj = new GameObject(modelInfo._modelName);

        _proxy = proxyObj.AddComponent <L2DModelProxy>();
        _proxy.Initialize(this, modelInfo._planeSize, _modelRenderPos);

        string modelJson = Live2DFramework.getPlatformManager().loadString(modelInfo._SettingFullPath);

        _modelSetting = new ModelSettingJson(modelJson);
        startTimeMSec = UtSystem.getUserTimeMSec();
        _updatedOnce  = false;

        // Live2D Model
        if (_modelSetting.GetModelFile() != null)
        {
            loadModelData(_modelHomeDir + _modelSetting.GetModelFile());

            var len = _modelSetting.GetTextureNum();
            for (int i = 0; i < len; i++)
            {
                loadTexture(i, _modelHomeDir + _modelSetting.GetTextureFile(i));
            }
        }

        // 모션은 미리 읽지 않고 각 모션 재생 시도 시 읽어들임

        // Expression
        if (_modelSetting.GetExpressionNum() != 0)
        {
            var len = _modelSetting.GetExpressionNum();
            for (int i = 0; i < len; i++)
            {
                loadExpression(_modelSetting.GetExpressionName(i), _modelHomeDir + _modelSetting.GetExpressionFile(i));
            }
        }

        // Physics
        if (_modelSetting.GetPhysicsFile() != null)
        {
            loadPhysics(_modelHomeDir + _modelSetting.GetPhysicsFile());
        }

        // Pose
        if (_modelSetting.GetPoseFile() != null)
        {
            loadPose(_modelHomeDir + _modelSetting.GetPoseFile());
        }

        // 파라미터 초기값
        for (int i = 0; i < _modelSetting.GetInitParamNum(); i++)
        {
            string id    = _modelSetting.GetInitParamID(i);
            float  value = _modelSetting.GetInitParamValue(i);
            live2DModel.setParamFloat(id, value);
        }

        // 파츠
        for (int i = 0; i < _modelSetting.GetInitPartsVisibleNum(); i++)
        {
            string id    = _modelSetting.GetInitPartsVisibleID(i);
            float  value = _modelSetting.GetInitPartsVisibleValue(i);
            live2DModel.setPartsOpacity(id, value);
        }

        // 눈 자동깜빡임
        eyeBlink = new L2DEyeBlink();

        // 레이아웃. 적용 순서에 따라 결과 달라짐에 주의
        getModelMatrix().multScale(modelInfo._layout._scale, modelInfo._layout._scale);
        getModelMatrix().setY(modelInfo._layout._y);

        setUpdating(false); // 갱신상태 완료
        setInitialized(true);
    }
Example #5
0
    private void Init(string modelJson, string modelId)
    {
        modelSetting = new ModelSettingJson(modelJson);

        _baseDir = AssetLoader.GetLive2dDirById(modelId) + "/";

        // Live2D Model
        if (modelSetting.GetModelFile() != null)
        {
            loadModelData(_baseDir + modelSetting.GetModelFile());

            var len = modelSetting.GetTextureNum();
            for (int i = 0; i < len; i++)
            {
                loadTexture(i, _baseDir + modelSetting.GetTextureFile(i));
            }
        }

        string[] motionGroup = modelSetting.GetMotionGroupNames();

        for (int i = 0; i < motionGroup.Length; i++)
        {
            int num = modelSetting.GetMotionNum(motionGroup[i]);
            if (num != 0)
            {
                for (int j = 0; j < num; j++)
                {
                    _motionList.Add(modelSetting.GetMotionFile(motionGroup[i], j));
                }
            }
        }

        // Expression
        if (modelSetting.GetExpressionNum() != 0)
        {
            var len = modelSetting.GetExpressionNum();
            for (int i = 0; i < len; i++)
            {
                string name = modelSetting.GetExpressionName(i);
                loadExpression(name, _baseDir + modelSetting.GetExpressionFile(i));
                _expressionList.Add(name);
            }
        }

        // Physics
        if (modelSetting.GetPhysicsFile() != null)
        {
            loadPhysics(_baseDir + modelSetting.GetPhysicsFile());
        }

        // Pose
        if (modelSetting.GetPoseFile() != null)
        {
            loadPose(_baseDir + modelSetting.GetPoseFile());
        }

        for (int i = 0; i < modelSetting.GetInitParamNum(); i++)
        {
            string id    = modelSetting.GetInitParamID(i);
            float  value = modelSetting.GetInitParamValue(i);
            live2DModel.setParamFloat(id, value);
        }

        for (int i = 0; i < modelSetting.GetInitPartsVisibleNum(); i++)
        {
            string id    = modelSetting.GetInitPartsVisibleID(i);
            float  value = modelSetting.GetInitPartsVisibleValue(i);
            live2DModel.setPartsOpacity(id, value);
        }
    }