コード例 #1
0
        public static void DrawCubeBlock(PrimitivesRenderer3D primitivesRenderer, int value, Vector3 size, ref Matrix matrix, Color color, Color topColor, DrawBlockEnvironmentData environmentData)
        {
            environmentData = (environmentData ?? m_defaultEnvironmentData);
            Texture2D       texture         = (environmentData.SubsystemTerrain != null) ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture : BlocksTexturesManager.DefaultBlocksTexture;
            TexturedBatch3D texturedBatch3D = primitivesRenderer.TexturedBatch(texture, useAlphaTest: true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);
            float           s = LightingManager.LightIntensityByLightValue[environmentData.Light];

            color    = Color.MultiplyColorOnly(color, s);
            topColor = Color.MultiplyColorOnly(topColor, s);
            Vector3 translation = matrix.Translation;
            Vector3 vector      = matrix.Right * size.X;
            Vector3 v           = matrix.Up * size.Y;
            Vector3 v2          = matrix.Forward * size.Z;
            Vector3 v3          = translation + 0.5f * (-vector - v - v2);
            Vector3 v4          = translation + 0.5f * (vector - v - v2);
            Vector3 v5          = translation + 0.5f * (-vector + v - v2);
            Vector3 v6          = translation + 0.5f * (vector + v - v2);
            Vector3 v7          = translation + 0.5f * (-vector - v + v2);
            Vector3 v8          = translation + 0.5f * (vector - v + v2);
            Vector3 v9          = translation + 0.5f * (-vector + v + v2);
            Vector3 v10         = translation + 0.5f * (vector + v + v2);

            if (environmentData.ViewProjectionMatrix.HasValue)
            {
                Matrix m = environmentData.ViewProjectionMatrix.Value;
                Vector3.Transform(ref v3, ref m, out v3);
                Vector3.Transform(ref v4, ref m, out v4);
                Vector3.Transform(ref v5, ref m, out v5);
                Vector3.Transform(ref v6, ref m, out v6);
                Vector3.Transform(ref v7, ref m, out v7);
                Vector3.Transform(ref v8, ref m, out v8);
                Vector3.Transform(ref v9, ref m, out v9);
                Vector3.Transform(ref v10, ref m, out v10);
            }
            int     num     = Terrain.ExtractContents(value);
            Block   block   = Blocks[num];
            Vector4 vector2 = m_slotTexCoords[block.GetFaceTextureSlot(0, value)];

            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Forward)), p1: v3, p2: v5, p3: v6, p4: v4, texCoord1: new Vector2(vector2.X, vector2.W), texCoord2: new Vector2(vector2.X, vector2.Y), texCoord3: new Vector2(vector2.Z, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.W));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(2, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Forward)), p1: v7, p2: v8, p3: v10, p4: v9, texCoord1: new Vector2(vector2.Z, vector2.W), texCoord2: new Vector2(vector2.X, vector2.W), texCoord3: new Vector2(vector2.X, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.Y));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(5, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Up)), p1: v3, p2: v4, p3: v8, p4: v7, texCoord1: new Vector2(vector2.X, vector2.Y), texCoord2: new Vector2(vector2.Z, vector2.Y), texCoord3: new Vector2(vector2.Z, vector2.W), texCoord4: new Vector2(vector2.X, vector2.W));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(4, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(topColor, LightingManager.CalculateLighting(matrix.Up)), p1: v5, p2: v9, p3: v10, p4: v6, texCoord1: new Vector2(vector2.X, vector2.W), texCoord2: new Vector2(vector2.X, vector2.Y), texCoord3: new Vector2(vector2.Z, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.W));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(1, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Right)), p1: v3, p2: v7, p3: v9, p4: v5, texCoord1: new Vector2(vector2.Z, vector2.W), texCoord2: new Vector2(vector2.X, vector2.W), texCoord3: new Vector2(vector2.X, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.Y));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(3, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Right)), p1: v4, p2: v6, p3: v10, p4: v8, texCoord1: new Vector2(vector2.X, vector2.W), texCoord2: new Vector2(vector2.X, vector2.Y), texCoord3: new Vector2(vector2.Z, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.W));
        }
コード例 #2
0
        public float?CalculateModelLight(ModelData modelData)
        {
            Vector3 p;

            if (modelData.ComponentBody != null)
            {
                p    = modelData.ComponentBody.Position;
                p.Y += 0.95f * (modelData.ComponentBody.BoundingBox.Max.Y - modelData.ComponentBody.BoundingBox.Min.Y);
            }
            else
            {
                Matrix?boneTransform = modelData.ComponentModel.GetBoneTransform(modelData.ComponentModel.Model.RootBone.Index);
                p = ((!boneTransform.HasValue) ? Vector3.Zero : (boneTransform.Value.Translation + new Vector3(0f, 0.9f, 0f)));
            }
            return(LightingManager.CalculateSmoothLight(m_subsystemTerrain, p));
        }
コード例 #3
0
        public LoadingScreen()
        {
            WidgetsManager.LoadWidgetContents((Widget)this.ScreenWidget, (object)this, ContentManager.Get <XElement>("Screens/LoadingScreen"));

            LabelWidget ExternalAssemblyInfo = new LabelWidget();

            ExternalAssemblyInfo.Text = "Powered By GScience Studio\n";
            //下列两行代码请勿随意删除
            ExternalAssemblyInfo.Text += "Author:" + Info.author + "\n";
            ExternalAssemblyInfo.Text += "Version:" + Info.version;

            ExternalAssemblyInfo.Color     = Color.LightBlue;
            ExternalAssemblyInfo.FontScale = 0.5f;
            this.ScreenWidget.Children.Add(ExternalAssemblyInfo);

            this.AddLoadAction((Action)(() => CommunityContentManager.Initialize()));
            this.AddLoadAction((Action)(() => MotdManager.Initialize()));
            this.AddLoadAction((Action)(() => LightingManager.Initialize()));
            this.AddLoadAction((Action)(() => StringsManager.LoadStrings()));
            this.AddLoadAction((Action)(() => TextureAtlasManager.LoadAtlases()));
            ReadOnlyList <ContentInfo> readOnlyList = ContentManager.List();

            // ISSUE: explicit reference operation
            using (ReadOnlyList <ContentInfo> .Enumerator enumerator = ((ReadOnlyList <ContentInfo>)@readOnlyList).GetEnumerator())
            {
                // ISSUE: explicit reference operation
                while (((ReadOnlyList <ContentInfo> .Enumerator)@enumerator).MoveNext())
                {
                    // ISSUE: explicit reference operation
                    ContentInfo localContentInfo = ((ReadOnlyList <ContentInfo> .Enumerator)@enumerator).Current;
                    this.AddLoadAction((Action)(() => ContentManager.Get((string)localContentInfo.Name)));
                }
            }
            this.AddLoadAction((Action)(() => DatabaseManager.LoadDatabase()));
            this.AddLoadAction((Action)(() => WorldsManager.Initialize()));
            this.AddLoadAction((Action)(() => BlocksTexturesManager.Initialize()));
            this.AddLoadAction((Action)(() => CharacterSkinsManager.Initialize()));
            this.AddLoadAction((Action)(() => FurniturePacksManager.Initialize()));
            this.AddLoadAction((Action)(() => BlocksManager.Initialize()));
            this.AddLoadAction((Action)(() => CraftingRecipesManager.Initialize()));
            this.AddLoadAction((Action)(() => GScienceStudio.InputManager.Initialize()));
        }
コード例 #4
0
ファイル: WireDevice.cs プロジェクト: Lixue9jiu/SCIE
        public static void GenerateWireVertices(BlockGeometryGenerator generator, int value, int x, int y, int z, int mountingFace, float centerBoxSize, Vector2 centerOffset, TerrainGeometrySubset subset)
        {
            var   terrain = generator.Terrain;
            Color color   = WireBlock.WireColor;
            int   num     = Terrain.ExtractContents(value);

            if (num == ElementBlock.Index)
            {
                int?color2 = PaintableItemBlock.GetColor(Terrain.ExtractData(value));
                if (color2.HasValue)
                {
                    color = SubsystemPalette.GetColor(generator, color2);
                }
            }
            float   num3         = LightingManager.LightIntensityByLightValue[Terrain.ExtractLight(value)];
            Vector3 v            = new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - 0.5f * CellFace.FaceToVector3(mountingFace);
            Vector3 vector       = CellFace.FaceToVector3(mountingFace);
            var     v2           = new Vector2(0.9376f, 0.0001f);
            var     v3           = new Vector2(0.03125f, 0.00550781237f);
            Point3  point        = CellFace.FaceToPoint3(mountingFace);
            int     cellContents = terrain.GetCellContents(x - point.X, y - point.Y, z - point.Z);
            bool    flag         = cellContents == 2 || cellContents == 7 || cellContents == 8 || cellContents == 6 || cellContents == 62 || cellContents == 72;
            Vector3 v4           = CellFace.FaceToVector3(SubsystemElectricity.GetConnectorFace(mountingFace, ElectricConnectorDirection.Top));
            Vector3 vector2      = CellFace.FaceToVector3(SubsystemElectricity.GetConnectorFace(mountingFace, ElectricConnectorDirection.Left)) * centerOffset.X + v4 * centerOffset.Y;
            int     num4         = 0;
            var     paths        = new DynamicArray <ElectricConnectionPath>();

            ElementBlock.Block.GetAllConnectedNeighbors(terrain, ElementBlock.Block.GetDevice(x, y, z, value), mountingFace, paths);
            foreach (ElectricConnectionPath tmpConnectionPath in paths)
            {
                if ((num4 & (1 << tmpConnectionPath.ConnectorFace)) == 0)
                {
                    ElectricConnectorDirection?connectorDirection = SubsystemElectricity.GetConnectorDirection(mountingFace, 0, tmpConnectionPath.ConnectorFace);
                    if (centerOffset != Vector2.Zero || connectorDirection != ElectricConnectorDirection.In)
                    {
                        num4 |= 1 << tmpConnectionPath.ConnectorFace;
                        Color color3 = color;
                        if (num != ElementBlock.Index)
                        {
                            int cellValue = terrain.GetCellValue(x + tmpConnectionPath.NeighborOffsetX, y + tmpConnectionPath.NeighborOffsetY, z + tmpConnectionPath.NeighborOffsetZ);
                            if (Terrain.ExtractContents(cellValue) == ElementBlock.Index)
                            {
                                int?color4 = PaintableItemBlock.GetColor(Terrain.ExtractData(cellValue));
                                if (color4.HasValue)
                                {
                                    color3 = SubsystemPalette.GetColor(generator, color4);
                                }
                            }
                        }
                        Vector3 vector3  = (connectorDirection != ElectricConnectorDirection.In) ? CellFace.FaceToVector3(tmpConnectionPath.ConnectorFace) : (-Vector3.Normalize(vector2));
                        var     vector4  = Vector3.Cross(vector, vector3);
                        float   s        = (centerBoxSize >= 0f) ? MathUtils.Max(0.03125f, centerBoxSize / 2f) : (centerBoxSize / 2f);
                        float   num5     = (connectorDirection == ElectricConnectorDirection.In) ? 0.03125f : 0.5f;
                        float   num6     = (connectorDirection == ElectricConnectorDirection.In) ? 0f : ((tmpConnectionPath.ConnectorFace == tmpConnectionPath.NeighborFace) ? (num5 + 0.03125f) : ((tmpConnectionPath.ConnectorFace != CellFace.OppositeFace(tmpConnectionPath.NeighborFace)) ? num5 : (num5 - 0.03125f)));
                        Vector3 vector5  = v - vector4 * 0.03125f + vector3 * s + vector2;
                        Vector3 vector6  = v - vector4 * 0.03125f + vector3 * num5;
                        Vector3 vector7  = v + vector4 * 0.03125f + vector3 * num5;
                        Vector3 vector8  = v + vector4 * 0.03125f + vector3 * s + vector2;
                        Vector3 vector9  = v + vector * 0.03125f + vector3 * (centerBoxSize / 2f) + vector2;
                        Vector3 vector10 = v + vector * 0.03125f + vector3 * num6;
                        if (flag && centerBoxSize == 0f)
                        {
                            Vector3 v5 = 0.25f * BlockGeometryGenerator.GetRandomWireOffset(0.5f * (vector5 + vector8), vector);
                            vector5 += v5;
                            vector8 += v5;
                            vector9 += v5;
                        }
                        Vector2 vector11 = v2 + v3 * new Vector2(MathUtils.Max(0.0625f, centerBoxSize), 0f);
                        Vector2 vector12 = v2 + v3 * new Vector2(num5 * 2f, 0f);
                        Vector2 vector13 = v2 + v3 * new Vector2(num5 * 2f, 1f);
                        Vector2 vector14 = v2 + v3 * new Vector2(MathUtils.Max(0.0625f, centerBoxSize), 1f);
                        Vector2 vector15 = v2 + v3 * new Vector2(centerBoxSize, 0.5f);
                        Vector2 vector16 = v2 + v3 * new Vector2(num6 * 2f, 0.5f);
                        float   num9     = 0.5f * (num3 + LightingManager.LightIntensityByLightValue[Terrain.ExtractLight(terrain.GetCellValue(x + tmpConnectionPath.NeighborOffsetX, y + tmpConnectionPath.NeighborOffsetY, z + tmpConnectionPath.NeighborOffsetZ))]);
                        float   num10    = LightingManager.CalculateLighting(-vector4);
                        float   num11    = LightingManager.CalculateLighting(vector4);
                        float   num12    = LightingManager.CalculateLighting(vector);
                        float   num13    = num10 * num3;
                        float   num14    = num10 * num9;
                        float   num15    = num11 * num9;
                        float   num16    = num11 * num3;
                        float   num17    = num12 * num3;
                        float   num18    = num12 * num9;
                        var     color5   = new Color((byte)(color3.R * num13), (byte)(color3.G * num13), (byte)(color3.B * num13));
                        var     color6   = new Color((byte)(color3.R * num14), (byte)(color3.G * num14), (byte)(color3.B * num14));
                        var     color7   = new Color((byte)(color3.R * num15), (byte)(color3.G * num15), (byte)(color3.B * num15));
                        var     color8   = new Color((byte)(color3.R * num16), (byte)(color3.G * num16), (byte)(color3.B * num16));
                        var     color9   = new Color((byte)(color3.R * num17), (byte)(color3.G * num17), (byte)(color3.B * num17));
                        var     color10  = new Color((byte)(color3.R * num18), (byte)(color3.G * num18), (byte)(color3.B * num18));
                        int     count    = subset.Vertices.Count;
                        subset.Vertices.Count += 6;
                        TerrainVertex[] array = subset.Vertices.Array;
                        BlockGeometryGenerator.SetupVertex(vector5.X, vector5.Y, vector5.Z, color5, vector11.X, vector11.Y, ref array[count]);
                        BlockGeometryGenerator.SetupVertex(vector6.X, vector6.Y, vector6.Z, color6, vector12.X, vector12.Y, ref array[count + 1]);
                        BlockGeometryGenerator.SetupVertex(vector7.X, vector7.Y, vector7.Z, color7, vector13.X, vector13.Y, ref array[count + 2]);
                        BlockGeometryGenerator.SetupVertex(vector8.X, vector8.Y, vector8.Z, color8, vector14.X, vector14.Y, ref array[count + 3]);
                        BlockGeometryGenerator.SetupVertex(vector9.X, vector9.Y, vector9.Z, color9, vector15.X, vector15.Y, ref array[count + 4]);
                        BlockGeometryGenerator.SetupVertex(vector10.X, vector10.Y, vector10.Z, color10, vector16.X, vector16.Y, ref array[count + 5]);
                        int count2 = subset.Indices.Count;
                        subset.Indices.Count += (connectorDirection == ElectricConnectorDirection.In) ? 15 : 12;
                        ushort[] array2 = subset.Indices.Array;
                        array2[count2]      = (ushort)count;
                        array2[count2 + 1]  = (ushort)(count + 5);
                        array2[count2 + 2]  = (ushort)(count + 1);
                        array2[count2 + 3]  = (ushort)(count + 5);
                        array2[count2 + 4]  = (ushort)count;
                        array2[count2 + 5]  = (ushort)(count + 4);
                        array2[count2 + 6]  = (ushort)(count + 4);
                        array2[count2 + 7]  = (ushort)(count + 2);
                        array2[count2 + 8]  = (ushort)(count + 5);
                        array2[count2 + 9]  = (ushort)(count + 2);
                        array2[count2 + 10] = (ushort)(count + 4);
                        array2[count2 + 11] = (ushort)(count + 3);
                        if (connectorDirection == ElectricConnectorDirection.In)
                        {
                            array2[count2 + 12] = (ushort)(count + 2);
                            array2[count2 + 13] = (ushort)(count + 1);
                            array2[count2 + 14] = (ushort)(count + 5);
                        }
                    }
                }
            }
            if (centerBoxSize == 0f && (num4 != 0 || (num == ElementBlock.Index && (Terrain.ExtractData(value) & 1023) == 5)))
            {
                for (int i = 0; i < 6; i++)
                {
                    if (i != mountingFace && i != CellFace.OppositeFace(mountingFace) && (num4 & (1 << i)) == 0)
                    {
                        Vector3 vector17 = CellFace.FaceToVector3(i);
                        var     v6       = Vector3.Cross(vector, vector17);
                        Vector3 vector18 = v - v6 * 0.03125f + vector17 * 0.03125f;
                        Vector3 vector19 = v + v6 * 0.03125f + vector17 * 0.03125f;
                        Vector3 vector20 = v + vector * 0.03125f;
                        if (flag)
                        {
                            Vector3 v7 = 0.25f * BlockGeometryGenerator.GetRandomWireOffset(0.5f * (vector18 + vector19), vector);
                            vector18 += v7;
                            vector19 += v7;
                            vector20 += v7;
                        }
                        Vector2 vector21 = v2 + v3 * new Vector2(0.0625f, 0f);
                        Vector2 vector22 = v2 + v3 * new Vector2(0.0625f, 1f);
                        Vector2 vector23 = v2 + v3 * new Vector2(0f, 0.5f);
                        float   num19    = LightingManager.CalculateLighting(vector17) * num3;
                        float   num20    = LightingManager.CalculateLighting(vector) * num3;
                        var     color11  = new Color((byte)(color.R * num19), (byte)(color.G * num19), (byte)(color.B * num19));
                        var     color12  = new Color((byte)(color.R * num20), (byte)(color.G * num20), (byte)(color.B * num20));
                        int     count3   = subset.Vertices.Count;
                        subset.Vertices.Count += 3;
                        var array3 = subset.Vertices.Array;
                        BlockGeometryGenerator.SetupVertex(vector18.X, vector18.Y, vector18.Z, color11, vector21.X, vector21.Y, ref array3[count3]);
                        BlockGeometryGenerator.SetupVertex(vector19.X, vector19.Y, vector19.Z, color11, vector22.X, vector22.Y, ref array3[count3 + 1]);
                        BlockGeometryGenerator.SetupVertex(vector20.X, vector20.Y, vector20.Z, color12, vector23.X, vector23.Y, ref array3[count3 + 2]);
                        int count4 = subset.Indices.Count;
                        subset.Indices.Count += 3;
                        ushort[] array4 = subset.Indices.Array;
                        array4[count4]     = (ushort)count3;
                        array4[count4 + 1] = (ushort)(count3 + 2);
                        array4[count4 + 2] = (ushort)(count3 + 1);
                    }
                }
            }
        }
コード例 #5
0
        public LoadingScreen()
        {
            XElement node = ContentManager.Get <XElement>("Screens/LoadingScreen");

            LoadContents(this, node);
            AddLoadAction(delegate
            {
                VrManager.Initialize();
            });
            AddLoadAction(delegate
            {
                CommunityContentManager.Initialize();
            });
            AddLoadAction(delegate
            {
                MotdManager.Initialize();
            });
            AddLoadAction(delegate
            {
                LightingManager.Initialize();
            });
            AddLoadAction(delegate
            {
                StringsManager.LoadStrings();
            });
            AddLoadAction(delegate
            {
                TextureAtlasManager.LoadAtlases();
            });
            foreach (ContentInfo item in ContentManager.List())
            {
                ContentInfo localContentInfo = item;
                AddLoadAction(delegate
                {
                    ContentManager.Get(localContentInfo.Name);
                });
            }
            AddLoadAction(delegate
            {
                DatabaseManager.Initialize();
            });
            AddLoadAction(delegate
            {
                WorldsManager.Initialize();
            });
            AddLoadAction(delegate
            {
                BlocksTexturesManager.Initialize();
            });
            AddLoadAction(delegate
            {
                CharacterSkinsManager.Initialize();
            });
            AddLoadAction(delegate
            {
                FurniturePacksManager.Initialize();
            });
            AddLoadAction(delegate
            {
                BlocksManager.Initialize();
            });
            AddLoadAction(delegate
            {
                CraftingRecipesManager.Initialize();
            });
            AddLoadAction(delegate
            {
                MusicManager.CurrentMix = MusicManager.Mix.Menu;
            });
        }
コード例 #6
0
        public void AppendModelMeshPart(ModelMeshPart meshPart, Matrix matrix, bool makeEmissive, bool flipWindingOrder, bool doubleSided, bool flipNormals, Color color)
        {
            VertexBuffer vertexBuffer = meshPart.VertexBuffer;
            IndexBuffer  indexBuffer  = meshPart.IndexBuffer;
            ReadOnlyList <VertexElement> vertexElements = vertexBuffer.VertexDeclaration.VertexElements;

            if (vertexElements.Count != 3 || vertexElements[0].Offset != 0 || vertexElements[0].Semantic != VertexElementSemantic.Position.GetSemanticString() || vertexElements[1].Offset != 12 || vertexElements[1].Semantic != VertexElementSemantic.Normal.GetSemanticString() || vertexElements[2].Offset != 24 || vertexElements[2].Semantic != VertexElementSemantic.TextureCoordinate.GetSemanticString())
            {
                throw new InvalidOperationException("Wrong vertex format for a block mesh.");
            }
            publicVertex[] vertexData = GetVertexData <publicVertex>(vertexBuffer);
            ushort[]       indexData  = GetIndexData <ushort>(indexBuffer);
            Dictionary <ushort, ushort> dictionary = new Dictionary <ushort, ushort>();

            for (int i = meshPart.StartIndex; i < meshPart.StartIndex + meshPart.IndicesCount; i++)
            {
                ushort num = indexData[i];
                if (!dictionary.ContainsKey(num))
                {
                    dictionary.Add(num, (ushort)Vertices.Count);
                    BlockMeshVertex item = default(BlockMeshVertex);
                    item.Position           = Vector3.Transform(vertexData[num].Position, matrix);
                    item.TextureCoordinates = vertexData[num].TextureCoordinate;
                    Vector3 vector = Vector3.Normalize(Vector3.TransformNormal(flipNormals ? (-vertexData[num].Normal) : vertexData[num].Normal, matrix));
                    if (makeEmissive)
                    {
                        item.IsEmissive = true;
                        item.Color      = color;
                    }
                    else
                    {
                        item.Color   = color * LightingManager.CalculateLighting(vector);
                        item.Color.A = color.A;
                    }
                    item.Face = (byte)CellFace.Vector3ToFace(vector);
                    Vertices.Add(item);
                }
            }
            for (int j = 0; j < meshPart.IndicesCount / 3; j++)
            {
                if (doubleSided)
                {
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]);
                }
                else if (flipWindingOrder)
                {
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]);
                }
                else
                {
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 1]]);
                    Indices.Add(dictionary[indexData[meshPart.StartIndex + 3 * j + 2]]);
                }
            }
            Trim();
        }
コード例 #7
0
        public static void DrawCubeBlock(PrimitivesRenderer3D primitivesRenderer, int value, Vector3 size,
                                         ref Matrix matrix, Color color, Color topColor, DrawBlockEnvironmentData environmentData)
        {
            environmentData = environmentData ?? m_defaultEnvironmentData;
            var texture = environmentData.SubsystemTerrain != null
                                ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture
                                : BlocksTexturesManager.DefaultBlocksTexture;
            var texturedBatch3D = primitivesRenderer.TexturedBatch(texture, true, 0, null,
                                                                   RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);
            var s = LightingManager.LightIntensityByLightValue[environmentData.Light];

            color    = Color.MultiplyColorOnly(color, s);
            topColor = Color.MultiplyColorOnly(topColor, s);
            var translation = matrix.Translation;
            var vector3_1   = matrix.Right * size.X;
            var vector3_2   = matrix.Up * size.Y;
            var vector3_3   = matrix.Forward * size.Z;
            var result1     = translation + 0.5f * (-vector3_1 - vector3_2 - vector3_3);
            var result2     = translation + 0.5f * (vector3_1 - vector3_2 - vector3_3);
            var result3     = translation + 0.5f * (-vector3_1 + vector3_2 - vector3_3);
            var result4     = translation + 0.5f * (vector3_1 + vector3_2 - vector3_3);
            var result5     = translation + 0.5f * (-vector3_1 - vector3_2 + vector3_3);
            var result6     = translation + 0.5f * (vector3_1 - vector3_2 + vector3_3);
            var result7     = translation + 0.5f * (-vector3_1 + vector3_2 + vector3_3);
            var result8     = translation + 0.5f * (vector3_1 + vector3_2 + vector3_3);

            if (environmentData.ViewProjectionMatrix.HasValue)
            {
                var m = environmentData.ViewProjectionMatrix.Value;
                Vector3.Transform(ref result1, ref m, out result1);
                Vector3.Transform(ref result2, ref m, out result2);
                Vector3.Transform(ref result3, ref m, out result3);
                Vector3.Transform(ref result4, ref m, out result4);
                Vector3.Transform(ref result5, ref m, out result5);
                Vector3.Transform(ref result6, ref m, out result6);
                Vector3.Transform(ref result7, ref m, out result7);
                Vector3.Transform(ref result8, ref m, out result8);
            }

            var block         = Blocks[Terrain.ExtractContents(value)];
            var slotTexCoord1 = m_slotTexCoords[block.GetFaceTextureSlot(0, value)];
            var color1        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Forward));

            texturedBatch3D.QueueQuad(result1, result3, result4, result2, new Vector2(slotTexCoord1.X, slotTexCoord1.W),
                                      new Vector2(slotTexCoord1.X, slotTexCoord1.Y), new Vector2(slotTexCoord1.Z, slotTexCoord1.Y),
                                      new Vector2(slotTexCoord1.Z, slotTexCoord1.W), color1);
            var slotTexCoord2 = m_slotTexCoords[block.GetFaceTextureSlot(2, value)];
            var color2        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Forward));

            texturedBatch3D.QueueQuad(result5, result6, result8, result7, new Vector2(slotTexCoord2.Z, slotTexCoord2.W),
                                      new Vector2(slotTexCoord2.X, slotTexCoord2.W), new Vector2(slotTexCoord2.X, slotTexCoord2.Y),
                                      new Vector2(slotTexCoord2.Z, slotTexCoord2.Y), color2);
            var slotTexCoord3 = m_slotTexCoords[block.GetFaceTextureSlot(5, value)];
            var color3        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Up));

            texturedBatch3D.QueueQuad(result1, result2, result6, result5, new Vector2(slotTexCoord3.X, slotTexCoord3.Y),
                                      new Vector2(slotTexCoord3.Z, slotTexCoord3.Y), new Vector2(slotTexCoord3.Z, slotTexCoord3.W),
                                      new Vector2(slotTexCoord3.X, slotTexCoord3.W), color3);
            var slotTexCoord4 = m_slotTexCoords[block.GetFaceTextureSlot(4, value)];
            var color4        = Color.MultiplyColorOnly(topColor, LightingManager.CalculateLighting(matrix.Up));

            texturedBatch3D.QueueQuad(result3, result7, result8, result4, new Vector2(slotTexCoord4.X, slotTexCoord4.W),
                                      new Vector2(slotTexCoord4.X, slotTexCoord4.Y), new Vector2(slotTexCoord4.Z, slotTexCoord4.Y),
                                      new Vector2(slotTexCoord4.Z, slotTexCoord4.W), color4);
            var slotTexCoord5 = m_slotTexCoords[block.GetFaceTextureSlot(1, value)];
            var color5        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Right));

            texturedBatch3D.QueueQuad(result1, result5, result7, result3, new Vector2(slotTexCoord5.Z, slotTexCoord5.W),
                                      new Vector2(slotTexCoord5.X, slotTexCoord5.W), new Vector2(slotTexCoord5.X, slotTexCoord5.Y),
                                      new Vector2(slotTexCoord5.Z, slotTexCoord5.Y), color5);
            var slotTexCoord6 = m_slotTexCoords[block.GetFaceTextureSlot(3, value)];
            var color6        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Right));

            texturedBatch3D.QueueQuad(result2, result4, result8, result6, new Vector2(slotTexCoord6.X, slotTexCoord6.W),
                                      new Vector2(slotTexCoord6.X, slotTexCoord6.Y), new Vector2(slotTexCoord6.Z, slotTexCoord6.Y),
                                      new Vector2(slotTexCoord6.Z, slotTexCoord6.W), color6);
        }
コード例 #8
0
        public void DrawIceOverlay(Camera camera, float factor)
        {
            Vector2 viewportSize = camera.ViewportSize;
            float   s            = camera.Eye.HasValue ? 1.3f : 1f;
            float   num          = camera.Eye.HasValue ? MathUtils.Pow(factor, 0.4f) : factor;
            Vector2 v            = camera.Eye.HasValue ? viewportSize : new Vector2(1f);
            float   num2         = v.Length();
            Point2  point        = new Point2((int)MathUtils.Round(12f * viewportSize.X / viewportSize.Y), (int)MathUtils.Round(12f));

            if (m_iceVertices == null || m_cellsCount != point)
            {
                m_cellsCount = point;
                m_random.Seed(0);
                m_iceVertices = new Vector2[(point.X + 1) * (point.Y + 1)];
                for (int i = 0; i <= point.X; i++)
                {
                    for (int j = 0; j <= point.Y; j++)
                    {
                        float num3 = i;
                        float num4 = j;
                        if (i != 0 && i != point.X)
                        {
                            num3 += m_random.Float(-0.4f, 0.4f);
                        }
                        if (j != 0 && j != point.Y)
                        {
                            num4 += m_random.Float(-0.4f, 0.4f);
                        }
                        float x = num3 / (float)point.X;
                        float y = num4 / (float)point.Y;
                        m_iceVertices[i + j * (point.X + 1)] = new Vector2(x, y);
                    }
                }
            }
            Vector3 vector  = Vector3.UnitX / camera.ProjectionMatrix.M11 * 2f * 0.2f * s;
            Vector3 vector2 = Vector3.UnitY / camera.ProjectionMatrix.M22 * 2f * 0.2f * s;
            Vector3 v2      = -0.2f * Vector3.UnitZ - 0.5f * (vector + vector2);

            if (!m_light.HasValue || Time.PeriodicEvent(0.05000000074505806, 0.0))
            {
                m_light = (LightingManager.CalculateSmoothLight(m_subsystemTerrain, camera.ViewPosition) ?? m_light ?? 1f);
            }
            Color color = Color.MultiplyColorOnly(Color.White, m_light.Value);

            m_random.Seed(0);
            Texture2D       texture         = ContentManager.Get <Texture2D>("Textures/IceOverlay");
            TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(texture, useAlphaTest: false, 0, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend, SamplerState.PointWrap);
            Vector2         v3      = new Vector2(viewportSize.X / viewportSize.Y, 1f);
            Vector2         vector3 = new Vector2(point.X - 1, point.Y - 1);

            for (int k = 0; k < point.X; k++)
            {
                for (int l = 0; l < point.Y; l++)
                {
                    float num5 = (new Vector2((float)(2 * k) / vector3.X - 1f, (float)(2 * l) / vector3.Y - 1f) * v).Length() / num2;
                    if (1f - num5 + m_random.Float(0f, 0.05f) < num)
                    {
                        Vector2 v4        = m_iceVertices[k + l * (point.X + 1)];
                        Vector2 v5        = m_iceVertices[k + 1 + l * (point.X + 1)];
                        Vector2 v6        = m_iceVertices[k + 1 + (l + 1) * (point.X + 1)];
                        Vector2 v7        = m_iceVertices[k + (l + 1) * (point.X + 1)];
                        Vector3 vector4   = v2 + v4.X * vector + v4.Y * vector2;
                        Vector3 p         = v2 + v5.X * vector + v5.Y * vector2;
                        Vector3 vector5   = v2 + v6.X * vector + v6.Y * vector2;
                        Vector3 p2        = v2 + v7.X * vector + v7.Y * vector2;
                        Vector2 vector6   = v4 * v3;
                        Vector2 texCoord  = v5 * v3;
                        Vector2 vector7   = v6 * v3;
                        Vector2 texCoord2 = v7 * v3;
                        texturedBatch3D.QueueTriangle(vector4, p, vector5, vector6, texCoord, vector7, color);
                        texturedBatch3D.QueueTriangle(vector5, p2, vector4, vector7, texCoord2, vector6, color);
                    }
                }
            }
            texturedBatch3D.Flush(camera.ProjectionMatrix);
        }
コード例 #9
0
        public void Draw(Camera camera, int drawOrder)
        {
            if (!(m_componentPlayer.ComponentHealth.Health > 0f) || !camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) || !m_componentPlayer.ComponentInput.IsControlledByVr)
            {
                return;
            }
            Vector3 eyePosition      = m_componentPlayer.ComponentCreatureModel.EyePosition;
            int     x                = Terrain.ToCell(eyePosition.X);
            int     num              = Terrain.ToCell(eyePosition.Y);
            int     z                = Terrain.ToCell(eyePosition.Z);
            int     activeBlockValue = m_componentMiner.ActiveBlockValue;

            if (Time.FrameStartTime >= m_nextHandLightTime)
            {
                float?num2 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition);
                if (num2.HasValue)
                {
                    m_nextHandLightTime = Time.FrameStartTime + 0.1;
                    m_handLight         = num2.Value;
                }
            }
            Matrix identity = Matrix.Identity;

            if (m_pokeAnimationTime > 0f)
            {
                float num3 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI);
                if (activeBlockValue != 0)
                {
                    identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num3);
                }
                else
                {
                    identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num3);
                }
            }
            if (!VrManager.IsControllerPresent(VrController.Right))
            {
                return;
            }
            Matrix m = VrManager.HmdMatrixInverted * Matrix.CreateWorld(camera.ViewPosition, camera.ViewDirection, camera.ViewUp) * camera.ViewMatrix;
            Matrix controllerMatrix = VrManager.GetControllerMatrix(VrController.Right);

            if (activeBlockValue == 0)
            {
                Display.DepthStencilState      = DepthStencilState.Default;
                Display.RasterizerState        = RasterizerState.CullCounterClockwiseScissor;
                m_shader.Texture               = m_componentPlayer.ComponentCreatureModel.TextureOverride;
                m_shader.SamplerState          = SamplerState.PointClamp;
                m_shader.MaterialColor         = Vector4.One;
                m_shader.AmbientLightColor     = new Vector3(m_handLight * LightingManager.LightAmbient);
                m_shader.DiffuseLightColor1    = new Vector3(m_handLight);
                m_shader.DiffuseLightColor2    = new Vector3(m_handLight);
                m_shader.LightDirection1       = -Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix);
                m_shader.LightDirection2       = -Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix);
                m_shader.Transforms.View       = Matrix.Identity;
                m_shader.Transforms.Projection = camera.ProjectionMatrix;
                m_shader.Transforms.World[0]   = Matrix.CreateScale(0.01f) * identity * controllerMatrix * m;
                foreach (ModelMesh mesh in m_vrHandModel.Meshes)
                {
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    {
                        Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount);
                    }
                }
            }
            else
            {
                if (num >= 0 && num <= 255)
                {
                    TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                    if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                    {
                        m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num, z);
                    }
                }
                int     num4   = Terrain.ExtractContents(activeBlockValue);
                Block   block  = BlocksManager.Blocks[num4];
                Vector3 vector = block.InHandRotation * ((float)Math.PI / 180f) + m_itemRotation;
                Matrix  matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * Matrix.CreateTranslation(block.InHandOffset) * identity * Matrix.CreateTranslation(m_itemOffset) * controllerMatrix * m;
                m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
                m_drawBlockEnvironmentData.InWorldMatrix    = matrix;
                m_drawBlockEnvironmentData.Light            = m_itemLight;
                m_drawBlockEnvironmentData.Humidity         = m_subsystemTerrain.Terrain.GetHumidity(x, z);
                m_drawBlockEnvironmentData.Temperature      = m_subsystemTerrain.Terrain.GetTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num);
                block.DrawBlock(m_primitivesRenderer, activeBlockValue, Color.White, block.InHandScale, ref matrix, m_drawBlockEnvironmentData);
            }
            m_primitivesRenderer.Flush(camera.ProjectionMatrix);
        }
コード例 #10
0
 public void Draw(Camera camera, int drawOrder)
 {
     if (m_componentPlayer.ComponentHealth.Health > 0f && camera.GameWidget.IsEntityFirstPersonTarget(base.Entity) && !m_componentPlayer.ComponentInput.IsControlledByVr)
     {
         Viewport viewport  = Display.Viewport;
         Viewport viewport2 = viewport;
         viewport2.MaxDepth *= 0.1f;
         Display.Viewport    = viewport2;
         try
         {
             Matrix identity = Matrix.Identity;
             if (m_swapAnimationTime > 0f)
             {
                 float num = MathUtils.Pow(MathUtils.Sin(m_swapAnimationTime * (float)Math.PI), 3f);
                 identity *= Matrix.CreateTranslation(0f, -0.8f * num, 0.2f * num);
             }
             if (m_pokeAnimationTime > 0f)
             {
                 float num2 = MathUtils.Sin(MathUtils.Sqrt(m_pokeAnimationTime) * (float)Math.PI);
                 if (m_value != 0)
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(90f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.5f * num2, 0.1f * num2, 0f * num2);
                 }
                 else
                 {
                     identity *= Matrix.CreateRotationX((0f - MathUtils.DegToRad(45f)) * num2);
                     identity *= Matrix.CreateTranslation(-0.1f * num2, 0.2f * num2, -0.05f * num2);
                 }
             }
             if (m_componentRider.Mount != null)
             {
                 ComponentCreatureModel componentCreatureModel = m_componentRider.Mount.Entity.FindComponent <ComponentCreatureModel>();
                 if (componentCreatureModel != null)
                 {
                     float   num3     = componentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f + 0.5f;
                     Vector3 position = default(Vector3);
                     position.Y = 0.02f * MathUtils.Sin(num3);
                     position.Z = 0.02f * MathUtils.Sin(num3);
                     identity  *= Matrix.CreateRotationX(0.05f * MathUtils.Sin(num3 * 1f)) * Matrix.CreateTranslation(position);
                 }
             }
             else
             {
                 float   num4      = m_componentPlayer.ComponentCreatureModel.MovementAnimationPhase * (float)Math.PI * 2f;
                 Vector3 position2 = default(Vector3);
                 position2.X = 0.03f * MathUtils.Sin(num4 * 1f);
                 position2.Y = 0.02f * MathUtils.Sin(num4 * 2f);
                 position2.Z = 0.02f * MathUtils.Sin(num4 * 1f);
                 identity   *= Matrix.CreateRotationZ(1f * position2.X) * Matrix.CreateTranslation(position2);
             }
             Vector3 eyePosition = m_componentPlayer.ComponentCreatureModel.EyePosition;
             int     x           = Terrain.ToCell(eyePosition.X);
             int     num5        = Terrain.ToCell(eyePosition.Y);
             int     z           = Terrain.ToCell(eyePosition.Z);
             Matrix  m           = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
             m.Translation = m_componentPlayer.ComponentCreatureModel.EyePosition;
             if (m_value != 0)
             {
                 if (num5 >= 0 && num5 <= 255)
                 {
                     TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
                     if (chunkAtCell != null && chunkAtCell.State >= TerrainChunkState.InvalidVertices1)
                     {
                         m_itemLight = m_subsystemTerrain.Terrain.GetCellLightFast(x, num5, z);
                     }
                 }
                 int     num6      = Terrain.ExtractContents(m_value);
                 Block   block     = BlocksManager.Blocks[num6];
                 Vector3 vector    = block.FirstPersonRotation * ((float)Math.PI / 180f) + m_itemRotation;
                 Vector3 position3 = block.FirstPersonOffset + m_itemOffset;
                 position3 += m_itemOffset;
                 Matrix matrix = Matrix.CreateFromYawPitchRoll(vector.Y, vector.X, vector.Z) * identity * Matrix.CreateTranslation(position3) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m;
                 m_drawBlockEnvironmentData.SubsystemTerrain = m_subsystemTerrain;
                 m_drawBlockEnvironmentData.InWorldMatrix    = matrix;
                 m_drawBlockEnvironmentData.Light            = m_itemLight;
                 m_drawBlockEnvironmentData.Humidity         = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
                 m_drawBlockEnvironmentData.Temperature      = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(num5);
                 block.DrawBlock(m_primitivesRenderer, m_value, Color.White, block.FirstPersonScale, ref matrix, m_drawBlockEnvironmentData);
                 m_primitivesRenderer.Flush(camera.ViewProjectionMatrix);
             }
             else
             {
                 if (Time.FrameStartTime >= m_nextHandLightTime)
                 {
                     float?num7 = LightingManager.CalculateSmoothLight(m_subsystemTerrain, eyePosition);
                     if (num7.HasValue)
                     {
                         m_nextHandLightTime = Time.FrameStartTime + 0.1;
                         m_handLight         = num7.Value;
                     }
                 }
                 Vector3 position4 = new Vector3(0.25f, -0.3f, -0.05f);
                 Matrix  matrix2   = Matrix.CreateScale(0.01f) * Matrix.CreateRotationX(0.8f) * Matrix.CreateRotationY(0.4f) * identity * Matrix.CreateTranslation(position4) * Matrix.CreateFromYawPitchRoll(m_lagAngles.X, m_lagAngles.Y, 0f) * m * camera.ViewMatrix;
                 Display.DepthStencilState      = DepthStencilState.Default;
                 Display.RasterizerState        = RasterizerState.CullCounterClockwiseScissor;
                 m_shader.Texture               = m_componentPlayer.ComponentCreatureModel.TextureOverride;
                 m_shader.SamplerState          = SamplerState.PointClamp;
                 m_shader.MaterialColor         = Vector4.One;
                 m_shader.AmbientLightColor     = new Vector3(m_handLight * LightingManager.LightAmbient);
                 m_shader.DiffuseLightColor1    = new Vector3(m_handLight);
                 m_shader.DiffuseLightColor2    = new Vector3(m_handLight);
                 m_shader.LightDirection1       = Vector3.TransformNormal(LightingManager.DirectionToLight1, camera.ViewMatrix);
                 m_shader.LightDirection2       = Vector3.TransformNormal(LightingManager.DirectionToLight2, camera.ViewMatrix);
                 m_shader.Transforms.World[0]   = matrix2;
                 m_shader.Transforms.View       = Matrix.Identity;
                 m_shader.Transforms.Projection = camera.ProjectionMatrix;
                 foreach (ModelMesh mesh in m_handModel.Meshes)
                 {
                     foreach (ModelMeshPart meshPart in mesh.MeshParts)
                     {
                         Display.DrawIndexed(PrimitiveType.TriangleList, m_shader, meshPart.VertexBuffer, meshPart.IndexBuffer, meshPart.StartIndex, meshPart.IndicesCount);
                     }
                 }
             }
         }
         finally
         {
             Display.Viewport = viewport;
         }
     }
 }