Esempio n. 1
0
        public void Render(ModelPart modelPart)
        {
            var renderArgs = new RenderArgs(modelPart);

            modelPart.SetRenderArgsSelection(renderArgs);

            WorldMatrix = modelPart.GetAnchorRotationAndPositionMatrix() * WorldMatrix;

            ModelPart(modelPart, renderArgs, false);

            var wireframeMode = Wireframe;

            if (RenderAnchors)
            {
                Wireframe = true;

                foreach (var anchor in modelPart.Anchors)
                {
                    Anchor(anchor);
                }

                Wireframe = wireframeMode;
            }

            var bMat = WorldMatrix;

            foreach (var anchor in modelPart.Anchors)
            {
                if (!anchor.HasChildren)
                    continue;

                WorldMatrix = Matrix.Translation(anchor.Position) * WorldMatrix;
                var wMat = WorldMatrix;

                foreach (var child in anchor.Children)
                {
                    WorldMatrix = Matrix.Translation(child.Position) * WorldMatrix;

                    Render(child);
                    WorldMatrix = wMat;
                }
            }

            WorldMatrix = bMat;
        }
Esempio n. 2
0
 public static RenderArgs CreateDefault()
 {
     var result = new RenderArgs();
     return result;
 }
Esempio n. 3
0
        public void ModelPart(ModelPart modelPart, RenderArgs renderArgs, bool wireframe)
        {
            var dataStream = _vertexRenderer.LockVertexBuffer();

            if (!wireframe)
            {
                SetTexture(modelPart.MaterialId);
            }
            else
            {
                SetTexture(-1);
            }

            var triCount = 0;

            int faceIndex = 0;
            foreach (var modelPartFace in modelPart.Faces)
            {
                var faceArgs = renderArgs.RenderArgsFaces[faceIndex];

                var colour = faceArgs.Colour;

                if (wireframe)
                {
                    colour = Colours.White;
                }

                faceIndex++;

                foreach (var modelTriangle in modelPartFace.Triangles)
                {
                    dataStream.Write(new TexturedColouredVertex4
                    {
                        Colour = colour,
                        Position = new Vector4(modelTriangle.V1, 1.0f),
                        TextureCoordinate = modelPartFace.TextureCoordinates[modelTriangle.V1TexCoordIndex]
                    });

                    dataStream.Write(new TexturedColouredVertex4
                    {
                        Colour = colour,
                        Position = new Vector4(modelTriangle.V2, 1.0f),
                        TextureCoordinate = modelPartFace.TextureCoordinates[modelTriangle.V2TexCoordIndex]
                    });

                    dataStream.Write(new TexturedColouredVertex4
                    {
                        Colour = colour,
                        Position = new Vector4(modelTriangle.V3, 1.0f),
                        TextureCoordinate = modelPartFace.TextureCoordinates[modelTriangle.V3TexCoordIndex]
                    });
                    triCount++;
                }
            }

            _vertexRenderer.UnlockVertexBuffer();

            _effect.SetMatrix("worldMat", WorldMatrix);
            _effect.SetMatrix("worldViewProjMat", WorldMatrix * _viewMat * _projection);
            _effect.CommitChanges();

            _vertexRenderer.RenderForShader(PrimitiveType.TriangleList, 0, triCount);
        }