update external headers

This commit is contained in:
Nick Fisher
2022-02-06 13:28:28 +08:00
parent 6d5a63d398
commit bd3d0d080b
150 changed files with 27445 additions and 14805 deletions

View File

@@ -44,7 +44,7 @@
#include "FFilamentInstance.h"
#include <tsl/robin_map.h>
#include <trie/htrie_map.h>
#include <tsl/htrie_map.h>
#include <vector>
@@ -65,13 +65,13 @@ namespace gltfio {
class Animator;
class Wireframe;
class MorphHelper;
// Encapsulates VertexBuffer::setBufferAt() or IndexBuffer::setBuffer().
struct BufferSlot {
const cgltf_accessor* accessor;
cgltf_attribute_type attribute;
int bufferIndex; // for vertex buffers only
int morphTarget; // 0 if no morphing, otherwise 1-based index
filament::VertexBuffer* vertexBuffer;
filament::IndexBuffer* indexBuffer;
};
@@ -97,8 +97,6 @@ struct Primitive {
filament::IndexBuffer* indices = nullptr;
filament::Aabb aabb; // object-space bounding box
UvMap uvmap; // mapping from each glTF UV set to either UV0 or UV1 (8 bytes)
uint8_t morphPositions[4] = {}; // Buffer indices for MORPH_POSITION_0, MORPH_POSITION_1 etc.
uint8_t morphTangents[4] = {}; // Buffer indices for MORPH_TANGENTS_0, MORPH_TANGENTS_1, etc.
};
using MeshCache = tsl::robin_map<const cgltf_mesh*, std::vector<Primitive>>;
@@ -194,6 +192,10 @@ struct FFilamentAsset : public FilamentAsset {
Animator* getAnimator() noexcept;
void setMorphWeights(utils::Entity entity , const float* weights, size_t count) noexcept;
int getMorphTargetCount(utils::Entity entity) noexcept;
utils::Entity getWireframe() noexcept;
filament::Engine* getEngine() const noexcept {
@@ -243,6 +245,7 @@ struct FFilamentAsset : public FilamentAsset {
std::vector<FFilamentInstance*> mInstances;
SkinVector mSkins; // unused for instanced assets
Animator* mAnimator = nullptr;
MorphHelper* mMorpher = nullptr;
Wireframe* mWireframe = nullptr;
bool mResourcesLoaded = false;
DependencyGraph mDependencyGraph;

View File

@@ -122,12 +122,16 @@ inline bool getPrimitiveType(cgltf_primitive_type in,
case cgltf_primitive_type_lines:
*out = filament::RenderableManager::PrimitiveType::LINES;
return true;
case cgltf_primitive_type_line_strip:
*out = filament::RenderableManager::PrimitiveType::LINE_STRIP;
return true;
case cgltf_primitive_type_triangles:
*out = filament::RenderableManager::PrimitiveType::TRIANGLES;
return true;
case cgltf_primitive_type_line_loop:
case cgltf_primitive_type_line_strip:
case cgltf_primitive_type_triangle_strip:
*out = filament::RenderableManager::PrimitiveType::TRIANGLE_STRIP;
return true;
case cgltf_primitive_type_line_loop:
case cgltf_primitive_type_triangle_fan:
return false;
}

25
ios/src/Log.h Normal file
View File

@@ -0,0 +1,25 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#elif defined __ANDROID__
#include <android/log.h>
#define LOGTAG "PolyvoxFilament"
#else
#include <stdio.h>
#endif
void Log(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
#ifdef __ANDROID__
__android_log_vprint(ANDROID_LOG_DEBUG, LOGTAG, fmt, args);
#elif defined __OBJC__
NSString *format = [[NSString alloc] initWithUTF8String:fmt];
NSLogv(format, args);
[format release];
#else
printf(fmt, args);
#endif
va_end(args);
}

73
ios/src/MorphHelper.h Normal file
View File

@@ -0,0 +1,73 @@
/*
* Copyright (C) 2021 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_MORPHHELPER_H
#define GLTFIO_MORPHHELPER_H
#include "FFilamentAsset.h"
#include "FFilamentInstance.h"
#include <filament/MorphTargetBuffer.h>
#include <math/vec4.h>
#include <tsl/robin_map.h>
#include <vector>
struct cgltf_node;
struct cgltf_mesh;
struct cgltf_primitive;
namespace gltfio {
/**
* Internal class that partitions lists of morph weights and maintains a cache of BufferObject
* instances. This allows gltfio to support up to 255 morph targets.
*
* Each partition is associated with an unordered set of 4 (or fewer) morph target indices, which
* we call the "primary indices" for that time slice.
*
* Animator has ownership over a single instance of MorphHelper, thus it is 1:1 with FilamentAsset.
*/
class MorphHelper {
public:
using Entity = utils::Entity;
MorphHelper(FFilamentAsset* asset, FFilamentInstance* inst);
~MorphHelper();
void setWeights(Entity entity, float const* weights, int count) noexcept;
int getTargetCount(Entity entity) const noexcept;
private:
struct GltfPrimitive {
filament::MorphTargetBuffer* targets;
};
struct TableEntry {
std::vector<GltfPrimitive> primitives; // TODO: flatten this?
};
void addPrimitive(cgltf_mesh const* mesh, int primitiveIndex, Entity entity);
tsl::robin_map<Entity, TableEntry> mMorphTable;
const FFilamentAsset* mAsset;
const FFilamentInstance* mInstance;
};
} // namespace gltfio
#endif // GLTFIO_MORPHHELPER_H

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2019 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.
@@ -14,30 +14,27 @@
* limitations under the License.
*/
#ifndef TNT_UTILS_LOG_H
#define TNT_UTILS_LOG_H
#ifndef GLTFIO_WIREFRAME_H
#define GLTFIO_WIREFRAME_H
#include <utils/compiler.h>
#include <utils/ostream.h>
#include <filament/IndexBuffer.h>
#include <filament/VertexBuffer.h>
namespace utils {
#include <utils/Entity.h>
struct UTILS_PUBLIC Loggers {
// DEBUG level logging stream
io::ostream& d;
namespace gltfio {
// ERROR level logging stream
io::ostream& e;
struct FFilamentAsset;
// WARNING level logging stream
io::ostream& w;
// INFORMATION level logging stream
io::ostream& i;
struct Wireframe {
Wireframe(FFilamentAsset* asset);
~Wireframe();
const FFilamentAsset* mAsset;
utils::Entity mEntity;
filament::VertexBuffer* mVertexBuffer;
filament::IndexBuffer* mIndexBuffer;
};
extern UTILS_PUBLIC Loggers const slog;
} // namsepace gltfio
} // namespace utils
#endif // TNT_UTILS_LOG_H
#endif // GLTFIO_WIREFRAME_H

View File

@@ -1,91 +0,0 @@
// /*
// * Copyright (C) 2021 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_CPUMORPHER_H
// #define GLTFIO_CPUMORPHER_H
// #include "Morpher.h"
// #include "FFilamentAsset.h"
// #include "FFilamentInstance.h"
// #include <math/vec4.h>
// #include <tsl/robin_map.h>
// #include <vector>
// struct cgltf_node;
// struct cgltf_mesh;
// struct cgltf_primitive;
// struct cgltf_attribute;
// using namespace gltfio;
// namespace agltfio {
// /**
// * Helper for supporting more than 4 active morph targets.
// *
// * All morph values are calculated on CPU and collected into a single target, which will be
// * uploaded with weight of 1. This is effectively doing the morphing on CPU.
// *
// * Obviously this is slower than the stock morpher as it needs to upload buffer every frame.
// * So beware of the performance penalty.
// */
// class CPUMorpher : public Morpher {
// public:
// using Entity = utils::Entity;
// CPUMorpher(FFilamentAsset* asset, FFilamentInstance* instance);
// ~CPUMorpher();
// void applyWeights(Entity targetEntity, float const* weights, size_t count) noexcept;
// private:
// struct GltfTarget {
// int morphTargetIndex;
// cgltf_attribute_type attribute_type;
// cgltf_type type;
// std::vector<uint16_t> indices;
// std::vector<float> values;
// };
// struct GltfPrimitive {
// filament::VertexBuffer* vertexBuffer;
// int baseSlot;
// size_t floatsCount;
// filament::BufferObject* morphBuffer1 = nullptr;
// filament::BufferObject* morphBuffer2 = nullptr;
// std::vector<GltfTarget> targets;
// };
// struct TableEntry {
// std::vector<GltfPrimitive> primitives;
// };
// void addPrimitive(cgltf_mesh const* mesh, int primitiveIndex, TableEntry* entry);
// int determineBaseSlot(const cgltf_primitive& prim) const;
// int findPositionAttribute(const cgltf_primitive& prim) const;
// std::vector<float> mPartiallySortedWeights;
// tsl::robin_map<Entity, TableEntry> mMorphTable;
// const FFilamentAsset* mAsset;
// };
// } // namespace gltfio
// #endif // GLTFIO_CPUMORPHER_H

View File

@@ -1,81 +0,0 @@
/*
* Copyright (C) 2021 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.
*/
#include "FFilamentAsset.h"
#include "FFilamentInstance.h"
#include "filament/Texture.h"
#include "filament/Engine.h"
#include <math/vec4.h>
#include <tsl/robin_map.h>
#include <vector>
using namespace filament;
struct cgltf_node;
struct cgltf_mesh;
struct cgltf_primitive;
namespace gltfio {
///
/// A GPUMorphHelper instance can be created per mesh (this avoids creating textures for meshes that do not require animation).
/// For each primitive in the mesh, a texture is created to store the target positions and normals.
/// The texture is laid out as x * 1 * z, where z is the number of morph targets and x is the number of vertices for the primitive.
/// A MaterialInstance is created for each primitive, then applied to the entity identified by entityName.
///
class GPUMorphHelper {
public:
using Entity = utils::Entity;
GPUMorphHelper(FFilamentAsset *asset, const char* meshName, int* primitives, int numPrimitives);
~GPUMorphHelper();
void applyWeights(float const *weights, size_t count) noexcept;
private:
struct GltfTarget {
const void *bufferObject;
uint32_t bufferSize;
int morphTargetIndex;
cgltf_attribute_type type;
};
struct GltfPrimitive {
filament::VertexBuffer *vertexBuffer;
Texture* texture;
std::vector <GltfTarget> targets; // TODO: flatten this?
const char* materialName;
cgltf_size numTargets = 0;
cgltf_size numVertices = 0;
MaterialInstance* materialInstance;
};
int numAttributes = 2;
void addPrimitive(cgltf_mesh const *mesh, int primitiveIndex);
void createTextures();
cgltf_mesh const* targetMesh;
FFilamentAsset *mAsset;
std::vector<std::unique_ptr<GltfPrimitive>> animatablePrimitives;
};
}

View File

@@ -1,120 +0,0 @@
/*
* Copyright (C) 2019 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_GLTFHELPERS_H
#define GLTFIO_GLTFHELPERS_H
#include <cgltf.h>
static const uint8_t* cgltf_buffer_view_data(const cgltf_buffer_view* view) {
if (view->data)
return (const uint8_t*)view->data;
if (!view->buffer->data)
return NULL;
const uint8_t* result = (const uint8_t*)view->buffer->data;
result += view->offset;
return result;
}
static cgltf_size cgltf_component_size(cgltf_component_type component_type) {
switch (component_type)
{
case cgltf_component_type_r_8:
case cgltf_component_type_r_8u:
return 1;
case cgltf_component_type_r_16:
case cgltf_component_type_r_16u:
return 2;
case cgltf_component_type_r_32u:
case cgltf_component_type_r_32f:
return 4;
case cgltf_component_type_invalid:
default:
return 0;
}
}
static cgltf_size cgltf_component_read_index(const void* in, cgltf_component_type component_type) {
switch (component_type)
{
case cgltf_component_type_r_16:
return *((const int16_t*) in);
case cgltf_component_type_r_16u:
return *((const uint16_t*) in);
case cgltf_component_type_r_32u:
return *((const uint32_t*) in);
case cgltf_component_type_r_32f:
return (cgltf_size)*((const float*) in);
case cgltf_component_type_r_8:
return *((const int8_t*) in);
case cgltf_component_type_r_8u:
return *((const uint8_t*) in);
default:
return 0;
}
}
static cgltf_float cgltf_component_read_float(const void* in, cgltf_component_type component_type,
cgltf_bool normalized) {
if (component_type == cgltf_component_type_r_32f)
{
return *((const float*) in);
}
if (normalized)
{
switch (component_type)
{
// note: glTF spec doesn't currently define normalized conversions for 32-bit integers
case cgltf_component_type_r_16:
return *((const int16_t*) in) / (cgltf_float)32767;
case cgltf_component_type_r_16u:
return *((const uint16_t*) in) / (cgltf_float)65535;
case cgltf_component_type_r_8:
return *((const int8_t*) in) / (cgltf_float)127;
case cgltf_component_type_r_8u:
return *((const uint8_t*) in) / (cgltf_float)255;
default:
return 0;
}
}
return (cgltf_float)cgltf_component_read_index(in, component_type);
}
static cgltf_bool cgltf_element_read_float(const uint8_t* element, cgltf_type type,
cgltf_component_type component_type, cgltf_bool normalized, cgltf_float* out,
cgltf_size element_size) {
cgltf_size num_components = cgltf_num_components(type);
if (element_size < num_components) {
return 0;
}
// There are three special cases for component extraction, see #data-alignment in the 2.0 spec.
cgltf_size component_size = cgltf_component_size(component_type);
for (cgltf_size i = 0; i < num_components; ++i)
{
out[i] = cgltf_component_read_float(element + component_size * i, component_type, normalized);
}
return 1;
}
#endif // GLTFIO_GLTFHELPERS_H