internal static AnimationClip Read(ContentReader input)
        {
            string animationName = input.ReadString();
            TimeSpan animationDuration = input.ReadObject<TimeSpan>();

            // Read animation clip channels
            Dictionary<string, AnimationChannel> animationChannelDictionary =
                new Dictionary<string, AnimationChannel>();

            int numAnimationChannels = input.ReadInt32();
            for (int i = 0; i < numAnimationChannels; i++)
            {
                string channelName = input.ReadString();

                // Read animation channel keyframes
                int numChannelKeyframes = input.ReadInt32();
                List<AnimationChannelKeyframe> keyframeList =
                    new List<AnimationChannelKeyframe>(numChannelKeyframes);

                for (int j = 0; j < numChannelKeyframes; j++)
                {
                    TimeSpan keyframeTime = input.ReadObject<TimeSpan>();

                    // Read keyframe pose
                    Pose keyframePose;
                    keyframePose.Translation = input.ReadVector3();
                    keyframePose.Orientation = input.ReadQuaternion();
                    keyframePose.Scale = input.ReadVector3();

                    keyframeList.Add(new AnimationChannelKeyframe(keyframeTime, keyframePose));
                }

                AnimationChannel animationChannel = new AnimationChannel(keyframeList);

                // Add the animation channel to the dictionary
                animationChannelDictionary.Add(channelName, animationChannel);
            }

            return
                new AnimationClip(animationName, animationDuration,
                    new AnimationChannelDictionary(animationChannelDictionary));
        }
Esempio n. 2
0
        protected internal override AlphaTestEffect Read(ContentReader input, AlphaTestEffect existingInstance)
        {
            AlphaTestEffect effect = new AlphaTestEffect(input.ContentManager.GetGraphicsDevice());

            effect.Texture            = input.ReadExternalReference <Texture>() as Texture2D;
            effect.AlphaFunction      = (CompareFunction)input.ReadInt32();
            effect.ReferenceAlpha     = (int)input.ReadUInt32();
            effect.DiffuseColor       = input.ReadVector3();
            effect.Alpha              = input.ReadSingle();
            effect.VertexColorEnabled = input.ReadBoolean();
            return(effect);
        }
Esempio n. 3
0
 protected internal override AlphaTestEffect Read(ContentReader input, AlphaTestEffect existingInstance)
 {
     return(new AlphaTestEffect(input.GraphicsDevice)
     {
         Texture = input.ReadExternalReference <Texture>() as Texture2D,
         AlphaFunction = (CompareFunction)input.ReadInt32(),
         ReferenceAlpha = (int)input.ReadUInt32(),
         DiffuseColor = input.ReadVector3(),
         Alpha = input.ReadSingle(),
         VertexColorEnabled = input.ReadBoolean()
     });
 }
Esempio n. 4
0
        protected internal override BasicEffect Read(
            ContentReader input,
            BasicEffect existingInstance
            )
        {
            BasicEffect effect  = new BasicEffect(input.GraphicsDevice);
            Texture2D   texture = input.ReadExternalReference <Texture>() as Texture2D;

            if (texture != null)
            {
                effect.Texture        = texture;
                effect.TextureEnabled = true;
            }
            effect.DiffuseColor       = input.ReadVector3();
            effect.EmissiveColor      = input.ReadVector3();
            effect.SpecularColor      = input.ReadVector3();
            effect.SpecularPower      = input.ReadSingle();
            effect.Alpha              = input.ReadSingle();
            effect.VertexColorEnabled = input.ReadBoolean();
            return(effect);
        }
Esempio n. 5
0
        protected internal override DualTextureEffect Read(
            ContentReader input,
            DualTextureEffect existingInstance
            )
        {
            DualTextureEffect effect = new DualTextureEffect(input.ContentManager.GetGraphicsDevice());

            effect.Texture            = input.ReadExternalReference <Texture>() as Texture2D;
            effect.Texture2           = input.ReadExternalReference <Texture>() as Texture2D;
            effect.DiffuseColor       = input.ReadVector3();
            effect.Alpha              = input.ReadSingle();
            effect.VertexColorEnabled = input.ReadBoolean();
            return(effect);
        }
Esempio n. 6
0
        public Terrain( ContentReader input)
        {
            m_xLength = input.ReadInt32();
            m_zLength = input.ReadInt32();
            m_objectMat = Matrix.Identity;

            m_verts = new VertexPositionNormalTexture[m_xLength * m_zLength];
            int i = 0;
            for (int x = 0; x < m_xLength; x++) {
                for (int z = 0; z < m_zLength; z++) {
                    Vector3 point = input.ReadVector3();
                    Vector2 texCoord = new Vector2(x, z);
                    m_verts[i++] = new VertexPositionNormalTexture(point, Vector3.Up, texCoord);
                }
            }
            GenerateIndices();
            VertexUtils.GenerateNormalsForTriangleStrip( m_verts, m_indices );
            CreateRenderData();
        }
Esempio n. 7
0
 protected internal override Vector3 Read(ContentReader input, Vector3 existingInstance)
 {
     return(input.ReadVector3());
 }
        internal static SkinnedEffect Read(ContentReader input)
        {
            IGraphicsDeviceService graphicsDeviceService = (IGraphicsDeviceService)
                    input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));

            GraphicsDevice graphicsDevice = graphicsDeviceService.GraphicsDevice;

            SkinnedEffect basicEffect = new SkinnedEffect(graphicsDevice);


            input.ReadVector3();
            input.ReadVector3();
            input.ReadVector3();
            input.ReadSingle();

            input.ReadBoolean();
            input.ReadBoolean();
            input.ReadBoolean();
            input.ReadObject<Texture2D>(); 
            input.ReadObject<Texture2D>(); 
            input.ReadObject<Texture2D>(); 

            return basicEffect;
        }
        internal static SkinnedModelBasicEffect Read(ContentReader input)
        {
            IGraphicsDeviceService graphicsDeviceService = (IGraphicsDeviceService)
                    input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));

            GraphicsDevice graphicsDevice = graphicsDeviceService.GraphicsDevice;

            //ResourceContentManager cnt = new ResourceContentManager(input.ContentManager.ServiceProvider, Resource1.ResourceManager);            z
#if WINDOWS           
            SkinnedModelBasicEffect basicEffect = new SkinnedModelBasicEffect(graphicsDevice, Resource1.SkinnedModelEffect);
#else
            SkinnedModelBasicEffect basicEffect = new SkinnedModelBasicEffect(graphicsDevice, Resource1.SkinnedModelEffect2);
#endif
            

            input.ReadVector3();
            input.ReadVector3();
            input.ReadVector3();
            input.ReadSingle();

            basicEffect.DiffuseMapEnabled = input.ReadBoolean();
            basicEffect.NormalMapEnabled = input.ReadBoolean();
            basicEffect.SpecularMapEnabled = input.ReadBoolean();
            basicEffect.DiffuseMap = input.ReadObject<Texture2D>(); ;
            basicEffect.NormalMap = input.ReadObject<Texture2D>(); ;
            basicEffect.SpecularMap = input.ReadObject<Texture2D>(); ;            

            return basicEffect;
        }
Esempio n. 10
0
 protected internal override Ray Read(ContentReader input, Ray existingInstance)
 {
     return(new Ray(input.ReadVector3(), input.ReadVector3()));
 }
Esempio n. 11
0
 private void ReadMeshes(ContentReader input, VertexDeclaration[] vertexDeclarations)
 {
     int length = input.ReadInt32();
     ModelMesh[] meshes = new ModelMesh[length];
     for (int i = 0; i < length; i++)
     {
         string name = input.ReadObject<string>();
         ModelBone parentBone = this.ReadBoneReference(input);
         BoundingSphere boundingSphere = new BoundingSphere();
         boundingSphere.Center = input.ReadVector3();
         boundingSphere.Radius = input.ReadSingle();
         VertexBuffer vertexBuffer = input.ReadObject<VertexBuffer>();
         IndexBuffer indexBuffer = input.ReadObject<IndexBuffer>();
         object tag = input.ReadObject<object>();
         ModelMeshPart[] meshParts = ReadMeshParts(input, vertexBuffer, indexBuffer, vertexDeclarations);
         meshes[i] = new ModelMesh(name, parentBone, boundingSphere, vertexBuffer, indexBuffer, meshParts, tag);
     }
     this.meshes = new ModelMeshCollection(meshes);
 }
        private void loadMD3Data(ContentReader input, MD3Object m)
        {
            //load meshes
            m.meshes = new List<MD3SubMeshes>();
            int part = input.ReadInt32();
            if (part == 0)
                m.part = TMD3Part.HEAD;
            else if (part == 1)
                m.part = TMD3Part.LOWER;
            else
                m.part = TMD3Part.UPPER;

            m.num_frames = input.ReadInt32();
            int sub_meshes_count = input.ReadInt32();
            for (int i = 0; i < sub_meshes_count; ++i)
            {
                MD3SubMeshes sub_mesh = new MD3SubMeshes();
                sub_mesh.indices = new List<int>();
                sub_mesh.vertices = new List<Vector3>();
                sub_mesh.normals = new List<Vector3>();
                sub_mesh.text_coord = new List<Vector2>();
                sub_mesh.skins = new List<string>();
                sub_mesh.meshinfo.strName = input.ReadString();
                input.ReadObject<List<int>>(sub_mesh.indices);
                input.ReadObject<List<Vector3>>(sub_mesh.vertices);
                input.ReadObject<List<Vector3>>(sub_mesh.normals);
                input.ReadObject<List<Vector2>>(sub_mesh.text_coord);
                m.meshes.Add(sub_mesh);
            }

            //load tags
            m.tags = new List<MD3tag>();
            int tags_count = input.ReadInt32();
            for (int i = 0; i < tags_count; ++i)
            {
                MD3tag tag = new MD3tag();
                tag.strName = input.ReadString();
                tag.vPosition = input.ReadVector3();
                tag.rotation = input.ReadMatrix();
                m.tags.Add(tag);
            }
            //load bounding_boxes
            m.bounding_boxes = new List<BoundingBox>();
            int bb_count = input.ReadInt32();
            for (int i = 0; i < bb_count; ++i)
            {
                BoundingBox bb = new BoundingBox();
                bb.Min = input.ReadVector3();
                bb.Max = input.ReadVector3();
                m.bounding_boxes.Add(bb);
            }
        }
Esempio n. 13
0
 protected internal override Plane Read(ContentReader input, Plane existingInstance)
 {
     existingInstance.Normal = input.ReadVector3();
     existingInstance.D      = input.ReadSingle();
     return(existingInstance);
 }
Esempio n. 14
0
 protected internal override BoundingSphere Read(ContentReader input, BoundingSphere existingInstance)
 {
     return(new BoundingSphere(input.ReadVector3(), input.ReadSingle()));
 }
Esempio n. 15
0
        internal static SkinnedModelBasicEffect Read(ContentReader input)
        {
            Effect effect = input.ReadObject<Effect>();

            SkinnedModelBasicEffect basicEffect = new SkinnedModelBasicEffect(effect);

            basicEffect.material.EmissiveColor = input.ReadVector3();
            basicEffect.material.DiffuseColor = input.ReadVector3();
            basicEffect.material.SpecularColor = input.ReadVector3();
            basicEffect.material.SpecularPower = input.ReadSingle();

            basicEffect.DiffuseMapEnabled = input.ReadBoolean();
            basicEffect.NormalMapEnabled = input.ReadBoolean();
            basicEffect.SpecularMapEnabled = input.ReadBoolean();

            basicEffect.DiffuseMap = input.ReadExternalReference<Texture2D>();
            basicEffect.NormalMap = input.ReadExternalReference<Texture2D>();
            basicEffect.SpecularMap = input.ReadExternalReference<Texture2D>();

            basicEffect.lightEnabled = false;
            basicEffect.enabledLights = EnabledLights.One;

            return basicEffect;
        }
        internal static SkinnedModelBasicEffect Read(ContentReader input)
        {
            IGraphicsDeviceService graphicsDeviceService = (IGraphicsDeviceService)
                    input.ContentManager.ServiceProvider.GetService(typeof(IGraphicsDeviceService));

            GraphicsDevice graphicsDevice = graphicsDeviceService.GraphicsDevice;
            SkinnedModelBasicEffect basicEffect = new SkinnedModelBasicEffect(graphicsDevice,
                (EffectPool)null);

            basicEffect.material.EmissiveColor = input.ReadVector3();
            basicEffect.material.DiffuseColor = input.ReadVector3();
            basicEffect.material.SpecularColor = input.ReadVector3();
            basicEffect.material.SpecularPower = input.ReadSingle();

            basicEffect.DiffuseMapEnabled = input.ReadBoolean();
            basicEffect.NormalMapEnabled = input.ReadBoolean();
            basicEffect.SpecularMapEnabled = input.ReadBoolean();
            basicEffect.DiffuseMap = input.ReadObject<Texture2D>(); ;
            basicEffect.NormalMap = input.ReadObject<Texture2D>(); ;
            basicEffect.SpecularMap = input.ReadObject<Texture2D>(); ;

            basicEffect.lightEnabled = false;
            basicEffect.enabledLights = EnabledLights.One;

            return basicEffect;
        }
        internal static SkinnedModelBone Read(ContentReader input)
        {
            // Read bone data
            ushort index = input.ReadUInt16();
            string name = input.ReadString();

            // Read bind pose
            Pose bindPose;
            bindPose.Translation = input.ReadVector3();
            bindPose.Orientation = input.ReadQuaternion();
            bindPose.Scale = input.ReadVector3();

            Matrix inverseBindPoseTransform = input.ReadMatrix();
            SkinnedModelBone skinnedBone =
                new SkinnedModelBone(index, name, bindPose, inverseBindPoseTransform);

            // Read bone parent
            input.ReadSharedResource<SkinnedModelBone>(
                delegate(SkinnedModelBone parentBone) { skinnedBone.parent = parentBone; });

            // Read bone children
            int numChildren = input.ReadInt32();
            List<SkinnedModelBone> childrenList = new List<SkinnedModelBone>(numChildren);
            for (int i = 0; i < numChildren; i++)
            {
                input.ReadSharedResource<SkinnedModelBone>(
                    delegate(SkinnedModelBone childBone) { childrenList.Add(childBone); });
            }
            skinnedBone.children = new SkinnedModelBoneCollection(childrenList);

            return skinnedBone;
        }
Esempio n. 18
0
 protected internal override BoundingBox Read(ContentReader input, BoundingBox existingInstance)
 {
     return(new BoundingBox(input.ReadVector3(), input.ReadVector3()));
 }