| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/vr_shell/vr_controller_model.h" | 5 #include "chrome/browser/android/vr_shell/vr_controller_model.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "chrome/browser/android/vr_shell/gltf_parser.h" | 11 #include "chrome/browser/android/vr_shell/gltf_parser.h" |
| 12 #include "components/component_updater/component_updater_paths.h" | 12 #include "components/component_updater/component_updater_paths.h" |
| 13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 14 #include "third_party/skia/include/core/SkRect.h" | 14 #include "third_party/skia/include/core/SkRect.h" |
| 15 #include "third_party/skia/include/core/SkSurface.h" | 15 #include "third_party/skia/include/core/SkSurface.h" |
| 16 #include "ui/gfx/codec/png_codec.h" | 16 #include "ui/gfx/codec/png_codec.h" |
| 17 | 17 |
| 18 namespace vr_shell { | 18 namespace vr_shell { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 enum { | 22 enum { |
| 23 ELEMENTS_BUFFER_ID = 0, | 23 ELEMENTS_BUFFER_ID = 2, |
| 24 INDICES_BUFFER_ID = 1, | 24 INDICES_BUFFER_ID = 3, |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 constexpr char kPosition[] = "POSITION"; | 27 constexpr char kPosition[] = "POSITION"; |
| 28 constexpr char kTexCoord[] = "TEXCOORD_0"; | 28 constexpr char kTexCoord[] = "TEXCOORD_0"; |
| 29 | 29 |
| 30 // TODO(acondor): Remove these hardcoded paths once VrShell resources | 30 // TODO(acondor): Remove these hardcoded paths once VrShell resources |
| 31 // are delivered through component updater. | 31 // are delivered through component updater. |
| 32 constexpr char const kComponentName[] = "VrShell"; | 32 constexpr char const kComponentName[] = "VrShell"; |
| 33 constexpr char const kDefaultVersion[] = "0"; | 33 constexpr char const kDefaultVersion[] = "0"; |
| 34 | 34 |
| 35 constexpr char const kModelsDirectory[] = "models"; | 35 constexpr char const kModelsDirectory[] = "models"; |
| 36 constexpr char const kModelFilename[] = "controller.gltf"; | 36 constexpr char const kModelFilename[] = "ddcontroller.glb"; |
| 37 constexpr char const kTexturesDirectory[] = "tex"; | 37 constexpr char const kTexturesDirectory[] = "tex"; |
| 38 constexpr char const kBaseTextureFilename[] = "ddcontroller_idle.png"; | 38 constexpr char const kBaseTextureFilename[] = "ddcontroller_idle.png"; |
| 39 constexpr char const* kTexturePatchesFilenames[] = { | 39 constexpr char const* kTexturePatchesFilenames[] = { |
| 40 "", "ddcontroller_touchpad.png", "ddcontroller_app.png", | 40 "", "ddcontroller_touchpad.png", "ddcontroller_app.png", |
| 41 "ddcontroller_system.png", | 41 "ddcontroller_system.png", |
| 42 }; | 42 }; |
| 43 const gfx::Point kPatchesLocations[] = {{}, {5, 5}, {47, 165}, {47, 234}}; | 43 const gfx::Point kPatchesLocations[] = {{}, {5, 5}, {47, 165}, {47, 234}}; |
| 44 | 44 |
| 45 sk_sp<SkImage> LoadPng(const base::FilePath& path) { | 45 sk_sp<SkImage> LoadPng(const base::FilePath& path) { |
| 46 std::string data; | 46 std::string data; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 .Append(kDefaultVersion) | 160 .Append(kDefaultVersion) |
| 161 .Append(kModelsDirectory); | 161 .Append(kModelsDirectory); |
| 162 auto model_path = models_path.Append(kModelFilename); | 162 auto model_path = models_path.Append(kModelFilename); |
| 163 | 163 |
| 164 // No further action if model file is not present | 164 // No further action if model file is not present |
| 165 if (!base::PathExists(model_path)) { | 165 if (!base::PathExists(model_path)) { |
| 166 LOG(WARNING) << "Controller model files not found"; | 166 LOG(WARNING) << "Controller model files not found"; |
| 167 return nullptr; | 167 return nullptr; |
| 168 } | 168 } |
| 169 | 169 |
| 170 GltfParser gltf_parser; | |
| 171 std::vector<std::unique_ptr<gltf::Buffer>> buffers; | 170 std::vector<std::unique_ptr<gltf::Buffer>> buffers; |
| 172 auto asset = gltf_parser.Parse(model_path, &buffers); | 171 |
| 172 std::string model_data; |
| 173 base::ReadFileToString(model_path, &model_data); |
| 174 auto asset = BinaryGltfParser::Parse(base::StringPiece(model_data), &buffers); |
| 173 if (!asset) { | 175 if (!asset) { |
| 174 LOG(ERROR) << "Failed to read controller model"; | 176 LOG(ERROR) << "Failed to read controller model"; |
| 175 return nullptr; | 177 return nullptr; |
| 176 } | 178 } |
| 177 | 179 |
| 178 auto controller_model = | 180 auto controller_model = |
| 179 base::MakeUnique<VrControllerModel>(std::move(asset), std::move(buffers)); | 181 base::MakeUnique<VrControllerModel>(std::move(asset), std::move(buffers)); |
| 180 | 182 |
| 181 auto textures_path = models_path.Append(kTexturesDirectory); | 183 auto textures_path = models_path.Append(kTexturesDirectory); |
| 182 | 184 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 196 LOG(ERROR) << "Failed to read controller texture patch"; | 198 LOG(ERROR) << "Failed to read controller texture patch"; |
| 197 continue; | 199 continue; |
| 198 } | 200 } |
| 199 controller_model->SetTexturePatch(i, patch_image); | 201 controller_model->SetTexturePatch(i, patch_image); |
| 200 } | 202 } |
| 201 | 203 |
| 202 return controller_model; | 204 return controller_model; |
| 203 } | 205 } |
| 204 | 206 |
| 205 } // namespace vr_shell | 207 } // namespace vr_shell |
| OLD | NEW |