|
|
@@ -1,90 +1,40 @@
|
|
|
-# Mesh Building
|
|
|
+# glTF2 Sharp
|
|
|
|
|
|
-One of key aspects of building a GPU optimized gltf model is to ensure that all
|
|
|
-meshes in the model share as few vertex and index buffers as possible; in this
|
|
|
-way, the number of state changes required to render a particular model is
|
|
|
-reduced to a minimum.
|
|
|
+This is my personal attempt to create a c# library to parse and also build
|
|
|
+Khronos glTF2 files.
|
|
|
|
|
|
-Given the hierarchical nature of gltf, it is very difficult to populate the meshes
|
|
|
-of a gltf model one by one, since we would need to "grow" the target buffers and
|
|
|
-buffer views, which is far from trivial.
|
|
|
+#### Development
|
|
|
|
|
|
-So, in order to solve the problem, we could have an external structure that could
|
|
|
-prepare all the stuff required to fill the data; example:
|
|
|
+The bulk of the code is generated from the schema using the glTF2Sharp.CodeGen tools.
|
|
|
|
|
|
-```c#
|
|
|
-class VertexColumn
|
|
|
-{
|
|
|
- private string _Attribute;
|
|
|
- private dimensions _Dimensions;
|
|
|
- private readonly List<Vector4> _Rows = new List<Vector4>();
|
|
|
-}
|
|
|
-
|
|
|
-class VertexView
|
|
|
-{
|
|
|
-public VertexView(IEnumerable<VertexColumn> columns)
|
|
|
-{
|
|
|
-fill columns
|
|
|
-}
|
|
|
-
|
|
|
-private VertexColumn _Position;
|
|
|
-private VertexColumn _Normals;
|
|
|
-
|
|
|
-public int UseRow(params Vector4[] row);
|
|
|
-
|
|
|
-public int UseRow(in SomeVertexStruct vertex);
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-class Indices
|
|
|
-{
|
|
|
- private readonly List<int> _Rows = new List<int();
|
|
|
- private primitiveType;
|
|
|
-}
|
|
|
-
|
|
|
-class MeshPrimitive
|
|
|
-{
|
|
|
- private VertexBufferCreationMode _VbCreationMode; // split columns, interleaved, etc
|
|
|
- private List<VertexColumn> _Columns = new List<VertexColumn>();
|
|
|
- private Indices _Indices;
|
|
|
- private int _MaterialIndex;
|
|
|
-
|
|
|
- // morphing? how
|
|
|
-}
|
|
|
+All generated classes are declared by default as non public, and its fields private.
|
|
|
+The public API functionality is provided with hand coded partial classes. Since this
|
|
|
+is a work in progress, not all the features might be publicly available yet.
|
|
|
|
|
|
-class Mesh
|
|
|
-{
|
|
|
-private string Name;
|
|
|
-private List<MeshPrimitive> _Primitives;
|
|
|
-private List<float> _MorphWeights;
|
|
|
+Internally, the ModelRoot object store almost all the model elements in plain lists,
|
|
|
+and cross referencing is done by integer indices. The public API implentation tries
|
|
|
+to simplify model access by resolving the references and offering a more C# friendly
|
|
|
+API.
|
|
|
|
|
|
-private List<Schema2.Node> _TargetNodes; // created mesh will be assigned to these
|
|
|
-}
|
|
|
+#### Extensions
|
|
|
|
|
|
+Extensions support is experimental, and at best it will be implemented on extensions that
|
|
|
+can be included seamlessly.
|
|
|
|
|
|
-class VertexEncoding
|
|
|
-{
|
|
|
-Encoding;
|
|
|
-bool normalized;
|
|
|
-}
|
|
|
-
|
|
|
-class MeshCollection
|
|
|
-{
|
|
|
-private Dicionaty<string,VertexEncoding> _VertexEncoding();
|
|
|
-
|
|
|
-private readonly List<Mesh> _Meshes;
|
|
|
-
|
|
|
-
|
|
|
-public IEnumerable<Schema2.Mesh> Commit(Schema2.ModelRoot root);
|
|
|
-}
|
|
|
+Then, there's extensions like Draco, which relies on [Google's DRACO](https://github.com/google/draco)
|
|
|
+library which is a highly optimized C++ Library.
|
|
|
|
|
|
+#### Examples
|
|
|
|
|
|
+Many examples can be found in the Tests project, but in essence, loading a model
|
|
|
+is as easy as this:
|
|
|
|
|
|
+```c#
|
|
|
+var model = Schema2.ModelRoot.Load("model.gltf");
|
|
|
```
|
|
|
|
|
|
+#### Alternative glTF2 c# libraries
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+[Khronos Group glTF-CSharp-Loader](https://github.com/KhronosGroup/glTF-CSharp-Loader)
|
|
|
+[Khronos Group UnityGLTF](https://github.com/KhronosGroup/UnityGLTF)
|
|
|
+[glTF viewer using SharpDX](https://github.com/ousttrue/DXGLTF)
|