Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for vrm. #199

Closed
wants to merge 8 commits into from
Closed

Support for vrm. #199

wants to merge 8 commits into from

Conversation

fire
Copy link

@fire fire commented Dec 5, 2020

Use a vrm file extension to trigger processing.

See #198 for test cases and examples.

The command to test is now:

./gltfpack -i "Miraikomachi.vrm" -o "Miraikomachi Opt.VRM"

@fire fire force-pushed the vrm branch 2 times, most recently from 9c101cd to a5368cd Compare December 5, 2020 05:39
@fire
Copy link
Author

fire commented Dec 5, 2020

How do I read those errors in the cicd?

Edited:

What are the step to recreate the error?

@fire
Copy link
Author

fire commented Dec 7, 2020

@zeux I wasn't able to recreate the errors. Do you know how that test works?

@zeux
Copy link
Owner

zeux commented Dec 7, 2020

The test validates that packing any model from glTF-Sample-Models repository produces a valid glTF file as validated by glTF-Validator. glTF-Sample-Models/2.0/Cameras/glTF/Cameras.gltf is the specific file on which the process fails with this change, you should be able to get the source file from glTF-Sample-Models Khronos repository.

@fire fire force-pushed the vrm branch 3 times, most recently from 83132ed to c24d873 Compare December 8, 2020 02:54
@fire
Copy link
Author

fire commented Dec 8, 2020

Green!

Use a vrm file extension to trigger processing.
@fire fire marked this pull request as ready for review December 8, 2020 03:28
@@ -165,6 +175,8 @@ static void parseMeshesGltf(cgltf_data* data, std::vector<Mesh>& meshes, std::ve
meshes.push_back(Mesh());
Mesh& result = meshes.back();

result.name = mesh.name;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a problem with variable lifetime

@@ -488,6 +498,11 @@ static void process(cgltf_data* data, const char* input_path, const char* output
append(json_meshes, ",\"indices\":");
append(json_meshes, index_accr);
}
if (settings.keep_extras && !prim.extras.empty())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? AFAICT the only "extras" node in the .VRM file from the issue is on the mesh, not on primitive, and that contains targetNames which should already be preserved by gltfpack.

for (size_t i = 0; i < data->data_extensions_count; ++i)
{
cgltf_extension extension = data->data_extensions[i];
if (!extension.name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This & above & below can be replaced with if (strcmp(extension.name, "VRM") == 0) (extension.name is guaranteed to be non-null)

@@ -676,6 +722,8 @@ static void process(cgltf_data* data, const char* input_path, const char* output
writeArray(json, "meshes", json_meshes);
writeArray(json, "skins", json_skins);
writeArray(json, "animations", json_animations);
comma(json);
append(json, json_extensions);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always emit "extensions" and also causes a conflict with top-level KHR_lights_punctual extension since there's now going to be two extension blocks for files that use that.

Instead what should happen is:

  • json_extensions should be initially empty
  • json_lights should be appended to it, if necessary
  • VRM data should be appended to it, if necessary
  • if json_extensions isn't empty when forming the final JSON blob, we should write out "extensions":{ followed by json_extensions contents followed by }

append(json_extensions, "\"");
append(json_extensions, extension.name);
append(json_extensions, "\":");
append(json_extensions, extension.data);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use appendJson to minify the output

@@ -790,8 +838,12 @@ int gltfpack(const char* input, const char* output, const char* report, Settings

const char* iext = strrchr(input, '.');
const char* oext = output ? strrchr(output, '.') : NULL;

if (iext && (strcmp(iext, ".vrm") == 0 || strcmp(iext, ".VRM") == 0)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use clang-format on this code, as this bracing style is inconsistent with the coding guidelines, see https://github.com/zeux/meshoptimizer/blob/master/CONTRIBUTING.md

if (oext && (strcmp(oext, ".vrm") == 0 || strcmp(oext, ".VRM") == 0))
{
settings.vrm = true;
settings.keep_extras = true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to omit these, esp. quantize but preferably others. It's not clear to me why these need to be present, and if a user wants to apply these optimizations to a VRM file there's not going to be a way to do this without adding more kinds of command-line options, if vrm extension acts as an override.

@@ -896,7 +958,7 @@ int gltfpack(const char* input, const char* output, const char* report, Settings
return 4;
}
}
else if (oext && (strcmp(oext, ".glb") == 0 || strcmp(oext, ".GLB") == 0))
else if (oext && (strcmp(oext, ".vrm") == 0 || strcmp(oext, ".VRM") == 0 || strcmp(oext, ".glb") == 0 || strcmp(oext, ".GLB") == 0))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be added to the condition above that sets texture_embed? Unclear what the de-facto rules are for VRM files, e.g. whether they are supposed to keep textures separately or not.

gltf/gltfpack.h Outdated
@@ -39,6 +39,7 @@ struct Transform

struct Mesh
{
const char* name;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string might be better.

gltf/write.cpp Outdated
@@ -739,6 +739,14 @@ static std::string decodeUri(const char* uri)

void writeImage(std::string& json, std::vector<BufferView>& views, const cgltf_image& image, const ImageInfo& info, size_t index, const char* input_path, const char* output_path, const Settings& settings)
{
if (image.name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is preserving the name of the image object necessary? It doesn't carry semantical meaning, and gltfpack right now only preserves names for objects that are likely to be used by-name externally, specifically nodes, materials and animations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to check if this is required by the internal material definition called MTOON.

gltf/write.cpp Outdated
@@ -1320,7 +1328,8 @@ void writeAnimation(std::string& json, std::vector<BufferView>& views, std::stri

comma(json_samplers);
append(json_samplers, "{\"input\":");
append(json_samplers, range ? range_accr : track.constant ? pose_accr : time_accr);
append(json_samplers, range ? range_accr : track.constant ? pose_accr
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change intended?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not intended.

@fire
Copy link
Author

fire commented Dec 9, 2020

Thank you for the review. I will be delayed until the weekend to submit the changes.

@fire fire marked this pull request as draft December 10, 2020 02:16
@fire
Copy link
Author

fire commented Dec 29, 2020

I slept thinking about this optimization, because Godot Engine added autolod, I don't have a requirement for this. This VRM pr is salvageable.

@fire fire closed this Dec 29, 2020
@arpu
Copy link

arpu commented Jan 14, 2021

still interessded in vrm optimation

@fire can you point me to how Godot Engine autolod works?

@fire
Copy link
Author

fire commented Jan 14, 2021

  1. Godot loads gltf2
  2. For every imported mesh run mesh optimizer with the error returned and create lod levels. Loop until stuck or index is 10. Determine metric to display lod level.
  3. (Would like tesselate first and the decimate second together option) because simplify gets stuck
  4. Implement vrm

I believe that mesh optimizer works under wasm, so you can follow the same flow.

The reason for this flow is that it doesn't make sense to modify the original gltf if the goal is to convert to the internal engine format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants