Skip to content

Commit

Permalink
Release v1.10.4
Browse files Browse the repository at this point in the history
  • Loading branch information
webermm committed Jul 5, 2024
1 parent 552d5dc commit f5adc3a
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
-->

## [1.10.4] Support for new Blender glTF exporter

### Added
* Added support for the new attribute naming convention of color attributes in the Blender glTF exporter. The `_COLOR_N` attributes are now imported as color attributes if no attribute using the `COLOR_N` form is present in the glTF file.
* Added support for import of `Vec3` color attributes in the glTF importer. The alpha channel will be set to `1.0` in this case.


## [1.10.3] Skinning Import Bugfix

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 3.19)

SET(CMAKE_CONFIGURATION_TYPES "Debug;RelWithDebInfo")

project(RaCoOS VERSION 1.10.3)
project(RaCoOS VERSION 1.10.4)

SET(RACO_RELEASE_DIRECTORY ${CMAKE_BINARY_DIR}/release)

Expand Down
4 changes: 4 additions & 0 deletions components/libMeshLoader/include/mesh_loader/glTFBufferData.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ struct glTFBufferData {
return numComponentsForType.at(accessor_.type);
}

int type() const {
return accessor_.type;
}

template <typename T, typename U = T>
T getDataArray(size_t index, bool useComponentSize = true) const {
auto componentSize = (useComponentSize) ? accessor_.ByteStride(view_) / sizeof(typename T::value_type) : 1;
Expand Down
14 changes: 12 additions & 2 deletions components/libMeshLoader/src/glTFMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void convertPositionData(const glTFBufferData &data, std::vector<float> &buffer,
}
}

void convertAttributeSet(const tinygltf::Primitive &primitive, const tinygltf::Model &scene, std::vector<std::vector<float>> &buffers, const std::string &attributeBaseName, const std::set<int> &allowedComponentTypes, const std::set<int> &allowedTypes, bool normalize, int numVertices) {
void convertAttributeSet(const tinygltf::Primitive &primitive, const tinygltf::Model &scene, std::vector<std::vector<float>> &buffers, const std::string &attributeBaseName, const std::set<int> &allowedComponentTypes, const std::set<int> &allowedTypes, bool normalize, int numVertices, bool padVec3Types = false) {
for (auto channel = 0; channel < std::numeric_limits<int>::max(); ++channel) {
auto attribName = fmt::format("{}_{}", attributeBaseName, channel);
if (primitive.attributes.find(attribName) != primitive.attributes.end()) {
Expand All @@ -286,6 +286,10 @@ void convertAttributeSet(const tinygltf::Primitive &primitive, const tinygltf::M
for (size_t vertexIndex = 0; vertexIndex < bufferData.accessor_.count; vertexIndex++) {
auto elementData = normalize ? bufferData.getNormalizedData(vertexIndex) : bufferData.getConvertedData<float>(vertexIndex);
buffer.insert(buffer.end(), elementData.begin(), elementData.end());
// Optionally add padding to convert RGB color to RGBA color using 1.0 for alpha as required by gltf spec:
if (padVec3Types && bufferData.type() == TINYGLTF_TYPE_VEC3) {
buffer.emplace_back(1.0f);
}
}
} else {
LOG_WARNING(log_system::MESH_LOADER, "Attribute '{}' has different size than vertex buffer, ignoring it.", attribName);
Expand Down Expand Up @@ -415,7 +419,13 @@ void glTFMesh::loadPrimitiveData(const tinygltf::Primitive &primitive, const tin

convertAttributeSet(primitive, scene, colorBuffers, "COLOR",
std::set<int>{TINYGLTF_COMPONENT_TYPE_FLOAT, TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE, TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT},
std::set<int>{TINYGLTF_TYPE_VEC3, TINYGLTF_TYPE_VEC4}, true, numVertices);
std::set<int>{TINYGLTF_TYPE_VEC3, TINYGLTF_TYPE_VEC4}, true, numVertices, true);

if (colorBuffers.empty()) {
convertAttributeSet(primitive, scene, colorBuffers, "_COLOR",
std::set<int>{TINYGLTF_COMPONENT_TYPE_FLOAT, TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE, TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT},
std::set<int>{TINYGLTF_TYPE_VEC3, TINYGLTF_TYPE_VEC4}, true, numVertices, true);
}

convertAttributeSet(primitive, scene, jointBuffers, "JOINTS",
std::set<int>{TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE, TINYGLTF_COMPONENT_TYPE_UNSIGNED_SHORT},
Expand Down
2 changes: 2 additions & 0 deletions components/libRamsesBase/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ raco_package_add_test_resources(
meshes/SimpleSkin/SimpleSkin.gltf
meshes/AnimatedMorphCube/AnimatedMorphCube.bin
meshes/AnimatedMorphCube/AnimatedMorphCube.gltf
meshes/cube_color_attr_no_underscore_vec3.gltf
meshes/cube_color_attr_with_underscore_vec4.gltf
)
52 changes: 51 additions & 1 deletion components/libRamsesBase/tests/MeshAdaptor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,54 @@ TEST_F(MeshAdaptorTest, gltf_with_meshes_but_no_mesh_refs_unbaked) {
ASSERT_TRUE(isRamsesNameInArray("Mesh Name_MeshVertexData_a_Normal", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("Mesh Name_MeshVertexData_a_TextureCoordinate", meshStuff));
ASSERT_EQ(context.errors().getError(mesh).level(), raco::core::ErrorLevel::INFORMATION);
}
}

TEST_F(MeshAdaptorTest, gltf_color_attribute_vec3_no_underscore) {
auto mesh = create<raco::user_types::Mesh>("mesh");
context.set({mesh, &raco::user_types::Mesh::bakeMeshes_}, false);
context.set({mesh, &raco::user_types::Mesh::uri_}, test_path().append("meshes/cube_color_attr_no_underscore_vec3.gltf").string());

dispatch();

auto data = mesh->meshData();

auto color_idx = data->attribIndex("a_Color");
ASSERT_TRUE(color_idx >= 0);
EXPECT_EQ(data->attribDataType(color_idx), raco::core::MeshData::VertexAttribDataType::VAT_Float4);

auto meshStuff{select<ramses::ArrayResource>(*sceneContext.scene(), ramses::ERamsesObjectType::ERamsesObjectType_ArrayResource)};
EXPECT_EQ(meshStuff.size(), 7);
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshIndexData", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Position", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Normal", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_TextureCoordinate", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Tangent", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Bitangent", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Color", meshStuff));
ASSERT_EQ(context.errors().getError({mesh}).level(), raco::core::ErrorLevel::INFORMATION);
}

TEST_F(MeshAdaptorTest, gltf_color_attribute_vec4_with_underscore) {
auto mesh = create<raco::user_types::Mesh>("mesh");
context.set({mesh, &raco::user_types::Mesh::bakeMeshes_}, false);
context.set({mesh, &raco::user_types::Mesh::uri_}, test_path().append("meshes/cube_color_attr_with_underscore_vec4.gltf").string());

dispatch();

auto data = mesh->meshData();

auto color_idx = data->attribIndex("a_Color");
ASSERT_TRUE(color_idx >= 0);
EXPECT_EQ(data->attribDataType(color_idx), raco::core::MeshData::VertexAttribDataType::VAT_Float4);

auto meshStuff{select<ramses::ArrayResource>(*sceneContext.scene(), ramses::ERamsesObjectType::ERamsesObjectType_ArrayResource)};
EXPECT_EQ(meshStuff.size(), 7);
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshIndexData", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Position", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Normal", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_TextureCoordinate", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Tangent", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Bitangent", meshStuff));
ASSERT_TRUE(isRamsesNameInArray("mesh_MeshVertexData_a_Color", meshStuff));
ASSERT_EQ(context.errors().getError({mesh}).level(), raco::core::ErrorLevel::INFORMATION);
}
144 changes: 144 additions & 0 deletions resources/meshes/cube_color_attr_no_underscore_vec3.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"asset":{
"generator":"Khronos glTF Blender I/O v4.1.62",
"version":"2.0"
},
"scene":0,
"scenes":[
{
"name":"Scene",
"nodes":[
0
]
}
],
"nodes":[
{
"mesh":0,
"name":"Cube"
}
],
"materials":[
{
"doubleSided":true,
"name":"Material",
"pbrMetallicRoughness":{
"metallicFactor":0,
"roughnessFactor":0.5
}
}
],
"meshes":[
{
"extras":{
"originalName":"Cube"
},
"name":"Cube_MeshData",
"primitives":[
{
"attributes":{
"POSITION":0,
"NORMAL":1,
"TEXCOORD_0":2,
"TANGENT":3,
"COLOR_0":4
},
"indices":5,
"material":0
}
]
}
],
"accessors":[
{
"bufferView":0,
"componentType":5126,
"count":24,
"max":[
1,
1,
1
],
"min":[
-1,
-1,
-1
],
"type":"VEC3"
},
{
"bufferView":1,
"componentType":5126,
"count":24,
"type":"VEC3"
},
{
"bufferView":2,
"componentType":5126,
"count":24,
"type":"VEC2"
},
{
"bufferView":3,
"componentType":5126,
"count":24,
"type":"VEC4"
},
{
"bufferView":4,
"componentType":5126,
"count":24,
"type":"VEC3"
},
{
"bufferView":5,
"componentType":5123,
"count":36,
"type":"SCALAR"
}
],
"bufferViews":[
{
"buffer":0,
"byteLength":288,
"byteOffset":0,
"target":34962
},
{
"buffer":0,
"byteLength":288,
"byteOffset":288,
"target":34962
},
{
"buffer":0,
"byteLength":192,
"byteOffset":576,
"target":34962
},
{
"buffer":0,
"byteLength":384,
"byteOffset":768,
"target":34962
},
{
"buffer":0,
"byteLength":288,
"byteOffset":1152,
"target":34962
},
{
"buffer":0,
"byteLength":72,
"byteOffset":1440,
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