Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code changes for closing 110 and 111 #112

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GLTFSDK.Samples/Deserialize/Deserialize.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<ProjectGuid>{DE6A7757-2DF3-4705-829B-96A77BABF0B2}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Deserialize</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down
2 changes: 1 addition & 1 deletion GLTFSDK.Samples/Serialize/Serialize.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<ProjectGuid>{DE6A7757-2DE3-4705-829B-96A77BABF0B2}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Serialize</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down
11 changes: 10 additions & 1 deletion GLTFSDK.Samples/Serialize/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,17 @@ namespace
0U, 1U, 2U
};

// Warning!: When your model has more than 65536 vertices then you must store in uint32_t as follows
// std::vector<uint32_t> indices = {
// 0U, 1U, 2U .... your indices here
// };


// Copy the Accessor's id - subsequent calls to AddAccessor may invalidate the returned reference
accessorIdIndices = bufferBuilder.AddAccessor(indices, { TYPE_SCALAR, COMPONENT_UNSIGNED_SHORT }).id;
accessorIdIndices = bufferBuilder.AddAccessor(indices, { TYPE_SCALAR, COMPONENT_UNSIGNED_SHORT }).id;

// Warning ! : When your model has more than 65536 vertices then this number should be INT but not SHORT
// accessorIdIndices = bufferBuilder.AddAccessor(indices, { Microsoft::glTF::TYPE_SCALAR, Microsoft::glTF::COMPONENT_UNSIGNED_INT}).id;

// Create a BufferView with target ARRAY_BUFFER (as it will reference vertex attribute data)
bufferBuilder.AddBufferView(BufferViewTarget::ARRAY_BUFFER);
Expand Down
2 changes: 1 addition & 1 deletion GLTFSDK.Test/GLTFSDK.Test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<ProjectGuid>{F170B140-6AB9-4014-97D9-D897E0493CEC}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>GLTFSDKTest</RootNamespace>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
<ProjectName>GLTFSDK.Test</ProjectName>
<TargetPlatform>$(Platform)</TargetPlatform>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion GLTFSDK/GLTFSDK.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{F656C078-7F2A-4753-9B92-5E959AF80E26}</ProjectGuid>
<RootNamespace>GLTFSDK</RootNamespace>
<WindowsTargetPlatformVersion>10.0.10586.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down
8 changes: 8 additions & 0 deletions GLTFSDK/Inc/GLTFSDK/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ namespace Microsoft
constexpr const char* ACCESSOR_TEXCOORD_0 = "TEXCOORD_0";
constexpr const char* ACCESSOR_TEXCOORD_1 = "TEXCOORD_1";
constexpr const char* ACCESSOR_COLOR_0 = "COLOR_0";
constexpr const char* ACCESSOR_COLOR_1 = "COLOR_1";
constexpr const char* ACCESSOR_COLOR_2 = "COLOR_2";
constexpr const char* ACCESSOR_COLOR_3 = "COLOR_3";
constexpr const char* ACCESSOR_ATTRIBUTE_0 = "ATTRIBUTE_0";
constexpr const char* ACCESSOR_ATTRIBUTE_1 = "ATTRIBUTE_1";
constexpr const char* ACCESSOR_ATTRIBUTE_2 = "ATTRIBUTE_2";
constexpr const char* ACCESSOR_JOINTS_0 = "JOINTS_0";
constexpr const char* ACCESSOR_WEIGHTS_0 = "WEIGHTS_0";

Expand All @@ -76,6 +82,8 @@ namespace Microsoft
constexpr const char* TARGETPATH_NAME_ROTATION = "rotation";
constexpr const char* TARGETPATH_NAME_SCALE = "scale";
constexpr const char* TARGETPATH_NAME_WEIGHTS = "weights";
constexpr const char* TARGETPATH_NAME_COLOR_0 = "color0";
constexpr const char* TARGETPATH_NAME_ATTRIBUTE_0 = "attribute0";

constexpr const char* INTERPOLATIONTYPE_NAME_LINEAR = "LINEAR";
constexpr const char* INTERPOLATIONTYPE_NAME_STEP = "STEP";
Expand Down
19 changes: 17 additions & 2 deletions GLTFSDK/Inc/GLTFSDK/GLTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ namespace Microsoft
TARGET_TRANSLATION,
TARGET_ROTATION,
TARGET_SCALE,
TARGET_WEIGHTS
TARGET_WEIGHTS,
TARGET_COLOR_0,
TARGET_ATTRIBUTE_0
};

enum InterpolationType
Expand Down Expand Up @@ -147,6 +149,14 @@ namespace Microsoft
{
return TARGET_WEIGHTS;
}
if (targetPath == TARGETPATH_NAME_COLOR_0)
{
return TARGET_COLOR_0;
}
if (targetPath == TARGETPATH_NAME_ATTRIBUTE_0)
{
return TARGET_ATTRIBUTE_0;
}

return TARGET_UNKNOWN;
}
Expand Down Expand Up @@ -544,11 +554,16 @@ namespace Microsoft
std::string positionsAccessorId;
std::string normalsAccessorId;
std::string tangentsAccessorId;
std::string color0AccessorId;
std::string attribute0AccessorId;

bool operator==(const MorphTarget& rhs) const
{
return this->positionsAccessorId == rhs.positionsAccessorId
&& this->normalsAccessorId == rhs.normalsAccessorId
&& this->tangentsAccessorId == rhs.tangentsAccessorId;
&& this->tangentsAccessorId == rhs.tangentsAccessorId
&& this->color0AccessorId == rhs.color0AccessorId
&& this->attribute0AccessorId == rhs.attribute0AccessorId;
}

bool operator!=(const MorphTarget& rhs) const
Expand Down
7 changes: 7 additions & 0 deletions GLTFSDK/Inc/GLTFSDK/MeshPrimitiveUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ namespace Microsoft

std::vector<uint32_t> GetColors(const Document& doc, const GLTFResourceReader& reader, const Accessor& accessor);
std::vector<uint32_t> GetColors_0(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive);
std::vector<uint32_t> GetColors_1(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive);
std::vector<uint32_t> GetColors_2(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive);
std::vector<uint32_t> GetColors_3(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive);

std::vector<float> GetFloatAttributes(const Document& doc, const GLTFResourceReader& reader, const Accessor& accessor);
std::vector<float> GetFloatAttributes_0(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive);


std::vector<uint32_t> GetJointIndices32(const Document& doc, const GLTFResourceReader& reader, const Accessor& accessor);
std::vector<uint32_t> GetJointIndices32_0(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive);
Expand Down
75 changes: 75 additions & 0 deletions GLTFSDK/Source/MeshPrimitiveUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,12 +752,87 @@ std::vector<uint32_t> MeshPrimitiveUtils::GetColors(const Document& doc, const G
}
}


// Custom Attributes
std::vector<float> MeshPrimitiveUtils::GetFloatAttributes(const Document& doc, const GLTFResourceReader& reader, const Accessor& Accessor)
{
// Vertex Attributes as Floats
// if (Accessor.componentType == COMPONENT_FLOAT)
// {
std::vector<float> data = reader.ReadFloatData(doc, Accessor);


return data;
// if (Accessor.type == TYPE_VEC4)
// return PackColorsRGBA(colorData);
// else
// return PackColorsRGB(colorData);

// throw GLTFException("Not implemented yet for Float Vertex Attributes " + Accessor.id);
// }


// // 3. 3Bytes = color
// if (Accessor.componentType == COMPONENT_UNSIGNED_BYTE )
// {
// std::vector<uint8_t> data = reader.ReadBinaryData<uint8_t>(doc, Accessor);
//
// if (Accessor.type == TYPE_VEC4)
// return PackColorsRGBA(data);
// else
// return PackColorsRGB(data);
//
// //throw GLTFException("Not implemented yet for Byte Vertex Attributes " + colorsAccessor.id);
// }
//
//
// // 4. Unsigned Short
// if (Accessor.componentType != COMPONENT_UNSIGNED_SHORT)
// {
// throw GLTFException("Not implement yet for Unsigned Shorts " + Accessor.id);
// }
//



}


std::vector<uint32_t> MeshPrimitiveUtils::GetColors_0(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive)
{
const auto& accessor = doc.accessors.Get(meshPrimitive.GetAttributeAccessorId(ACCESSOR_COLOR_0));
return GetColors(doc, reader, accessor);
}

std::vector<uint32_t> MeshPrimitiveUtils::GetColors_1(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive)
{
const auto& accessor = doc.accessors.Get(meshPrimitive.GetAttributeAccessorId(ACCESSOR_COLOR_1));
return GetColors(doc, reader, accessor);
}

std::vector<uint32_t> MeshPrimitiveUtils::GetColors_2(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive)
{
const auto& accessor = doc.accessors.Get(meshPrimitive.GetAttributeAccessorId(ACCESSOR_COLOR_2));
return GetColors(doc, reader, accessor);
}

std::vector<uint32_t> MeshPrimitiveUtils::GetColors_3(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive)
{
const auto& accessor = doc.accessors.Get(meshPrimitive.GetAttributeAccessorId(ACCESSOR_COLOR_3));
return GetColors(doc, reader, accessor);
}


std::vector<float> MeshPrimitiveUtils::GetFloatAttributes_0(const Document& doc, const GLTFResourceReader& reader, const MeshPrimitive& meshPrimitive)
{
const auto& accessor = doc.accessors.Get(meshPrimitive.GetAttributeAccessorId(ACCESSOR_ATTRIBUTE_0));
return GetFloatAttributes(doc, reader, accessor);
}





// Joints
std::vector<uint32_t> MeshPrimitiveUtils::GetJointIndices32(const Document& doc, const GLTFResourceReader& reader, const Accessor& jointsAccessor)
{
Expand Down
2 changes: 1 addition & 1 deletion GLTFSDK/Source/SchemaValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace
throw GLTFException("Schema document at " + uri + " is not valid JSON");
}

auto result = schemaDocuments.emplace(uri, rapidjson::SchemaDocument(document, nullptr, 0, this));
auto result = schemaDocuments.emplace(uri, rapidjson::SchemaDocument(document)); // , nullptr, 0, this));
assert(result.second);
auto resultSchemaDoc = &(result.first->second);
assert(resultSchemaDoc);
Expand Down
6 changes: 6 additions & 0 deletions GLTFSDK/Source/Serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ namespace
return TARGETPATH_NAME_SCALE;
case TARGET_WEIGHTS:
return TARGETPATH_NAME_WEIGHTS;
case TARGET_COLOR_0:
return TARGETPATH_NAME_COLOR_0;
case TARGET_ATTRIBUTE_0:
return TARGETPATH_NAME_ATTRIBUTE_0;
default:
return "";
}
Expand Down Expand Up @@ -503,6 +507,8 @@ namespace
RapidJsonUtils::AddOptionalMemberIndex(ACCESSOR_POSITION, targetValue, target.positionsAccessorId, gltfDocument.accessors, a);
RapidJsonUtils::AddOptionalMemberIndex(ACCESSOR_NORMAL, targetValue, target.normalsAccessorId, gltfDocument.accessors, a);
RapidJsonUtils::AddOptionalMemberIndex(ACCESSOR_TANGENT, targetValue, target.tangentsAccessorId, gltfDocument.accessors, a);
RapidJsonUtils::AddOptionalMemberIndex(ACCESSOR_ATTRIBUTE_0, targetValue, target.attribute0AccessorId, gltfDocument.accessors, a);
RapidJsonUtils::AddOptionalMemberIndex(ACCESSOR_COLOR_0, targetValue, target.color0AccessorId, gltfDocument.accessors, a);

return targetValue;
}
Expand Down
4 changes: 4 additions & 0 deletions GLTFSDK/Source/Validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ void Validation::ValidateMeshPrimitiveAttributeAccessors(
{ ACCESSOR_TEXCOORD_0, { { TYPE_VEC2 }, { COMPONENT_FLOAT, COMPONENT_UNSIGNED_BYTE, COMPONENT_UNSIGNED_SHORT } } },
{ ACCESSOR_TEXCOORD_1, { { TYPE_VEC2 }, { COMPONENT_FLOAT, COMPONENT_UNSIGNED_BYTE, COMPONENT_UNSIGNED_SHORT } } },
{ ACCESSOR_COLOR_0, { { TYPE_VEC3, TYPE_VEC4 }, { COMPONENT_FLOAT, COMPONENT_UNSIGNED_BYTE, COMPONENT_UNSIGNED_SHORT } } },
{ ACCESSOR_COLOR_1, { { TYPE_VEC3, TYPE_VEC4 }, { COMPONENT_FLOAT, COMPONENT_UNSIGNED_BYTE, COMPONENT_UNSIGNED_SHORT } } },
{ ACCESSOR_COLOR_2, { { TYPE_VEC3, TYPE_VEC4 }, { COMPONENT_FLOAT, COMPONENT_UNSIGNED_BYTE, COMPONENT_UNSIGNED_SHORT } } },
{ ACCESSOR_COLOR_3, { { TYPE_VEC3, TYPE_VEC4 }, { COMPONENT_FLOAT, COMPONENT_UNSIGNED_BYTE, COMPONENT_UNSIGNED_SHORT } } },
{ ACCESSOR_ATTRIBUTE_0, { { TYPE_SCALAR }, { COMPONENT_FLOAT } } },
{ ACCESSOR_JOINTS_0, { { TYPE_VEC4 }, { COMPONENT_UNSIGNED_BYTE, COMPONENT_UNSIGNED_SHORT } } },
{ ACCESSOR_WEIGHTS_0, { { TYPE_VEC4 }, { COMPONENT_FLOAT, COMPONENT_UNSIGNED_BYTE, COMPONENT_UNSIGNED_SHORT } } }
};
Expand Down