Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/vr_shell/gltf_parser.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "base/values.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace vr_shell { | |
| 14 | |
| 15 TEST(GltfParser, Parse) { | |
| 16 base::DictionaryValue asset; | |
|
mthiesse
2017/03/21 20:24:38
I think rather than constructing a dictionary that
cjgrant
2017/03/21 20:38:02
I agree. The JSON would be easier to read, and ev
acondor_
2017/03/22 16:25:29
Done.
| |
| 17 asset.SetString("asset.version", "1.0"); | |
| 18 | |
| 19 auto buffers = base::MakeUnique<base::DictionaryValue>(); | |
| 20 auto buffer_dict = base::MakeUnique<base::DictionaryValue>(); | |
| 21 buffer_dict->SetString( | |
| 22 "uri", "data:application/octet-stream;base64,SEVMTE8gV09STEQh"); | |
| 23 buffer_dict->SetInteger("byteLength", 12); | |
| 24 buffers->Set("dummyBuffer", std::move(buffer_dict)); | |
| 25 asset.Set("buffers", std::move(buffers)); | |
| 26 | |
| 27 auto buffer_views = base::MakeUnique<base::DictionaryValue>(); | |
| 28 auto buffer_view_dict = base::MakeUnique<base::DictionaryValue>(); | |
| 29 buffer_view_dict->SetString("buffer", "dummyBuffer"); | |
| 30 buffer_view_dict->SetInteger("byteLength", 20); | |
| 31 buffer_view_dict->SetInteger("byteOffset", 10); | |
| 32 buffer_view_dict->SetInteger("target", 1); | |
| 33 buffer_views->Set("dummyBufferView", std::move(buffer_view_dict)); | |
| 34 asset.Set("bufferViews", std::move(buffer_views)); | |
| 35 | |
| 36 auto accessors = base::MakeUnique<base::DictionaryValue>(); | |
| 37 auto accessor_dict = base::MakeUnique<base::DictionaryValue>(); | |
| 38 accessor_dict->SetString("bufferView", "dummyBufferView"); | |
| 39 accessor_dict->SetInteger("byteOffset", 10); | |
| 40 accessor_dict->SetInteger("byteStride", 16); | |
| 41 accessor_dict->SetInteger("componentType", 5); | |
| 42 accessor_dict->SetInteger("count", 24); | |
| 43 accessor_dict->SetString("type", "VEC3"); | |
| 44 accessors->Set("dummyAccessor", std::move(accessor_dict)); | |
| 45 asset.Set("accessors", std::move(accessors)); | |
| 46 | |
| 47 auto meshes = base::MakeUnique<base::DictionaryValue>(); | |
| 48 auto mesh_dict = base::MakeUnique<base::DictionaryValue>(); | |
| 49 auto primitive_list = base::MakeUnique<base::ListValue>(); | |
| 50 auto primitive_dict = base::MakeUnique<base::DictionaryValue>(); | |
| 51 auto attributes_dict = base::MakeUnique<base::DictionaryValue>(); | |
| 52 attributes_dict->SetString("POSITION", "dummyAccessor"); | |
| 53 primitive_dict->Set("attributes", std::move(attributes_dict)); | |
| 54 primitive_dict->SetString("indices", "dummyAccessor"); | |
| 55 primitive_dict->SetInteger("mode", 4); | |
| 56 primitive_list->Append(std::move(primitive_dict)); | |
| 57 mesh_dict->Set("primitives", std::move(primitive_list)); | |
| 58 meshes->Set("dummyMesh", std::move(mesh_dict)); | |
| 59 asset.Set("meshes", std::move(meshes)); | |
| 60 | |
| 61 auto nodes = base::MakeUnique<base::DictionaryValue>(); | |
| 62 auto node_dict = base::MakeUnique<base::DictionaryValue>(); | |
| 63 auto children_list = base::MakeUnique<base::ListValue>(); | |
| 64 children_list->AppendString("dummyNode2"); | |
| 65 node_dict->Set("children", std::move(children_list)); | |
| 66 nodes->Set("dummyNode1", std::move(node_dict)); | |
| 67 node_dict = base::MakeUnique<base::DictionaryValue>(); | |
| 68 auto mesh_list = base::MakeUnique<base::ListValue>(); | |
| 69 mesh_list->AppendString("dummyMesh"); | |
| 70 node_dict->Set("meshes", std::move(mesh_list)); | |
| 71 nodes->Set("dummyNode2", std::move(node_dict)); | |
| 72 asset.Set("nodes", std::move(nodes)); | |
| 73 | |
| 74 auto scenes = base::MakeUnique<base::DictionaryValue>(); | |
| 75 auto scene_dict = base::MakeUnique<base::DictionaryValue>(); | |
| 76 auto node_list = base::MakeUnique<base::ListValue>(); | |
| 77 node_list->AppendString("dummyNode1"); | |
| 78 scene_dict->Set("nodes", std::move(node_list)); | |
| 79 scenes->Set("dummyScene", std::move(scene_dict)); | |
| 80 asset.Set("scenes", std::move(scenes)); | |
| 81 | |
| 82 asset.SetString("scene", "dummyScene"); | |
| 83 | |
| 84 GltfParser parser; | |
| 85 auto gltf_model = parser.Parse(asset); | |
| 86 EXPECT_TRUE(gltf_model); | |
| 87 | |
| 88 const gltf::Buffer* buffer = gltf_model->GetBuffer(0); | |
| 89 EXPECT_NE(nullptr, buffer); | |
| 90 EXPECT_EQ(nullptr, gltf_model->GetBuffer(1)); | |
| 91 EXPECT_EQ("HELLO WORLD!", *buffer); | |
| 92 EXPECT_EQ(12u, buffer->length()); | |
| 93 | |
| 94 const gltf::BufferView* buffer_view = gltf_model->GetBufferView(0); | |
| 95 EXPECT_NE(nullptr, buffer_view); | |
| 96 EXPECT_EQ(nullptr, gltf_model->GetBufferView(1)); | |
| 97 EXPECT_EQ(buffer, buffer_view->buffer); | |
| 98 EXPECT_EQ(20, buffer_view->byte_length); | |
| 99 EXPECT_EQ(10, buffer_view->byte_offset); | |
| 100 EXPECT_EQ(1, buffer_view->target); | |
| 101 | |
| 102 const gltf::Accessor* accessor = gltf_model->GetAccessor(0); | |
| 103 EXPECT_NE(nullptr, accessor); | |
| 104 EXPECT_EQ(nullptr, gltf_model->GetAccessor(1)); | |
| 105 EXPECT_EQ(buffer_view, accessor->buffer_view); | |
| 106 EXPECT_EQ(10, accessor->byte_offset); | |
| 107 EXPECT_EQ(16, accessor->byte_stride); | |
| 108 EXPECT_EQ(5, accessor->component_type); | |
| 109 EXPECT_EQ(24, accessor->count); | |
| 110 EXPECT_EQ(gltf::VEC3, accessor->type); | |
| 111 | |
| 112 const gltf::Mesh* mesh = gltf_model->GetMesh(0); | |
| 113 EXPECT_NE(nullptr, mesh); | |
| 114 EXPECT_EQ(nullptr, gltf_model->GetAccessor(1)); | |
| 115 EXPECT_EQ(1u, mesh->primitives.size()); | |
| 116 gltf::Mesh::Primitive* primitive = mesh->primitives[0].get(); | |
| 117 EXPECT_EQ(1u, primitive->attributes.size()); | |
| 118 auto attr_it = primitive->attributes.begin(); | |
| 119 EXPECT_EQ("POSITION", attr_it->first); | |
| 120 EXPECT_EQ(accessor, attr_it->second); | |
| 121 EXPECT_EQ(accessor, primitive->indices); | |
| 122 EXPECT_EQ(4, primitive->mode); | |
| 123 | |
| 124 const gltf::Node* node_1 = gltf_model->GetNode(0); | |
| 125 const gltf::Node* node_2 = gltf_model->GetNode(1); | |
| 126 EXPECT_NE(nullptr, node_1); | |
| 127 EXPECT_NE(nullptr, node_2); | |
| 128 EXPECT_EQ(nullptr, gltf_model->GetNode(2)); | |
| 129 EXPECT_EQ(1u, node_1->children.size()); | |
| 130 EXPECT_EQ(0u, node_1->meshes.size()); | |
| 131 EXPECT_EQ(node_2, node_1->children[0]); | |
| 132 EXPECT_EQ(0u, node_2->children.size()); | |
| 133 EXPECT_EQ(1u, node_2->meshes.size()); | |
| 134 EXPECT_EQ(mesh, node_2->meshes[0]); | |
| 135 | |
| 136 const gltf::Scene* scene = gltf_model->GetScene(0); | |
| 137 EXPECT_NE(nullptr, scene); | |
| 138 EXPECT_EQ(nullptr, gltf_model->GetNode(2)); | |
| 139 EXPECT_EQ(1u, scene->nodes.size()); | |
| 140 EXPECT_EQ(node_1, scene->nodes[0]); | |
| 141 | |
| 142 EXPECT_EQ(scene, gltf_model->GetMainScene()); | |
| 143 } | |
| 144 | |
| 145 } // namespace vr_shell | |
| OLD | NEW |