public GameObject(string MeshName)
        {
            Position = new DVector3();

            MMC = ContentManager.LoadMultiMesh(MeshName);
            LocalAABBMin = Conversion.ToDoubleVector(MMC.LocalAABBMin);
            LocalAABBMax = Conversion.ToDoubleVector(MMC.LocalAABBMax);

            Transformation =  DMatrix.CreateScale(1d)*DMatrix.CreateTranslation(Position) * DMatrix.CreateFromYawPitchRoll(0, 0, 0);

            RecalcAABB();

            InitObj();
            Lens = ContentManager.LoadTexture2D("Content/Textures/Lens");
        }
        public TestSprite(Device device, DVector3 Position)
        {
            this.Position = Position;
            MMesh = ContentManager.LoadMesh("Content/Models/BaseSprite.mesh");
            EEEM = ContentManager.LoadEffect("Content/Shaders/BaseSprite");
            TexCont = ContentManager.LoadTexture2D("Content/Textures/Particl");
            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();
        }
        public GSSprite(Device device, DVector3 Position)
        {
            //float3 Position //12
            //half2 Size //16
            //half4 AABBTexCoord //24
            //half4 AditiveColor //32
            InputElement[] elements = new[] {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R16G16_Float, 12, 0),
                new InputElement("TEXCOORD", 1, Format.R16G16B16A16_Float, 16, 0),
                new InputElement("TEXCOORD", 2, Format.R16G16B16A16_Float, 24, 0),
            };

            BytesPerVertex = 32;
            VertexsCount = 1;

            var vertices = new DataStream(BytesPerVertex * VertexsCount, true, true);

            vertices.Write(Conversion.ToVector3(Position));
            vertices.Write(new Half2(10, 10));
            vertices.Write(new Half4(0, 0, 1, 1));
            vertices.Write(new Half4(1, 0, 0, 1));
            vertices.Position = 0;

            Vertexs = new Buffer(device, vertices, BytesPerVertex * VertexsCount, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
            binding = new VertexBufferBinding(Vertexs, BytesPerVertex, 0);
            vertices.Dispose();

            this.Position = Position;
            EEEM = ContentManager.LoadEffect("Content/Shaders/GSSprite", elements);
            TexCont = ContentManager.LoadTexture2D("Content/Textures/Particl");
            // Подготовка константного буффера
            BufferDescription bd = new BufferDescription();
            bd.SizeInBytes = Marshal.SizeOf(typeof(ShaderConstants));
            bd.Usage = ResourceUsage.Dynamic;
            bd.BindFlags = BindFlags.ConstantBuffer;
            bd.CpuAccessFlags = CpuAccessFlags.Write;
            bd.OptionFlags = ResourceOptionFlags.None;
            bd.StructureByteStride = 0;

            constantsBuffer = new Buffer(device, bd);
            constants = new ShaderConstants();
        }
        /// <summary>
        /// Загрузить указанный скайбокс
        /// </summary>
        /// <param name="Index">Индекс в файле скайбоксов</param>
        public void LoadSky(uint Index)
        {
            RVtextures = new TextureContainer[6];

            float  s_size = 1.0f;
            int s_count = 10000, s_factor1 = 25, s_factor2 = 50;
            ModelViewer.Program.MyScene.InitCubeMap = true;
            try
            {
                XmlTextReader reader = new XmlTextReader("GameData/SkyList.xml");
                while (reader.Read())
                {
                    if (reader.Name == "sky" && Index == System.Convert.ToInt32(reader.GetAttribute("id")))
                    {
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "back")
                        {
                            RVtextures[0] = ContentManager.LoadTexture2D(reader.GetAttribute("path"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "fron")
                        {
                            RVtextures[1] = ContentManager.LoadTexture2D(reader.GetAttribute("path"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "bttm")
                        {
                            RVtextures[2] = ContentManager.LoadTexture2D(reader.GetAttribute("path"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "topp")
                        {
                            RVtextures[3] = ContentManager.LoadTexture2D(reader.GetAttribute("path"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "left")
                        {
                            RVtextures[4] = ContentManager.LoadTexture2D(reader.GetAttribute("path"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "rght")
                        {
                            RVtextures[5] = ContentManager.LoadTexture2D(reader.GetAttribute("path"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "star_disp")
                        {
                            RVStarsDisp = ContentManager.LoadTexture2D(reader.GetAttribute("path"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "star_grad")
                        {
                            RVGrad = ContentManager.LoadTexture2D(reader.GetAttribute("path"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "star_count")
                        {
                            s_count = System.Convert.ToInt32(reader.GetAttribute("int"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "star_factor1")
                        {
                            s_factor1 = System.Convert.ToInt32(reader.GetAttribute("int"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "star_factor2")
                        {
                            s_factor2 = System.Convert.ToInt32(reader.GetAttribute("int"));
                        }
                        reader.Read();
                        reader.Read();
                        if (reader.Name == "star_size")
                        {
                            s_size = System.Convert.ToInt32(reader.GetAttribute("int"));
                            InitStars((int)Index, s_count, s_factor1, s_factor2, s_size/100f);
                            /////////////////
                            return;
                        }
                    }
                }
            }

            catch
            {
                System.Windows.Forms.MessageBox.Show("Error! Проблема при чтении 'GameData/SkyList.xml' O_O. Запаролся на индесе " + Index.ToString());
                //throw new XmlException("Error! Проблема при чтении 'GameData/ModelList.xml' O_O. Запаролся на индесе " + p_ind.ToString());
            }
            System.Windows.Forms.MessageBox.Show("Error! Проблема при чтении 'GameData/SkyList.xml' O_O. Нет такого скайбокса, либо скайбокс прописан с ошибкой: " + Index.ToString());
            //throw new XmlException("Error! Проблема при чтении 'GameData/ModelList.xml' O_O. Запаролся на индесе " + p_ind.ToString());
            for (int i = 0; i < 6; i++)
            {
                RVtextures[i] = ContentManager.LoadTexture2D("Content/Textures/Def_light");
            }
            RVStarsDisp = ContentManager.LoadTexture2D("Content/Textures/Def_occl");
            RVGrad = ContentManager.LoadTexture2D("Content/Textures/Def_occl");

            InitStars((int)Index, s_count, s_factor1, s_factor2, s_size);
        }
        public MaterialContainer(Material M)
        {
            if (M != null)
            {
                Name = M.MaterialName;
                InputElement[] IE = GetInputElementFromShaderName(M.Shader);
                Effect = ContentManager.LoadEffect(M.Shader, IE);
                Diffuse = ContentManager.LoadTexture2D(M.Diffuse);
                UV2Diffuse = ContentManager.LoadTexture2D(M.UV2Diffuse);
                NormalMap = ContentManager.LoadTexture2D(M.NormalMap);
                SpecularMap = ContentManager.LoadTexture2D(M.SpecularMap);
                SelfMap = ContentManager.LoadTexture2D(M.SelfMap);

                MipNormal = NormalMap.Texture2d.Description.MipLevels > 7;
                MipSpecular = SpecularMap.Texture2d.Description.MipLevels > 7;
                MipDiffuse = Diffuse.Texture2d.Description.MipLevels > 7;
                MipSelf = SelfMap.Texture2d.Description.MipLevels > 7;
                MipUV2Diffuse = UV2Diffuse.Texture2d.Description.MipLevels > 7;

                DiffuseMultipler = M.DiffuseMultipler;
                SpecularMultipler = M.SpecularMultipler;
                SelfMultipler = M.SelfMultipler;
                DoubleSide = M.DoubleSide;
                Alpha = M.Alpha;

                if (Global.Settings.TextureFiltering > -1)
                {
                    if (MipDiffuse) DiffuseSamplerState = DrawHelper.SamplAnsWrapMip;
                    else DiffuseSamplerState = DrawHelper.SamplAnsWrap;
                    if (MipSpecular) SpecularMapSamplerState = DrawHelper.SamplAnsWrapMip;
                    else SpecularMapSamplerState = DrawHelper.SamplAnsWrap;
                    if (MipNormal) NormalMapSamplerState = DrawHelper.SamplAnsWrapMip;
                    else NormalMapSamplerState = DrawHelper.SamplAnsWrap;
                    if (MipSelf) SelfMapSamplerState = DrawHelper.SamplAnsWrapMip;
                    else SelfMapSamplerState = DrawHelper.SamplAnsWrap;
                    if (MipUV2Diffuse) UV2DiffuseSamplerState = DrawHelper.SamplAnsWrapMip;
                    else UV2DiffuseSamplerState = DrawHelper.SamplAnsWrap;
                }
                else if (Global.Settings.TextureFiltering == -1)
                {
                    if (MipDiffuse) DiffuseSamplerState = DrawHelper.SamplLinWrapMip;
                    else DiffuseSamplerState = DrawHelper.SamplLinWrap;
                    if (MipSpecular) SpecularMapSamplerState = DrawHelper.SamplLinWrapMip;
                    else SpecularMapSamplerState = DrawHelper.SamplLinWrap;
                    if (MipNormal) NormalMapSamplerState = DrawHelper.SamplLinWrapMip;
                    else NormalMapSamplerState = DrawHelper.SamplLinWrap;
                    if (MipSelf) SelfMapSamplerState = DrawHelper.SamplLinWrapMip;
                    else SelfMapSamplerState = DrawHelper.SamplLinWrap;
                    if (MipUV2Diffuse) UV2DiffuseSamplerState = DrawHelper.SamplLinWrapMip;
                    else UV2DiffuseSamplerState = DrawHelper.SamplLinWrap;
                }
                else
                {
                    if (MipDiffuse) DiffuseSamplerState = DrawHelper.SamplPntWrapMip;
                    else DiffuseSamplerState = DrawHelper.SamplPntWrap;
                    if (MipSpecular) SpecularMapSamplerState = DrawHelper.SamplPntWrapMip;
                    else SpecularMapSamplerState = DrawHelper.SamplPntWrap;
                    if (MipNormal) NormalMapSamplerState = DrawHelper.SamplPntWrapMip;
                    else NormalMapSamplerState = DrawHelper.SamplPntWrap;
                    if (MipSelf) SelfMapSamplerState = DrawHelper.SamplPntWrapMip;
                    else SelfMapSamplerState = DrawHelper.SamplPntWrap;
                    if (MipUV2Diffuse) UV2DiffuseSamplerState = DrawHelper.SamplPntWrapMip;
                    else UV2DiffuseSamplerState = DrawHelper.SamplPntWrap;
                }
            }
        }
        public static void DrawLens(DVector3 Position, Vector2 Size, Vector2 UVMin, Vector2 UVMax, Vector4 Color, TextureContainer Textur)
        {
            if (Textur == null) return;
            if (LastFreeIndex >= MassSize)
            {
                //resize
                MassSize = Utils.GetBinResize(LastFreeIndex + 1);
                System.Array.Resize(ref MasterRequest, MassSize);
                System.Array.Resize(ref SlaveRequest, MassSize);

                for (int i = LastFreeIndex; i < MassSize; i++)
                {
                    MasterRequest[i] = new Request();
                    SlaveRequest[i] = new Request();
                    ResizeVertex = true;
                }
            }

            MasterRequest[LastFreeIndex].Position = Position;
            MasterRequest[LastFreeIndex].Size = Size;
            MasterRequest[LastFreeIndex].UVMin = UVMin;
            MasterRequest[LastFreeIndex].UVMax = UVMax;
            MasterRequest[LastFreeIndex].Color = Color;
            MasterRequest[LastFreeIndex].Textur = Textur;

            LastFreeIndex++;
        }
Example #7
0
        public void LoadContent(Device device)
        {
            Light = new EELightShadow(new DVector3(10, 40, 40), new Vector3(2.4f, 2.2f, 2.0f));
            Camera = new EEDCamera(Global.Settings.Width, Global.Settings.Height, 45, 1, 10000);

            //Camera = new EEDCamera(Global.Settings.Width, Global.Settings.Height, 90, 1, 1000);
            Light = new EELightShadow(new DVector3(10, 40, 40), new Vector3(2.4f, 2.2f, 2.0f));
            SkyBox = new EESkyBox();
            SkyBox.Initialize();
            //TestCube_UV2
            //"Content\\Models\\Argon_1_export.material"
            AllObjects.Add(new GameObject("Content\\Models\\Argon_1_export.material"));
            AllObjects.Add(new GameObject("Content\\Models\\Argon_1_export.material"));
            AllObjects.Add(new GameObject("Content\\Models\\TestCube_UV2.material"));

            AllObjects[1].TempSetPos(new DVector3(0, 50, -200));
            AllObjects[2].TempSetPos(new DVector3(-100, -1000, 1000));

            Random R = new Random(1);
            for (int y = 0; y < 10; y++)
            {
                GameObject GO = new GameObject("Content\\Models\\Argon_1_export.material");
                GO.TempSetPos(new DVector3(R.NextDouble(-300, 300), R.NextDouble(-500, 500), R.NextDouble(-500, 500)));
                AllObjects.Add(GO);
            }

            float yawn = (float)Math.PI/ 2f;
            float pitch = 0f;

            Vector3 t_vec = new Vector3(0, 0, 350);
            Quaternion quat = Quaternion.RotationYawPitchRoll((float)yawn, (float)pitch, 0);
            Camera.position = Conversion.ToDoubleVector(Vector3.Transform(t_vec, quat));// +target;
            Camera.quaternion = quat;

            /*
            TS = new List<GSSprite> { };

            R = new Random(2);
            for (int i = 0; i < 1; i++)
            {
                DVector3 t = new DVector3(R.NextDouble(-500, 500), R.NextDouble(-500, 500), R.NextDouble(-500, 500));
                TS.Add(new GSSprite(device, t));
            }*/
            TC1 = ContentManager.LoadTexture2D("Content/Textures/Particl");
            TC2 = ContentManager.LoadTexture2D("Content/Textures/Particl2");
        }
        public static TextureContainer LoadTexture2D(string FileName)
        {
            string Origin = FileName;
            if (Textures.ContainsKey(Origin) && Textures[Origin].IsAlive)
            {
                //Уже есть
                TextureContainer t = (TextureContainer)Textures[Origin].Target;
                return t;
            }
            else
            {
                //нужно загрузить
                TextureContainer t = new TextureContainer();
                t.Name = FileName;
                t.Texture2d = (Texture2D)Texture2D.FromFile(ModelViewer.Program.device, FileName + ".dds");
                t.TextureResource = new ShaderResourceView(ModelViewer.Program.device, t.Texture2d);
                WeakReference wr = new WeakReference(t, false);

                Textures.Add(Origin, wr);
                return t;
                //TODO проверка на валидность загрузки
            }
        }