示例#1
0
        private int Render(ILevel level, TileCoordinates coordinates, Geometry output, TextureAtlas textures, bool allFaces)
        {
            // Draw adjoining faces only
            int facesDrawn   = 0;
            var diffuseArea  = textures.GetTextureArea("models/tiles/xray.png").Value;
            var specularArea = textures.GetTextureArea("black.png").Value;
            var emissiveArea = textures.GetTextureArea("black.png").Value;
            var normalArea   = textures.GetTextureArea("flat.png").Value;
            var center       = new Vector3(coordinates.X + 0.5f, coordinates.Y * 0.5f + 0.5f, coordinates.Z + 0.5f);

            for (int i = 0; i < 6; ++i)
            {
                var dir           = (Direction)i;
                var neighbour     = (dir == Direction.Up) ? coordinates.Move(dir, Tile.Height) : coordinates.Move(dir);
                var neighbourTile = level.Tiles[neighbour];
                if (allFaces ||
                    (!(neighbourTile.GetBehaviour(level, neighbour) is XRayTileBehaviour) &&
                     neighbourTile.IsOpaqueOnSide(level, neighbour, dir.Opposite())))
                {
                    Vector3 fwd = 0.45f * dir.ToVector();
                    if (allFaces)
                    {
                        fwd = -fwd;
                    }

                    Vector3 up, right;
                    if (dir.IsFlat())
                    {
                        up    = 0.45f * Vector3.UnitY;
                        right = 0.45f * dir.RotateRight().ToVector();
                    }
                    else if (dir == Direction.Up)
                    {
                        up    = 0.45f * Vector3.UnitZ;
                        right = 0.45f * Vector3.UnitX;
                    }
                    else// if( dir == Direction.Down )
                    {
                        up    = -0.45f * Vector3.UnitZ;
                        right = 0.45f * Vector3.UnitX;
                    }
                    output.AddQuad(
                        center + fwd + up - right,
                        center + fwd + up + right,
                        center + fwd - up - right,
                        center + fwd - up + right,
                        diffuseArea,
                        specularArea,
                        normalArea,
                        emissiveArea,
                        Vector4.One
                        );
                    ++facesDrawn;
                }
            }
            return(facesDrawn);
        }
示例#2
0
        protected void RenderModel(ILevel level, TileCoordinates coordinates, Geometry output, TextureAtlas textures, Model model, FlatDirection direction, bool cullLeft, bool cullRight, bool cullTop, bool cullBottom, bool cullFront, bool cullBack)
        {
            // Build the transform
            var transform = Tile.BuildTransform(coordinates, direction);

            // Build the geometry
            for (int i = 0; i < model.GroupCount; ++i)
            {
                if (ShouldRenderModelGroup(level, coordinates, model.GetGroupName(i)))
                {
                    var material           = model.GetGroupMaterial(i);
                    var diffuseTexture     = material.DiffuseTexture;
                    var diffuseTextureArea = textures.GetTextureArea(diffuseTexture);
                    if (!diffuseTextureArea.HasValue)
                    {
                        App.Log("Error: Atlas {0} does not contain diffuse texture {1}", textures.Path, diffuseTexture);
                        diffuseTextureArea = textures.GetTextureArea("defaults/default.png");
                    }
                    var specularTexture     = material.SpecularTexture;
                    var specularTextureArea = textures.GetTextureArea(specularTexture);
                    if (!specularTextureArea.HasValue)
                    {
                        App.Log("Error: Atlas {0} does not contain specular texture {1}", textures.Path, specularTexture);
                        specularTextureArea = textures.GetTextureArea("defaults/default.png");
                    }
                    var normalTexture     = material.NormalTexture;
                    var normalTextureArea = textures.GetTextureArea(normalTexture);
                    if (!normalTextureArea.HasValue)
                    {
                        App.Log("Error: Atlas {0} does not contain normal texture {1}", textures.Path, normalTexture);
                        normalTextureArea = textures.GetTextureArea("defaults/default.png");
                    }
                    var emissiveTexture     = material.EmissiveTexture;
                    var emissiveTextureArea = textures.GetTextureArea(emissiveTexture);
                    if (!emissiveTextureArea.HasValue)
                    {
                        App.Log("Error: Atlas {0} does not contain emissive texture {1}", textures.Path, emissiveTexture);
                        emissiveTextureArea = textures.GetTextureArea("defaults/default.png");
                    }
                    output.AddGeometry(
                        model.GetGroupGeometry(i),
                        ref transform,
                        diffuseTextureArea.Value,
                        specularTextureArea.Value,
                        normalTextureArea.Value,
                        emissiveTextureArea.Value,
                        cullLeft, cullRight,
                        cullTop, cullBottom,
                        cullFront, cullBack
                        );
                }
            }
        }