Comments (15)
I've just commited some fixes, take a look at this test case
you will have to create your own vertex type, you can just copy VertexColor1Texture1Custom1 struct, and modify it to your needs.
from sharpgltf.
fyi: wrote little global tool to inspect the custom vertex attributes: https://github.com/bertt/gltf.tooling
from sharpgltf.
Hi
I've checked your model with glTF validator and it gives the same error as SharpGLTF. Chunks must be aligned to 4 bytes length to be valid.
Technically speaking, I should do nothing, as per the glTF specification the model is invalid, and whoever wrote this GLB file should fix his code to write correct glTF files.
After all, we're all aiming to have a healthy glTF ecosystem with tools writing correct files, not an insane ecosystem with readers trying to fix others writers mishaps.
But we live in an imperfect world, and it's not the first time I find malformed glTF files that could probably be loaded, so it's a bit of a compromise.... my thoughts about this is to add an extra argument to bypass all the validation checks after loading a model.
By loading a model without the loading validation checks you would be open to unexpected behaviour all the way through the model parsing, so your code would need to be a lot more defensive when dealing with unchecked models, also, when something goes wrong, it would be difficult to tell if it's been because the model is malformed, or because an incorrect API usage.
Anyway, this feature is way down my priority list right now.
But even if the model didn't have the chunk misalignment, it would not load anyway since CESIUM_RTC is declared as a required extension, and SharpGLTF does not support that extension.
There's a discussion here whether this extension should be officially supported. Right now I'm only sticking to official extensions listed here , but if it's an extension that is commonly used, and not very hard to implement, I would consider adding it.
Btw, I can't add CESIUM_RTC extension unless the extension schema for glTF2 is published somewhere; SharpGLTF uses automatic code generation based of the schemas, so I need the CESIUM_RTC schema for glTF2 to generate the code from it.
from sharpgltf.
In my case I only want to write the extra batch id for each vertice, see more info
https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/TileFormats/Batched3DModel/README.md#binary-gltf
It seems to me the Cesium RTC extension does not cover this topic, I've got the impression its outdated (can only find a 1.0 schema).
Maybe there is a way to create valid glTF's and also add the _BATCHID attribute for each vertice? Or is there another way in glTF to indicate to which model a vertice belongs?
from sharpgltf.
Hmmm... if you want to write cesium compatible glTF files I think you'll need to do a lot more work... and I don't think SharpGLTF could do that out of the box right now.
To begin with, the Cesium_RTC is not supported... I believe that's a show stopper.
Then to write a custom vertex attribute with MeshBuilder, you would need to create your own vertex type (like a VertexPositionNormalBatchId or something like that), which MeshBuilder would accept and it could let you create MeshBuilders in that way.... but when writing the actual glTF, with the current pipeline, the attribute would probably be skipped.
Right now I'm struggling with morph targets support, I don't know how much time it will take.... afterwards I'll look at this issue.
from sharpgltf.
ok thanks, I'm just investigating whats easily possible. In Cesium the models (like buildings) are grouped together in glTF's based on distance (for performance). The batchid is needed so the user can click/highlight an individual building to get more information about it.
from sharpgltf.
I've created an GLB file with another tool (warning contains not valid glTF) which contains the batchid attribute but does not have RTC extension. It's a better example of what I want to be able to read/write.
1.glb.zip
from sharpgltf.
one thing I noticed with this solution: VertexColor1Texture1Custom1 is calling FragmentPreprocessors but that class is inaccessible (internal by default)
from sharpgltf.
one thing I noticed with this solution: VertexColor1Texture1Custom1 is calling FragmentPreprocessors but that class is inaccessible (internal by default)
Ah, yes, that's true...
I could look at it to see if it's worth/useful to make it public...
But for custom attributes, FragmentPreprocessor has not way to tell if the custom values of the structure are fine or not...
So you have to implement your own checks... or simply leave it empty.
from sharpgltf.
a question: ideally I want to generate glb with only vertex attributes POSITION,NORMAL,_CUSTOM_1, the attributes COLOR_0 and TEXCOORD_0 are not needed. Is there a way to do this?
from sharpgltf.
Just create a struct implementing IVertexMaterial with the attributes you need.
public struct VertexCustom1 : IVertexMaterial
{
public VertexCustom1 (Single customId) { CustomId = customId; }
public static implicit operator VertexCustom1(Single customId value)
{
return new VertexCustom1(value);
}
public const string CUSTOMATTRIBUTENAME = "_CUSTOM_1";
[VertexAttribute(CUSTOMATTRIBUTENAME, Schema2.EncodingType.FLOAT, false)]
public Single CustomId;
public int MaxColors => 0;
public int MaxTextCoords => 0;
public void SetColor(int setIndex, Vector4 color) { }
public void SetTexCoord(int setIndex, Vector2 coord) { }
public Vector4 GetColor(int index) { throw new ArgumentOutOfRangeException(nameof(index)); }
public Vector2 GetTexCoord(int index) { throw new ArgumentOutOfRangeException(nameof(index)); }
public void Validate() { }
public object GetCustomAttribute(string attributeName)
{
return attributeName == CUSTOMATTRIBUTENAME ? (Object)CustomId : null;
}
}
from sharpgltf.
great, that works!
from sharpgltf.
Think we can close this issue, adding a custom vertex attribute now works for me. Will there be a nuget alpha-0012 package with this functionality? At the moment I use a custom build package.
from sharpgltf.
Yes, we can close it up.
Creating custom vertex types has always been part of the Toolkit since the introduction of MeshBuilder... although it was not tested properly.
I'm still polishing a few details since I began working with morph targets building, which is one of the itchy issues I was not suporting yet, and also I found some issues that might be bugs and I want to confirm them first.... so expect a new package in about 1 or 2 weeks...
from sharpgltf.
Ok great 👍
from sharpgltf.
Related Issues (20)
- [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
- [BUG] Accessors with sparse storage but without bufferView fail validation HOT 2
- [Feature Request] Only material file HOT 2
- [QUESTION] Is there a more propper way to generate a mesh which contains primitives that have different vertex fragment types? HOT 3
- [QUESTION] Any reason morph targets count is sometimes 0 on a mesh? HOT 6
- Reflection Problems for Trimming HOT 15
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.