Ejemplo n.º 1
0
 private void TrySetFrameValue(H3DFloatKeyFrameGroup Group, ref float Value)
 {
     if (Group.Exists)
     {
         Value = Group.GetFrameValue(Frame);
     }
 }
Ejemplo n.º 2
0
        public CameraState GetCameraState()
        {
            if (State == AnimationState.Stopped)
            {
                ResetState();
            }

            if (State != AnimationState.Playing || Elements.Count == 0)
            {
                return(CamState);
            }

            for (int i = 0; i < Elements.Count; i++)
            {
                H3DAnimationElement Elem = Elements[i];

                if (Elem.PrimitiveType == H3DPrimitiveType.Transform)
                {
                    SetStateTransform((H3DAnimTransform)Elem.Content);
                }
                else if (Elem.PrimitiveType == H3DPrimitiveType.Vector3D)
                {
                    H3DAnimVector3D Vector = (H3DAnimVector3D)Elem.Content;

                    switch (Elem.TargetType)
                    {
                    case H3DTargetType.CameraUpVector:     SetVector3(Vector, ref CamState.UpVector);     break;

                    case H3DTargetType.CameraTargetPos:    SetVector3(Vector, ref CamState.Target);       break;

                    case H3DTargetType.CameraViewRotation: SetVector3(Vector, ref CamState.ViewRotation); break;
                    }
                }
                else if (Elem.PrimitiveType == H3DPrimitiveType.Float)
                {
                    H3DFloatKeyFrameGroup Float = ((H3DAnimFloat)Elem.Content).Value;

                    if (!Float.Exists)
                    {
                        continue;
                    }

                    float Value = Float.GetFrameValue(Frame);

                    switch (Elem.TargetType)
                    {
                    case H3DTargetType.CameraZNear: CamState.ZNear = Value; break;

                    case H3DTargetType.CameraZFar:  CamState.ZFar = Value; break;

                    case H3DTargetType.CameraTwist: CamState.Twist = Value; break;
                    }
                }
            }

            return(CamState);
        }
Ejemplo n.º 3
0
        private void SetKeyFrames(List <GFMotKeyFrame> Source, H3DFloatKeyFrameGroup Target, uint FramesCount)
        {
            Target.InterpolationType = H3DInterpolationType.Hermite;

            Target.EndFrame = FramesCount;

            foreach (GFMotKeyFrame KF in Source)
            {
                Target.KeyFrames.Add(new KeyFrame(
                                         KF.Frame,
                                         KF.Value,
                                         KF.Slope));
            }
        }
Ejemplo n.º 4
0
        private void SetKeyFrameGroup(List <GF1MotKeyFrame> Source, H3DFloatKeyFrameGroup Target, ushort CurveIndex)
        {
            Target.StartFrame        = 0;
            Target.EndFrame          = FramesCount;
            Target.CurveIndex        = CurveIndex;
            Target.InterpolationType = H3DInterpolationType.Hermite;

            foreach (GF1MotKeyFrame KF in Source)
            {
                Target.KeyFrames.Add(new KeyFrame(
                                         KF.Frame,
                                         KF.Value,
                                         KF.Slope * SlopeScale));
            }
        }
Ejemplo n.º 5
0
        private void AddVectors(
            Vector3[]             Vectors,
            H3DFloatKeyFrameGroup X,
            H3DFloatKeyFrameGroup Y,
            H3DFloatKeyFrameGroup Z)
        {
            X.InterpolationType = Y.InterpolationType = Z.InterpolationType = H3DInterpolationType.Linear;

            X.KeyFrames.Clear();
            Y.KeyFrames.Clear();
            Z.KeyFrames.Clear();

            int Frame = 0;

            foreach (Vector3 Vector in Vectors)
            {
                X.KeyFrames.Add(new KeyFrame(Frame, Vector.X));
                Y.KeyFrames.Add(new KeyFrame(Frame, Vector.Y));
                Z.KeyFrames.Add(new KeyFrame(Frame, Vector.Z));

                Frame++;
            }
        }
Ejemplo n.º 6
0
        public MaterialState[] GetMaterialStates()
        {
            if (State == AnimationState.Stopped)
            {
                ResetStates();
            }

            if (State != AnimationState.Playing || Elements.Count == 0)
            {
                return(States);
            }

            for (int i = 0; i < Elements.Count; i++)
            {
                int Index = Indices[i];

                MaterialState State = States[Index];

                H3DMaterial Material = Materials[Index];

                H3DMaterialParams Params = Material.MaterialParams;

                H3DAnimationElement Elem = Elements[i];

                H3DTextureCoord[] TC = new H3DTextureCoord[]
                {
                    Params.TextureCoords[0],
                    Params.TextureCoords[1],
                    Params.TextureCoords[2]
                };

                if (Elem.PrimitiveType == H3DPrimitiveType.RGBA)
                {
                    H3DAnimRGBA RGBA = (H3DAnimRGBA)Elem.Content;

                    switch (Elem.TargetType)
                    {
                    case H3DTargetType.MaterialEmission:  SetRGBA(RGBA, ref State.Emission);  break;

                    case H3DTargetType.MaterialAmbient:   SetRGBA(RGBA, ref State.Ambient);   break;

                    case H3DTargetType.MaterialDiffuse:   SetRGBA(RGBA, ref State.Diffuse);   break;

                    case H3DTargetType.MaterialSpecular0: SetRGBA(RGBA, ref State.Specular0); break;

                    case H3DTargetType.MaterialSpecular1: SetRGBA(RGBA, ref State.Specular1); break;

                    case H3DTargetType.MaterialConstant0: SetRGBA(RGBA, ref State.Constant0); break;

                    case H3DTargetType.MaterialConstant1: SetRGBA(RGBA, ref State.Constant1); break;

                    case H3DTargetType.MaterialConstant2: SetRGBA(RGBA, ref State.Constant2); break;

                    case H3DTargetType.MaterialConstant3: SetRGBA(RGBA, ref State.Constant3); break;

                    case H3DTargetType.MaterialConstant4: SetRGBA(RGBA, ref State.Constant4); break;

                    case H3DTargetType.MaterialConstant5: SetRGBA(RGBA, ref State.Constant5); break;
                    }
                }
                else if (Elem.PrimitiveType == H3DPrimitiveType.Vector2D)
                {
                    H3DAnimVector2D Vector = (H3DAnimVector2D)Elem.Content;

                    switch (Elem.TargetType)
                    {
                    case H3DTargetType.MaterialTexCoord0Scale: SetVector2(Vector, ref TC[0].Scale);       break;

                    case H3DTargetType.MaterialTexCoord1Scale: SetVector2(Vector, ref TC[1].Scale);       break;

                    case H3DTargetType.MaterialTexCoord2Scale: SetVector2(Vector, ref TC[2].Scale);       break;

                    case H3DTargetType.MaterialTexCoord0Trans: SetVector2(Vector, ref TC[0].Translation); break;

                    case H3DTargetType.MaterialTexCoord1Trans: SetVector2(Vector, ref TC[1].Translation); break;

                    case H3DTargetType.MaterialTexCoord2Trans: SetVector2(Vector, ref TC[2].Translation); break;
                    }
                }
                else if (Elem.PrimitiveType == H3DPrimitiveType.Float)
                {
                    H3DFloatKeyFrameGroup Float = ((H3DAnimFloat)Elem.Content).Value;

                    if (!Float.Exists)
                    {
                        continue;
                    }

                    float Value = Float.GetFrameValue(Frame);

                    switch (Elem.TargetType)
                    {
                    case H3DTargetType.MaterialTexCoord0Rot: TC[0].Rotation = Value; break;

                    case H3DTargetType.MaterialTexCoord1Rot: TC[1].Rotation = Value; break;

                    case H3DTargetType.MaterialTexCoord2Rot: TC[2].Rotation = Value; break;
                    }
                }
                else if (Elem.PrimitiveType == H3DPrimitiveType.Texture)
                {
                    H3DFloatKeyFrameGroup Int = ((H3DAnimFloat)Elem.Content).Value;

                    if (!Int.Exists)
                    {
                        continue;
                    }

                    int Value = (int)Int.GetFrameValue(Frame);

                    string Name = TextureNames[Value];

                    switch (Elem.TargetType)
                    {
                    case H3DTargetType.MaterialMapper0Texture: State.Texture0Name = Name; break;

                    case H3DTargetType.MaterialMapper1Texture: State.Texture1Name = Name; break;

                    case H3DTargetType.MaterialMapper2Texture: State.Texture2Name = Name; break;
                    }
                }

                State.Transforms[0] = TC[0].GetTransform().ToMatrix4();
                State.Transforms[1] = TC[1].GetTransform().ToMatrix4();
                State.Transforms[2] = TC[2].GetTransform().ToMatrix4();
            }

            return(States);
        }