mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1418 lines
48 KiB
1418 lines
48 KiB
|
8 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
6 years ago
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
|
||
|
3 years ago
|
2020, 2021, 2022, 2023 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
8 years ago
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
|
*/
|
||
|
|
|
||
|
3 years ago
|
/* In order to have the CORRADE_PLUGIN_REGISTER() macro not a no-op. Doesn't
|
||
|
|
affect anything else. */
|
||
|
|
#define CORRADE_STATIC_PLUGIN
|
||
|
|
|
||
|
8 years ago
|
#include <unordered_map>
|
||
|
5 years ago
|
#include <Corrade/Containers/ArrayTuple.h>
|
||
|
7 years ago
|
#include <Corrade/Containers/Optional.h>
|
||
|
3 years ago
|
#include <Corrade/Containers/StringIterable.h>
|
||
|
4 years ago
|
#include <Corrade/Containers/StringStl.h> /** @todo remove once file callbacks are <string>-free */
|
||
|
5 years ago
|
#include <Corrade/Containers/Pair.h>
|
||
|
5 years ago
|
#include <Corrade/Utility/Algorithms.h>
|
||
|
5 years ago
|
#include <Corrade/Utility/DebugStl.h>
|
||
|
4 years ago
|
#include <Corrade/Utility/Path.h>
|
||
|
7 years ago
|
#include <Corrade/Utility/Resource.h>
|
||
|
8 years ago
|
|
||
|
7 years ago
|
#include "Magnum/FileCallback.h"
|
||
|
5 years ago
|
#include "Magnum/Image.h"
|
||
|
7 years ago
|
#include "Magnum/ImageView.h"
|
||
|
7 years ago
|
#include "Magnum/Mesh.h"
|
||
|
8 years ago
|
#include "Magnum/PixelFormat.h"
|
||
|
8 years ago
|
#include "Magnum/Animation/Player.h"
|
||
|
6 years ago
|
#include "Magnum/Math/Color.h"
|
||
|
6 years ago
|
#include "Magnum/Math/Swizzle.h"
|
||
|
|
#include "Magnum/MeshTools/Interleave.h"
|
||
|
4 years ago
|
#include "Magnum/MeshTools/RemoveDuplicates.h"
|
||
|
8 years ago
|
#include "Magnum/MeshTools/Transform.h"
|
||
|
5 years ago
|
#include "Magnum/Trade/AbstractImageConverter.h"
|
||
|
8 years ago
|
#include "Magnum/Trade/AbstractImporter.h"
|
||
|
5 years ago
|
#include "Magnum/Trade/AbstractSceneConverter.h"
|
||
|
8 years ago
|
#include "Magnum/Trade/AnimationData.h"
|
||
|
8 years ago
|
#include "Magnum/Trade/ImageData.h"
|
||
|
6 years ago
|
#include "Magnum/Trade/LightData.h"
|
||
|
6 years ago
|
#include "Magnum/Trade/MaterialData.h"
|
||
|
7 years ago
|
#include "Magnum/Trade/MeshData.h"
|
||
|
6 years ago
|
#include "Magnum/Trade/PbrClearCoatMaterialData.h"
|
||
|
|
#include "Magnum/Trade/PbrSpecularGlossinessMaterialData.h"
|
||
|
|
#include "Magnum/Trade/PbrMetallicRoughnessMaterialData.h"
|
||
|
8 years ago
|
#include "Magnum/Trade/PhongMaterialData.h"
|
||
|
5 years ago
|
#include "Magnum/Trade/SceneData.h"
|
||
|
|
#include "Magnum/SceneGraph/Drawable.h"
|
||
|
|
#include "Magnum/SceneGraph/Scene.h"
|
||
|
|
#include "Magnum/SceneGraph/Object.h"
|
||
|
|
#include "Magnum/SceneGraph/MatrixTransformation3D.h"
|
||
|
8 years ago
|
#ifdef MAGNUM_TARGET_GL
|
||
|
|
#include "Magnum/GL/Texture.h"
|
||
|
6 years ago
|
#include "Magnum/GL/TextureFormat.h"
|
||
|
7 years ago
|
#include "Magnum/GL/Mesh.h"
|
||
|
6 years ago
|
#include "Magnum/MeshTools/Compile.h"
|
||
|
5 years ago
|
#include "Magnum/Shaders/PhongGL.h"
|
||
|
8 years ago
|
#endif
|
||
|
6 years ago
|
#ifdef MAGNUM_TARGET_VK
|
||
|
|
#include "Magnum/Vk/Vulkan.h"
|
||
|
|
#endif
|
||
|
8 years ago
|
|
||
|
6 years ago
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
|
#define _MAGNUM_NO_DEPRECATED_MESHDATA /* So it doesn't yell here */
|
||
|
5 years ago
|
#define _MAGNUM_NO_DEPRECATED_OBJECTDATA /* So it doesn't yell here */
|
||
|
6 years ago
|
|
||
|
|
#include "Magnum/Trade/MeshData2D.h"
|
||
|
|
#include "Magnum/Trade/MeshData3D.h"
|
||
|
5 years ago
|
#include "Magnum/Trade/MeshObjectData3D.h"
|
||
|
|
#include "Magnum/Trade/ObjectData2D.h"
|
||
|
6 years ago
|
#endif
|
||
|
|
|
||
|
4 years ago
|
#define DOXYGEN_ELLIPSIS(...) __VA_ARGS__
|
||
|
5 years ago
|
#define DOXYGEN_IGNORE(...) __VA_ARGS__
|
||
|
6 years ago
|
|
||
|
8 years ago
|
using namespace Magnum;
|
||
|
|
using namespace Magnum::Math::Literals;
|
||
|
|
|
||
|
3 years ago
|
namespace MyNamespace {
|
||
|
|
|
||
|
|
struct MyImporter: Trade::AbstractImporter {
|
||
|
|
explicit MyImporter(PluginManager::AbstractManager& manager, Containers::StringView plugin): Trade::AbstractImporter{manager, plugin} {}
|
||
|
|
|
||
|
|
Trade::ImporterFeatures doFeatures() const override { return {}; }
|
||
|
|
bool doIsOpened() const override { return false; }
|
||
|
|
void doClose() override {}
|
||
|
|
};
|
||
|
|
struct MyImageConverter: Trade::AbstractImageConverter {
|
||
|
|
explicit MyImageConverter(PluginManager::AbstractManager& manager, Containers::StringView plugin): Trade::AbstractImageConverter{manager, plugin} {}
|
||
|
|
|
||
|
|
Trade::ImageConverterFeatures doFeatures() const override { return {}; }
|
||
|
|
};
|
||
|
|
struct MySceneConverter: Trade::AbstractSceneConverter {
|
||
|
|
explicit MySceneConverter(PluginManager::AbstractManager& manager, Containers::StringView plugin): Trade::AbstractSceneConverter{manager, plugin} {}
|
||
|
|
|
||
|
|
Trade::SceneConverterFeatures doFeatures() const override { return {}; }
|
||
|
|
};
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/* [MAGNUM_TRADE_ABSTRACTIMPORTER_PLUGIN_INTERFACE] */
|
||
|
|
CORRADE_PLUGIN_REGISTER(MyImporter, MyNamespace::MyImporter,
|
||
|
|
MAGNUM_TRADE_ABSTRACTIMPORTER_PLUGIN_INTERFACE)
|
||
|
|
/* [MAGNUM_TRADE_ABSTRACTIMPORTER_PLUGIN_INTERFACE] */
|
||
|
|
|
||
|
|
/* [MAGNUM_TRADE_ABSTRACTIMAGECONVERTER_PLUGIN_INTERFACE] */
|
||
|
|
CORRADE_PLUGIN_REGISTER(MyImageConverter, MyNamespace::MyImageConverter,
|
||
|
|
MAGNUM_TRADE_ABSTRACTIMAGECONVERTER_PLUGIN_INTERFACE)
|
||
|
|
/* [MAGNUM_TRADE_ABSTRACTIMAGECONVERTER_PLUGIN_INTERFACE] */
|
||
|
|
|
||
|
|
/* [MAGNUM_TRADE_ABSTRACTSCENECONVERTER_PLUGIN_INTERFACE] */
|
||
|
|
CORRADE_PLUGIN_REGISTER(MySceneConverter, MyNamespace::MySceneConverter,
|
||
|
|
MAGNUM_TRADE_ABSTRACTSCENECONVERTER_PLUGIN_INTERFACE)
|
||
|
|
/* [MAGNUM_TRADE_ABSTRACTSCENECONVERTER_PLUGIN_INTERFACE] */
|
||
|
|
|
||
|
2 years ago
|
/* Make sure the name doesn't conflict with any other snippets to avoid linker
|
||
|
|
warnings, unlike with `int main()` there now has to be a declaration to
|
||
|
|
avoid -Wmisssing-prototypes */
|
||
|
|
void mainTrade();
|
||
|
|
void mainTrade() {
|
||
|
5 years ago
|
{
|
||
|
|
Vector2i size;
|
||
|
|
/* [AbstractImageConverter-usage-file] */
|
||
|
|
PluginManager::Manager<Trade::AbstractImageConverter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractImageConverter> converter =
|
||
|
|
manager.loadAndInstantiate("AnyImageConverter");
|
||
|
|
|
||
|
4 years ago
|
Image2D image{PixelFormat::RGBA8Unorm, size, DOXYGEN_ELLIPSIS({})};
|
||
|
5 years ago
|
if(!converter || !converter->convertToFile(image, "image.png"))
|
||
|
|
Fatal{} << "Can't save image.png with AnyImageConverter";
|
||
|
|
/* [AbstractImageConverter-usage-file] */
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
{
|
||
|
|
/* [AbstractImageConverter-usage-file-levels] */
|
||
|
|
PluginManager::Manager<Trade::AbstractImageConverter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractImageConverter> converter =
|
||
|
|
manager.loadAndInstantiate("AnyImageConverter");
|
||
|
|
|
||
|
4 years ago
|
Image2D level0{PixelFormat::RGBA16F, {256, 256}, DOXYGEN_ELLIPSIS({})};
|
||
|
|
Image2D level1{PixelFormat::RGBA16F, {128, 128}, DOXYGEN_ELLIPSIS({})};
|
||
|
|
Image2D level2{PixelFormat::RGBA16F, {64, 64}, DOXYGEN_ELLIPSIS({})};
|
||
|
5 years ago
|
|
||
|
|
if(!converter || !converter->convertToFile({level0, level1, level2}, "image.exr"))
|
||
|
|
Fatal{} << "Can't save image.exr with AnyImageConverter";
|
||
|
|
/* [AbstractImageConverter-usage-file-levels] */
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
{
|
||
|
|
Image2D image{{}, {}, {}};
|
||
|
|
/* [AbstractImageConverter-usage-image] */
|
||
|
|
PluginManager::Manager<Trade::AbstractImageConverter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractImageConverter> converter =
|
||
|
|
manager.loadAndInstantiate("StbDxtImageConverter");
|
||
|
|
|
||
|
|
Containers::Optional<Trade::ImageData2D> compressed;
|
||
|
|
if(!converter || !(compressed = converter->convert(image)))
|
||
|
|
Fatal{} << "Can't convert the image with StbDxtImageConverter";
|
||
|
|
CORRADE_INTERNAL_ASSERT(compressed->isCompressed());
|
||
|
|
/* [AbstractImageConverter-usage-image] */
|
||
|
|
}
|
||
|
|
|
||
|
8 years ago
|
{
|
||
|
|
/* [AbstractImporter-usage] */
|
||
|
|
PluginManager::Manager<Trade::AbstractImporter> manager;
|
||
|
7 years ago
|
Containers::Pointer<Trade::AbstractImporter> importer =
|
||
|
8 years ago
|
manager.loadAndInstantiate("AnyImageImporter");
|
||
|
|
if(!importer || !importer->openFile("image.png"))
|
||
|
|
Fatal{} << "Can't open image.png with AnyImageImporter";
|
||
|
|
|
||
|
|
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
|
||
|
|
if(!image) Fatal{} << "Importing the image failed";
|
||
|
|
|
||
|
|
// use the image ...
|
||
|
|
/* [AbstractImporter-usage] */
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
{
|
||
|
3 years ago
|
/* -Wnonnull in GCC 11+ "helpfully" says "this is null" if I don't initialize
|
||
|
|
the converter pointer. I don't care, I just want you to check compilation
|
||
|
|
errors, not more! */
|
||
|
|
PluginManager::Manager<Trade::AbstractImporter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractImporter> importer = manager.loadAndInstantiate("SomethingWhatever");
|
||
|
5 years ago
|
/* [AbstractImporter-usage-data] */
|
||
|
|
Utility::Resource rs{"data"};
|
||
|
|
Containers::ArrayView<const char> data = rs.getRaw("image.png");
|
||
|
5 years ago
|
if(!importer->openData(data)) /* or openMemory() */
|
||
|
5 years ago
|
Fatal{} << "Can't open image data with AnyImageImporter";
|
||
|
|
|
||
|
|
// import & use the image like above ...
|
||
|
|
/* [AbstractImporter-usage-data] */
|
||
|
|
}
|
||
|
|
|
||
|
8 years ago
|
#if defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT))
|
||
|
|
{
|
||
|
3 years ago
|
/* -Wnonnull in GCC 11+ "helpfully" says "this is null" if I don't initialize
|
||
|
|
the converter pointer. I don't care, I just want you to check compilation
|
||
|
|
errors, not more! */
|
||
|
|
PluginManager::Manager<Trade::AbstractImporter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractImporter> importer = manager.loadAndInstantiate("SomethingWhatever");
|
||
|
8 years ago
|
/* [AbstractImporter-usage-callbacks] */
|
||
|
|
struct Data {
|
||
|
4 years ago
|
std::unordered_map<std::string, Containers::Optional<
|
||
|
|
Containers::Array<const char, Utility::Path::MapDeleter>>> files;
|
||
|
8 years ago
|
} data;
|
||
|
|
|
||
|
|
importer->setFileCallback([](const std::string& filename,
|
||
|
7 years ago
|
InputFileCallbackPolicy policy, Data& data)
|
||
|
8 years ago
|
-> Containers::Optional<Containers::ArrayView<const char>>
|
||
|
|
{
|
||
|
8 years ago
|
auto found = data.files.find(filename);
|
||
|
|
|
||
|
|
/* Discard the memory mapping, if not needed anymore */
|
||
|
7 years ago
|
if(policy == InputFileCallbackPolicy::Close) {
|
||
|
8 years ago
|
if(found != data.files.end()) data.files.erase(found);
|
||
|
8 years ago
|
return {};
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
4 years ago
|
/* Load if not there yet. If the mapping fails, remember that to not
|
||
|
|
attempt to load the same file again next time. */
|
||
|
8 years ago
|
if(found == data.files.end()) found = data.files.emplace(
|
||
|
4 years ago
|
filename, Utility::Path::mapRead(filename)).first;
|
||
|
8 years ago
|
|
||
|
4 years ago
|
if(!found->second) return {};
|
||
|
|
return Containers::arrayView(*found->second);
|
||
|
8 years ago
|
}, data);
|
||
|
|
|
||
|
|
importer->openFile("scene.gltf"); // memory-maps all files
|
||
|
|
/* [AbstractImporter-usage-callbacks] */
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
8 years ago
|
{
|
||
|
3 years ago
|
/* -Wnonnull in GCC 11+ "helpfully" says "this is null" if I don't initialize
|
||
|
|
the converter pointer. I don't care, I just want you to check compilation
|
||
|
|
errors, not more! */
|
||
|
|
PluginManager::Manager<Trade::AbstractImporter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractImporter> importer = manager.loadAndInstantiate("SomethingWhatever");
|
||
|
8 years ago
|
/* [AbstractImporter-setFileCallback] */
|
||
|
|
importer->setFileCallback([](const std::string& filename,
|
||
|
7 years ago
|
InputFileCallbackPolicy, void*) {
|
||
|
6 years ago
|
Utility::Resource rs{"data"};
|
||
|
8 years ago
|
return Containers::optional(rs.getRaw(filename));
|
||
|
8 years ago
|
});
|
||
|
|
/* [AbstractImporter-setFileCallback] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
3 years ago
|
/* -Wnonnull in GCC 11+ "helpfully" says "this is null" if I don't initialize
|
||
|
|
the converter pointer. I don't care, I just want you to check compilation
|
||
|
|
errors, not more! */
|
||
|
|
PluginManager::Manager<Trade::AbstractImporter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractImporter> importer = manager.loadAndInstantiate("SomethingWhatever");
|
||
|
8 years ago
|
/* [AbstractImporter-setFileCallback-template] */
|
||
|
6 years ago
|
const Utility::Resource rs{"data"};
|
||
|
8 years ago
|
importer->setFileCallback([](const std::string& filename,
|
||
|
6 years ago
|
InputFileCallbackPolicy, const Utility::Resource& rs) {
|
||
|
|
return Containers::optional(rs.getRaw(filename));
|
||
|
|
}, rs);
|
||
|
8 years ago
|
/* [AbstractImporter-setFileCallback-template] */
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
{
|
||
|
|
struct: Trade::AbstractImporter {
|
||
|
|
Trade::ImporterFeatures doFeatures() const override { return {}; }
|
||
|
|
bool doIsOpened() const override { return false; }
|
||
|
|
void doClose() override {}
|
||
|
|
|
||
|
|
Containers::Array<char> _in;
|
||
|
|
|
||
|
|
/* [AbstractImporter-doOpenData-ownership] */
|
||
|
|
void doOpenData(Containers::Array<char>&& data, Trade::DataFlags dataFlags) override
|
||
|
|
{
|
||
|
|
/* Take over the existing array or copy the data if we can't */
|
||
|
5 years ago
|
if(dataFlags & (Trade::DataFlag::Owned|Trade::DataFlag::ExternallyOwned)) {
|
||
|
5 years ago
|
_in = std::move(data);
|
||
|
|
} else {
|
||
|
|
_in = Containers::Array<char>{NoInit, data.size()};
|
||
|
|
Utility::copy(data, _in);
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
DOXYGEN_ELLIPSIS()
|
||
|
5 years ago
|
}
|
||
|
|
/* [AbstractImporter-doOpenData-ownership] */
|
||
|
|
} importer;
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
{
|
||
|
4 years ago
|
/* [AbstractSceneConverter-usage-mesh-file] */
|
||
|
5 years ago
|
PluginManager::Manager<Trade::AbstractSceneConverter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractSceneConverter> converter =
|
||
|
|
manager.loadAndInstantiate("AnySceneConverter");
|
||
|
|
|
||
|
4 years ago
|
Trade::MeshData mesh = DOXYGEN_ELLIPSIS(Trade::MeshData{{}, {}});
|
||
|
5 years ago
|
if(!converter || !converter->convertToFile(mesh, "mesh.ply"))
|
||
|
|
Fatal{} << "Can't save mesh.ply with AnySceneConverter";
|
||
|
4 years ago
|
/* [AbstractSceneConverter-usage-mesh-file] */
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Trade::MeshData mesh{{}, {}};
|
||
|
|
/* [AbstractSceneConverter-usage-mesh] */
|
||
|
|
PluginManager::Manager<Trade::AbstractSceneConverter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractSceneConverter> converter =
|
||
|
|
manager.loadAndInstantiate("MeshOptimizerSceneConverter");
|
||
|
|
|
||
|
|
Containers::Optional<Trade::MeshData> optimized;
|
||
|
|
if(!converter || !(optimized = converter->convert(mesh)))
|
||
|
|
Fatal{} << "Can't optimize the mesh with MeshOptimizerSceneConverter";
|
||
|
|
/* [AbstractSceneConverter-usage-mesh] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Trade::MeshData mesh{{}, {}};
|
||
|
|
Containers::Pointer<Trade::AbstractSceneConverter> converter;
|
||
|
|
/* [AbstractSceneConverter-usage-mesh-in-place] */
|
||
|
|
if(!converter || !converter->convertInPlace(mesh))
|
||
|
|
Fatal{} << "Can't optimize the mesh with MeshOptimizerSceneConverter";
|
||
|
|
/* [AbstractSceneConverter-usage-mesh-in-place] */
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
{
|
||
|
|
/* [AbstractSceneConverter-usage-multiple-file] */
|
||
|
|
PluginManager::Manager<Trade::AbstractImporter> importerManager;
|
||
|
|
Containers::Pointer<Trade::AbstractImporter> importer =
|
||
|
|
importerManager.loadAndInstantiate("AnySceneImporter");
|
||
|
|
if(!importer || importer->openFile("file.dae"))
|
||
|
|
Fatal{} << "Can't open the input file";
|
||
|
|
|
||
|
|
PluginManager::Manager<Trade::AbstractSceneConverter> manager;
|
||
|
|
Containers::Pointer<Trade::AbstractSceneConverter> converter =
|
||
|
|
manager.loadAndInstantiate("AnySceneConverter");
|
||
|
|
|
||
|
|
if(!converter->beginFile("file.gltf") ||
|
||
|
|
!converter->addSupportedImporterContents(*importer) ||
|
||
|
|
!converter->endFile())
|
||
|
|
Fatal{} << "Can't save the output file";
|
||
|
|
/* [AbstractSceneConverter-usage-multiple-file] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Containers::Pointer<Trade::AbstractImporter> importer;
|
||
|
|
Containers::Pointer<Trade::AbstractSceneConverter> converter;
|
||
|
|
/* [AbstractSceneConverter-usage-multiple-file-selective] */
|
||
|
|
if(!converter->beginFile("file.gltf"))
|
||
|
|
Fatal{} << "Can't begin the output file";
|
||
|
|
|
||
|
|
/* Add meshes manually, removing duplicates in each in the process */
|
||
|
|
for(UnsignedInt i = 0; i != importer->meshCount(); ++i) {
|
||
|
|
Containers::Optional<Trade::MeshData> mesh = importer->mesh(i);
|
||
|
|
if(!mesh ||
|
||
|
|
!converter->add(MeshTools::removeDuplicates(*mesh), importer->meshName(i)))
|
||
|
|
Fatal{} << "Can't add mesh" << i;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Add the rest of the input file and finish */
|
||
|
|
if(!converter->addSupportedImporterContents(*importer, ~Trade::SceneContent::Meshes) ||
|
||
|
|
!converter->endFile())
|
||
|
|
Fatal{} << "Can't save the output file";
|
||
|
|
/* [AbstractSceneConverter-usage-multiple-file-selective] */
|
||
|
|
}
|
||
|
|
|
||
|
8 years ago
|
{
|
||
|
|
UnsignedInt id{};
|
||
|
7 years ago
|
Containers::Pointer<Trade::AbstractImporter> importer;
|
||
|
8 years ago
|
/* [AnimationData-usage] */
|
||
|
|
|
||
|
|
Containers::Optional<Trade::AnimationData> data = importer->animation(id);
|
||
|
|
|
||
|
|
Animation::Player<Float> player;
|
||
|
|
Containers::Array<Vector3> positions; /* Translations for all objects */
|
||
|
|
for(UnsignedInt i = 0; i != data->trackCount(); ++i) {
|
||
|
3 years ago
|
if(data->trackTargetName(i) == Trade::AnimationTrackTarget::Translation3D) {
|
||
|
8 years ago
|
CORRADE_INTERNAL_ASSERT(data->trackType(i) ==
|
||
|
|
Trade::AnimationTrackType::Vector3);
|
||
|
8 years ago
|
player.add(data->track<Vector3>(i), positions[data->trackTarget(i)]);
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
|
// similarly for rotation / scaling ...
|
||
|
|
}
|
||
|
|
|
||
|
|
Containers::Array<char> animationData = data->release(); /* Take ownership */
|
||
|
|
/* [AnimationData-usage] */
|
||
|
|
}
|
||
|
|
|
||
|
7 years ago
|
{
|
||
|
|
Trade::AnimationData data{nullptr, {}};
|
||
|
|
/* [AnimationData-usage-mutable] */
|
||
|
|
for(UnsignedInt i = 0; i != data.trackCount(); ++i) {
|
||
|
3 years ago
|
if(data.trackTargetName(i) != Trade::AnimationTrackTarget::Translation3D)
|
||
|
7 years ago
|
continue;
|
||
|
|
/* Check prerequisites */
|
||
|
|
if(!(data.dataFlags() & Trade::DataFlag::Mutable) ||
|
||
|
|
data.trackType(i) != Trade::AnimationTrackType::Vector2)
|
||
|
|
Fatal{} << "Oops";
|
||
|
|
|
||
|
|
MeshTools::transformVectorsInPlace(Matrix4::scaling(Vector3::yScale(-1.0f)),
|
||
|
|
data.mutableTrack<Vector3>(i).values());
|
||
|
|
}
|
||
|
|
/* [AnimationData-usage-mutable] */
|
||
|
|
}
|
||
|
|
|
||
|
8 years ago
|
{
|
||
|
3 years ago
|
/* [ImageData-populating] */
|
||
|
|
Containers::Array<char> uncompressedData = DOXYGEN_ELLIPSIS({});
|
||
|
|
Trade::ImageData2D uncompressed{PixelFormat::RGB8Unorm,
|
||
|
|
{32, 32}, std::move(uncompressedData)};
|
||
|
|
|
||
|
|
Containers::Array<char> compressedData = DOXYGEN_ELLIPSIS({});
|
||
|
|
Trade::ImageData2D compressed{CompressedPixelFormat::Bc1RGBUnorm,
|
||
|
|
{32, 32}, std::move(compressedData)};
|
||
|
|
/* [ImageData-populating] */
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
|
{
|
||
|
3 years ago
|
/* [ImageData-populating-non-owned] */
|
||
|
|
Color3ub uncompressedData[]{DOXYGEN_ELLIPSIS({})};
|
||
|
|
Trade::ImageData2D uncompressed{PixelFormat::RGB8Unorm,
|
||
|
|
{32, 32}, Trade::DataFlag::Mutable, uncompressedData};
|
||
|
|
|
||
|
|
Containers::ArrayView<const char> compressedData = DOXYGEN_ELLIPSIS({});
|
||
|
|
Trade::ImageData2D compressed{CompressedPixelFormat::Bc1RGBUnorm,
|
||
|
|
{32, 32}, Trade::DataFlags{}, compressedData};
|
||
|
|
/* [ImageData-populating-non-owned] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
/* [ImageData-populating-padding] */
|
||
|
|
PixelFormat format = DOXYGEN_ELLIPSIS({});
|
||
|
|
Vector2i size = DOXYGEN_ELLIPSIS({});
|
||
|
|
std::size_t rowStride = 4*((size.x()*pixelFormatSize(format) + 3)/4);
|
||
|
|
Containers::Array<char> data{ValueInit, std::size_t(size.y()*rowStride)};
|
||
|
|
DOXYGEN_ELLIPSIS()
|
||
|
|
|
||
|
|
Trade::ImageData2D image{format, size, std::move(data)};
|
||
|
|
/* [ImageData-populating-padding] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
/* [ImageData-populating-alignment] */
|
||
|
|
PixelFormat format = DOXYGEN_ELLIPSIS({});
|
||
|
|
Vector2i size = DOXYGEN_ELLIPSIS({});
|
||
|
|
std::size_t rowLength = size.x()*pixelFormatSize(format);
|
||
|
|
Containers::Array<char> data{ValueInit, std::size_t(size.y()*rowLength)};
|
||
|
|
DOXYGEN_ELLIPSIS()
|
||
|
|
|
||
|
|
Trade::ImageData2D image{
|
||
|
|
PixelStorage{}.setAlignment(rowLength % 4 == 0 ? 4 : 1),
|
||
|
|
format, size, std::move(data)};
|
||
|
|
/* [ImageData-populating-alignment] */
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
|
#ifdef MAGNUM_TARGET_GL
|
||
|
|
{
|
||
|
|
/* [ImageData-usage] */
|
||
|
3 years ago
|
Trade::ImageData2D image = DOXYGEN_ELLIPSIS(Trade::ImageData2D{PixelFormat{}, {}, nullptr});
|
||
|
8 years ago
|
|
||
|
|
GL::Texture2D texture;
|
||
|
4 years ago
|
DOXYGEN_ELLIPSIS()
|
||
|
3 years ago
|
texture.setStorage(1, GL::textureFormat(image.format()), image.size());
|
||
|
|
if(!image.isCompressed())
|
||
|
|
texture.setSubImage(0, {}, image);
|
||
|
8 years ago
|
else
|
||
|
3 years ago
|
texture.setCompressedSubImage(0, {}, image);
|
||
|
8 years ago
|
/* [ImageData-usage] */
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
7 years ago
|
{
|
||
|
|
Trade::ImageData2D data{PixelFormat::RGB8Unorm, {}, nullptr};
|
||
|
|
/* [ImageData-usage-mutable] */
|
||
|
|
if(data.isCompressed() ||
|
||
|
|
data.format() != PixelFormat::RGB8Unorm ||
|
||
|
|
!(data.dataFlags() & Trade::DataFlag::Mutable))
|
||
|
|
Fatal{} << ":(";
|
||
|
|
|
||
|
|
for(auto&& row: data.mutablePixels<Color3ub>())
|
||
|
|
for(Color3ub& pixel: row)
|
||
|
|
pixel = Math::gather<'b', 'g', 'r'>(pixel);
|
||
|
|
/* [ImageData-usage-mutable] */
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
{
|
||
|
|
/* [LightData-populating-range] */
|
||
|
3 years ago
|
Trade::LightData data{Trade::LightType::Point,
|
||
|
6 years ago
|
0xfff3d6_srgbf, 1.0f,
|
||
|
|
15.0f};
|
||
|
|
/* [LightData-populating-range] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
/* [LightData-populating-attenuation] */
|
||
|
3 years ago
|
Trade::LightData data{Trade::LightType::Spot,
|
||
|
6 years ago
|
0xf3d6ff_srgbf, 10.0f,
|
||
|
|
{0.01f, 0.5f, 2.0f},
|
||
|
|
25.0_degf, 55.0_degf};
|
||
|
|
/* [LightData-populating-attenuation] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
/* [LightData-populating-none] */
|
||
|
3 years ago
|
Trade::LightData data{Trade::LightType::Directional,
|
||
|
6 years ago
|
0xd6fff3_srgbf, 0.25f};
|
||
|
|
/* [LightData-populating-none] */
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
{
|
||
|
|
/* [MaterialAttributeData-name] */
|
||
|
|
Trade::MaterialAttributeData a{
|
||
|
6 years ago
|
Trade::MaterialAttribute::DiffuseColor, 0x3bd267ff_srgbaf};
|
||
|
|
Trade::MaterialAttributeData b{"DiffuseColor", 0x3bd267ff_srgbaf};
|
||
|
6 years ago
|
/* [MaterialAttributeData-name] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
/* [MaterialData-usage] */
|
||
|
4 years ago
|
Trade::MaterialData data = DOXYGEN_ELLIPSIS(Trade::MaterialData{{}, {}});
|
||
|
6 years ago
|
|
||
|
|
// Assumes the attribute exists
|
||
|
|
Float roughness = data.attribute<Float>(Trade::MaterialAttribute::Roughness);
|
||
|
|
|
||
|
|
// Optional access
|
||
|
|
Color4 color = data.attributeOr(Trade::MaterialAttribute::BaseColor,
|
||
|
6 years ago
|
0x3bd267ff_srgbaf);
|
||
|
6 years ago
|
if(Containers::Optional<UnsignedInt> texture =
|
||
|
4 years ago
|
data.findAttribute<UnsignedInt>(Trade::MaterialAttribute::BaseColorTexture))
|
||
|
6 years ago
|
{
|
||
|
|
// ...
|
||
|
|
}
|
||
|
|
/* [MaterialData-usage] */
|
||
|
|
static_cast<void>(roughness);
|
||
|
|
static_cast<void>(color);
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Trade::MaterialData data{{}, {}};
|
||
|
|
/* [MaterialData-usage-types] */
|
||
|
5 years ago
|
/* Prefer a specular/glossiness workflow, if present */
|
||
|
6 years ago
|
if(data.types() & Trade::MaterialType::PbrSpecularGlossiness) {
|
||
|
|
const auto& pbr = data.as<Trade::PbrSpecularGlossinessMaterialData>();
|
||
|
|
|
||
|
|
Color4 diffuse = pbr.diffuseColor();
|
||
|
|
Color4 specular = pbr.specularColor();
|
||
|
|
Float glossiness = pbr.glossiness();
|
||
|
|
|
||
|
4 years ago
|
DOXYGEN_ELLIPSIS(static_cast<void>(diffuse), static_cast<void>(specular), static_cast<void>(glossiness);)
|
||
|
6 years ago
|
|
||
|
|
/* Otherwise use metallic/roughness (or defaults if no attributes present) */
|
||
|
|
} else {
|
||
|
|
const auto& pbr = data.as<Trade::PbrMetallicRoughnessMaterialData>();
|
||
|
|
|
||
|
|
Color4 base = pbr.baseColor();
|
||
|
|
Float metalness = pbr.metalness();
|
||
|
|
Float roughness = pbr.roughness();
|
||
|
|
|
||
|
4 years ago
|
DOXYGEN_ELLIPSIS(static_cast<void>(base), static_cast<void>(metalness), static_cast<void>(roughness);)
|
||
|
6 years ago
|
}
|
||
|
|
/* [MaterialData-usage-types] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
6 years ago
|
/* [MaterialData-usage-texture-complexity] */
|
||
|
4 years ago
|
Trade::PbrSpecularGlossinessMaterialData data = DOXYGEN_ELLIPSIS(Trade::PbrSpecularGlossinessMaterialData{{}, {}});
|
||
|
6 years ago
|
|
||
|
6 years ago
|
/* Simple case for diffuse + packed specular/glossiness texture, the default
|
||
|
|
coordinate set and a common coordinate transformation for all textures */
|
||
|
|
if(data.hasAttribute(Trade::MaterialAttribute::DiffuseTexture) &&
|
||
|
|
data.hasSpecularGlossinessTexture() &&
|
||
|
|
data.hasCommonTextureTransformation() && !data.hasTextureCoordinates())
|
||
|
|
{
|
||
|
|
UnsignedInt diffuse = data.diffuseTexture();
|
||
|
6 years ago
|
UnsignedInt specularGlossiness = data.specularTexture();
|
||
|
6 years ago
|
Matrix3 textureMatrix = data.commonTextureMatrix();
|
||
|
6 years ago
|
|
||
|
4 years ago
|
DOXYGEN_ELLIPSIS(static_cast<void>(diffuse), static_cast<void>(specularGlossiness), static_cast<void>(textureMatrix);)
|
||
|
6 years ago
|
|
||
|
6 years ago
|
/* Extra work needed when using a non-default texture coordinate set */
|
||
|
|
} else if(data.hasTextureCoordinates() && data.hasCommonTextureCoordinates()) {
|
||
|
4 years ago
|
DOXYGEN_ELLIPSIS()
|
||
|
6 years ago
|
|
||
|
|
/* Etc... */
|
||
|
|
} else Fatal{} << "Material too complex, giving up";
|
||
|
|
/* [MaterialData-usage-texture-complexity] */
|
||
|
6 years ago
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Trade::MaterialData data{{}, {}};
|
||
|
|
/* [MaterialData-usage-layers] */
|
||
|
|
if(data.hasLayer(Trade::MaterialLayer::ClearCoat)) {
|
||
|
|
Float clearCoatFactor = data.attributeOr(Trade::MaterialLayer::ClearCoat,
|
||
|
|
Trade::MaterialAttribute::LayerFactor, 1.0f);
|
||
|
|
Float clearCoatRoughness = data.attributeOr(Trade::MaterialLayer::ClearCoat,
|
||
|
|
Trade::MaterialAttribute::Roughness, 0.0f);
|
||
|
|
|
||
|
4 years ago
|
DOXYGEN_ELLIPSIS(static_cast<void>(clearCoatFactor), static_cast<void>(clearCoatRoughness);)
|
||
|
6 years ago
|
}
|
||
|
|
/* [MaterialData-usage-layers] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Trade::MaterialData data{{}, {}};
|
||
|
|
/* [MaterialData-usage-layers-types] */
|
||
|
|
if(data.types() & Trade::MaterialType::PbrClearCoat) {
|
||
|
|
const auto& clearCoat = data.as<Trade::PbrClearCoatMaterialData>();
|
||
|
|
|
||
|
|
Float clearCoatFactor = clearCoat.layerFactor();
|
||
|
|
Float clearCoatRoughness = clearCoat.roughness();
|
||
|
|
|
||
|
4 years ago
|
DOXYGEN_ELLIPSIS(static_cast<void>(clearCoatFactor), static_cast<void>(clearCoatRoughness);)
|
||
|
6 years ago
|
}
|
||
|
|
/* [MaterialData-usage-layers-types] */
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
{
|
||
|
|
Trade::MaterialData data{{}, {}};
|
||
|
|
/* [MaterialData-usage-mutable] */
|
||
|
|
Color4& color = data.mutableAttribute<Color4>(Trade::MaterialAttribute::BaseColor);
|
||
|
|
ColorHsv hsv = color.toHsv();
|
||
|
|
color.rgb() = Color3::fromHsv({hsv.hue, hsv.saturation*0.85f, hsv.value});
|
||
|
|
/* [MaterialData-usage-mutable] */
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
{
|
||
|
|
/* [MaterialData-populating] */
|
||
|
|
Trade::MaterialData data{Trade::MaterialType::PbrMetallicRoughness, {
|
||
|
|
{Trade::MaterialAttribute::DoubleSided, true},
|
||
|
|
{Trade::MaterialAttribute::BaseColor, 0x3bd267ff_srgbaf},
|
||
|
|
{Trade::MaterialAttribute::BaseColorTexture, 17u},
|
||
|
|
{Trade::MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})}
|
||
|
|
}};
|
||
|
|
/* [MaterialData-populating] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
/* [MaterialData-populating-non-owned] */
|
||
|
|
using namespace Containers::Literals;
|
||
|
|
|
||
|
|
constexpr Trade::MaterialAttributeData attributes[]{
|
||
|
|
{"BaseColor"_s, Color4{0.043735f, 0.64448f, 0.135633f, 1.0f}},
|
||
|
|
{"BaseColorTexture"_s, 5u},
|
||
|
6 years ago
|
{"DoubleSided"_s, true},
|
||
|
6 years ago
|
{"TextureMatrix"_s, Matrix3{{0.5f, 0.0f, 0.0f},
|
||
|
|
{0.0f, 1.0f, 0.0f},
|
||
|
|
{0.0f, 0.0f, 1.0f}}}
|
||
|
|
};
|
||
|
|
|
||
|
|
Trade::MaterialData data{Trade::MaterialType::Phong, {}, attributes};
|
||
|
|
/* [MaterialData-populating-non-owned] */
|
||
|
|
}
|
||
|
|
|
||
|
|
#ifdef MAGNUM_TARGET_GL
|
||
|
|
{
|
||
|
|
GL::Texture2D baseColorTexture;
|
||
|
|
/* [MaterialData-populating-custom] */
|
||
|
4 years ago
|
char sha1[20]{DOXYGEN_ELLIPSIS()};
|
||
|
|
|
||
|
6 years ago
|
Trade::MaterialData data{Trade::MaterialType::PbrMetallicRoughness, {
|
||
|
|
{Trade::MaterialAttribute::BaseColor, 0x3bd267ff_srgbaf},
|
||
|
|
{Trade::MaterialAttribute::TextureMatrix, Matrix3::scaling({0.5f, 1.0f})},
|
||
|
|
{"baseColorTexturePointer", &baseColorTexture},
|
||
|
|
{"highlightColor", 0x00ffff_srgbf},
|
||
|
4 years ago
|
{"name", "Canary Green Plastic, really ugly"},
|
||
|
|
{"hash", Containers::ArrayView<const void>{sha1}},
|
||
|
6 years ago
|
}};
|
||
|
|
|
||
|
|
// Retrieving the texture pointer
|
||
|
|
GL::Texture2D* texture = data.attribute<GL::Texture2D*>("baseColorTexturePointer");
|
||
|
|
/* [MaterialData-populating-custom] */
|
||
|
|
static_cast<void>(texture);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
|
{
|
||
|
|
/* [MaterialData-populating-layers] */
|
||
|
|
Trade::MaterialData data{
|
||
|
|
Trade::MaterialType::PbrMetallicRoughness|Trade::MaterialType::PbrClearCoat,
|
||
|
|
{
|
||
|
|
{Trade::MaterialAttribute::BaseColor, 0xffcc33_srgbf},
|
||
|
6 years ago
|
{Trade::MaterialAttribute::NoneRoughnessMetallicTexture, 0u},
|
||
|
6 years ago
|
|
||
|
|
{Trade::MaterialLayer::ClearCoat},
|
||
|
|
{Trade::MaterialAttribute::LayerFactorTexture, 1u},
|
||
|
|
{Trade::MaterialAttribute::RoughnessTexture, 1u},
|
||
|
|
{Trade::MaterialAttribute::RoughnessTextureSwizzle,
|
||
|
|
Trade::MaterialTextureSwizzle::G}
|
||
|
|
},
|
||
|
|
|
||
|
|
{2, 6}
|
||
|
|
};
|
||
|
|
/* [MaterialData-populating-layers] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
UnsignedInt a, b, c, d, sandTile, grassTile, rockTile;
|
||
|
|
/* [MaterialData-populating-layers-custom] */
|
||
|
|
Trade::MaterialData proceduralLandscape{
|
||
|
|
Trade::MaterialTypes{}, // Doesn't match any builtin material type
|
||
|
|
{
|
||
|
|
// Rock layer
|
||
|
|
{Trade::MaterialAttribute::LayerFactorTexture, a},
|
||
|
|
{Trade::MaterialAttribute::BaseColorTexture, rockTile},
|
||
|
|
|
||
|
|
// Sand layer
|
||
|
|
{Trade::MaterialAttribute::LayerFactorTexture, b},
|
||
|
|
{"blendType", "mix"},
|
||
|
|
{Trade::MaterialAttribute::BaseColorTexture, sandTile},
|
||
|
|
|
||
|
|
// Grass layer
|
||
|
|
{Trade::MaterialAttribute::LayerFactorTexture, c},
|
||
|
|
{"blendType", "overlay"},
|
||
|
|
{"strandLengthTexture", d},
|
||
|
|
{Trade::MaterialAttribute::BaseColorTexture, grassTile},
|
||
|
|
},
|
||
|
|
|
||
|
|
// There's no base material, everything is in layers
|
||
|
|
{0, 2, 5, 9}
|
||
|
|
};
|
||
|
|
/* [MaterialData-populating-layers-custom] */
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
{
|
||
|
|
/* [MeshIndexData-usage] */
|
||
|
|
Containers::ArrayView<const UnsignedShort> indices;
|
||
|
|
|
||
|
|
Trade::MeshIndexData data{indices};
|
||
|
|
/* [MeshIndexData-usage] */
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
{
|
||
|
|
Vector3 normal;
|
||
|
|
Vector4 tangent;
|
||
|
|
/* [MeshAttribute-bitangent-from-tangent] */
|
||
|
|
Vector3 bitangent = Math::cross(normal, tangent.xyz())*tangent.w();
|
||
|
|
/* [MeshAttribute-bitangent-from-tangent] */
|
||
|
|
static_cast<void>(bitangent);
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
{
|
||
|
|
/* [MeshAttributeData-usage] */
|
||
|
|
Containers::StridedArrayView1D<const Vector3> positions;
|
||
|
|
|
||
|
|
Trade::MeshAttributeData data{Trade::MeshAttribute::Position, positions};
|
||
|
|
/* [MeshAttributeData-usage] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
3 years ago
|
UnsignedInt vertexCount{};
|
||
|
6 years ago
|
/* [MeshAttributeData-usage-offset-only] */
|
||
|
|
struct Vertex {
|
||
|
|
Vector3 position;
|
||
|
|
Vector4 color;
|
||
|
|
};
|
||
|
|
|
||
|
3 years ago
|
Trade::MeshAttributeData positions{Trade::MeshAttribute::Position,
|
||
|
|
VertexFormat::Vector3, offsetof(Vertex, position), vertexCount, sizeof(Vertex)};
|
||
|
|
Trade::MeshAttributeData colors{Trade::MeshAttribute::Color,
|
||
|
|
VertexFormat::Vector4, offsetof(Vertex, color), vertexCount, sizeof(Vertex)};
|
||
|
6 years ago
|
/* [MeshAttributeData-usage-offset-only] */
|
||
|
3 years ago
|
static_cast<void>(positions);
|
||
|
|
static_cast<void>(colors);
|
||
|
6 years ago
|
}
|
||
|
|
|
||
|
|
#ifdef MAGNUM_TARGET_VK
|
||
|
|
{
|
||
|
|
Containers::StridedArrayView1D<const void> data;
|
||
|
|
/* [MeshAttributeData-custom-vertex-format] */
|
||
|
|
Trade::MeshAttributeData normals{Trade::MeshAttribute::Normal,
|
||
|
|
vertexFormatWrap(VK_FORMAT_B10G11R11_UFLOAT_PACK32),
|
||
|
|
data};
|
||
|
|
/* [MeshAttributeData-custom-vertex-format] */
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
7 years ago
|
#ifdef MAGNUM_TARGET_GL
|
||
|
5 years ago
|
{
|
||
|
5 years ago
|
/* This snippet is also used by GL::Mesh, bear that in mind when updating */
|
||
|
5 years ago
|
/* [MeshData-usage-compile] */
|
||
|
4 years ago
|
Trade::MeshData data = DOXYGEN_ELLIPSIS(Trade::MeshData{MeshPrimitive::Points, 0});
|
||
|
5 years ago
|
|
||
|
|
GL::Mesh mesh = MeshTools::compile(data);
|
||
|
|
/* [MeshData-usage-compile] */
|
||
|
|
}
|
||
|
|
|
||
|
7 years ago
|
{
|
||
|
|
Trade::MeshData data{MeshPrimitive::Points, 0};
|
||
|
|
/* [MeshData-usage] */
|
||
|
|
/* Check that we have at least positions and normals */
|
||
|
|
GL::Mesh mesh{data.primitive()};
|
||
|
|
if(!data.hasAttribute(Trade::MeshAttribute::Position) ||
|
||
|
|
!data.hasAttribute(Trade::MeshAttribute::Normal))
|
||
|
|
Fatal{} << "Oh well";
|
||
|
|
|
||
|
|
/* Interleave vertex data */
|
||
|
|
GL::Buffer vertices;
|
||
|
|
vertices.setData(MeshTools::interleave(data.positions3DAsArray(),
|
||
|
|
data.normalsAsArray()));
|
||
|
|
mesh.addVertexBuffer(std::move(vertices), 0,
|
||
|
5 years ago
|
Shaders::PhongGL::Position{}, Shaders::PhongGL::Normal{});
|
||
|
7 years ago
|
|
||
|
5 years ago
|
/* Set up an index buffer, if the mesh is indexed */
|
||
|
7 years ago
|
if(data.isIndexed()) {
|
||
|
|
GL::Buffer indices;
|
||
|
|
indices.setData(data.indicesAsArray());
|
||
|
|
mesh.setIndexBuffer(std::move(indices), 0, MeshIndexType::UnsignedInt)
|
||
|
|
.setCount(data.indexCount());
|
||
|
|
} else mesh.setCount(data.vertexCount());
|
||
|
|
/* [MeshData-usage] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Trade::MeshData data{MeshPrimitive::Points, 0};
|
||
|
|
GL::Mesh mesh{data.primitive()};
|
||
|
|
/* [MeshData-usage-advanced] */
|
||
|
|
/* Upload the original packed vertex data */
|
||
|
|
GL::Buffer vertices;
|
||
|
|
vertices.setData(data.vertexData());
|
||
|
|
|
||
|
6 years ago
|
/* Set up the position and normal attributes */
|
||
|
7 years ago
|
mesh.addVertexBuffer(vertices,
|
||
|
|
data.attributeOffset(Trade::MeshAttribute::Position),
|
||
|
6 years ago
|
data.attributeStride(Trade::MeshAttribute::Position),
|
||
|
5 years ago
|
GL::DynamicAttribute{Shaders::PhongGL::Position{},
|
||
|
6 years ago
|
data.attributeFormat(Trade::MeshAttribute::Position)});
|
||
|
|
mesh.addVertexBuffer(vertices,
|
||
|
|
data.attributeOffset(Trade::MeshAttribute::Normal),
|
||
|
|
data.attributeStride(Trade::MeshAttribute::Normal),
|
||
|
5 years ago
|
GL::DynamicAttribute{Shaders::PhongGL::Normal{},
|
||
|
6 years ago
|
data.attributeFormat(Trade::MeshAttribute::Normal)});
|
||
|
7 years ago
|
|
||
|
|
/* Upload the original packed index data */
|
||
|
|
if(data.isIndexed()) {
|
||
|
|
GL::Buffer indices;
|
||
|
|
indices.setData(data.indexData());
|
||
|
|
mesh.setIndexBuffer(std::move(indices), 0, data.indexType())
|
||
|
|
.setCount(data.indexCount());
|
||
|
|
} else mesh.setCount(data.vertexCount());
|
||
|
|
/* [MeshData-usage-advanced] */
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
7 years ago
|
{
|
||
|
|
Trade::MeshData data{MeshPrimitive::Points, 0};
|
||
|
|
/* [MeshData-usage-mutable] */
|
||
|
|
/* Check prerequisites */
|
||
|
|
if(!(data.vertexDataFlags() & Trade::DataFlag::Mutable) ||
|
||
|
|
!data.hasAttribute(Trade::MeshAttribute::Position) ||
|
||
|
|
data.attributeFormat(Trade::MeshAttribute::Position) != VertexFormat::Vector3)
|
||
|
|
Fatal{} << "Oh well";
|
||
|
|
|
||
|
|
/* Scale the mesh two times */
|
||
|
|
MeshTools::transformPointsInPlace(Matrix4::scaling(Vector3{2.0f}),
|
||
|
|
data.mutableAttribute<Vector3>(Trade::MeshAttribute::Position));
|
||
|
|
/* [MeshData-usage-mutable] */
|
||
|
|
}
|
||
|
|
|
||
|
3 years ago
|
{
|
||
|
|
Trade::MeshData data{MeshPrimitive::Points, 0};
|
||
|
|
/* [MeshData-usage-morph-targets] */
|
||
|
|
Float weights[]{0.25f, 0.5f};
|
||
|
|
|
||
|
|
/* Calculate morphed positions with the above weights, assuming the mesh has
|
||
|
|
a Vector3 Position attribute in morph targets 0 and 1 */
|
||
|
|
Containers::Array<Vector3> positions = data.positions3DAsArray(0, -1);
|
||
|
|
for(Int morphTargetId: {0, 1}) {
|
||
|
|
Containers::StridedArrayView1D<const Vector3> morphed =
|
||
|
|
data.attribute<Vector3>(Trade::MeshAttribute::Position, 0, morphTargetId);
|
||
|
|
for(std::size_t i = 0; i != data.vertexCount(); ++i)
|
||
|
|
positions[i] += morphed[i]*weights[morphTargetId];
|
||
|
|
}
|
||
|
|
/* [MeshData-usage-morph-targets] */
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
{
|
||
|
|
Trade::MeshData data{MeshPrimitive::Points, 0};
|
||
|
|
/* [MeshData-usage-special-layouts] */
|
||
|
|
if(data.attributeStride(Trade::MeshAttribute::Position) <= 0 ||
|
||
|
4 years ago
|
data.attributeStride(Trade::MeshAttribute::Normal) <= 0 ||
|
||
|
|
(data.isIndexed() && !data.indices().isContiguous()))
|
||
|
4 years ago
|
Fatal{} << "Uh oh";
|
||
|
|
|
||
|
4 years ago
|
// Now it's safe to use the Position and Normal attributes and the index buffer
|
||
|
|
// in a GPU mesh
|
||
|
4 years ago
|
/* [MeshData-usage-special-layouts] */
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
{
|
||
|
|
std::size_t vertexCount{}, indexCount{};
|
||
|
|
/* [MeshData-populating] */
|
||
|
|
struct Vertex {
|
||
|
|
Vector3 position;
|
||
|
|
Vector4 color;
|
||
|
|
};
|
||
|
|
|
||
|
|
Containers::Array<char> indexData{indexCount*sizeof(UnsignedShort)};
|
||
|
|
Containers::Array<char> vertexData{vertexCount*sizeof(Vertex)};
|
||
|
4 years ago
|
DOXYGEN_ELLIPSIS()
|
||
|
3 years ago
|
Containers::StridedArrayView1D<const Vertex> vertices =
|
||
|
|
Containers::arrayCast<const Vertex>(vertexData);
|
||
|
|
Containers::ArrayView<const UnsignedShort> indices =
|
||
|
|
Containers::arrayCast<const UnsignedShort>(indexData);
|
||
|
6 years ago
|
|
||
|
|
Trade::MeshData data{MeshPrimitive::Triangles,
|
||
|
|
std::move(indexData), Trade::MeshIndexData{indices},
|
||
|
|
std::move(vertexData), {
|
||
|
|
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
|
||
|
3 years ago
|
vertices.slice(&Vertex::position)},
|
||
|
6 years ago
|
Trade::MeshAttributeData{Trade::MeshAttribute::Color,
|
||
|
3 years ago
|
vertices.slice(&Vertex::color)}
|
||
|
6 years ago
|
}};
|
||
|
|
/* [MeshData-populating] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
struct Vertex {
|
||
|
|
Vector3 position;
|
||
|
|
Vector4 color;
|
||
|
|
};
|
||
|
|
/* [MeshData-populating-non-owned] */
|
||
|
3 years ago
|
const UnsignedShort indices[]{
|
||
|
|
DOXYGEN_ELLIPSIS(0)
|
||
|
|
};
|
||
|
|
Vertex vertices[]{
|
||
|
|
DOXYGEN_ELLIPSIS({})
|
||
|
6 years ago
|
};
|
||
|
|
|
||
|
|
Trade::MeshData data{MeshPrimitive::Triangles,
|
||
|
|
Trade::DataFlags{}, indices, Trade::MeshIndexData{indices},
|
||
|
|
Trade::DataFlag::Mutable, vertices, {
|
||
|
|
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
|
||
|
3 years ago
|
Containers::stridedArrayView(vertices).slice(&Vertex::position)},
|
||
|
6 years ago
|
Trade::MeshAttributeData{Trade::MeshAttribute::Color,
|
||
|
3 years ago
|
Containers::stridedArrayView(vertices).slice(&Vertex::color)}
|
||
|
6 years ago
|
}};
|
||
|
|
/* [MeshData-populating-non-owned] */
|
||
|
|
}
|
||
|
|
|
||
|
3 years ago
|
{
|
||
|
|
UnsignedInt vertexCount{};
|
||
|
|
/* [MeshData-populating-offset-only] */
|
||
|
|
struct Vertex {
|
||
|
|
Vector3 position;
|
||
|
|
Vector4 color;
|
||
|
|
};
|
||
|
|
|
||
|
|
/* Layout known in advance, except for vertex count */
|
||
|
|
constexpr Trade::MeshAttributeData attributes[]{
|
||
|
|
Trade::MeshAttributeData{Trade::MeshAttribute::Position,
|
||
|
|
VertexFormat::Vector3, offsetof(Vertex, position), 0, sizeof(Vertex)},
|
||
|
|
Trade::MeshAttributeData{Trade::MeshAttribute::Color,
|
||
|
|
VertexFormat::Vector4, offsetof(Vertex, color), 15, sizeof(Vertex)}
|
||
|
|
};
|
||
|
|
|
||
|
|
/* Actual data populated later */
|
||
|
|
Containers::Array<char> vertexData{vertexCount*sizeof(Vertex)};
|
||
|
|
DOXYGEN_ELLIPSIS()
|
||
|
|
|
||
|
|
/* Using the statically defined attribute layout together with explicitly
|
||
|
|
passed vertex count */
|
||
|
|
Trade::MeshData mesh{MeshPrimitive::Triangles, std::move(vertexData),
|
||
|
|
Trade::meshAttributeDataNonOwningArray(attributes), vertexCount};
|
||
|
|
/* [MeshData-populating-offset-only] */
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
{
|
||
|
|
/* [MeshData-populating-custom] */
|
||
|
|
/* Each face can consist of 15 triangles at most, triangleCount says how many
|
||
|
|
indices in triangleIds are valid */
|
||
|
|
struct Face {
|
||
|
|
UnsignedShort triangleIds[15];
|
||
|
|
UnsignedByte triangleCount;
|
||
|
|
};
|
||
|
|
|
||
|
|
constexpr Trade::MeshAttribute TriangleIds = Trade::meshAttributeCustom(0x01);
|
||
|
|
constexpr Trade::MeshAttribute TriangleCount = Trade::meshAttributeCustom(0x02);
|
||
|
|
|
||
|
|
Containers::Array<char> vertexData;
|
||
|
|
auto faces = Containers::arrayCast<const Face>(vertexData);
|
||
|
|
|
||
|
|
Trade::MeshData data{MeshPrimitive::Faces, std::move(vertexData), {
|
||
|
|
Trade::MeshAttributeData{TriangleIds,
|
||
|
|
Containers::StridedArrayView2D<const UnsignedShort>{faces,
|
||
|
|
&faces[0].triangleIds[0],
|
||
|
|
{faces.size(), 15},
|
||
|
|
{sizeof(Face), sizeof(UnsignedShort)}}},
|
||
|
|
Trade::MeshAttributeData{TriangleCount,
|
||
|
|
Containers::StridedArrayView1D<const UnsignedByte>{faces,
|
||
|
|
&faces[0].triangleCount, faces.size(), sizeof(Face)}}
|
||
|
|
}};
|
||
|
|
/* [MeshData-populating-custom] */
|
||
|
|
|
||
|
|
/* [MeshData-populating-custom-retrieve] */
|
||
|
|
Containers::StridedArrayView2D<const UnsignedShort> triangleIds =
|
||
|
|
data.attribute<UnsignedShort[]>(TriangleIds);
|
||
|
|
Containers::StridedArrayView1D<const UnsignedByte> triangleCounts =
|
||
|
|
data.attribute<UnsignedByte>(TriangleCount);
|
||
|
|
/* [MeshData-populating-custom-retrieve] */
|
||
|
|
static_cast<void>(triangleIds);
|
||
|
|
static_cast<void>(triangleCounts);
|
||
|
|
}
|
||
|
|
|
||
|
4 years ago
|
{
|
||
|
|
/* [MeshData-jointIdsAsArray] */
|
||
|
|
Trade::MeshData data = DOXYGEN_ELLIPSIS(Trade::MeshData{{}, 0});
|
||
|
|
|
||
|
|
Containers::Array<UnsignedInt> array = data.jointIdsAsArray();
|
||
|
|
Containers::StridedArrayView2D<UnsignedInt> array2D{array,
|
||
|
|
{data.vertexCount(), data.attributeArraySize(Trade::MeshAttribute::JointIds)}};
|
||
|
|
|
||
|
|
for(Containers::StridedArrayView1D<UnsignedInt> i: array2D) {
|
||
|
|
for(UnsignedInt j: i) {
|
||
|
|
DOXYGEN_IGNORE(static_cast<void>(j);)// do something with joint ID j in vertex i
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/* [MeshData-jointIdsAsArray] */
|
||
|
|
}
|
||
|
|
|
||
|
6 years ago
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
8 years ago
|
{
|
||
|
6 years ago
|
CORRADE_IGNORE_DEPRECATED_PUSH
|
||
|
8 years ago
|
Trade::MeshData2D& foo();
|
||
|
|
Trade::MeshData2D& data = foo();
|
||
|
|
/* [MeshData2D-transform] */
|
||
|
|
Matrix3 transformation =
|
||
|
|
Matrix3::translation({3.0f, -2.0f})*
|
||
|
|
Matrix3::scaling(Vector2{2.0f})*
|
||
|
|
Matrix3::rotation(45.0_degf);
|
||
|
|
MeshTools::transformPointsInPlace(transformation, data.positions(0));
|
||
|
|
/* [MeshData2D-transform] */
|
||
|
6 years ago
|
CORRADE_IGNORE_DEPRECATED_POP
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
|
{
|
||
|
5 years ago
|
CORRADE_IGNORE_DEPRECATED_PUSH
|
||
|
8 years ago
|
Trade::ObjectData2D& baz();
|
||
|
|
Trade::ObjectData2D& data = baz();
|
||
|
8 years ago
|
/* [ObjectData2D-transformation] */
|
||
|
|
Matrix3 transformation =
|
||
|
|
Matrix3::from(data.rotation().toMatrix(), data.translation())*
|
||
|
|
Matrix3::scaling(data.scaling());
|
||
|
|
/* [ObjectData2D-transformation] */
|
||
|
|
static_cast<void>(transformation);
|
||
|
5 years ago
|
CORRADE_IGNORE_DEPRECATED_POP
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
|
{
|
||
|
6 years ago
|
CORRADE_IGNORE_DEPRECATED_PUSH
|
||
|
8 years ago
|
Trade::MeshData3D& bar();
|
||
|
|
Trade::MeshData3D& data = bar();
|
||
|
|
/* [MeshData3D-transform] */
|
||
|
|
Matrix4 transformation =
|
||
|
|
Matrix4::translation({3.0f, 1.5f, -2.0f})*
|
||
|
|
Matrix4::rotationX(45.0_degf);
|
||
|
|
MeshTools::transformPointsInPlace(transformation, data.positions(0));
|
||
|
|
MeshTools::transformVectorsInPlace(transformation, data.normals(0));
|
||
|
|
/* [MeshData3D-transform] */
|
||
|
6 years ago
|
CORRADE_IGNORE_DEPRECATED_POP
|
||
|
8 years ago
|
}
|
||
|
|
|
||
|
|
{
|
||
|
5 years ago
|
CORRADE_IGNORE_DEPRECATED_PUSH
|
||
|
8 years ago
|
Trade::ObjectData3D& fizz();
|
||
|
|
Trade::ObjectData3D& data = fizz();
|
||
|
8 years ago
|
/* [ObjectData3D-transformation] */
|
||
|
|
Matrix4 transformation =
|
||
|
|
Matrix4::from(data.rotation().toMatrix(), data.translation())*
|
||
|
|
Matrix4::scaling(data.scaling());
|
||
|
|
/* [ObjectData3D-transformation] */
|
||
|
|
static_cast<void>(transformation);
|
||
|
5 years ago
|
CORRADE_IGNORE_DEPRECATED_POP
|
||
|
8 years ago
|
}
|
||
|
5 years ago
|
#endif
|
||
|
8 years ago
|
|
||
|
5 years ago
|
{
|
||
|
|
/* [SceneFieldData-usage] */
|
||
|
|
Containers::StridedArrayView1D<UnsignedInt> transformationMapping = DOXYGEN_ELLIPSIS({});
|
||
|
|
Containers::StridedArrayView1D<Matrix4> transformations = DOXYGEN_ELLIPSIS({});
|
||
|
|
|
||
|
|
Trade::SceneFieldData field{Trade::SceneField::Transformation,
|
||
|
|
transformationMapping, transformations};
|
||
|
|
/* [SceneFieldData-usage] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
3 years ago
|
std::size_t objectCount = 120;
|
||
|
5 years ago
|
/* [SceneFieldData-usage-offset-only] */
|
||
|
|
struct Node {
|
||
|
3 years ago
|
UnsignedInt mapping;
|
||
|
5 years ago
|
Int parent;
|
||
|
3 years ago
|
Matrix4 transformation;
|
||
|
5 years ago
|
};
|
||
|
|
|
||
|
3 years ago
|
Trade::SceneFieldData parents{Trade::SceneField::Parent, objectCount,
|
||
|
|
Trade::SceneMappingType::UnsignedInt, offsetof(Node, mapping), sizeof(Node),
|
||
|
5 years ago
|
Trade::SceneFieldType::Int, offsetof(Node, parent), sizeof(Node)};
|
||
|
3 years ago
|
Trade::SceneFieldData transformations{Trade::SceneField::Transformation, objectCount,
|
||
|
|
Trade::SceneMappingType::UnsignedInt, offsetof(Node, mapping), sizeof(Node),
|
||
|
|
Trade::SceneFieldType::Matrix4x4, offsetof(Node, transformation), sizeof(Node)};
|
||
|
5 years ago
|
/* [SceneFieldData-usage-offset-only] */
|
||
|
3 years ago
|
static_cast<void>(parents);
|
||
|
|
static_cast<void>(transformations);
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
3 years ago
|
{
|
||
|
|
/* [SceneFieldData-usage-strings] */
|
||
|
|
Containers::StridedArrayView1D<UnsignedInt> mapping = DOXYGEN_ELLIPSIS({});
|
||
|
|
Containers::StringView string = DOXYGEN_ELLIPSIS({});
|
||
|
|
Containers::StridedArrayView1D<Containers::Pair<UnsignedInt, UnsignedInt>> ranges = DOXYGEN_ELLIPSIS({});
|
||
|
|
|
||
|
|
Trade::SceneFieldData field{Trade::sceneFieldCustom(35), mapping,
|
||
|
|
string.data(), Trade::SceneFieldType::StringRange32, ranges};
|
||
|
|
/* [SceneFieldData-usage-strings] */
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
{
|
||
|
|
typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D> Scene3D;
|
||
|
|
typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D> Object3D;
|
||
|
|
/* [SceneData-usage1] */
|
||
|
|
Trade::SceneData data = DOXYGEN_ELLIPSIS(Trade::SceneData{{}, 0, nullptr, nullptr});
|
||
|
|
if(!data.is3D() ||
|
||
|
|
!data.hasField(Trade::SceneField::Parent) ||
|
||
|
|
!data.hasField(Trade::SceneField::Mesh))
|
||
|
|
Fatal{} << "Oh noes!";
|
||
|
|
|
||
|
|
Scene3D scene;
|
||
|
|
Containers::Array<Object3D*> objects{std::size_t(data.mappingBound())};
|
||
|
|
/* [SceneData-usage1] */
|
||
|
|
|
||
|
|
/* [SceneData-usage2] */
|
||
|
|
auto parents = data.parentsAsArray();
|
||
|
|
for(Containers::Pair<UnsignedInt, Int>& parent: parents)
|
||
|
|
objects[parent.first()] = new Object3D{};
|
||
|
|
/* [SceneData-usage2] */
|
||
|
|
|
||
|
|
/* [SceneData-usage3] */
|
||
|
|
for(Containers::Pair<UnsignedInt, Int>& parent: parents)
|
||
|
|
objects[parent.first()]->setParent(
|
||
|
|
parent.second() == -1 ? &scene : objects[parent.second()]
|
||
|
|
);
|
||
|
|
/* [SceneData-usage3] */
|
||
|
|
|
||
|
|
/* [SceneData-usage4] */
|
||
|
|
for(Containers::Pair<UnsignedInt, Matrix4>& transformation:
|
||
|
|
data.transformations3DAsArray())
|
||
|
|
{
|
||
|
|
if(Object3D* const object = objects[transformation.first()])
|
||
|
|
object->setTransformation(transformation.second());
|
||
|
|
}
|
||
|
|
/* [SceneData-usage4] */
|
||
|
|
|
||
|
|
/* [SceneData-usage5] */
|
||
|
|
class Drawable: public SceneGraph::Drawable3D {
|
||
|
|
public:
|
||
|
|
explicit Drawable(Object3D& object, UnsignedInt mesh, Int material, DOXYGEN_ELLIPSIS(int))DOXYGEN_IGNORE(: SceneGraph::Drawable3D{object} {
|
||
|
|
static_cast<void>(mesh);
|
||
|
|
static_cast<void>(material);
|
||
|
|
} int foo);
|
||
|
|
|
||
|
|
DOXYGEN_ELLIPSIS(void draw(const Matrix4&, SceneGraph::Camera3D&) override {})
|
||
|
|
};
|
||
|
|
|
||
|
|
for(const Containers::Pair<UnsignedInt, Containers::Pair<UnsignedInt, Int>>&
|
||
|
|
meshMaterial: data.meshesMaterialsAsArray())
|
||
|
|
{
|
||
|
|
if(Object3D* const object = objects[meshMaterial.first()])
|
||
|
|
new Drawable{*object, meshMaterial.second().first(),
|
||
|
|
meshMaterial.second().second(), DOXYGEN_ELLIPSIS(0)};
|
||
|
|
}
|
||
|
|
/* [SceneData-usage5] */
|
||
|
|
|
||
|
|
/* [SceneData-usage-advanced] */
|
||
|
|
Containers::StridedArrayView1D<const UnsignedInt> transformationMapping =
|
||
|
|
data.mapping<UnsignedInt>(Trade::SceneField::Transformation);
|
||
|
|
Containers::StridedArrayView1D<const Matrix4> transformations =
|
||
|
|
data.field<Matrix4>(Trade::SceneField::Transformation);
|
||
|
|
for(std::size_t i = 0; i != transformationMapping.size(); ++i) {
|
||
|
|
if(Object3D* const object = objects[transformationMapping[i]])
|
||
|
|
object->setTransformation(transformations[i]);
|
||
|
|
}
|
||
|
|
/* [SceneData-usage-advanced] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Trade::SceneData data{{}, 0, nullptr, nullptr};
|
||
|
|
/* [SceneData-per-object] */
|
||
|
|
Containers::Pointer<Trade::AbstractImporter> importer = DOXYGEN_ELLIPSIS({});
|
||
|
|
|
||
|
|
for(const Containers::Pair<UnsignedInt, Int>& meshMaterial:
|
||
|
|
data.meshesMaterialsFor(importer->objectForName("Chair")))
|
||
|
|
{
|
||
|
|
Debug{} << "Mesh:" << importer->meshName(meshMaterial.first());
|
||
|
|
if(meshMaterial.second() != -1)
|
||
|
|
Debug{} << "With a material:" << importer->materialName(meshMaterial.second());
|
||
|
|
}
|
||
|
|
/* [SceneData-per-object] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
Trade::SceneData data{{}, 0, nullptr, nullptr};
|
||
|
|
typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D> Object3D;
|
||
|
|
Containers::Array<Object3D*> objects;
|
||
|
|
/* [SceneData-usage-mutable] */
|
||
|
|
Containers::StridedArrayView1D<const UnsignedInt> transformationMapping =
|
||
|
|
data.mapping<UnsignedInt>(Trade::SceneField::Transformation);
|
||
|
|
Containers::StridedArrayView1D<Matrix4> mutableTransformations =
|
||
|
|
data.mutableField<Matrix4>(Trade::SceneField::Transformation);
|
||
|
|
for(std::size_t i = 0; i != transformationMapping.size(); ++i) {
|
||
|
|
if(Object3D* const object = objects[transformationMapping[i]])
|
||
|
|
mutableTransformations[i] = object->transformation();
|
||
|
|
}
|
||
|
|
/* [SceneData-usage-mutable] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
const std::size_t nodeCount{}, meshAssignmentCount{};
|
||
|
|
/* [SceneData-populating] */
|
||
|
|
struct Common {
|
||
|
3 years ago
|
UnsignedShort mapping;
|
||
|
5 years ago
|
Short parent;
|
||
|
|
Matrix4 transformation;
|
||
|
|
};
|
||
|
|
|
||
|
|
Containers::StridedArrayView1D<Common> common;
|
||
|
|
Containers::ArrayView<UnsignedShort> meshMaterialMapping;
|
||
|
|
Containers::ArrayView<UnsignedShort> meshes;
|
||
|
|
Containers::ArrayView<UnsignedShort> meshMaterials;
|
||
|
|
Containers::Array<char> data = Containers::ArrayTuple{
|
||
|
|
{nodeCount, common},
|
||
|
|
{meshAssignmentCount, meshMaterialMapping},
|
||
|
|
{meshAssignmentCount, meshes},
|
||
|
|
{meshAssignmentCount, meshMaterials}
|
||
|
|
};
|
||
|
|
|
||
|
|
// populate the views ...
|
||
|
|
|
||
|
|
Trade::SceneData scene{
|
||
|
|
Trade::SceneMappingType::UnsignedShort, nodeCount,
|
||
|
|
std::move(data), {
|
||
|
|
Trade::SceneFieldData{Trade::SceneField::Parent,
|
||
|
3 years ago
|
common.slice(&Common::mapping),
|
||
|
|
common.slice(&Common::parent)},
|
||
|
5 years ago
|
Trade::SceneFieldData{Trade::SceneField::Transformation,
|
||
|
3 years ago
|
common.slice(&Common::mapping), common.slice(&Common::transformation)},
|
||
|
5 years ago
|
Trade::SceneFieldData{Trade::SceneField::Mesh,
|
||
|
3 years ago
|
meshMaterialMapping,
|
||
|
|
meshes},
|
||
|
5 years ago
|
Trade::SceneFieldData{Trade::SceneField::MeshMaterial,
|
||
|
3 years ago
|
meshMaterialMapping,
|
||
|
|
meshMaterials}
|
||
|
5 years ago
|
}};
|
||
|
|
/* [SceneData-populating] */
|
||
|
|
}
|
||
|
|
|
||
|
3 years ago
|
{
|
||
|
|
constexpr std::size_t objectCount = 1;
|
||
|
|
/* [SceneData-populating-non-owned] */
|
||
|
|
constexpr struct Data {
|
||
|
|
UnsignedShort mapping;
|
||
|
|
Short parent;
|
||
|
|
Matrix4 transformation;
|
||
|
|
} data[objectCount]{
|
||
|
|
DOXYGEN_ELLIPSIS({})
|
||
|
|
};
|
||
|
|
|
||
|
|
Trade::SceneData scene{
|
||
|
|
Trade::SceneMappingType::UnsignedShort, objectCount,
|
||
|
|
Trade::DataFlag::Global, data, {
|
||
|
|
Trade::SceneFieldData{Trade::SceneField::Parent,
|
||
|
|
Containers::stridedArrayView(data).slice(&Data::mapping),
|
||
|
|
Containers::stridedArrayView(data).slice(&Data::parent)},
|
||
|
|
DOXYGEN_ELLIPSIS()
|
||
|
|
}};
|
||
|
|
/* [SceneData-populating-non-owned] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
constexpr std::size_t objectCount = 1;
|
||
|
|
/* [SceneData-populating-offset-only] */
|
||
|
|
struct Data {
|
||
|
|
UnsignedInt mapping;
|
||
|
|
Int parent;
|
||
|
|
Matrix4 transformation;
|
||
|
|
};
|
||
|
|
|
||
|
|
/* Layout defined statically */
|
||
|
|
constexpr Trade::SceneFieldData fields[]{
|
||
|
|
Trade::SceneFieldData{Trade::SceneField::Parent, objectCount,
|
||
|
|
Trade::SceneMappingType::UnsignedInt, offsetof(Data, mapping), sizeof(Data),
|
||
|
|
Trade::SceneFieldType::Int, offsetof(Data, parent), sizeof(Data)},
|
||
|
|
Trade::SceneFieldData{Trade::SceneField::Transformation, objectCount,
|
||
|
|
Trade::SceneMappingType::UnsignedInt, offsetof(Data, mapping), sizeof(Data),
|
||
|
|
Trade::SceneFieldType::Matrix4x4, offsetof(Data, transformation), sizeof(Data)}
|
||
|
|
};
|
||
|
|
|
||
|
|
/* Actual data populated later */
|
||
|
|
Containers::Array<char> data{objectCount*sizeof(Data)};
|
||
|
|
DOXYGEN_ELLIPSIS()
|
||
|
|
|
||
|
|
/* Using the statically defined field layout */
|
||
|
|
Trade::SceneData scene{Trade::SceneMappingType::UnsignedInt, objectCount,
|
||
|
|
std::move(data), Trade::sceneFieldDataNonOwningArray(fields)};
|
||
|
|
/* [SceneData-populating-offset-only] */
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
{
|
||
|
|
std::size_t nodeCount{};
|
||
|
|
/* [SceneData-populating-custom1] */
|
||
|
|
DOXYGEN_ELLIPSIS()
|
||
|
|
Containers::ArrayView<UnsignedShort> cellMapping;
|
||
|
|
Containers::ArrayView<Matrix4> cellFrustums;
|
||
|
|
Containers::StridedArrayView2D<Int> cellLights;
|
||
|
|
Containers::Array<char> data = Containers::ArrayTuple{
|
||
|
|
DOXYGEN_ELLIPSIS()
|
||
|
|
{32*24, cellMapping},
|
||
|
|
{32*24, cellFrustums},
|
||
|
|
{{32*24, 8}, cellLights},
|
||
|
|
};
|
||
|
|
|
||
|
|
for(std::size_t i = 0; i != cellMapping.size(); ++i) {
|
||
|
|
cellMapping[i] = nodeCount + i;
|
||
|
|
cellFrustums[i] = DOXYGEN_ELLIPSIS({});
|
||
|
|
for(std::size_t j = 0; j != cellLights[i].size(); ++j)
|
||
|
|
cellLights[i][j] = DOXYGEN_ELLIPSIS({});
|
||
|
|
}
|
||
|
|
/* [SceneData-populating-custom1] */
|
||
|
|
|
||
|
|
/* [SceneData-populating-custom2] */
|
||
|
3 years ago
|
constexpr Trade::SceneField SceneFieldCellFrustum = Trade::sceneFieldCustom(0);
|
||
|
|
constexpr Trade::SceneField SceneFieldCellLights = Trade::sceneFieldCustom(1);
|
||
|
5 years ago
|
|
||
|
|
Trade::SceneData scene{
|
||
|
|
Trade::SceneMappingType::UnsignedShort, nodeCount + cellMapping.size(),
|
||
|
|
std::move(data), {
|
||
|
|
DOXYGEN_ELLIPSIS()
|
||
|
3 years ago
|
Trade::SceneFieldData{SceneFieldCellFrustum, cellMapping, cellFrustums},
|
||
|
|
Trade::SceneFieldData{SceneFieldCellLights, cellMapping, cellLights},
|
||
|
5 years ago
|
}};
|
||
|
|
/* [SceneData-populating-custom2] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
3 years ago
|
constexpr Trade::SceneField SceneFieldCellFrustum = Trade::sceneFieldCustom(0);
|
||
|
|
constexpr Trade::SceneField SceneFieldCellLights = Trade::sceneFieldCustom(1);
|
||
|
5 years ago
|
Trade::SceneData scene{{}, 0, nullptr, nullptr};
|
||
|
|
/* [SceneData-populating-custom-retrieve] */
|
||
|
|
Containers::StridedArrayView1D<const Matrix4> cellFrustums =
|
||
|
3 years ago
|
scene.field<Matrix4>(SceneFieldCellFrustum);
|
||
|
5 years ago
|
Containers::StridedArrayView2D<const Int> cellLights =
|
||
|
3 years ago
|
scene.field<Int[]>(SceneFieldCellLights);
|
||
|
5 years ago
|
/* [SceneData-populating-custom-retrieve] */
|
||
|
|
static_cast<void>(cellFrustums);
|
||
|
|
static_cast<void>(cellLights);
|
||
|
|
}
|
||
|
|
|
||
|
3 years ago
|
{
|
||
|
|
using namespace Containers::Literals;
|
||
|
|
/* [SceneData-populating-strings] */
|
||
|
|
constexpr Containers::StringView CategoryStrings =
|
||
|
|
"wall\0furniture\0lighting\0artwork"_s;
|
||
|
|
constexpr UnsignedByte CategoryWall = 0;
|
||
|
|
constexpr UnsignedByte CategoryFurniture = 5;
|
||
|
|
constexpr UnsignedByte CategoryLighting = 15;
|
||
|
|
constexpr UnsignedByte CategoryArtwork = 24;
|
||
|
|
|
||
|
|
Containers::MutableStringView categoryStrings;
|
||
|
|
Containers::ArrayView<UnsignedInt> mapping;
|
||
|
|
Containers::ArrayView<UnsignedByte> categories;
|
||
|
|
Containers::ArrayTuple data{
|
||
|
|
{CategoryStrings.size(), categoryStrings},
|
||
|
|
{DOXYGEN_ELLIPSIS(5), mapping},
|
||
|
|
{DOXYGEN_ELLIPSIS(5), categories},
|
||
|
|
};
|
||
|
|
|
||
|
|
Utility::copy(CategoryStrings, categoryStrings);
|
||
|
|
mapping[0] = 7;
|
||
|
|
categories[0] = CategoryWall;
|
||
|
|
mapping[1] = 19;
|
||
|
|
categories[1] = CategoryFurniture;
|
||
|
|
DOXYGEN_ELLIPSIS(static_cast<void>(CategoryLighting); static_cast<void>(CategoryArtwork);)
|
||
|
|
|
||
|
|
constexpr Trade::SceneField SceneFieldCategory = Trade::sceneFieldCustom(25);
|
||
|
|
Trade::SceneData scene{Trade::SceneMappingType::UnsignedInt, DOXYGEN_ELLIPSIS(5), std::move(data), {
|
||
|
|
Trade::SceneFieldData{SceneFieldCategory, mapping,
|
||
|
|
categoryStrings.data(), Trade::SceneFieldType::StringRangeNullTerminated8,
|
||
|
|
categories}
|
||
|
|
}};
|
||
|
|
/* [SceneData-populating-strings] */
|
||
|
|
}
|
||
|
|
|
||
|
|
{
|
||
|
|
constexpr Trade::SceneField SceneFieldCategory = Trade::sceneFieldCustom(25);
|
||
|
|
Trade::SceneData scene{{}, 0, nullptr, nullptr};
|
||
|
|
/* [SceneData-populating-strings-retrieve] */
|
||
|
|
Containers::StringIterable categories = scene.fieldStrings(SceneFieldCategory);
|
||
|
|
|
||
|
|
// Prints "furniture"
|
||
|
|
Debug{} << categories[scene.fieldObjectOffset(SceneFieldCategory, 19)];
|
||
|
|
/* [SceneData-populating-strings-retrieve] */
|
||
|
|
}
|
||
|
|
|
||
|
8 years ago
|
}
|