Exemplo n.º 1
0
        /// <summary>
        /// ストリームからポーズデータを読み込む。
        /// </summary>
        /// <param name="stream">ストリーム</param>
        /// <param name="model">対象のモデル</param>
        public CubismPose(Stream stream, CubismModel model)
        {
            var json = CubismPoseJson.Create(stream);

            if (!double.IsNaN(json.FadeInTime) && (0.0 <= json.FadeInTime))
            {
                FadeTimeSeconds = json.FadeInTime;
            }

            var part_groups = new List <PartData[]>();

            foreach (var group_item in json.Groups)
            {
                var part_group = new List <PartData>();
                foreach (var item in group_item)
                {
                    CubismPart id              = model.GetPart(item.Id);
                    var        part_data       = new PartData(model, id);
                    var        linked_part_ids = new List <CubismPart>();
                    foreach (string linked_id_name in item.Link)
                    {
                        CubismPart linked_id = model.GetPart(linked_id_name);
                        if (linked_id != null)
                        {
                            linked_part_ids.Add(linked_id);
                        }
                    }
                    part_data.LinkedParts = linked_part_ids.ToArray();
                    part_group.Add(part_data);
                }
                part_groups.Add(part_group.ToArray());
            }
            PartGroups = part_groups.ToArray();

            Reset();
        }
Exemplo n.º 2
0
        private static CubismMotionCurve ParseCurve(CubismMotionJson.CurveItem item, CubismModel model)
        {
            CubismMotionCurve curve = new CubismMotionCurve();

            if (item.Target == "Model")
            {
                curve.Target = CubismMotionCurve.TargetType.Model;
                curve.Effect = new CubismId(item.Id);
            }
            else if (item.Target == "Parameter")
            {
                curve.Target    = CubismMotionCurve.TargetType.Parameter;
                curve.Parameter = model.GetParameter(item.Id);
                if (curve.Parameter == null)
                {
                    return(null);
                }
            }
            else if (item.Target == "PartOpacity")
            {
                curve.Target = CubismMotionCurve.TargetType.PartOpacity;
                curve.Part   = model.GetPart(item.Id);
                if (curve.Part == null)
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
            curve.FadeInTime  = item.FadeInTime;
            curve.FadeOutTime = item.FadeOutTime;

            // 制御点を読み込む
            // 初めの2アイテムは最初の制御点を示す
            var segment_item             = item.Segments;
            int segment_count            = item.Segments.Length;
            CubismMotionPoint last_point = new CubismMotionPoint(segment_item[0], segment_item[1]);

            // 以降の制御点を読み込む
            var segments = new List <ICubismMotionSegment>();

            for (int segment_index = 2; segment_index < segment_count;)
            {
                switch ((CubismMotionSegmentType)segment_item[segment_index])
                {
                case CubismMotionSegmentType.Linear:
                {
                    var segment = new CubismMotionLinearSegment();
                    segment.Points[0] = last_point;
                    segment.Points[1] = new CubismMotionPoint(segment_item[segment_index + 1], segment_item[segment_index + 2]);
                    segments.Add(segment);
                    last_point     = segment.Points[1];
                    segment_index += 3;
                    break;
                }

                case CubismMotionSegmentType.Bezier:
                {
                    var segment = new CubismMotionBezierSegment();
                    segment.Points[0] = last_point;
                    segment.Points[1] = new CubismMotionPoint(segment_item[segment_index + 1], segment_item[segment_index + 2]);
                    segment.Points[2] = new CubismMotionPoint(segment_item[segment_index + 3], segment_item[segment_index + 4]);
                    segment.Points[3] = new CubismMotionPoint(segment_item[segment_index + 5], segment_item[segment_index + 6]);
                    segments.Add(segment);
                    last_point     = segment.Points[3];
                    segment_index += 7;
                    break;
                }

                case CubismMotionSegmentType.Stepped:
                {
                    var segment = new CubismMotionSteppedSegment();
                    segment.Points[0] = last_point;
                    segment.Points[1] = new CubismMotionPoint(segment_item[segment_index + 1], segment_item[segment_index + 2]);
                    segments.Add(segment);
                    last_point     = segment.Points[1];
                    segment_index += 3;
                    break;
                }

                case CubismMotionSegmentType.InverseStepped:
                {
                    var segment = new CubismMotionInverseSteppedSegment();
                    segment.Points[0] = last_point;
                    segment.Points[1] = new CubismMotionPoint(segment_item[segment_index + 1], segment_item[segment_index + 2]);
                    segments.Add(segment);
                    last_point     = segment.Points[1];
                    segment_index += 3;
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            curve.Segments = segments.ToArray();

            return(curve);
        }