Skip to content

Commit

Permalink
glTF: Added support for EXT_meshopt_compression.
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonJoker committed Apr 3, 2024
1 parent 6f4ef13 commit 551bdab
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 113 deletions.
37 changes: 9 additions & 28 deletions data/vcpkg/ports/fastgltf/fix_uri_escape_spaces.patch
Original file line number Diff line number Diff line change
@@ -1,60 +1,41 @@
diff --git a/src/fastgltf.cpp b/src/fastgltf.cpp
index 775c9bd..510f82d 100644
index a5d1206..eca5ad0 100644
--- a/src/fastgltf.cpp
+++ b/src/fastgltf.cpp
@@ -1733,7 +1733,8 @@ fg::Error fg::Parser::parseBuffers(simdjson::dom::array& buffers, Asset& asset)
@@ -1864,7 +1864,8 @@ fg::Error fg::Parser::parseBuffers(simdjson::dom::array& buffers, Asset& asset)
// file. Otherwise, data must be specified in the "uri" field.
std::string_view uriString;
if (bufferObject["uri"].get_string().get(uriString) == SUCCESS) FASTGLTF_LIKELY {
- URIView uriView(uriString);
+ fg::URI uri(uriString);
+ fg::URIView uriView(uri.string());
+ URIView uriView(uri);

if (!uriView.valid()) {
return Error::InvalidURI;
@@ -2073,7 +2074,8 @@ fg::Error fg::Parser::parseImages(simdjson::dom::array& images, Asset& asset) {
@@ -2255,7 +2256,8 @@ fg::Error fg::Parser::parseImages(simdjson::dom::array& images, Asset& asset) {
return Error::InvalidGltf;
}

- URIView uriView(uriString);
+ fg::URI uri(uriString);
+ fg::URIView uriView(uri.string());
+ URIView uriView(uri);
if (!uriView.valid()) {
return Error::InvalidURI;
}
@@ -3196,21 +3198,21 @@ fg::Error fg::Parser::parseNodes(simdjson::dom::array& nodes, Asset& asset) {
@@ -3451,14 +3453,14 @@ fg::Error fg::Parser::parseNodes(simdjson::dom::array& nodes, Asset& asset) {
if (nodeObject["extensions"].get_object().get(extensionsObject) == SUCCESS) FASTGLTF_LIKELY {
if (hasBit(config.extensions, Extensions::KHR_lights_punctual)) {
dom::object lightsObject;
- if (extensionsObject[extensions::KHR_lights_punctual].get_object().get(lightsObject) == SUCCESS) FASTGLTF_LIKELY {
+ if (auto lightsError = extensionsObject[extensions::KHR_lights_punctual].get_object().get(lightsObject); lightsError == SUCCESS) FASTGLTF_LIKELY {
+ if (auto lightsError = extensionsObject[extensions::KHR_lights_punctual].get_object().get(lightsObject) == SUCCESS) FASTGLTF_LIKELY {
std::uint64_t light;
- if (auto lightError = lightsObject["light"].get_uint64().get(light); error == SUCCESS) FASTGLTF_LIKELY {
+ if (auto lightError = lightsObject["light"].get_uint64().get(light); lightError == SUCCESS) FASTGLTF_LIKELY {
if (auto lightError = lightsObject["light"].get_uint64().get(light); lightError == SUCCESS) FASTGLTF_LIKELY {
node.lightIndex = static_cast<std::size_t>(light);
} else {
- return error == NO_SUCH_FIELD || error == INCORRECT_TYPE ? Error::InvalidGltf : Error::InvalidJson;
+ return lightError == NO_SUCH_FIELD || lightError == INCORRECT_TYPE ? Error::InvalidGltf : Error::InvalidJson;
return lightError == NO_SUCH_FIELD || lightError == INCORRECT_TYPE ? Error::InvalidGltf : Error::InvalidJson;
}
- } else if (error != NO_SUCH_FIELD) {
+ } else if (lightsError != NO_SUCH_FIELD) {
return Error::InvalidGltf;
}
}

if (hasBit(config.extensions, Extensions::EXT_mesh_gpu_instancing)) {
dom::object gpuInstancingObject;
- if (extensionsObject[extensions::EXT_mesh_gpu_instancing].get_object().get(gpuInstancingObject) == SUCCESS) FASTGLTF_LIKELY {
+ if (auto instancingError = extensionsObject[extensions::EXT_mesh_gpu_instancing].get_object().get(gpuInstancingObject); instancingError == SUCCESS) FASTGLTF_LIKELY {
dom::object attributesObject;
if (gpuInstancingObject["attributes"].get_object().get(attributesObject) == SUCCESS) FASTGLTF_LIKELY {
auto parseAttributes = [this](dom::object& object, decltype(node.instancingAttributes)& attributes) -> auto {
@@ -3234,7 +3236,7 @@ fg::Error fg::Parser::parseNodes(simdjson::dom::array& nodes, Asset& asset) {
} else {
return Error::InvalidGltf;
}
- } else if (error != NO_SUCH_FIELD) {
+ } else if (instancingError != NO_SUCH_FIELD) {
return Error::InvalidGltf;
}
}
4 changes: 2 additions & 2 deletions data/vcpkg/ports/fastgltf/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO spnda/fastgltf
REF "v${VERSION}"
SHA512 66be8e5a05210d023ec5e47dd3aa721b3cf98428bd00e227007cfc97fda35c669b5e8b82254d26c6ce2254297d16fd7a5f6bbbf3da17432df09186091d1ae351
REF 4cd9855d50efa287f39ac0074ce3044bebd2e520
SHA512 314714d82d884feb528e16dcc77c33f1db741aa002e4f1924d5e9b4f68fee60a454a0fbbac340eed250f9e5a8b69f5f3504b67dfd8ff72660e609dfa598a6a2b
HEAD_REF main
PATCHES fix_uri_escape_spaces.patch
)
Expand Down
11 changes: 10 additions & 1 deletion source/Core/Castor3D/Shader/Shaders/GlslLighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ namespace castor3d::shader

if ( fresnelFactor.isEnabled() )
{
debugOutput.registerOutput( cuT( "Combine" ), cuT( "Fresnel Factor" ), fresnelFactor );

IF( m_writer, components.refractionRatio != 0.0_f
&& components.hasRefraction != 0_u
&& components.hasTransmission == 0_u )
Expand All @@ -165,7 +167,7 @@ namespace castor3d::shader
, ambientOcclusion
, reflectedDiffuse ) );
debugOutput.registerOutput( cuT( "Combine" ), cuT( "Diffuse BRDF" ), diffuseBrdf );
debugOutput.registerOutput( cuT( "Combine" ), cuT( "AdjustedSpecular" ), directLighting.specular() );
debugOutput.registerOutput( cuT( "Combine" ), cuT( "Adjusted Specular" ), directLighting.specular() );
auto specularBrdf = m_writer.declLocale( "c3d_specularBrdf"
, doGetSpecularBrdf( components
, directLighting, indirectLighting
Expand Down Expand Up @@ -202,8 +204,15 @@ namespace castor3d::shader
, clamp( components.getMember< sdw::Float >( "specularFactor" ), 0.0_f, 1.0_f ) );
specularBrdf *= specularFactor * fresnelFactor;
diffuseBrdf *= 1.0_f - specularFactor * fresnelFactor;
debugOutput.registerOutput( cuT( "Combine" ), cuT( "Specular Factor" ), specularFactor );
}
else
{
debugOutput.registerOutput( cuT( "Combine" ), cuT( "Specular Factor" ), 0.0_f );
}

debugOutput.registerOutput( cuT( "Combine" ), cuT( "Final Specular" ), specularBrdf );
debugOutput.registerOutput( cuT( "Combine" ), cuT( "Final Diffuse" ), diffuseBrdf );
debugOutput.registerOutput( cuT( "Combine" ), cuT( "Emissive" ), emissive );
auto combineResult = m_writer.declLocale( "c3d_combineResult"
, emissive + specularBrdf + diffuseBrdf );
Expand Down
1 change: 1 addition & 0 deletions source/Plugins/Importers/GltfImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ if( fastgltf_FOUND )
${ImporterDependencies}
simdjson::simdjson
fastgltf::fastgltf
meshoptimizer::meshoptimizer
)
set_target_properties( ${PROJECT_NAME}
PROPERTIES
Expand Down
40 changes: 24 additions & 16 deletions source/Plugins/Importers/GltfImporter/GltfAnimationImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ namespace c3d_gltf
, NodeAnimationChannelSampler const & animChannels
, fastgltf::AnimationPath channel
, castor::Map< castor::Milliseconds, KeyT > & result
, castor::Set< castor::Milliseconds > & allTimes )
, castor::Set< castor::Milliseconds > & allTimes
, CompressedBufferDataAdapter const & adapter )
{
auto it = std::find_if( animChannels.begin()
, animChannels.end()
Expand All @@ -177,20 +178,22 @@ namespace c3d_gltf
{
AnimationChannelSampler const & channelSampler = *it;
castor::Vector< float > times;
fastgltf::iterateAccessor< float >( impAsset
iterateAccessor< float >( impAsset
, impAsset.accessors[channelSampler.second.inputAccessor]
, [&times]( float value )
{
times.push_back( value );
} );
}
, adapter );
castor::Vector< KeyT > values;
fastgltf::iterateAccessor< KeyDataTypeT< KeyT > >( impAsset
iterateAccessor< KeyDataTypeT< KeyT > >( impAsset
, impAsset.accessors[channelSampler.second.outputAccessor]
, [&values]( KeyDataTypeT< KeyT > value )
{
values.push_back( KeyT{ castor::move( value ) } );
} );
// for AnimationInterpolation::CubicSpline can have more outputs
}
, adapter );
// for AnimationInterpolation::CubicSpline can have more outputs
uint32_t weightStride = uint32_t( values.size() / times.size() );
uint32_t ii = ( channelSampler.second.interpolation == fastgltf::AnimationInterpolation::CubicSpline )
? 1u
Expand All @@ -217,15 +220,16 @@ namespace c3d_gltf
, uint32_t wantedFps
, AnimationT & animation
, castor::Map< castor::Milliseconds, castor::UniquePtr< KeyFrameT > > & keyframes
, FuncT fillKeyFrame )
, FuncT fillKeyFrame
, CompressedBufferDataAdapter const & adapter )
{
castor::Set< castor::Milliseconds > times;
castor::Map< castor::Milliseconds, castor::Point3f > translates;
castor::Map< castor::Milliseconds, castor::Quaternion > rotates;
castor::Map< castor::Milliseconds, castor::Point3f > scales;
auto maxTranslateTime = processKeys( impAsset, animChannels, fastgltf::AnimationPath::Translation, translates, times );
auto maxRotateTime = processKeys( impAsset, animChannels, fastgltf::AnimationPath::Rotation, rotates, times );
auto maxScaleTime = processKeys( impAsset, animChannels, fastgltf::AnimationPath::Scale, scales, times );
auto maxTranslateTime = processKeys( impAsset, animChannels, fastgltf::AnimationPath::Translation, translates, times, adapter );
auto maxRotateTime = processKeys( impAsset, animChannels, fastgltf::AnimationPath::Rotation, rotates, times, adapter );
auto maxScaleTime = processKeys( impAsset, animChannels, fastgltf::AnimationPath::Scale, scales, times, adapter );
synchroniseKeys( translates
, rotates
, scales
Expand Down Expand Up @@ -311,7 +315,8 @@ namespace c3d_gltf
, castor::Point3f const & scale )
{
keyframe.addAnimationObject( *object, position, orientation, scale );
} );
}
, file.getAdapter() );
}
else
{
Expand Down Expand Up @@ -449,19 +454,21 @@ namespace c3d_gltf
for ( AnimationChannelSampler & channelSampler : impNodeAnim )
{
castor::Vector< float > times;
fastgltf::iterateAccessor< float >( impAsset
iterateAccessor< float >( impAsset
, impAsset.accessors[channelSampler.second.inputAccessor]
, [&times]( float value )
{
times.push_back( value );
} );
}
, file.getAdapter() );
castor::Vector< float > values;
fastgltf::iterateAccessor< float >( impAsset
iterateAccessor< float >( impAsset
, impAsset.accessors[channelSampler.second.outputAccessor]
, [&values]( float value )
{
values.push_back( value );
} );
}
, file.getAdapter() );

// for AnimationInterpolation::CubicSpline can have more outputs
uint32_t weightStride = uint32_t( values.size() / times.size() );
Expand Down Expand Up @@ -549,7 +556,8 @@ namespace c3d_gltf
, castor::Point3f const & scale )
{
keyframe.setTransform( position, orientation, scale );
} );
}
, file.getAdapter() );

for ( auto & keyFrame : keyFrames )
{
Expand Down
Loading

0 comments on commit 551bdab

Please sign in to comment.