Code Monkey home page Code Monkey logo

Comments (8)

syoyo avatar syoyo commented on May 29, 2024

Thank you for using tinygltf and the proposal!

Validating the loaded model is important, but at the moment I have no enough dev resource for data validation so the contribution is welcome!

Sorry for late response. For some reason, there is no e-mail notification so I've missed this issue for a week.

Option 3 or 4 looks good for me. The code would be something like this:

#include "tinygltf.h"
#include "tinygltf-validator.h" // tinygltf_validator::Validator

tinygltf::Model model = ...;

tinygltf_validator::Validator validator;

std::string err;
bool ret = validator.Validate(model, &err);
if (!err.empty()) {
  std::cerr << err << std::endl;
}
...

from tinygltf.

AurL avatar AurL commented on May 29, 2024

Good point @brycehutchings, and the issues you mention are already well detected by the official glTF validator: https://github.com/KhronosGroup/glTF-Validator, you can have an overview of the detected issues here.

To be honest, I'm wondering if validation should be part of tinygltf, I guess this responsibility should be given to a dedicated tool. We are using it for glTF import and export on Sketchfab but our validation is different on each process. Tinygltf performs a validation for glTF import/processing, and for export we validate output files with the official glTF validator: https://github.com/KhronosGroup/glTF-Validator.
The glTF-Validator is updated very quickly after any change in the specification, and it's a very useful tool to assert that the glTF you read or write is sane.

So I would say 4) with the official and up-to-date glTF-Validator.

@syoyo what's your opinion on this ?

from tinygltf.

syoyo avatar syoyo commented on May 29, 2024

Thank you for the comment, @AurL !

So I would say 4) with the official and up-to-date glTF-Validator.

It looks gTF-Validator is now very mature, so I would also like to go with 4) + use gltf-Validator for a while.

I have a plan to rewrite tinygltf parser/writer using a code generator from JSON spec #10 which can also be used for creating validator program especially suited for TinyGLTF as a derivative(approach 3), but I cannot promise when I could finish implementing #10 ...

from tinygltf.

brycehutchings avatar brycehutchings commented on May 29, 2024

Absolutely glTF-Validator should be used to validate glTF files when possible. My thinking was more about consuming glTF files from unknown sources, potentially malicious sources. For example, I made a glTF file with circular node references. When I upload and view it on BablyonJS's Sandbox, I get the error "Unable to load from 'Cube.gltf': Maximum call stack size exceeded". To me, it would be nice to have glTF parsers catch issues like this, which would remove the burden of doing checks at a later stage. glTF-Validator can't be used in many cases at runtime, especially for native applications. To me this falls into a set of functionality that TinyGLTF doesn't expose but I assume many people need, like parsing accessors into more structured data (e.g. primitive POSITION attribute into vector of Vec3). These are both kinds of optional things which could be built on top of TinyGLTF and consumers could find useful.

from tinygltf.

syoyo avatar syoyo commented on May 29, 2024

I made a glTF file with circular node references

For detecting circular node references, we could implement DFA(Data Flow Analysis) e.g. using topological sort.

Maximum call stack size exceeded

I guess this is an error in JavaScript runtime layer, not in JavaScript program itself. In C++, it is difficult to detect out-of-memory, stack-overflow, etc in pure C++ programming level without specialized compiler options and runtime library(e.g. AddressSanitizer, MemorySanitizer, VC's CRT stack protection mechanism).

Another way is to introduce secure tiny VM layer e.g. using duktape https://github.com/svaarala/duktape . This kind of approach would be better when we load unknown, malcious glTF model in Mobile environment(Android, iOS) but may be a bit overkill for TinyGLTF library...

from tinygltf.

syoyo avatar syoyo commented on May 29, 2024

https://github.com/syoyo/tinygltf/tree/validator/examples/validator

I have created validator example using https://github.com/pboettch/json-schema-validator in validator branch.

Currently it only tests the syntax of glTF, but it would be a good starting point of the validation of glTF files in a C++ program.

from tinygltf.

syoyo avatar syoyo commented on May 29, 2024

And now validator has been merged into devel

from tinygltf.

syoyo avatar syoyo commented on May 29, 2024

devel is now master.

from tinygltf.

Related Issues (20)

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.