update headers to Filament v1.25.0
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
#include <gltfio/FilamentInstance.h>
|
||||
|
||||
namespace gltfio {
|
||||
namespace filament::gltfio {
|
||||
|
||||
struct FFilamentAsset;
|
||||
struct FFilamentInstance;
|
||||
@@ -56,6 +56,32 @@ public:
|
||||
*/
|
||||
void updateBoneMatrices();
|
||||
|
||||
/**
|
||||
* Applies a blended transform to the union of nodes affected by two animations.
|
||||
* Used for cross-fading from a previous skinning-based animation or rigid body animation.
|
||||
*
|
||||
* First, this stashes the current transform hierarchy into a transient memory buffer.
|
||||
*
|
||||
* Next, this applies previousAnimIndex / previousAnimTime to the actual asset by internally
|
||||
* calling applyAnimation().
|
||||
*
|
||||
* Finally, the stashed local transforms are lerped (via the scale / translation / rotation
|
||||
* components) with their live counterparts, and the results are pushed to the asset.
|
||||
*
|
||||
* To achieve a cross fade effect with skinned models, clients will typically call animator
|
||||
* methods in this order: (1) applyAnimation (2) applyCrossFade (3) updateBoneMatrices. The
|
||||
* animation that clients pass to applyAnimation is the "current" animation corresponding to
|
||||
* alpha=1, while the "previous" animation passed to applyCrossFade corresponds to alpha=0.
|
||||
*/
|
||||
void applyCrossFade(size_t previousAnimIndex, float previousAnimTime, float alpha);
|
||||
|
||||
/**
|
||||
* Pass the identity matrix into all bone nodes, useful for returning to the T pose.
|
||||
*
|
||||
* NOTE: this operation is independent of \c animation.
|
||||
*/
|
||||
void resetBoneMatrices();
|
||||
|
||||
/** Returns the number of \c animation definitions in the glTF asset. */
|
||||
size_t getAnimationCount() const;
|
||||
|
||||
@@ -88,6 +114,6 @@ private:
|
||||
AnimatorImpl* mImpl;
|
||||
};
|
||||
|
||||
} // namespace gltfio
|
||||
} // namespace filament::gltfio
|
||||
|
||||
#endif // GLTFIO_ANIMATOR_H
|
||||
|
||||
@@ -34,7 +34,9 @@ namespace utils {
|
||||
/**
|
||||
* Loader and pipeline for glTF 2.0 assets.
|
||||
*/
|
||||
namespace gltfio {
|
||||
namespace filament::gltfio {
|
||||
|
||||
class NodeManager;
|
||||
|
||||
/**
|
||||
* \struct AssetConfiguration AssetLoader.h gltfio/AssetLoader.h
|
||||
@@ -47,7 +49,7 @@ struct AssetConfiguration {
|
||||
|
||||
//! Controls whether the loader uses filamat to generate materials on the fly, or loads a small
|
||||
//! set of precompiled ubershader materials. Deleting the MaterialProvider is the client's
|
||||
//! responsibility. See createMaterialGenerator() and createUbershaderLoader().
|
||||
//! responsibility. See createJitShaderProvider() and createUbershaderProvider().
|
||||
MaterialProvider* materials;
|
||||
|
||||
//! Optional manager for associating string names with entities in the transform hierarchy.
|
||||
@@ -70,7 +72,8 @@ struct AssetConfiguration {
|
||||
* object, which is a bundle of Filament entities, material instances, textures, vertex buffers,
|
||||
* and index buffers.
|
||||
*
|
||||
* Clients must use AssetLoader to create and destroy FilamentAsset objects.
|
||||
* Clients must use AssetLoader to create and destroy FilamentAsset objects. This is similar to
|
||||
* how filament::Engine is used to create and destroy core objects like VertexBuffer.
|
||||
*
|
||||
* AssetLoader does not fetch external buffer data or create textures on its own. Clients can use
|
||||
* ResourceLoader for this, which obtains the URI list from the asset. This is demonstrated in the
|
||||
@@ -83,7 +86,8 @@ struct AssetConfiguration {
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* auto engine = Engine::create();
|
||||
* auto materials = createMaterialGenerator(engine);
|
||||
* auto materials = createJitShaderProvider(engine);
|
||||
* auto decoder = createStbProvider(engine);
|
||||
* auto loader = AssetLoader::create({engine, materials});
|
||||
*
|
||||
* // Parse the glTF content and create Filament entities.
|
||||
@@ -92,7 +96,10 @@ struct AssetConfiguration {
|
||||
* content.clear();
|
||||
*
|
||||
* // Load buffers and textures from disk.
|
||||
* ResourceLoader({engine, ".", true}).loadResources(asset);
|
||||
* ResourceLoader resourceLoader({engine, ".", true});
|
||||
* resourceLoader.addTextureProvider("image/png", decoder)
|
||||
* resourceLoader.addTextureProvider("image/jpeg", decoder)
|
||||
* resourceLoader.loadResources(asset);
|
||||
*
|
||||
* // Free the glTF hierarchy as it is no longer needed.
|
||||
* asset->releaseSourceData();
|
||||
@@ -114,6 +121,7 @@ struct AssetConfiguration {
|
||||
* loader->destroyAsset(asset);
|
||||
* materials->destroyMaterials();
|
||||
* delete materials;
|
||||
* delete decoder;
|
||||
* AssetLoader::destroy(&loader);
|
||||
* Engine::destroy(&engine);
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -221,7 +229,9 @@ public:
|
||||
|
||||
utils::NameComponentManager* getNames() const noexcept;
|
||||
|
||||
MaterialProvider* getMaterialProvider() const noexcept;
|
||||
NodeManager& getNodeManager() noexcept;
|
||||
|
||||
MaterialProvider& getMaterialProvider() noexcept;
|
||||
|
||||
/*! \cond PRIVATE */
|
||||
protected:
|
||||
@@ -236,6 +246,6 @@ public:
|
||||
/*! \endcond */
|
||||
};
|
||||
|
||||
} // namespace gltfio
|
||||
} // namespace filament::gltfio
|
||||
|
||||
#endif // GLTFIO_ASSETLOADER_H
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include <filament/Box.h>
|
||||
#include <filament/TextureSampler.h>
|
||||
|
||||
#include <gltfio/NodeManager.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Entity.h>
|
||||
|
||||
@@ -27,9 +29,10 @@ namespace filament {
|
||||
class Camera;
|
||||
class Engine;
|
||||
class MaterialInstance;
|
||||
class Scene;
|
||||
}
|
||||
|
||||
namespace gltfio {
|
||||
namespace filament::gltfio {
|
||||
|
||||
class Animator;
|
||||
class FilamentInstance;
|
||||
@@ -42,7 +45,7 @@ class FilamentInstance;
|
||||
*
|
||||
* This class owns a hierarchy of entities that have been loaded from a glTF asset. Every entity has
|
||||
* a filament::TransformManager component, and some entities also have \c Name, \c Renderable,
|
||||
* \c Light, or \c Camera components.
|
||||
* \c Light, \c Camera, or \c Node components.
|
||||
*
|
||||
* In addition to the aforementioned entities, an asset has strong ownership over a list of
|
||||
* filament::VertexBuffer, filament::IndexBuffer, filament::MaterialInstance, filament::Texture,
|
||||
@@ -55,12 +58,14 @@ class FilamentInstance;
|
||||
*/
|
||||
class UTILS_PUBLIC FilamentAsset {
|
||||
public:
|
||||
using Entity = utils::Entity;
|
||||
using SceneMask = NodeManager::SceneMask;
|
||||
|
||||
/**
|
||||
* Gets the list of entities, one for each glTF node. All of these have a Transform component.
|
||||
* Some of the returned entities may also have a Renderable component and/or a Light component.
|
||||
*/
|
||||
const utils::Entity* getEntities() const noexcept;
|
||||
const Entity* getEntities() const noexcept;
|
||||
|
||||
/**
|
||||
* Gets the number of entities returned by getEntities().
|
||||
@@ -70,13 +75,23 @@ public:
|
||||
/**
|
||||
* Gets the list of entities in the scene representing lights. All of these have a Light component.
|
||||
*/
|
||||
const utils::Entity* getLightEntities() const noexcept;
|
||||
const Entity* getLightEntities() const noexcept;
|
||||
|
||||
/**
|
||||
* Gets the number of entities returned by getLightEntities().
|
||||
*/
|
||||
size_t getLightEntityCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Gets the list of entities in the asset that have renderable components.
|
||||
*/
|
||||
const utils::Entity* getRenderableEntities() const noexcept;
|
||||
|
||||
/**
|
||||
* Gets the number of entities returned by getRenderableEntities().
|
||||
*/
|
||||
size_t getRenderableEntityCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Gets the list of entities in the scene representing cameras. All of these have a \c Camera
|
||||
* component.
|
||||
@@ -95,7 +110,7 @@ public:
|
||||
*
|
||||
* @see filament::Camera::setScaling
|
||||
*/
|
||||
const utils::Entity* getCameraEntities() const noexcept;
|
||||
const Entity* getCameraEntities() const noexcept;
|
||||
|
||||
/**
|
||||
* Gets the number of entities returned by getCameraEntities().
|
||||
@@ -109,7 +124,7 @@ public:
|
||||
* assets, this is a "super root" where each of its children is a root in a particular instance.
|
||||
* This allows users to transform all instances en masse if they wish to do so.
|
||||
*/
|
||||
utils::Entity getRoot() const noexcept;
|
||||
Entity getRoot() const noexcept;
|
||||
|
||||
/**
|
||||
* Pops a ready renderable off the queue, or returns 0 if no renderables have become ready.
|
||||
@@ -122,12 +137,12 @@ public:
|
||||
* textures gradually become ready through asynchronous loading. For example, on every frame
|
||||
* progressive applications can do something like this:
|
||||
*
|
||||
* while (utils::Entity e = popRenderable()) { scene.addEntity(e); }
|
||||
* while (Entity e = popRenderable()) { scene.addEntity(e); }
|
||||
*
|
||||
* \see ResourceLoader#asyncBeginLoad
|
||||
* \see popRenderables()
|
||||
*/
|
||||
utils::Entity popRenderable() noexcept;
|
||||
Entity popRenderable() noexcept;
|
||||
|
||||
/**
|
||||
* Pops up to "count" ready renderables off the queue, or returns the available number.
|
||||
@@ -138,7 +153,7 @@ public:
|
||||
*
|
||||
* \see ResourceLoader#asyncBeginLoad
|
||||
*/
|
||||
size_t popRenderables(utils::Entity* entities, size_t count) noexcept;
|
||||
size_t popRenderables(Entity* entities, size_t count) noexcept;
|
||||
|
||||
/** Gets all material instances. These are already bound to renderables. */
|
||||
const filament::MaterialInstance* const* getMaterialInstances() const noexcept;
|
||||
@@ -159,10 +174,10 @@ public:
|
||||
filament::Aabb getBoundingBox() const noexcept;
|
||||
|
||||
/** Gets the NameComponentManager label for the given entity, if it exists. */
|
||||
const char* getName(utils::Entity) const noexcept;
|
||||
const char* getName(Entity) const noexcept;
|
||||
|
||||
/** Returns the first entity with the given name, or 0 if none exist. */
|
||||
utils::Entity getFirstEntityByName(const char* name) noexcept;
|
||||
Entity getFirstEntityByName(const char* name) noexcept;
|
||||
|
||||
/**
|
||||
* Gets a list of entities with the given name.
|
||||
@@ -174,7 +189,7 @@ public:
|
||||
* @return If entities is non-null, the number of entities written to the entity pointer.
|
||||
* Otherwise this returns the number of entities with the given name.
|
||||
*/
|
||||
size_t getEntitiesByName(const char* name, utils::Entity* entities,
|
||||
size_t getEntitiesByName(const char* name, Entity* entities,
|
||||
size_t maxCount) const noexcept;
|
||||
|
||||
/**
|
||||
@@ -187,11 +202,11 @@ public:
|
||||
* @return If entities is non-null, the number of entities written to the entity pointer.
|
||||
* Otherwise this returns the number of entities with the given prefix.
|
||||
*/
|
||||
size_t getEntitiesByPrefix(const char* prefix, utils::Entity* entities,
|
||||
size_t getEntitiesByPrefix(const char* prefix, Entity* entities,
|
||||
size_t maxCount) const noexcept;
|
||||
|
||||
/** Gets the glTF extras string for a specific node, or for the asset, if it exists. */
|
||||
const char* getExtras(utils::Entity entity = {}) const noexcept;
|
||||
const char* getExtras(Entity entity = {}) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the animation engine.
|
||||
@@ -221,17 +236,32 @@ public:
|
||||
/**
|
||||
* Gets joints at skin index.
|
||||
*/
|
||||
const utils::Entity* getJointsAt(size_t skinIndex) const noexcept;
|
||||
const Entity* getJointsAt(size_t skinIndex) const noexcept;
|
||||
|
||||
/**
|
||||
* Attaches the given skin to the given node, which must have an associated mesh with
|
||||
* BONE_INDICES and BONE_WEIGHTS attributes.
|
||||
*
|
||||
* This is a no-op if the given skin index or target is invalid.
|
||||
*/
|
||||
void attachSkin(size_t skinIndex, Entity target) noexcept;
|
||||
|
||||
/**
|
||||
* Detaches the given skin from the given node.
|
||||
*
|
||||
* This is a no-op if the given skin index or target is invalid.
|
||||
*/
|
||||
void detachSkin(size_t skinIndex, Entity target) noexcept;
|
||||
|
||||
/**
|
||||
* Gets the morph target name at the given index in the given entity.
|
||||
*/
|
||||
const char* getMorphTargetNameAt(utils::Entity entity, size_t targetIndex) const noexcept;
|
||||
const char* getMorphTargetNameAt(Entity entity, size_t targetIndex) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the number of morph targets in the given entity.
|
||||
*/
|
||||
size_t getMorphTargetCountAt(utils::Entity entity) const noexcept;
|
||||
size_t getMorphTargetCountAt(Entity entity) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the number of material variants in the asset.
|
||||
@@ -261,7 +291,7 @@ public:
|
||||
* Lazily creates a single LINES renderable that draws the transformed bounding-box hierarchy
|
||||
* for diagnostic purposes. The wireframe is owned by the asset so clients should not delete it.
|
||||
*/
|
||||
utils::Entity getWireframe() noexcept;
|
||||
Entity getWireframe() noexcept;
|
||||
|
||||
/**
|
||||
* Returns the Filament engine associated with the AssetLoader that created this asset.
|
||||
@@ -282,6 +312,28 @@ public:
|
||||
*/
|
||||
const void* getSourceAsset() noexcept;
|
||||
|
||||
/**
|
||||
* Returns the number of scenes in the asset.
|
||||
*/
|
||||
size_t getSceneCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the name of the given scene.
|
||||
*
|
||||
* Returns null if the given scene does not have a name or is out of bounds.
|
||||
*/
|
||||
const char* getSceneName(size_t sceneIndex) const noexcept;
|
||||
|
||||
/**
|
||||
* Adds entities to a Filament scene only if they belong to at least one of the given glTF
|
||||
* scenes.
|
||||
*
|
||||
* This is just a helper that provides an alternative to directly calling scene->addEntities()
|
||||
* and provides filtering functionality.
|
||||
*/
|
||||
void addEntitiesToScene(filament::Scene& targetScene, const Entity* entities, size_t count,
|
||||
SceneMask sceneFilter);
|
||||
|
||||
/*! \cond PRIVATE */
|
||||
|
||||
FilamentInstance** getAssetInstances() noexcept;
|
||||
@@ -299,6 +351,6 @@ public:
|
||||
/*! \endcond */
|
||||
};
|
||||
|
||||
} // namespace gltfio
|
||||
} // namespace filament::gltfio
|
||||
|
||||
#endif // GLTFIO_FILAMENTASSET_H
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/Entity.h>
|
||||
|
||||
namespace gltfio {
|
||||
namespace filament::gltfio {
|
||||
|
||||
class Animator;
|
||||
class FilamentAsset;
|
||||
@@ -76,6 +76,6 @@ public:
|
||||
Animator* getAnimator() noexcept;
|
||||
};
|
||||
|
||||
} // namespace gltfio
|
||||
} // namespace filament::gltfio
|
||||
|
||||
#endif // GLTFIO_FILAMENTINSTANCE_H
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
namespace gltfio {
|
||||
namespace filament::gltfio {
|
||||
|
||||
enum class AlphaMode : uint8_t {
|
||||
OPAQUE,
|
||||
@@ -118,12 +118,12 @@ inline uint8_t getNumUvSets(const UvMap& uvmap) {
|
||||
* \class MaterialProvider MaterialProvider.h gltfio/MaterialProvider.h
|
||||
* \brief Interface to a provider of glTF materials (has two implementations).
|
||||
*
|
||||
* - The \c MaterialGenerator implementation generates materials at run time (which can be slow) and
|
||||
* requires the filamat library, but produces streamlined shaders. See createMaterialGenerator().
|
||||
* - The \c JitShaderProvider implementation generates materials at run time (which can be slow) and
|
||||
* requires the filamat library, but produces streamlined shaders. See createJitShaderProvider().
|
||||
*
|
||||
* - The \c UbershaderLoader implementation uses a small number of pre-built materials with complex
|
||||
* - The \c UbershaderProvider implementation uses a small number of pre-built materials with complex
|
||||
* fragment shaders, but does not require any run time work or usage of filamat. See
|
||||
* createUbershaderLoader().
|
||||
* createUbershaderProvider().
|
||||
*
|
||||
* Both implementations of MaterialProvider maintain a small cache of materials which must be
|
||||
* explicitly freed using destroyMaterials(). These materials are not freed automatically when the
|
||||
@@ -186,23 +186,22 @@ void processShaderString(std::string* shader, const UvMap& uvmap,
|
||||
*
|
||||
* Requires \c libfilamat to be linked in. Not available in \c libgltfio_core.
|
||||
*
|
||||
* @see createUbershaderLoader
|
||||
* @see createUbershaderProvider
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
MaterialProvider* createMaterialGenerator(filament::Engine* engine, bool optimizeShaders = false);
|
||||
MaterialProvider* createJitShaderProvider(filament::Engine* engine, bool optimizeShaders = false);
|
||||
|
||||
/**
|
||||
* Creates a material provider that loads a small set of pre-built materials.
|
||||
*
|
||||
* @return New material provider that can quickly load a material from a cache.
|
||||
*
|
||||
* Requires \c libgltfio_resources to be linked in.
|
||||
*
|
||||
* @see createMaterialGenerator
|
||||
* @see createJitShaderProvider
|
||||
*/
|
||||
UTILS_PUBLIC
|
||||
MaterialProvider* createUbershaderLoader(filament::Engine* engine);
|
||||
MaterialProvider* createUbershaderProvider(filament::Engine* engine, const void* archive,
|
||||
size_t archiveByteCount);
|
||||
|
||||
} // namespace gltfio
|
||||
} // namespace filament::gltfio
|
||||
|
||||
#endif // GLTFIO_MATERIALPROVIDER_H
|
||||
|
||||
110
ios/include/gltfio/NodeManager.h
Normal file
110
ios/include/gltfio/NodeManager.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GLTFIO_NODEMANAGER_H
|
||||
#define GLTFIO_NODEMANAGER_H
|
||||
|
||||
#include <filament/FilamentAPI.h>
|
||||
|
||||
#include <utils/bitset.h>
|
||||
#include <utils/compiler.h>
|
||||
#include <utils/CString.h>
|
||||
#include <utils/EntityInstance.h>
|
||||
#include <utils/FixedCapacityVector.h>
|
||||
|
||||
namespace utils {
|
||||
class Entity;
|
||||
} // namespace utils
|
||||
|
||||
namespace filament::gltfio {
|
||||
|
||||
class FNodeManager;
|
||||
|
||||
/**
|
||||
* NodeManager is used to add annotate entities with glTF-specific information.
|
||||
*
|
||||
* Node components are created by gltfio and exposed to users to allow inspection.
|
||||
*
|
||||
* Nodes do not store the glTF hierarchy or names; see TransformManager and NameComponentManager.
|
||||
*/
|
||||
class UTILS_PUBLIC NodeManager {
|
||||
public:
|
||||
using Instance = utils::EntityInstance<NodeManager>;
|
||||
using Entity = utils::Entity;
|
||||
using CString = utils::CString;
|
||||
using SceneMask = utils::bitset32;
|
||||
|
||||
static constexpr size_t MAX_SCENE_COUNT = 32;
|
||||
|
||||
/**
|
||||
* Returns whether a particular Entity is associated with a component of this NodeManager
|
||||
* @param e An Entity.
|
||||
* @return true if this Entity has a component associated with this manager.
|
||||
*/
|
||||
bool hasComponent(Entity e) const noexcept;
|
||||
|
||||
/**
|
||||
* Gets an Instance representing the node component associated with the given Entity.
|
||||
* @param e An Entity.
|
||||
* @return An Instance object, which represents the node component associated with the Entity e.
|
||||
* @note Use Instance::isValid() to make sure the component exists.
|
||||
* @see hasComponent()
|
||||
*/
|
||||
Instance getInstance(Entity e) const noexcept;
|
||||
|
||||
/**
|
||||
* Creates a node component and associates it with the given entity.
|
||||
* @param entity An Entity to associate a node component with.
|
||||
*
|
||||
* If this component already exists on the given entity, it is first destroyed as if
|
||||
* destroy(Entity e) was called.
|
||||
*
|
||||
* @see destroy()
|
||||
*/
|
||||
void create(Entity entity);
|
||||
|
||||
/**
|
||||
* Destroys this component from the given entity.
|
||||
* @param e An entity.
|
||||
*
|
||||
* @see create()
|
||||
*/
|
||||
void destroy(Entity e) noexcept;
|
||||
|
||||
void setMorphTargetNames(Instance ci, utils::FixedCapacityVector<CString> names) noexcept;
|
||||
const utils::FixedCapacityVector<CString>& getMorphTargetNames(Instance ci) const noexcept;
|
||||
|
||||
void setExtras(Instance ci, CString extras) noexcept;
|
||||
const CString& getExtras(Instance ci) const noexcept;
|
||||
|
||||
void setSceneMembership(Instance ci, SceneMask scenes) noexcept;
|
||||
SceneMask getSceneMembership(Instance ci) const noexcept;
|
||||
|
||||
protected:
|
||||
NodeManager() noexcept = default;
|
||||
~NodeManager() = default;
|
||||
|
||||
public:
|
||||
NodeManager(NodeManager const&) = delete;
|
||||
NodeManager(NodeManager&&) = delete;
|
||||
NodeManager& operator=(NodeManager const&) = delete;
|
||||
NodeManager& operator=(NodeManager&&) = delete;
|
||||
};
|
||||
|
||||
} // namespace filament::gltfio
|
||||
|
||||
|
||||
#endif // GLTFIO_NODEMANAGER_H
|
||||
@@ -27,10 +27,11 @@ namespace filament {
|
||||
class Engine;
|
||||
}
|
||||
|
||||
namespace gltfio {
|
||||
namespace filament::gltfio {
|
||||
|
||||
struct FFilamentAsset;
|
||||
class AssetPool;
|
||||
class TextureProvider;
|
||||
|
||||
/**
|
||||
* \struct ResourceConfiguration ResourceLoader.h gltfio/ResourceLoader.h
|
||||
@@ -53,8 +54,8 @@ struct ResourceConfiguration {
|
||||
//! do not need this, but it is useful for robustness.
|
||||
bool recomputeBoundingBoxes;
|
||||
|
||||
//! If true, ignore skinned primitives bind transform when compute bounding box. Implicitly true
|
||||
//! for instanced asset. Only applicable when recomputeBoundingBoxes is set to true
|
||||
//! If true, ignores skinning when computing bounding boxes. Implicitly true for instanced
|
||||
//! assets. Only applicable when recomputeBoundingBoxes is set to true.
|
||||
bool ignoreBindTransform;
|
||||
};
|
||||
|
||||
@@ -94,6 +95,13 @@ public:
|
||||
*/
|
||||
void addResourceData(const char* uri, BufferDescriptor&& buffer);
|
||||
|
||||
/**
|
||||
* Register a plugin that can consume PNG / JPEG content and produce filament::Texture objects.
|
||||
*
|
||||
* Destruction of the given provider is the client's responsibility.
|
||||
*/
|
||||
void addTextureProvider(const char* mimeType, TextureProvider* provider);
|
||||
|
||||
/**
|
||||
* Checks if the given resource has already been added to the URI cache.
|
||||
*/
|
||||
@@ -153,7 +161,6 @@ public:
|
||||
|
||||
private:
|
||||
bool loadResources(FFilamentAsset* asset, bool async);
|
||||
void applySparseData(FFilamentAsset* asset) const;
|
||||
void normalizeSkinningWeights(FFilamentAsset* asset) const;
|
||||
void updateBoundingBoxes(FFilamentAsset* asset) const;
|
||||
AssetPool* mPool;
|
||||
@@ -161,7 +168,7 @@ private:
|
||||
Impl* pImpl;
|
||||
};
|
||||
|
||||
} // namespace gltfio
|
||||
} // namespace filament::gltfio
|
||||
|
||||
#endif // GLTFIO_RESOURCELOADER_H
|
||||
|
||||
|
||||
180
ios/include/gltfio/TextureProvider.h
Normal file
180
ios/include/gltfio/TextureProvider.h
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GLTFIO_TEXTUREPROVIDER_H
|
||||
#define GLTFIO_TEXTUREPROVIDER_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <utils/compiler.h>
|
||||
|
||||
namespace filament {
|
||||
class Engine;
|
||||
class Texture;
|
||||
}
|
||||
|
||||
namespace filament::gltfio {
|
||||
|
||||
/**
|
||||
* TextureProvider is an interface that allows clients to implement their own texture decoding
|
||||
* facility for JPEG, PNG, or KTX2 content. It constructs Filament Texture objects synchronously,
|
||||
* but populates their miplevels asynchronously.
|
||||
*
|
||||
* gltfio calls all public methods from the foreground thread, i.e. the thread that the Filament
|
||||
* engine was created with. However the implementation may create 0 or more background threads to
|
||||
* perform decoding work.
|
||||
*
|
||||
* The following pseudocode illustrates how this interface could be used, but in practice the only
|
||||
* client is the gltfio ResourceLoader.
|
||||
*
|
||||
* filament::Engine* engine = ...;
|
||||
* TextureProvider* provider = createStbProvider(engine);
|
||||
*
|
||||
* for (auto filename : textureFiles) {
|
||||
* std::vector<uint8_t> buf = readEntireFile(filename);
|
||||
* Texture* texture = provider->pushTexture(buf.data(), buf.size(), "image/png", 0);
|
||||
* if (texture == nullptr) { puts(provider->getPushMessage()); exit(1); }
|
||||
* }
|
||||
*
|
||||
* // At this point, the returned textures can be bound to material instances, but none of their
|
||||
* // miplevel images have been populated yet.
|
||||
*
|
||||
* while (provider->getPoppedCount() < provider->getPushedCount()) {
|
||||
* sleep(200);
|
||||
*
|
||||
* // The following call gives the provider an opportunity to reap the results of any
|
||||
* // background decoder work that has been completed (e.g. by calling Texture::setImage).
|
||||
* provider->updateQueue();
|
||||
*
|
||||
* // Check for textures that now have all their miplevels initialized.
|
||||
* while (Texture* texture = provider->popTexture()) {
|
||||
* printf("%p has all its miplevels ready.\n", texture);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* delete provider;
|
||||
*/
|
||||
class UTILS_PUBLIC TextureProvider {
|
||||
public:
|
||||
using Texture = filament::Texture;
|
||||
using FlagBits = uint64_t;
|
||||
|
||||
enum class Flags {
|
||||
sRGB = 1 << 0,
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a Filament texture and pushes it to the asynchronous decoding queue.
|
||||
*
|
||||
* If construction fails, nothing is pushed to the queue and null is returned. The failure
|
||||
* reason can be obtained with getPushMessage(). The given buffer pointer is not held, so the
|
||||
* caller can free it immediately. It is also the caller's responsibility to free the returned
|
||||
* Texture object, but it is only safe to do so after it has been popped from the queue.
|
||||
*/
|
||||
virtual Texture* pushTexture(const uint8_t* data, size_t byteCount,
|
||||
const char* mimeType, FlagBits flags) = 0;
|
||||
|
||||
/**
|
||||
* Checks if any texture is ready to be removed from the asynchronous decoding queue, and if so
|
||||
* pops it off.
|
||||
*
|
||||
* Unless an error or cancellation occurred during the decoding process, the returned texture
|
||||
* should have all its miplevels populated. If the texture is not complete, the reason can be
|
||||
* obtained with getPopMessage().
|
||||
*
|
||||
* Due to concurrency, textures are not necessarily popped off in the same order they were
|
||||
* pushed. Returns null if there are no textures that are ready to be popped.
|
||||
*/
|
||||
virtual Texture* popTexture() = 0;
|
||||
|
||||
/**
|
||||
* Polls textures in the queue and uploads mipmap images if any have emerged from the decoder.
|
||||
*
|
||||
* This gives the provider an opportunity to call Texture::setImage() on the foreground thread.
|
||||
* If needed, it can also call Texture::generateMipmaps() here.
|
||||
*
|
||||
* Items in the decoding queue can become "poppable" only during this call.
|
||||
*/
|
||||
virtual void updateQueue() = 0;
|
||||
|
||||
/**
|
||||
* Returns a failure message for the most recent call to pushTexture(), or null for success.
|
||||
*
|
||||
* Note that this method does not pertain to the decoding process. If decoding fails, clients to
|
||||
* can pop the incomplete texture off the queue and obtain a failure message using the
|
||||
* getPopFailure() method.
|
||||
*
|
||||
* The returned string is owned by the provider and becomes invalid after the next call to
|
||||
* pushTexture().
|
||||
*/
|
||||
virtual const char* getPushMessage() const = 0;
|
||||
|
||||
/**
|
||||
* Returns a failure message for the most recent call to popTexture(), or null for success.
|
||||
*
|
||||
* If the most recent call to popTexture() returned null, then no error occurred and this
|
||||
* returns null. If the most recent call to popTexture() returned a "complete" texture (i.e.
|
||||
* all miplevels present), then this returns null. This returns non-null only if an error or
|
||||
* cancellation occurred while decoding the popped texture.
|
||||
*
|
||||
* The returned string is owned by the provider and becomes invalid after the next call to
|
||||
* popTexture().
|
||||
*/
|
||||
virtual const char* getPopMessage() const = 0;
|
||||
|
||||
/**
|
||||
* Waits for all outstanding decoding jobs to complete.
|
||||
*
|
||||
* Clients should call updateQueue() afterwards if they wish to update the push / pop queue.
|
||||
*/
|
||||
virtual void waitForCompletion() = 0;
|
||||
|
||||
/**
|
||||
* Cancels all not-yet-started decoding jobs and waits for all other jobs to complete.
|
||||
*
|
||||
* Jobs that have already started cannot be canceled. Textures whose decoding process has
|
||||
* been cancelled will be made poppable on the subsequent call to updateQueue().
|
||||
*/
|
||||
virtual void cancelDecoding() = 0;
|
||||
|
||||
/** Total number of successful push calls since the provider was created. */
|
||||
virtual size_t getPushedCount() const = 0;
|
||||
|
||||
/** Total number of successful pop calls since the provider was created. */
|
||||
virtual size_t getPoppedCount() const = 0;
|
||||
|
||||
/** Total number of textures that have become ready-to-pop since the provider was created. */
|
||||
virtual size_t getDecodedCount() const = 0;
|
||||
|
||||
virtual ~TextureProvider() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a simple decoder based on stb_image that can handle "image/png" and "image/jpeg".
|
||||
* This works only if your build configuration includes STB.
|
||||
*/
|
||||
TextureProvider* createStbProvider(filament::Engine* engine);
|
||||
|
||||
/**
|
||||
* Creates a decoder that can handle certain types of "image/ktx2" content as specified in
|
||||
* the KHR_texture_basisu specification.
|
||||
*/
|
||||
TextureProvider* createKtx2Provider(filament::Engine* engine);
|
||||
|
||||
} // namespace filament::gltfio
|
||||
|
||||
#endif // GLTFIO_TEXTUREPROVIDER_H
|
||||
13
ios/include/gltfio/materials/uberarchive.h
Normal file
13
ios/include/gltfio/materials/uberarchive.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef UBERARCHIVE_H_
|
||||
#define UBERARCHIVE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
extern const uint8_t UBERARCHIVE_PACKAGE[];
|
||||
extern int UBERARCHIVE_DEFAULT_OFFSET;
|
||||
extern int UBERARCHIVE_DEFAULT_SIZE;
|
||||
}
|
||||
#define UBERARCHIVE_DEFAULT_DATA (UBERARCHIVE_PACKAGE + UBERARCHIVE_DEFAULT_OFFSET)
|
||||
|
||||
#endif
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <math/mat4.h>
|
||||
#include <math/TVecHelpers.h>
|
||||
|
||||
namespace gltfio {
|
||||
namespace filament::gltfio {
|
||||
|
||||
template <typename T>
|
||||
UTILS_PUBLIC T cubicSpline(const T& vert0, const T& tang0, const T& vert1, const T& tang1, float t) {
|
||||
@@ -121,6 +121,6 @@ inline filament::math::mat3f matrixFromUvTransform(const float offset[2], float
|
||||
return filament::math::mat3f(sx * c, sx * s, tx, -sy * s, sy * c, ty, 0.0f, 0.0f, 1.0f);
|
||||
};
|
||||
|
||||
} // namespace gltfio
|
||||
} // namespace filament::gltfio
|
||||
|
||||
#endif // GLTFIO_MATH_H
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#ifndef GLTFRESOURCES_H_
|
||||
#define GLTFRESOURCES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
extern const uint8_t GLTFRESOURCES_PACKAGE[];
|
||||
extern int GLTFRESOURCES_LIT_FADE_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_FADE_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_OPAQUE_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_OPAQUE_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_MASKED_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_MASKED_SIZE;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_FADE_OFFSET;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_FADE_SIZE;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_OPAQUE_OFFSET;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_OPAQUE_SIZE;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_MASKED_OFFSET;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_MASKED_SIZE;
|
||||
extern int GLTFRESOURCES_UNLIT_FADE_OFFSET;
|
||||
extern int GLTFRESOURCES_UNLIT_FADE_SIZE;
|
||||
extern int GLTFRESOURCES_UNLIT_OPAQUE_OFFSET;
|
||||
extern int GLTFRESOURCES_UNLIT_OPAQUE_SIZE;
|
||||
extern int GLTFRESOURCES_UNLIT_MASKED_OFFSET;
|
||||
extern int GLTFRESOURCES_UNLIT_MASKED_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_VOLUME_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_VOLUME_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_TRANSMISSION_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_TRANSMISSION_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_SHEEN_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_SHEEN_SIZE;
|
||||
}
|
||||
#define GLTFRESOURCES_LIT_FADE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_FADE_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_OPAQUE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_OPAQUE_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_MASKED_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_MASKED_OFFSET)
|
||||
#define GLTFRESOURCES_SPECULARGLOSSINESS_FADE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_SPECULARGLOSSINESS_FADE_OFFSET)
|
||||
#define GLTFRESOURCES_SPECULARGLOSSINESS_OPAQUE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_SPECULARGLOSSINESS_OPAQUE_OFFSET)
|
||||
#define GLTFRESOURCES_SPECULARGLOSSINESS_MASKED_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_SPECULARGLOSSINESS_MASKED_OFFSET)
|
||||
#define GLTFRESOURCES_UNLIT_FADE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_UNLIT_FADE_OFFSET)
|
||||
#define GLTFRESOURCES_UNLIT_OPAQUE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_UNLIT_OPAQUE_OFFSET)
|
||||
#define GLTFRESOURCES_UNLIT_MASKED_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_UNLIT_MASKED_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_VOLUME_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_VOLUME_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_TRANSMISSION_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_TRANSMISSION_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_SHEEN_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_SHEEN_OFFSET)
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
#ifndef GLTFRESOURCES_LITE_H_
|
||||
#define GLTFRESOURCES_LITE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
extern const uint8_t GLTFRESOURCES_LITE_PACKAGE[];
|
||||
extern int GLTFRESOURCES_LITE_LIT_OPAQUE_OFFSET;
|
||||
extern int GLTFRESOURCES_LITE_LIT_OPAQUE_SIZE;
|
||||
extern int GLTFRESOURCES_LITE_LIT_FADE_OFFSET;
|
||||
extern int GLTFRESOURCES_LITE_LIT_FADE_SIZE;
|
||||
}
|
||||
#define GLTFRESOURCES_LITE_LIT_OPAQUE_DATA (GLTFRESOURCES_LITE_PACKAGE + GLTFRESOURCES_LITE_LIT_OPAQUE_OFFSET)
|
||||
#define GLTFRESOURCES_LITE_LIT_FADE_DATA (GLTFRESOURCES_LITE_PACKAGE + GLTFRESOURCES_LITE_LIT_FADE_OFFSET)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user