Exemple #1
0
        public static List <RenderItem> RenderOrders(string username)
        {
            var cartItems = new List <RenderItem>();

            var unrenderedCartItems = GetOrderItems(username);

            foreach (var cartItem in unrenderedCartItems)
            {
                var computer            = ComputerController.GetComputerById(cartItem.ComputerId, cartItem.TypeName);
                var newRenderedCartItem = new RenderItem();

                newRenderedCartItem.ImageUrl       = GetImageUrl(cartItem.TypeName);
                newRenderedCartItem.ComputerIdType = $"{cartItem.ComputerId}, {cartItem.TypeName}";
                newRenderedCartItem.ComputerName   = GetComputerName(cartItem.TypeName);
                newRenderedCartItem.Part1          = computer.Part1;
                newRenderedCartItem.Part2          = computer.Part2;
                newRenderedCartItem.Part3          = computer.Part3;
                newRenderedCartItem.Part4          = computer.Part4;
                newRenderedCartItem.Part5          = computer.Part5;
                newRenderedCartItem.Price          = cartItem.Price;

                cartItems.Add(newRenderedCartItem);
            }

            return(cartItems);
        }
Exemple #2
0
        private void BuildRenderItems()
        {
            RGrid = new RenderItem()
            {
                // Reset World
                Worlds = new Matrix[1],

                Light = new LightBuffer()
                {
                    AmbientColor   = new Vector4(0.15f, 0.15f, 0.15f, 1.0f),
                    Diffuse        = new Vector4(1.0f, 1.0f, 1.0f, 1.0f),
                    LightDirection = new Vector3(0, -1, 0),
                    SpecularColor  = new Vector4(1, 1, 1, 1),
                    SpecularPower  = 50,
                },

                VertexBuffer = new Buffer(Grid.Vertices.SizeInBytes, Grid.Vertices.Size, Device, ResourceInfo.VertexBuffer),

                IndexBuffer = new Buffer(Grid.Indices.SizeInBytes, Grid.Indices.Size, Device, ResourceInfo.IndexBuffer),

                ConstantBuffer = new Buffer[]
                {
                    new Buffer(Utilities.SizeOf <Transform>(), Utilities.SizeOf <Transform>(), Device, ResourceInfo.ConstantBuffer),
                    new Buffer(Utilities.SizeOf <LightBuffer>(), Utilities.SizeOf <LightBuffer>(), Device, ResourceInfo.ConstantBuffer),
                    new Buffer(Utilities.SizeOf <CameraBuffer>(), Utilities.SizeOf <CameraBuffer>(), Device, ResourceInfo.ConstantBuffer)
                },

                Texture = DDSLoader.LoadTextureFromFile(Device.NativeDevice, Device.NativeDeviceContext, "Text/Test.dds"),
            };



            RMesh = new RenderItem()
            {
                // Reset World
                Worlds = new Matrix[20],

                Light = new LightBuffer()
                {
                    AmbientColor   = new Vector4(0.15f, 0.15f, 0.15f, 1.0f),
                    Diffuse        = new Vector4(0.6f, 0.6f, 0.6f, 1.0f),
                    LightDirection = new Vector3(0, 0, 1.05f),
                    SpecularColor  = new Vector4(1, 1, 1, 1),
                    SpecularPower  = 20,
                },

                VertexBuffer = new Buffer(Mesh.Vertices.SizeInBytes, Mesh.Vertices.Size, Device, ResourceInfo.VertexBuffer),

                IndexBuffer = new Buffer(Mesh.Indices.SizeInBytes, Mesh.Indices.Size, Device, ResourceInfo.IndexBuffer),

                ConstantBuffer = new Buffer[]
                {
                    new Buffer(Utilities.SizeOf <Transform>(), Utilities.SizeOf <Transform>(), Device, ResourceInfo.ConstantBuffer),
                    new Buffer(Utilities.SizeOf <LightBuffer>(), Utilities.SizeOf <LightBuffer>(), Device, ResourceInfo.ConstantBuffer),
                    new Buffer(Utilities.SizeOf <CameraBuffer>(), Utilities.SizeOf <CameraBuffer>(), Device, ResourceInfo.ConstantBuffer)
                },

                Texture = Texture.LoadFromFile(Device, "Text/CesiumMan.jpg")
            };
        }
            public void ReplaceRenderItem(RenderItem oldItem, RenderItem newItem)
            {
                int index = RenderQueue.IndexOf(oldItem);

                RenderQueue.Remove(oldItem);
                RenderQueue.Insert(index, newItem);
                CallDirty();
            }
Exemple #4
0
        private static Report Render(ICollection <LootReport> loot)
        {
            // период за который собираем статистику
            var interval = loot.SelectMany(x => x.BoxData, (_, box) => box.RcvTime)
                           .ToArray();

            var report = new Report
            {
                // всего открыто коробок за указанный период
                TotalBoxes = loot.Sum(x => x.StatInfo.GiftsCollectedTotal)
            };

            if (interval.Any())
            {
                report.DateFrom = interval.Min().Date;
                report.DateTo   = interval.Max().AddDays(1).Date;
            }

            Log.Debug("Report period: {min} - {max}", interval.Min(), interval.Max());

            var players = loot.SelectMany(p => p.BoxData)
                          .GroupBy(box => box.PlayerName)
                          .OrderBy(gr => gr.Key)
                          .ToArray();

            report.PlayersCount = players.Length;
            Log.Debug("Report players: {N}", report.PlayersCount);

            IList <RenderItem> renderItems = new List <RenderItem>();

            foreach (var gr in players)
            {
                // все коробки от монстров 2 уровня и выше
                var boxes = gr.Where(box => !box.IsPurchase && box.BoxLevel >= LootLevel._2)
                            .ToArray();

                if (boxes.Any())
                {
                    var item = new RenderItem(report)
                    {
                        PlayerName = gr.Key.Or("Анонимно"),
                        Lvl2       = boxes.Count(box => box.BoxLevel == LootLevel._2),
                        Lvl3       = boxes.Count(box => box.BoxLevel >= LootLevel._3),
                        Paid       = gr.Count(box => box.IsPurchase)
                    };

                    renderItems.Add(item);
                }
            }

            Log.Debug("Total counts: LVL 2: {LVL2}, LVL 3+: {LVL3}, Paid: {Paid}",
                      renderItems.Sum(p => p.Lvl2),
                      renderItems.Sum(p => p.Lvl3),
                      renderItems.Sum(p => p.Paid));

            report.Items = (IReadOnlyCollection <RenderItem>)renderItems;
            return(report);
        }
Exemple #5
0
        public void RemoveRenderItem(RenderItem item)
        {
            foreach (string stage in item.GetStagesParticipated())
            {
                GetStageList(stage).Remove(item);
            }

            _distinctRenderItems.Remove(item);
        }
Exemple #6
0
        public void RemoveFreeRenderItem(RenderItem ri)
        {
            if (ri == null)
            {
                throw new ArgumentNullException(nameof(ri));
            }

            _visiblityManager.RemoveRenderItem(ri);
        }
Exemple #7
0
        public void AddRenderItem(RenderItem item)
        {
            foreach (string stage in item.GetStagesParticipated())
            {
                var list = GetStageList(stage);
                list.Add(item);
            }

            _distinctRenderItems.Add(item);
        }
 public void RemoveRenderItem(RenderItem ri)
 {
     if (!_octree.RemoveItem(ri))
     {
         if (!_freeRenderItems.Remove(ri))
         {
             throw new InvalidOperationException("Couldn't remove RenderItem " + ri + ". It wasn't contained in the scene.");
         }
     }
 }
        private void BuildRenderItems()
        {
            RGrid = new RenderItem()
            {
                // Reset World
                Worlds = new Matrix[1],

                Light = new LightBuffer()
                {
                    AmbientColor = new Vector4(0.15f, 0.15f, 0.15f, 1.0f),

                    Diffuse        = new Vector4(1.0f, 1.0f, 1.0f, 1.0f),
                    LightDirection = new Vector3(0, -1, 0),
                },

                VertexBuffer = new Buffer(Grid.Vertices.SizeInBytes, Grid.Vertices.Size, Device, ResourceInfo.VertexBuffer),

                IndexBuffer = new Buffer(Grid.Indices.SizeInBytes, Grid.Indices.Size, Device, ResourceInfo.IndexBuffer),

                ConstantBuffer = new Buffer[]
                {
                    new Buffer(Utilities.SizeOf <Transform>(), Utilities.SizeOf <Transform>(), Device, ResourceInfo.ConstantBuffer),
                    new Buffer(Utilities.SizeOf <LightBuffer>(), Utilities.SizeOf <LightBuffer>(), Device, ResourceInfo.ConstantBuffer)
                },

                Texture = Texture.LoadFromFile(Device, "Text/test.bmp")
            };



            RMesh = new RenderItem()
            {
                // Reset World
                Worlds = new Matrix[20],

                Light = new LightBuffer()
                {
                    AmbientColor   = new Vector4(0.18f, 0.18f, 0.18f, 1.0f),
                    Diffuse        = new Vector4(0.5f, 0.5f, 0.5f, 1.0f),
                    LightDirection = new Vector3(0, 0, -1.05f),
                },

                VertexBuffer = new Buffer(Mesh.Vertices.SizeInBytes, Mesh.Vertices.Size, Device, ResourceInfo.VertexBuffer),

                IndexBuffer = new Buffer(Mesh.Indices.SizeInBytes, Mesh.Indices.Size, Device, ResourceInfo.IndexBuffer),

                ConstantBuffer = new Buffer[]
                {
                    new Buffer(Utilities.SizeOf <Transform>(), Utilities.SizeOf <Transform>(), Device, ResourceInfo.ConstantBuffer),
                    new Buffer(Utilities.SizeOf <LightBuffer>(), Utilities.SizeOf <LightBuffer>(), Device, ResourceInfo.ConstantBuffer)
                },

                Texture = Texture.LoadFromFile(Device, "Text/UVCheckerMap08-512.png")
            };
        }
 public override void Render(List <RenderItem> renderItems, ref Matrix view, ref Matrix projection, ref Matrix viewProjection)
 {
     for (int i = 0; i < renderItems.Count; i++)
     {
         RenderItem item = renderItems[i];
         MatrixExtension.Multiply(in item.XNAMatrix, in viewProjection, out Matrix wvp);
         shader.WorldViewProjection = wvp;
         //                    shader.WorldViewProjection = item.XNAMatrix * matrices[0] * matrices[1];
         shader.CurrentTechnique.Passes[0].Apply();
         item.RenderPrimitive.Draw();
     }
 }
    private static void ShowRenderInfo(RenderItem renderItem, String filename)
    {
        StringBuilder msg = new StringBuilder("Render info\n");

        msg.Append("\n    file name: ");
        msg.Append(filename);
        msg.Append("\n    Renderer: ");
        msg.Append(renderItem.Renderer.FileTypeName);
        msg.Append("\n    Template: ");
        msg.Append(renderItem.Template.Name);
        msg.Append("\n    Start Time: ");
        MessageBox.Show(msg.ToString());
    }
Exemple #12
0
        public void PrepareRenderItem(StorageBlock block)
        {
            var vp = _realVpGenerator.Next(block);

            _dispatcher.BeginInvoke(
                (GetRenderingItemDelegate)((viewport) => {
                _item = _pool.GetNextRenderingRealPointItem();
                _item.RealViewport = viewport;
                _item.BeginRenderRealData();
                _isCreated.Set();
            }),
                vp
                );
        }
Exemple #13
0
        private int RayCastFilter(Ray ray, RenderItem ri, List <RayCastHit <RenderItem> > hits)
        {
            _rayCastDistances.Clear();
            int numHits = ((BoundsRenderItem)ri).RayCast(ray, _rayCastDistances);

            if (numHits > 0)
            {
                foreach (float distance in _rayCastDistances)
                {
                    hits.Add(new RayCastHit <RenderItem>(ri, ray.Origin + ray.Direction * distance, distance));
                }
            }

            return(numHits);
        }
Exemple #14
0
        //методы
        public override string BuildUrl(RenderItem renderItem, CompositionContext context)
        {
            //route values
            IDictionary <string, object> routeValues = renderItem.Item == null
                ? renderItem.Node.RouteValues
                : Combine(renderItem.Node.RouteValues, renderItem.Item.RouteValues);

            if (_routeKeys != null)
            {
                foreach (string qsKey in _routeKeys)
                {
                    if (renderItem.MatchQueryString[qsKey] != null)
                    {
                        routeValues        = routeValues ?? new Dictionary <string, object>();
                        routeValues[qsKey] = "*";
                    }
                }
            }

            string url = routeValues == null
                ? context.UrlHelper.Action(renderItem.Node.Action, renderItem.Node.Controller)
                : context.UrlHelper.Action(renderItem.Node.Action, renderItem.Node.Controller
                                           , ToRouteValueDictionary(renderItem, routeValues));


            //queryString values
            IDictionary <string, string> queryValues = renderItem.Item == null
                ? renderItem.Node.QueryStringValues
                : Combine(renderItem.Node.QueryStringValues, renderItem.Item.QueryStringValues);

            if (_queryStringKeys != null)
            {
                foreach (string qsKey in _queryStringKeys)
                {
                    if (renderItem.MatchQueryString[qsKey] != null)
                    {
                        queryValues        = queryValues ?? new Dictionary <string, string>();
                        queryValues[qsKey] = "*";
                    }
                }
            }

            return(queryValues == null
                ? url
                : string.Format("{0}?{1}", url, ToQueryString(renderItem, queryValues)));
        }
    private ArrayList FindMatchingTemplates(ArrayList lookup)
    {
        ArrayList result = new ArrayList();

        for (int i = 0; i < lookup.Count; i++)
        {
            KeyValuePair keyVal = (KeyValuePair)lookup[i];
            RenderItem   item   = FindMatch(keyVal.RendererName, keyVal.TemplateName);
            if (item == null)
            {
                MessageBox.Show("Could not find renderer " + keyVal.RendererName + " and template " + keyVal.TemplateName);
                continue;
            }
            result.Add(item);
        }
        return(result);
    }
Exemple #16
0
        /// <summary>
        /// 从RenderItem初始化过程
        /// </summary>
        /// <returns></returns>
        internal static EngineInput CreateInputModel(RenderItem renderItem, double Modulation)
        {
            EngineInput Ret = new EngineInput();

            Ret.inputWaveFile  = renderItem.RawFile;
            Ret.NoteString     = MusicMath.GetNoteString(renderItem.NoteNum);
            Ret.Velocity       = renderItem.Velocity;
            Ret.StrFlags       = renderItem.StrFlags;
            Ret.Offset         = renderItem.Oto.Offset;
            Ret.RequiredLength = renderItem.RequiredLength;
            Ret.Consonant      = renderItem.Oto.Consonant;
            Ret.Cutoff         = renderItem.Oto.Cutoff;
            Ret.Volume         = renderItem.Volume;
            Ret.Modulation     = Modulation;
            Ret.pitchBend      = renderItem.PitchData.ToArray();
            Ret.nPitchBend     = renderItem.PitchData.Count;
            Ret.Tempo          = renderItem.Tempo;
            return(Ret);
        }
Exemple #17
0
        /// <summary>
        /// 从RenderItem初始化过程
        /// </summary>
        /// <returns></returns>
        internal static EngineInput CreateInputModel(RenderItem renderItem, double Modulation)
        {
            EngineInput Ret = new EngineInput
            {
                inputWaveFile  = renderItem.SourceFile,
                NoteString     = MusicMath.GetNoteString(renderItem.NoteNum),
                Velocity       = renderItem.Velocity,
                StrFlags       = renderItem.StrFlags,
                Offset         = renderItem.Oto.Offset,
                RequiredLength = renderItem.RequiredLength,
                Consonant      = renderItem.Oto.Consonant,
                Cutoff         = renderItem.Oto.Cutoff,
                Volume         = renderItem.Volume,
                Modulation     = Modulation,
                pitchBend      = renderItem.PitchData.ToArray(),
                nPitchBend     = renderItem.PitchData.Count,
                Tempo          = renderItem.Tempo
            };

            return(Ret);
        }
Exemple #18
0
    // perform the render.  The Render method returns a member of the
    // RenderStatus enumeration.  If it is anything other than OK,
    // exit the loops.  This will throw an error message string if the
    // render does not complete successfully.
    RenderStatus DoRender(String filePath, RenderItem renderItem, Timecode start, Timecode length)
    {
        ValidateFilePath(filePath);

        // make sure the file does not already exist
        if (!OverwriteExistingFiles && File.Exists(filePath))
        {
            throw new ApplicationException("File already exists: " + filePath);
        }

        // perform the render.  The Render method returns
        // a member of the RenderStatus enumeration.  If
        // it is anything other than OK, exit the loops.
        RenderStatus status = myVegas.Render(filePath, renderItem.Template, start, length);

        switch (status)
        {
        case RenderStatus.Complete:
        case RenderStatus.Canceled:
            break;

        case RenderStatus.Failed:
        default:
            StringBuilder msg = new StringBuilder("Render failed:\n");
            msg.Append("\n    file name: ");
            msg.Append(filePath);
            msg.Append("\n    Renderer: ");
            msg.Append(renderItem.Renderer.FileTypeName);
            msg.Append("\n    Template: ");
            msg.Append(renderItem.Template.Name);
            msg.Append("\n    Start Time: ");
            msg.Append(start.ToString());
            msg.Append("\n    Length: ");
            msg.Append(length.ToString());
            throw new ApplicationException(msg.ToString());
        }
        return(status);
    }
Exemple #19
0
 internal RenderItemView(RenderItem RenderItem)
 {
     _renderItem = RenderItem;
 }
Exemple #20
0
		internal RenderItemView(RenderItem RenderItem)
		{
			_renderItem = RenderItem;
		}
    // perform the render.  The Render method returns a member of the
    // RenderStatus enumeration.  If it is anything other than OK,
    // exit the loops.  This will throw an error message string if the
    // render does not complete successfully.
    RenderStatus DoRender(String filePath, RenderItem renderItem, Timecode start, Timecode length)
    {
        ValidateFilePath(filePath);

        // make sure the file does not already exist
        if (!OverwriteExistingFiles && File.Exists(filePath))
        {
            throw new ApplicationException("File already exists: " + filePath);
        }

        // perform the render.  The Render method returns
        // a member of the RenderStatus enumeration.  If
        // it is anything other than OK, exit the loops.
        RenderStatus status = myVegas.Render(filePath, renderItem.Template, start, length);

        switch (status)
        {
            case RenderStatus.Complete:
            case RenderStatus.Canceled:
                break;
            case RenderStatus.Failed:
            default:
                StringBuilder msg = new StringBuilder("Render failed:\n");
                msg.Append("\n    file name: ");
                msg.Append(filePath);
                msg.Append("\n    Renderer: ");
                msg.Append(renderItem.Renderer.FileTypeName);
                msg.Append("\n    Template: ");
                msg.Append(renderItem.Template.Name);
                msg.Append("\n    Start Time: ");
                msg.Append(start.ToString());
                msg.Append("\n    Length: ");
                msg.Append(length.ToString());
                throw new ApplicationException(msg.ToString());
        }
        return status;
    }
 private static void ShowRenderInfo(RenderItem renderItem, String filename)
 {
     StringBuilder msg = new StringBuilder("Render info\n");
     msg.Append("\n    file name: ");
     msg.Append(filename);
     msg.Append("\n    Renderer: ");
     msg.Append(renderItem.Renderer.FileTypeName);
     msg.Append("\n    Template: ");
     msg.Append(renderItem.Template.Name);
     msg.Append("\n    Start Time: ");
     MessageBox.Show(msg.ToString());
 }
Exemple #23
0
        private void Render(ListItem item, Graphics g, bool selected, int x, int y, bool drawText)
        {
            if (item.BackColor.A != 0)
            {
                using (SolidBrush brush = new SolidBrush(item.BackColor)) {
                    g.FillRectangle(brush, x, y, item.Width, item.Height);
                }
            }

            if (item.Image == null)
            {
                if (RenderItem != null)
                {
                    Bitmap img = new Bitmap(item.Width, item.Height);
                    using (Graphics graphics = Graphics.FromImage(img)) {
                        RenderItem.Invoke(item, graphics);
                    }
                    item.Image = img;
                }
            }
            g.InterpolationMode = InterpolationMode.NearestNeighbor;
            g.PixelOffsetMode   = PixelOffsetMode.Half;
            if (item.Image != null)
            {
                g.DrawImage(item.Image, x, y);
            }

            Rectangle bounds = new Rectangle(x + 2, y + 2, item.Width - 4, item.Height - 4);

            if (drawText)
            {
                if (!string.IsNullOrEmpty(item.Text))
                {
                    TextRenderer.DrawText(g, item.Text, this.Font, bounds, this.ForeColor, Color.Empty, TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom);
                }
                string valueText = item.Value == null ? string.Empty : item.Value.ToString();
                if (!string.IsNullOrEmpty(valueText))
                {
                    TextRenderer.DrawText(g, valueText, this.Font, bounds, this.ForeColor, Color.Empty, TextFormatFlags.HorizontalCenter | TextFormatFlags.Top);
                }
            }

            if (item.Changed && Warning != null)
            {
                Size size  = TopLevelControl.ClientSize;
                int  sizeX = size.Width / 90;
                int  sizeY = size.Height / 90;
                if (sizeX > sizeY)
                {
                    sizeX = sizeY;
                }
                sizeY = bounds.Width / 4;
                if (sizeX > sizeY)
                {
                    sizeX = sizeY;
                }
                sizeY = bounds.Height / 4;
                if (sizeX > sizeY)
                {
                    sizeX = sizeY;
                }
                g.DrawImage(Warning, new Rectangle(bounds.X - 1, bounds.Y - 1, sizeX, sizeX), 0, 0, Warning.Width, Warning.Height, GraphicsUnit.Pixel);
            }

            if (selected)
            {
                g.DrawRectangle(Pens.DarkRed, bounds.X - 2, bounds.Y - 2, bounds.Width + 4, bounds.Height + 4);
                g.DrawRectangle(Pens.Red, bounds.X - 1, bounds.Y - 1, bounds.Width + 2, bounds.Height + 2);
            }
        }
Exemple #24
0
        private void Init(string texturename)
        {
            VertexPositionNormalTextured[] verts = new VertexPositionNormalTextured[36];

            // Front face
             verts[0] = new VertexPositionNormalTextured(-1.0f, 1.0f, 1.0f, 1.0f, 0.0f);
             verts[1] = new VertexPositionNormalTextured(-1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
             verts[2] = new VertexPositionNormalTextured(1.0f, 1.0f, 1.0f, 0.0f, 0.0f);
             verts[3] = new VertexPositionNormalTextured(-1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
             verts[4] = new VertexPositionNormalTextured(1.0f, -1.0f, 1.0f, 0.0f, 1.0f);
            verts[5] = new VertexPositionNormalTextured(1.0f, 1.0f, 1.0f, 0.0f, 0.0f);

            // Back face (remember this is facing *away* from the camera, so vertices should be
            //    clockwise order)
            verts[6] = new VertexPositionNormalTextured(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f);
            verts[7] = new VertexPositionNormalTextured(1.0f, 1.0f, -1.0f, 1.0f, 0.0f);
            verts[8] = new VertexPositionNormalTextured(-1.0f, -1.0f, -1.0f, 0.0f, 1.0f);
            verts[9] = new VertexPositionNormalTextured(-1.0f, -1.0f, -1.0f, 0.0f, 1.0f);
            verts[10] = new VertexPositionNormalTextured(1.0f, 1.0f, -1.0f, 1.0f, 0.0f);
            verts[11] = new VertexPositionNormalTextured(1.0f, -1.0f, -1.0f, 1.0f, 1.0f);

            // Top face
            verts[12] = new VertexPositionNormalTextured(-1.0f, 1.0f, 1.0f, 1.0f, 0.0f);
            verts[13] = new VertexPositionNormalTextured(1.0f, 1.0f, -1.0f, 0.0f, 1.0f);
            verts[14] = new VertexPositionNormalTextured(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f);
            verts[15] = new VertexPositionNormalTextured(-1.0f, 1.0f, 1.0f, 1.0f, 0.0f);
            verts[16] = new VertexPositionNormalTextured(1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
            verts[17] = new VertexPositionNormalTextured(1.0f, 1.0f, -1.0f, 0.0f, 1.0f);

            // Bottom face (remember this is facing *away* from the camera, so vertices should be
            //    clockwise order)
            verts[18] = new VertexPositionNormalTextured(-1.0f, -1.0f, 1.0f, 0.0f, 0.0f);
            verts[19] = new VertexPositionNormalTextured(-1.0f, -1.0f, -1.0f, 0.0f, 1.0f);
            verts[20] = new VertexPositionNormalTextured(1.0f, -1.0f, -1.0f, 1.0f, 1.0f);
            verts[21] = new VertexPositionNormalTextured(-1.0f, -1.0f, 1.0f, 0.0f, 0.0f);
            verts[22] = new VertexPositionNormalTextured(1.0f, -1.0f, -1.0f, 1.0f, 1.0f);
            verts[23] = new VertexPositionNormalTextured(1.0f, -1.0f, 1.0f, 1.0f, 0.0f);

            // Left face
            verts[24] = new VertexPositionNormalTextured(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f);
            verts[25] = new VertexPositionNormalTextured(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f);
            verts[26] = new VertexPositionNormalTextured(-1.0f, -1.0f, 1.0f, 0.0f, 1.0f);

            verts[27] = new VertexPositionNormalTextured(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f);
            verts[28] = new VertexPositionNormalTextured(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f);
            verts[29] = new VertexPositionNormalTextured(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f);

            // Right face (remember this is facing *away* from the camera, so vertices should be
            //    clockwise order)
            verts[30] = new VertexPositionNormalTextured(1.0f, 1.0f, 1.0f, 1.0f, 0.0f);
            verts[31] = new VertexPositionNormalTextured(1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
            verts[32] = new VertexPositionNormalTextured(1.0f, -1.0f, -1.0f, 0.0f, 1.0f);
            verts[33] = new VertexPositionNormalTextured(1.0f, 1.0f, -1.0f, 0.0f, 0.0f);
            verts[34] = new VertexPositionNormalTextured(1.0f, 1.0f, 1.0f, 1.0f, 0.0f);
            verts[35] = new VertexPositionNormalTextured(1.0f, -1.0f, -1.0f, 0.0f, 1.0f);
            Matrix translation = Matrix.RotationYawPitchRoll(0f, 90f * (float)(Math.PI / 180f), 0f);
            for (int i = 0; i < verts.Length; i++)
            {
                //verts[i].Position =
                verts[i].Position = Vector3.Multiply(verts[i].Position, 5000f);
                verts[i].Position = Vector3.TransformCoordinate(verts[i].Position, translation);
                verts[i].TextureCoordinate.X = (verts[i].TextureCoordinate.X + (1f / 512)) * (510f / 512f);
                verts[i].TextureCoordinate.Y = (verts[i].TextureCoordinate.Y + (1f / 512)) * (510f / 512f);
            }
            vb = new HagsVertexBuffer();
            vb.SetVB<VertexPositionNormalTextured>(verts, verts.Length * VertexPositionNormalTextured.SizeInBytes, VertexPositionNormalTextured.Format, Usage.WriteOnly);

            for (int i = 0; i < 6; i++)
            {
                List<uint> ind = new List<uint>();
                string texname = "skybox/"+ texturename;
                switch(i)
                {
                    case 0:
                        texname += "ft";
                        ind.AddRange(new uint[] { 0, 2, 1, 3, 5, 4 });
                        break;
                    case 1:
                        texname += "bk";
                        ind.AddRange(new uint[] {6,8,7,9,11,10 });
                        break;
                    case 2:
                        texname += "up";
                        ind.AddRange(new uint[] {12,14,13,15,17,16 });
                        break;
                    case 3:
                        texname += "dn";
                        ind.AddRange(new uint[] {18,20,19,21,23,22 });
                        break;
                    case 4:
                        texname += "lf";
                        ind.AddRange(new uint[] { 24,26,25,27,29,28});
                        break;
                    case 5:
                        texname += "rt";
                        ind.AddRange(new uint[] {30,32,31,33,35,34 });
                        break;
                }
                RenderItem item = new RenderItem(this, TextureManager.Instance.LoadMaterial(texname));
                item.DontOptimize = true;
                item.indices = ind;
                item.GenerateIndexBuffer();
                items.Add(item);
                rendercalls.Add(new KeyValuePair<ulong, RenderDelegate>(SortItem.GenerateBits(SortItem.FSLayer.GAME, SortItem.Viewport.STATIC, SortItem.VPLayer.SKYBOX, SortItem.Translucency.OPAQUE, item.material.MaterialID, 0, item.ib.IndexBufferID, item.vb.VertexBufferID), new RenderDelegate(item.Render)));
            }
        }
Exemple #25
0
        public void UpdateMesh()
        {
            // copy mesh from srcModel, and apply lighting, etc..
            if (srcModel == null)
                return;
            items.Clear();
            int leaf = Renderer.Instance.SourceMap.FindLeaf(prop_t.LightingOrigin);
            CompressedLightCube ambient = Renderer.Instance.SourceMap.world.leafs[leaf].ambientLighting;
            Matrix matrix = Matrix.RotationYawPitchRoll(prop_t.Angles.X * (float)(Math.PI / 180f), -prop_t.Angles.Z * (float)(Math.PI / 180f), prop_t.Angles.Y * (float)(Math.PI / 180f)) * Matrix.Translation(prop_t.Origin.X, prop_t.Origin.Y, prop_t.Origin.Z);
            //Renderer.Instance.SourceMap.
            foreach (BodyPart part in srcModel.BodyParts)
            {
                foreach (Model model in part.Models)
                {
                    MDLMesh mesh = model.GetLODMesh(0);
                    foreach (RenderItem item in mesh.items)
                    {
                        // Here we have the vertex data
                        RenderItem child = new RenderItem(this, item.material);
                        VertexPositonNormalColorTexture[] v = new VertexPositonNormalColorTexture[item.verts.Count];
                        item.verts.CopyTo(v);
                        for (int i = 0; i < v.Length; i++)
                        {
                            Vector4 temp =  Vector3.Transform(v[i].Position, matrix);
                            v[i].Position = new Vector3(temp.X, temp.Y, temp.Z);
                            v[i].Normal = Vector3.TransformNormal(v[i].Normal, matrix);
                            Vector3 col;
                            bool inSolid = SourceParser.Instance.ComputeVertexLightFromSpericalSamples(v[i].Position, v[i].Normal, this, out col);

                            // add in ambient light
                            Vector3 normal = v[i].Normal;
                            col += (normal.X * normal.X) * ambient.Color[(normal.X < 0.0f ? 1 : 0)];
                            col += (normal.Y * normal.Y) * ambient.Color[(normal.Y < 0.0f ? 1 : 0) + 2];
                            col += (normal.Z * normal.Z) * ambient.Color[(normal.Z < 0.0f ? 1 : 0) + 4];

                            col *= 255f;

                            // Convert to RGBE8

                            // Determine the largest color component
                            float maxComponent = Math.Max(Math.Max(col.X, col.Y), col.Z);

                            if (maxComponent < 0.000125f)
                            {
                                v[i].Color = new Color4(0.5f, 0f, 0f, 0f).ToArgb();
                                continue;
                            }

                            // Round to the nearest integer exponent
                            float fExp = (float)Math.Ceiling(Math.Log(maxComponent,2));
                            // Divide the components by the shared exponent

                            Vector3 enc = col / (float)(Math.Pow(2, fExp));

                            // Store the shared exponent in the alpha channel
                            float a = ((fExp + 128f) /255f);
                            v[i].Color = new Color4(a, enc.X, enc.Y, enc.Z).ToArgb();

                        }
                        child.verts = new List<VertexPositonNormalColorTexture>(v);
                        child.vb = new HagsVertexBuffer();
                        int vertexBytes = v.Length * VertexPositonNormalColorTexture.SizeInBytes;
                        child.vb.SetVB<VertexPositonNormalColorTexture>(v, vertexBytes, VertexPositonNormalColorTexture.Format, Usage.WriteOnly);

                        child.nVerts = v.Length;
                        child.DontOptimize = true;
                        child.indices = item.indices;
                        child.GenerateIndexBuffer();
                        items.Add(child);
                    }
                }
            }

            int test = 2;
        }
Exemple #26
0
 public Node[] Render <T>(IEnumerable <T> items, RenderItem <T> render)
 {
     return(this.Render(items, (t, idx) => (idx.ToString(), render(t, idx))));
 }
Exemple #27
0
        public new void Init()
        {
            this.SharedTexture2 = true;
            this.tex2 = world.LightmapTexture;
            this.stride = VertexPositionNormalTexturedLightmap.SizeInBytes;

            // Make renderitem for each face
            for (int fi = 0; fi < world.faces.Length;fi++ )
            {
                Face face = world.faces[fi];
                face.Format = VertexPositionNormalTexturedLightmap.Format;
                RenderItem item = new RenderItem(this, face.texinfo.texdata_t.mat);

                //if (face.texinfo.texdata_t.mat != null && face.texinfo.texdata_t.mat.Bumpmap)
                //    face.Format = VertexPositionNormalTexturedLightmapTangent.Format;

                // Create index list for non-displacement faces only
                if (face.face_t.dispinfo == -1 && !face.HasDisplacement && face.VertexOffset != -1)
                {
                    // Make TriangleList
                    int newIndices = (face.face_t.numedges - 2) * 3;
                    face.indices = new uint[newIndices];
                    face.nVerts = HagsIndexBuffer.GetVertexCount(item.indices);
                    for (int i = 0; i < (face.face_t.numedges - 2); i++)
                    {
                        face.indices[3 * i] = (uint)(face.VertexOffset);
                        face.indices[3 * i + 1] = (uint)(face.VertexOffset + i + 1);
                        face.indices[3 * i + 2] = (uint)(face.VertexOffset + i + 2);
                    }
                    item.indices = new List<uint>(face.indices);
                }
                else
                {
                    // Use pre-generated displacement index list
                    if (face.indices != null)
                    {
                        item.indices = new List<uint>(face.indices);
                        //face.nVerts = HagsIndexBuffer.GetVertexCount(item.indices);
                    }
                }

                // Setup item
                item.DontOptimize = true;
                item.face = face;
                item.Type = PrimitiveType.TriangleList;
                item.nVerts = face.nVerts;
                item.Init();
                world.faces[fi].item = item;
                items.Add(item);
            }

            // Create shared vertex buffer
            int vertexBytes = world.verts.Count * VertexPositionNormalTexturedLightmap.SizeInBytes;
            vb = new HagsVertexBuffer();
            vb.SetVB<VertexPositionNormalTexturedLightmap>(world.verts.ToArray(), vertexBytes, VertexPositionNormalTexturedLightmap.Format, Usage.WriteOnly);
            ib = new HagsIndexBuffer();

            Entity light_environment = null;
            foreach (Entity ent in world.Entities)
            {
                //System.Console.WriteLine("\n"+ ent.ClassName);
                foreach (string val in ent.Values.Keys)
                {
                    //System.Console.WriteLine("\t"+val + ": " + ent.Values[val]);
                }
                if (ent.ClassName == "light_environment")
                {
                    light_environment = ent;
                }
                else if (ent.ClassName.Equals("sky_camera"))
                {
                    skybox3d = new SkyBox3D(this, ent);
                }
                else if (ent.ClassName.Equals("env_fog_controller"))
                {
                    fogController = new FogController(ent.Values);
                    fogController.Init();
                }
            }

            if (skybox3d == null)
            {
                // Look for area 1
            }

            // Handle worldspawn entity (skybox)
            if (world.Entities[0].ClassName == "worldspawn")
            {
                if (world.Entities[0].Values.ContainsKey("skyname"))
                {
                    string skyname = world.Entities[0].Values["skyname"];
                    skybox = new SkyBox(this, skyname, light_environment);
                }
            }

            // Make leafs point towards nodes also
            SetParent(ref world.nodes[0], ref world.nodes[0]);
            world.nodes[0].parent = null;

            // Prepare visibleRenderItems memorisation structure
            foreach (RenderItem item in items)
            {
                if (!visibleRenderItems.ContainsKey(item.material.MaterialID))
                {
                    visibleRenderItems.Add(item.material.MaterialID, new List<RenderItem>());
                    if (skybox3d != null)
                        skybox3d.visibleRenderItems.Add(item.material.MaterialID, new List<RenderItem>());
                }

            }
        }
 public void AddRenderItem(RenderItem ri)
 {
     _freeRenderItems.Add(ri);
 }
 public OctreeItem <RenderItem> AddRenderItem(BoundingBox bounds, RenderItem ri)
 {
     return(_octree.AddItem(bounds, ri));
 }
Exemple #30
0
        public static VTXStripGroup ReadStripGroup(BinaryReader br, int offset, int lodNum, int vertexOffset, MDLMesh mesh)
        {
            br.BaseStream.Seek(offset, SeekOrigin.Begin);
            VTXStripGroup strGroup = new VTXStripGroup();
            strGroup.num_vertices  = br.ReadInt32();
            strGroup.vertex_offset = br.ReadInt32();
            strGroup.num_indices = br.ReadInt32();
            strGroup.index_offset = br.ReadInt32();
            strGroup.num_strips = br.ReadInt32();
            strGroup.strip_offset = br.ReadInt32();
            strGroup.strip_group_flags = br.ReadByte();

            // Fill vertex arrays
            List<Vector3> vertexArray = new List<Vector3>();
            List<Vector3> normalArray = new List<Vector3>();
            List<Vector2> texcoordArray = new List<Vector2>();
            List<VertexPositonNormalColorTexture> verts = new List<VertexPositonNormalColorTexture>();
            br.BaseStream.Seek(strGroup.vertex_offset + offset, SeekOrigin.Begin);
            for (int i = 0; i < strGroup.num_vertices; i++)
            {
                VTXVertex vertex = ReadVertex(br);
                int vertexID = vertex.orig_mesh_vertex_id + vertexOffset;

                // Get vvd info
                VVDVertex vvdVertex = VVDReader.vertex_buffer[lodNum][vertexID];
                vertexArray.Add(vvdVertex.vertex_position);
                normalArray.Add(vvdVertex.vertex_normal);
                texcoordArray.Add(vvdVertex.vertex_texcoord);
                verts.Add(new VertexPositonNormalColorTexture(vvdVertex.vertex_position, vvdVertex.vertex_normal, new Color4(Color.Blue), vvdVertex.vertex_texcoord));
            }
            strGroup.Verts = vertexArray;
            strGroup.Normals = normalArray;
            strGroup.Coords = texcoordArray;
            // Fill index array
            br.BaseStream.Seek(offset + strGroup.index_offset, SeekOrigin.Begin);
            List<uint> indexArray = new List<uint>();
            for (int i = 0; i < strGroup.num_indices; i++)
            {
                indexArray.Add((uint)br.ReadUInt16());
            }
            strGroup.Indices = indexArray;
            // Create SourceModel
            RenderItem stripitem = new RenderItem(mesh, mesh.material);
            stripitem.verts = verts;
            stripitem.nVerts = verts.Count;

            // Set IB
            stripitem.indices = indexArray;
            // Create VB
            //stripitem.vb = new HagsVertexBuffer();
            //int vertexBytes = verts.Count * VertexPositonNormalColorTexture.SizeInBytes;
            //stripitem.vb.SetVB<VertexPositonNormalColorTexture>(verts.ToArray(), vertexBytes, VertexPositonNormalColorTexture.Format, Usage.WriteOnly);
            //stripitem.DontOptimize = true;
            //stripitem.GenerateIndexBuffer();
            strGroup.Strips = new VTXStrip[strGroup.num_strips];
            // Process strips
            for (int i = 0; i < strGroup.num_strips; i++)
            {
                RenderItem item = new RenderItem(stripitem, null);
                VTXStrip strip = ReadStrip(br, offset + strGroup.strip_offset + (i* VTXStrip.VTX_STRIP_SIZE), indexArray);
                item.nVerts = strip.num_vertices;
                item.nIndices = strip.num_indices;
                item.IndiceStartIndex = strip.index_offset;
                item.vertexStartIndex = strip.vertex_offset;
                item.DontOptimize = true;
                if (strip.strip_flags == 0x02)
                    item.Type = PrimitiveType.TriangleStrip;

                stripitem.items.Add(item);
            }
            mesh.items.Add(stripitem);

            return strGroup;
        }