コード例 #1
0
ファイル: BasicModel.cs プロジェクト: hatano0x06/Coroppoxus
        void UpdateBone(BasicMotion motion)
        {
            float weight = 1.0f;

            float[] value = new float[4];
            foreach (var fcurve in motion.FCurves)
            {
                if (fcurve.TargetType == BasicFCurveTargetType.Bone)
                {
                    EvalFCurve(fcurve, motion.Frame, value);
                    BasicBone bone = Bones[fcurve.TargetIndex];
                    switch (fcurve.ChannelType)
                    {
                    case BasicFCurveChannelType.Translation:
                        Vector3 translation = new Vector3(value[0], value[1], value[2]);
                        bone.Translation = bone.Translation.Lerp(translation, weight);
                        break;

                    case BasicFCurveChannelType.Rotation:
                        Quaternion rotation;
                        if (fcurve.DimCount == 4)
                        {
                            rotation = new Quaternion(value[0], value[1], value[2], value[3]);
                        }
                        else
                        {
                            Vector3 angles = new Vector3(value[0], value[1], value[2]);
                            // [note] 旧API
                            // rotation = Quaternion.FromEulerAnglesZYX( angles ) ;
                            rotation = Quaternion.RotationZyx(angles);
                        }
                        // [note] 旧API
                        // bone.Rotation = Quaternion.Slerp( bone.Rotation, rotation, weight, 0.0f ) ;
                        bone.Rotation = bone.Rotation.Slerp(rotation, weight);
                        break;

                    case BasicFCurveChannelType.Scaling:
                        Vector3 scaling = new Vector3(value[0], value[1], value[2]);
                        bone.Scaling = bone.Scaling.Lerp(scaling, weight);
                        break;
                    }
                }
                else if (fcurve.TargetType == BasicFCurveTargetType.Material)
                {
                    EvalFCurve(fcurve, motion.Frame, value);
                    BasicMaterial material = Materials[fcurve.TargetIndex];

                    switch (fcurve.ChannelType)
                    {
                    // 追加
                    case BasicFCurveChannelType.Diffuse:
                        material.Diffuse.X = value[0];
                        material.Diffuse.Y = value[1];
                        material.Diffuse.Z = value[2];
                        material.Diffuse.W = value[3];
                        break;
                    }
                }
            }
        }
コード例 #2
0
ファイル: BasicModel.cs プロジェクト: hatano0x06/Coroppoxus
 /// Motion の長さをフレームで取得
 public float GetMotionFrameMax(int idx)
 {
     if (Motions.Length > idx)
     {
         BasicMotion motion = Motions[idx];
         return(motion.FrameEnd);
     }
     return(0.0f);
 }
コード例 #3
0
ファイル: BasicModel.cs プロジェクト: hatano0x06/Coroppoxus
 /// Motion の長さを秒で取得
 public float GetMotionLength(int idx)
 {
     if (Motions.Length > idx)
     {
         BasicMotion motion = Motions[idx];
         return(motion.FrameEnd / motion.FrameRate);
     }
     return(0.0f);
 }
コード例 #4
0
ファイル: BasicModel.cs プロジェクト: hatano0x06/Coroppoxus
        /// step秒 分だけアニメーションを進める
        public void Animate(int idx, float step)
        {
            if (Motions.Length > idx)
            {
                BasicMotion motion = Motions[idx];
                motion.Frame += step * motion.FrameRate;

                if (motion.Frame > motion.FrameEnd)
                {
                    motion.Frame = motion.FrameStart;
                }
                UpdateBone(motion);
            }
        }
コード例 #5
0
ファイル: BasicModel.cs プロジェクト: hatano0x06/Coroppoxus
        /// 指定フレームのアニメーションを適用する
        public void SetAnimFrame(int idx, float frame)
        {
            if (Motions.Length > idx)
            {
                BasicMotion motion = Motions[idx];
                motion.Frame = frame;

                if (motion.Frame > motion.FrameEnd)
                {
                    motion.Frame = motion.FrameStart;
                }
                UpdateBone(motion);
            }
        }
コード例 #6
0
        void LoadMotion(Chunk chunk, BasicMotion motion)
        {
            int nFCurves = CountChild(chunk, ChunkType.Animate);

            motion.FCurves = new BasicFCurve[nFCurves];
            for (int i = 0; i < nFCurves; i++)
            {
                motion.FCurves[i] = new BasicFCurve();
            }
            int iFCurve = 0;

            Chunk child;

            for (int pos = chunk.Child; pos < chunk.Next; pos = child.Next)
            {
                child = ReadChunk(pos);
                int args = child.Args;
                switch (child.Type)
                {
                case ChunkType.Animate:
                    LoadFCurve(child, chunk, motion.FCurves[iFCurve++]);
                    break;

                case ChunkType.FrameRate:
                    motion.FrameRate = ReadFloat(args);
                    break;

                case ChunkType.FrameLoop:
                    motion.FrameStart = ReadFloat(args + 0);
                    motion.FrameEnd   = ReadFloat(args + 4);
                    break;

                case ChunkType.FrameRepeat:
                    motion.FrameRepeat = (BasicMotionRepeatMode)ReadInt32(args);
                    break;
                }
            }
        }
コード例 #7
0
        void UpdateBone( BasicMotion motion )
        {
            float weight = 1.0f ;

            float[] value = new float[ 4 ] ;
            foreach ( var fcurve in motion.FCurves ) {
            if ( fcurve.TargetType == BasicFCurveTargetType.Bone ){
                EvalFCurve( fcurve, motion.Frame, value ) ;
                BasicBone bone = Bones[ fcurve.TargetIndex ] ;
                switch ( fcurve.ChannelType ) {
                  case BasicFCurveChannelType.Translation :
                    Vector3 translation = new Vector3( value[ 0 ], value[ 1 ], value[ 2 ] ) ;
                    bone.Translation = bone.Translation.Lerp( translation, weight ) ;
                    break ;
                  case BasicFCurveChannelType.Rotation :
                    Quaternion rotation ;
                    if ( fcurve.DimCount == 4 ) {
                        rotation = new Quaternion( value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] ) ;
                    } else {
                        Vector3 angles = new Vector3( value[ 0 ], value[ 1 ], value[ 2 ] ) ;
                        // [note] 旧API
                        // rotation = Quaternion.FromEulerAnglesZYX( angles ) ;
                        rotation = Quaternion.RotationZyx( angles ) ;
                    }
                    // [note] 旧API
                    // bone.Rotation = Quaternion.Slerp( bone.Rotation, rotation, weight, 0.0f ) ;
                    bone.Rotation = bone.Rotation.Slerp( rotation, weight ) ;
                    break ;
                  case BasicFCurveChannelType.Scaling :
                    Vector3 scaling = new Vector3( value[ 0 ], value[ 1 ], value[ 2 ] ) ;
                    bone.Scaling = bone.Scaling.Lerp( scaling, weight ) ;
                    break ;
                }
            }else if( fcurve.TargetType == BasicFCurveTargetType.Material ){
                EvalFCurve( fcurve, motion.Frame, value ) ;
                BasicMaterial material = Materials[ fcurve.TargetIndex ];

                switch ( fcurve.ChannelType ) {
                    // 追加
                  case BasicFCurveChannelType.Diffuse:
                    material.Diffuse.X = value[ 0 ];
                    material.Diffuse.Y = value[ 1 ];
                    material.Diffuse.Z = value[ 2 ];
                    material.Diffuse.W = value[ 3 ];
                    break;
                }
            }
            }
        }
コード例 #8
0
 private float getFrame( BasicMotion motion )
 {
     return motion.Frame;
 }
コード例 #9
0
ファイル: BasicModel.cs プロジェクト: hatano0x06/Coroppoxus
 private float getFrame(BasicMotion motion)
 {
     return(motion.Frame);
 }
コード例 #10
0
ファイル: MdxLoader.cs プロジェクト: hatano0x06/Coroppoxus
        void LoadMotion( Chunk chunk, BasicMotion motion )
        {
            int nFCurves = CountChild( chunk, ChunkType.Animate ) ;
            motion.FCurves = new BasicFCurve[ nFCurves ] ;
            for ( int i = 0 ; i < nFCurves ; i ++ ) motion.FCurves[ i ] = new BasicFCurve() ;
            int iFCurve = 0 ;

            Chunk child ;
            for ( int pos = chunk.Child ; pos < chunk.Next ; pos = child.Next ) {
            child = ReadChunk( pos ) ;
            int args = child.Args ;
            switch ( child.Type ) {
                case ChunkType.Animate :
                    LoadFCurve( child, chunk, motion.FCurves[ iFCurve ++ ] ) ;
                    break ;
                case ChunkType.FrameRate :
                    motion.FrameRate = ReadFloat( args ) ;
                    break ;
                case ChunkType.FrameLoop :
                    motion.FrameStart = ReadFloat( args + 0 ) ;
                    motion.FrameEnd = ReadFloat( args + 4 ) ;
                    break ;
                case ChunkType.FrameRepeat :
                    motion.FrameRepeat = (BasicMotionRepeatMode)ReadInt32( args ) ;
                    break ;
            }
            }
        }