示例#1
0
        public MeshInspector(HxMesh mesh)
        {
            float maxPoint = 0;

            this.mesh = mesh;
            points    = new HxMesh.Point[mesh.Triangles.Length * 3];
            for (int i = 0; i < mesh.Triangles.Length; i++)
            {
                points[i * 3 + 0] = mesh.Points[mesh.Triangles[i].V3];
                points[i * 3 + 1] = mesh.Points[mesh.Triangles[i].V2];
                points[i * 3 + 2] = mesh.Points[mesh.Triangles[i].V1];
                if (points[i * 3].X > maxPoint)
                {
                    maxPoint = points[i * 3].X;
                }
                if (points[i * 3].Y > maxPoint)
                {
                    maxPoint = points[i * 3].Y;
                }
                if (points[i * 3].Z > maxPoint)
                {
                    maxPoint = points[i * 3].Z;
                }
            }
            scaleFactor = 1 / maxPoint;
            InitializeComponent();
            trisLabel.Text         = $"Tris: {mesh.Triangles.Length}";
            vertsLabel.Text        = $"Verts: {mesh.Points.Length}";
            glControl1.MouseWheel += GlControl1_MouseWheel;
        }
示例#2
0
        public void Render(GraphicsDevice graphicsDevice, HxCamera hxCamera)
        {
            if (Material == null)
            {
                return;
            }

            if (HxGameObject.Get <HxMeshFilter>() != null)
            {
                HxMesh mesh = HxGameObject.Get <HxMeshFilter>().HxMesh;

                if (Material.Effect != null)
                {
                    if (mesh.HxMeshData.VertexCount < 3)
                    {
                        return;
                    }

                    Matrix translationMatrix = Matrix.CreateTranslation(HxGameObject.Get <HxTransform>().Position);
                    Matrix rotationMatrix    =
                        Matrix.CreateRotationX(MathHelper.ToRadians(HxGameObject.Get <HxTransform>().Rotation.X)) *
                        Matrix.CreateRotationY(MathHelper.ToRadians(HxGameObject.Get <HxTransform>().Rotation.Y)) *
                        Matrix.CreateRotationZ(MathHelper.ToRadians(HxGameObject.Get <HxTransform>().Rotation.Z));
                    Matrix world = Matrix.CreateScale(HxGameObject.Get <HxTransform>().Scale) * rotationMatrix * translationMatrix;
                    Material.Effect.Parameters["WorldViewProjection"]
                    .SetValue(world * hxCamera.ViewMatrix * hxCamera.ProjectionMatrix);
                    Material.Effect.Parameters["Texture"]
                    .SetValue(Material.MainTexture);
                    Material.Effect.Parameters["Tiling"]
                    .SetValue(Material.Tiling);
                    Material.Effect.Parameters["Offset"]
                    .SetValue(Material.Offset);
                    if (Material.MainTexture != null)
                    {
                        Material.Effect.Parameters["useTexture"]
                        .SetValue(true);
                    }
                    else
                    {
                        Material.Effect.Parameters["useTexture"]
                        .SetValue(false);
                    }
                    Material.Effect.Parameters["Color"]
                    .SetValue(Material.Color.ToVector4());

                    foreach (EffectPass effectPass in Material.Effect.CurrentTechnique.Passes)
                    {
                        effectPass.Apply();
                        graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, mesh.HxMeshData.VertexData, 0,
                                                          mesh.HxMeshData.VertexCount / 3);
                    }
                }
            }
        }
示例#3
0
        public HxSpriteRenderer()
        {
            if (!_generated)
            {
                _data.Add(new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector2(1, 1)));
                _data.Add(new VertexPositionNormalTexture(new Vector3(-1, 0, 0), new Vector3(0, 0, 0), new Vector2(0, 1)));
                _data.Add(new VertexPositionNormalTexture(new Vector3(-1, 1, 0), new Vector3(0, 0, 0), new Vector2(0, 0)));

                _data.Add(new VertexPositionNormalTexture(new Vector3(-1, 1, 0), new Vector3(0, 0, 0), new Vector2(0, 0)));
                _data.Add(new VertexPositionNormalTexture(new Vector3(0, 1, 0), new Vector3(0, 0, 0), new Vector2(1, 0)));
                _data.Add(new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector2(1, 1)));

                _quad      = new HxMesh(_data);
                _generated = true;
            }
        }