Пример #1
0
        // I/F
        public object Load(IResource resource)
        {
            var definition = (MeshDefinition) serializer.Deserialize(resource);

            var mesh = new Mesh
            {
                Name = definition.Name
            };
            mesh.MeshParts[Side.Top] = ToMeshPart(definition.Top);
            mesh.MeshParts[Side.Bottom] = ToMeshPart(definition.Bottom);
            mesh.MeshParts[Side.Front] = ToMeshPart(definition.Front);
            mesh.MeshParts[Side.Back] = ToMeshPart(definition.Back);
            mesh.MeshParts[Side.Left] = ToMeshPart(definition.Left);
            mesh.MeshParts[Side.Right] = ToMeshPart(definition.Right);

            return mesh;
        }
Пример #2
0
        public BrushMesh(string name, GraphicsDevice graphicsDevice, Mesh mesh)
            : base(name)
        {
            if (graphicsDevice == null) throw new ArgumentNullException("graphicsDevice");
            if (mesh == null) throw new ArgumentNullException("mesh");

            this.graphicsDevice = graphicsDevice;
            this.mesh = mesh;

            effect = new BasicEffect(graphicsDevice);

            Translucent = true;

            for (int i = 0; i < Side.Count; i++)
            {
                var meshPart = mesh.MeshParts[i];
                if (meshPart == null) continue;

                var vertexCount = meshPart.Vertices.Length;
                var indexCount = meshPart.Indices.Length;

                if (vertexCount == 0 || indexCount == 0) continue;

                vertexBuffers[i] = new VertexBuffer(graphicsDevice, typeof(VertexPositionNormalTexture), vertexCount, BufferUsage.WriteOnly);
                vertexBuffers[i].SetData(meshPart.Vertices);

                indexBuffers[i] = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indexCount, BufferUsage.WriteOnly);
                indexBuffers[i].SetData(meshPart.Indices);
            }

            fillTexture = Texture2DHelper.CreateFillTexture(graphicsDevice);
            effect.Texture = fillTexture;
            effect.TextureEnabled = true;

            Matrix.CreateScale(1.001f, out scale);
        }