Comments (4)
I think what you're looking for is the MeshBuilder<> class, which is included in the Toolkit package, in SharpGLTF.Geometry namespace.
This is a minimal example of how to create a triangle scene:
using SharpGLTF.Scenes;
using SharpGLTF.Geometry;
using SharpGLTF.Geometry.VertexTypes;
using SharpGLTF.Materials;
...
// Create a mesh with a triangle.
var mesh = new MeshBuilder<VertexPosition>();
var prim = mesh.UsePrimitive(MaterialBuilder.CreateDefault());
prim.AddTriangle
(
new VertexPosition(0, -1, 0),
new VertexPosition(1, 0, 0),
new VertexPosition(0, 1, 0)
);
// Create a scene and add the mesh:
var scene = new SceneBuilder();
scene.AddRigidMesh(mesh, Matrix4x4.Identity);
// save it to GLB:
scene.ToGltf2().Save("scene.glb");
let me know if this is what you're looking for, or you need something different.
from sharpgltf.
Whoa, that's pretty much it! I didn't know this was possible, thank you.
Is there a way to do this if I have UV coordinates for the vertices and/or vertex colors?
from sharpgltf.
yes, MeshBuilder<> uses predefined vertex fragment structures, so you can do this:
new MeshBuilder<VertexPositionNormal, VertexColor1Texture1>();
The MeshBuilder API is more or less explained here , although the documentation is a bit old.
from sharpgltf.
Excellent, thank you! I'll close this.
from sharpgltf.
Related Issues (20)
- How to Load glb from stream? HOT 5
- Armature being exported improperly HOT 6
- SharpGLTF.Validation.LinkException: Extensions: KHR_draco_mesh_compressionModel ? HOT 1
- Release version of SharpGLTF nuget HOT 4
- Missing lines HOT 5
- [QUESTION] HOT 1
- [Question] How to create "Stop Motion Animation" HOT 2
- [Feature Request] Mesh Smoothing HOT 1
- Question: How best to split a model, based on `KHRMaterialVariants`? HOT 2
- When compiling with AOT, I encountered a problem HOT 2
- Should Ktx2Header length check be changed? HOT 1
- [QUESTION] How to properly access GLTF mesh data for GL use HOT 2
- [QUESTION] HOT 1
- [Question] MESH_PRIMITIVE_TOO_FEW_TEXCOORDS HOT 6
- Discord server HOT 1
- Parenting Assumption in `Skin.BindJoints()` and `Skin._FindCommonAncestor()` HOT 1
- [BUG] While loading a GLTF file, an error occurs in the MemoryAccessor class, preventing the loading process. HOT 6
- [Feature / Help Request] Sharing animation sampler input HOT 2
- [BUG] when merging meshes with buffers exceeding the maximum capacity HOT 10
- [QUESTION] Could you please help me with fixing the model viewer rendering issue in the code? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharpgltf.