Code Monkey home page Code Monkey logo

Comments (14)

syoyo avatar syoyo commented on May 30, 2024

There is a validator example using json-schema-validator https://github.com/syoyo/tinygltf/tree/master/examples/validator , so you can run it as a postprocess after serialization or in an unit tester.
(Or you could use python script if you don't need to stick with C++11)

Alternatively, I imagine the json parser implements the equals operator, so perhaps we could refactor to make use of that?

Do you mean you'd like to compare input(or serialized) glTF and glTF schema with == operator?

It could be possible and rather easy, but in such a case we need to include/prepare glTF schema files in some way(stringify and embed glTF schema files into .h are one possible solution)

from tinygltf.

Selmar avatar Selmar commented on May 30, 2024

In my case I really want to validate the contents of the files actually, e.g. missing parameters that exist in one but not the other, or mismatching values due to forgetting to serialize something. I'm not too worried about the schema, because if the format is not correct that will either result in a crash or show itself otherwise (e.g. through missing parameters or indeed through any other validation methods we use).

from tinygltf.

Selmar avatar Selmar commented on May 30, 2024

I already implemented the == operator locally, so the question right now is really just whether you want this functionality in the header or not.

Of course I still need to actually test the serialization.

from tinygltf.

syoyo avatar syoyo commented on May 30, 2024

I already implemented the == operator locally

Good! Is this feature only requires current tinygltf dependency(i.e. json.hpp), if so PR is appreciated.

It would also be nice if we could have out-of-bounds check for integer indices(node, texture, target, etc) which cannot be validated using JSON schema.

from tinygltf.

Selmar avatar Selmar commented on May 30, 2024

Do you prefer the operator==() declaration and/or implementation inside or outside of the class definition?

class ClassName
{
  bool operator==(const ClassName& other); // ... declaration
}
// ... implementation
class ClassName
{
  bool operator==(const ClassName& other)
  {
    // ... implementation with declaration
  }
}
class ClassName;
bool operator==(const ClassName& one, const ClassName& other); // ... declaration
...
class ClassName
{
}
...
bool operator==(const ClassName& one, const ClassName& other)
{
  // ... implementation
}

from tinygltf.

syoyo avatar syoyo commented on May 30, 2024

I think 3 is best since it has less dependency than 1
We cannot use approach 2 when the amount of implementation of == become large.

from tinygltf.

Selmar avatar Selmar commented on May 30, 2024

An advantage of 1 is maybe that you'll be reminded to change the operator== if you change the class?

from tinygltf.

syoyo avatar syoyo commented on May 30, 2024

An advantage of 1 is maybe that you'll be reminded to change the operator== if you change the class?

I see. PR with either 1 or 3 style is appreciated.

from tinygltf.

Selmar avatar Selmar commented on May 30, 2024

It all works and now I'm running into missing serialization; e.g. accessor.name is not serialized

Is it okay if I fix all serialization issues I encounter and make a combined pull request?

from tinygltf.

Selmar avatar Selmar commented on May 30, 2024

There are a few issues/concerns, not necessarily a problem:

  • Looking at the code, loading embedded buffers seems to take up more memory/cpu, which can be significant for large models. The embedded data is completely stored in the buffer.uri property and then duplicated in the buffer.data property, but for external buffers it's only loaded into buffer.data directly.
  • Comparing pre-serialization and post-serialization model data will not work for the buffer property and has to be handled separately if the user wants to verify it, because currently the buffer.uri property is coded to copy the gltf file name and replace the extension instead of keeping the previous buffer uri.
  • Every buffer is saved with the same filename, which should either overwrite the previously written buffer or generate an exception.
  • Comparing pre-serialization and post-serialization model data will not work for neither buffers nor images if they are embedded, because for obvious reasons the uri changes. This has to be handled separately by the user.

from tinygltf.

Selmar avatar Selmar commented on May 30, 2024

Of course the equality comparison for floats and doubles won't work; I'll have to add specific functions for those using some epsilon. This is okay?

Some of the variables are currently floats, like PerspectiveCamera::aspectRatio. Change to double?

from tinygltf.

syoyo avatar syoyo commented on May 30, 2024

Of course the equality comparison for floats and doubles won't work; I'll have to add specific functions for those using some epsilon. This is okay?

Yes. You may be interested in floating point comparison technique used in Catch2:

https://github.com/catchorg/Catch2/blob/master/docs/assertions.md#floating-point-comparisons

Some of the variables are currently floats, like PerspectiveCamera::aspectRatio. Change to double?

I think there won't be precision problem for variables in Camera struct, but rewriting it to double type is appreciated for keeping consistency with other variables(e.g. Node::rotation)

For other comments, I will evaluate it(pr comment/review it in github PR thread) with given PR.

from tinygltf.

Selmar avatar Selmar commented on May 30, 2024

Closing, as using the equals operator works fine for us.

from tinygltf.

syoyo avatar syoyo commented on May 30, 2024

Thank you for PR!

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.