Code Monkey home page Code Monkey logo

gfx-mesh's Introduction

gfx-mesh

Helper crate for gfx-hal to create and use meshes with vertex semantics.

Vertex semantics

Vertex formats usually has semantics attached to field names. This crate provides traits and types to have semantics explicitly defined on the type level.

Position, Normal, TexCoord etc. are attributes that have unambiguous semantics. Users can define their own attribute types by implementing the Attribute trait.

While the attribute type on its own is a trivial vertex format (with single attribute), complex vertex formats are created by composing attribute types.

The WithAttribute trait allows to get formatting info for individual attributes defined in a vertex format. The Query trait allows to get formatting info for several attributes at once.

VertexFormat queried from vertex formats can be used to build graphics pipelines and bind required vertex buffers from mesh to command buffer.

To define a custom vertex format type, the AsVertexFormat trait must be implemented providing a VertexFormat associated constant.

WithAttribute can be implemented also for all attributes and VertexFormat associated constant in AsVertexFormat can be defined more clearly utilizing WithAttribute implementation. Query is automatically implemented.

Mesh

Mesh is a collection of vertex buffers and optionally an index buffer together with vertex formats of the buffers and index type. Also there is a primitive type specified which defines how vertices form primitives (lines, triangles etc). To create instances of Mesh you need to use MeshBuilder.

  1. Fill MeshBuilder with typed vertex data.
  2. Provide the index data.
  3. Set the primitive type (Triangles list by default).
  4. Call MeshBuilder::build. It uses Factory from gfx-render to create buffers and upload data.

Here is your fresh new Mesh. Or an Error from gfx-render.

To bind vertex buffers to a command buffer use Mesh::bind with a sorted array of VertexFormats (the same that was used to setup the graphics pipeline).

gfx-mesh's People

Contributors

anderejd avatar

Watchers

James Cloos avatar LaiJF avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.