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

Material and imagery refactor for Kit 105 #384

Merged
merged 5 commits into from
Jul 3, 2023
Merged
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
5 changes: 1 addition & 4 deletions src/core/include/cesium/omniverse/FabricGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ class FabricGeometry {
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
bool smoothNormals,
bool hasImagery,
const glm::dvec2& imageryTexcoordTranslation,
const glm::dvec2& imageryTexcoordScale,
uint64_t imageryTexcoordSetIndex);
bool hasImagery);

void setActive(bool active);
void setVisibility(bool visible);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class FabricGeometryDefinition {
const CesiumGltf::MeshPrimitive& primitive,
bool smoothNormals,
bool hasImagery,
uint64_t imageryTexcoordSetIndex,
bool disableMaterials);

[[nodiscard]] bool hasMaterial() const;
Expand Down
9 changes: 7 additions & 2 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ class FabricMaterial {
int64_t tilesetId,
int64_t tileId,
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
const CesiumGltf::ImageCesium* imagery);
const CesiumGltf::MeshPrimitive& primitive);

void setImagery(
const CesiumGltf::ImageCesium* imagery,
const glm::dvec2& imageryTexcoordTranslation,
const glm::dvec2& imageryTexcoordScale,
uint64_t imageryTexcoordSetIndex);

void setActive(bool active);

Expand Down
21 changes: 0 additions & 21 deletions src/core/include/cesium/omniverse/FabricMaterialDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,11 @@ class FabricMaterialDefinition {
[[nodiscard]] bool hasBaseColorTexture() const;
[[nodiscard]] bool hasVertexColors() const;

[[nodiscard]] float getAlphaCutoff() const;
[[nodiscard]] int getAlphaMode() const;
[[nodiscard]] float getBaseAlpha() const;
[[nodiscard]] pxr::GfVec3f getBaseColorFactor() const;
[[nodiscard]] pxr::GfVec3f getEmissiveFactor() const;
[[nodiscard]] float getMetallicFactor() const;
[[nodiscard]] float getRoughnessFactor() const;
[[nodiscard]] int getWrapS() const;
[[nodiscard]] int getWrapT() const;

bool operator==(const FabricMaterialDefinition& other) const;

private:
bool _hasBaseColorTexture;
bool _hasVertexColors;

// Remove these once dynamic material values are supported in Kit 105
float _alphaCutoff;
int _alphaMode;
float _baseAlpha;
pxr::GfVec3f _baseColorFactor;
pxr::GfVec3f _emissiveFactor;
float _metallicFactor;
float _roughnessFactor;
int _wrapS;
int _wrapT;
};

} // namespace cesium::omniverse
3 changes: 3 additions & 0 deletions src/core/include/cesium/omniverse/FabricMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class FabricMesh {
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
bool smoothNormals,
bool hasImagery);

void setImagery(
const CesiumGltf::ImageCesium* imagery,
const glm::dvec2& imageryTexcoordTranslation,
const glm::dvec2& imageryTexcoordScale,
Expand Down
12 changes: 4 additions & 8 deletions src/core/include/cesium/omniverse/FabricMeshManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class FabricMeshManager {
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
bool smoothNormals,
const CesiumGltf::ImageCesium* imagery,
uint64_t imageryTexcoordSetIndex);
bool hasImagery);

void releaseMesh(const std::shared_ptr<FabricMesh>& mesh);

Expand All @@ -57,13 +56,10 @@ class FabricMeshManager {
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
bool smoothNormals,
const CesiumGltf::ImageCesium* imagery,
uint64_t imageryTexcoordSetIndex);
bool hasImagery);

std::shared_ptr<FabricMaterial> acquireMaterial(
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
const CesiumGltf::ImageCesium* imagery);
std::shared_ptr<FabricMaterial>
acquireMaterial(const CesiumGltf::Model& model, const CesiumGltf::MeshPrimitive& primitive, bool hasImagery);

void releaseGeometry(const std::shared_ptr<FabricGeometry>& geometry);
void releaseMaterial(const std::shared_ptr<FabricMaterial>& material);
Expand Down
9 changes: 1 addition & 8 deletions src/core/include/cesium/omniverse/GltfAccessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,13 @@ class NormalsAccessor {
class TexcoordsAccessor {
public:
TexcoordsAccessor();
TexcoordsAccessor(
const CesiumGltf::AccessorView<glm::fvec2>& view,
const glm::fvec2& translation,
const glm::fvec2& scale,
bool flipVertical);
TexcoordsAccessor(const CesiumGltf::AccessorView<glm::fvec2>& view, bool flipVertical);

void fill(const gsl::span<pxr::GfVec2f>& values) const;
uint64_t size() const;

private:
CesiumGltf::AccessorView<glm::fvec2> _view;
glm::fvec2 _translation;
glm::fvec2 _scale;
bool _applyTransform;
bool _flipVertical;
uint64_t _size;
};
Expand Down
16 changes: 4 additions & 12 deletions src/core/include/cesium/omniverse/GltfUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ NormalsAccessor getNormals(
const IndicesAccessor& indices,
bool smoothNormals);

TexcoordsAccessor getTexcoords(
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
uint64_t setIndex,
const glm::fvec2& translation,
const glm::fvec2& scale);
TexcoordsAccessor
getTexcoords(const CesiumGltf::Model& model, const CesiumGltf::MeshPrimitive& primitive, uint64_t setIndex);

VertexColorsAccessor
getVertexColors(const CesiumGltf::Model& model, const CesiumGltf::MeshPrimitive& primitive, uint64_t setIndex);
Expand Down Expand Up @@ -67,12 +63,8 @@ std::optional<uint64_t> getBaseColorTextureIndex(const CesiumGltf::Model& model,

bool getDoubleSided(const CesiumGltf::Model& model, const CesiumGltf::MeshPrimitive& primitive);

TexcoordsAccessor getImageryTexcoords(
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
uint64_t setIndex,
const glm::fvec2& translation,
const glm::fvec2& scale);
TexcoordsAccessor
getImageryTexcoords(const CesiumGltf::Model& model, const CesiumGltf::MeshPrimitive& primitive, uint64_t setIndex);

const CesiumGltf::ImageCesium& getImageCesium(const CesiumGltf::Model& model, const CesiumGltf::Texture& texture);

Expand Down
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ bool hasStage();
glm::dvec3 usdToGlmVector(const pxr::GfVec3d& vector);
glm::dmat4 usdToGlmMatrix(const pxr::GfMatrix4d& matrix);
pxr::GfVec3d glmToUsdVector(const glm::dvec3& vector);
pxr::GfVec2f glmToUsdVector(const glm::fvec2& vector);
pxr::GfMatrix4d glmToUsdMatrix(const glm::dmat4& matrix);
Decomposed glmToUsdMatrixDecomposed(const glm::dmat4& matrix);
glm::dmat4 computeUsdWorldTransform(const pxr::SdfPath& path);
Expand Down
14 changes: 3 additions & 11 deletions src/core/src/FabricGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,7 @@ void FabricGeometry::setTile(
const CesiumGltf::Model& model,
const CesiumGltf::MeshPrimitive& primitive,
bool smoothNormals,
bool hasImagery,
const glm::dvec2& imageryTexcoordTranslation,
const glm::dvec2& imageryTexcoordScale,
uint64_t imageryTexcoordSetIndex) {
bool hasImagery) {

const auto hasTexcoords = _geometryDefinition.hasTexcoords();
const auto hasNormals = _geometryDefinition.hasNormals();
Expand All @@ -262,13 +259,8 @@ void FabricGeometry::setTile(
const auto indices = GltfUtil::getIndices(model, primitive, positions);
const auto normals = GltfUtil::getNormals(model, primitive, positions, indices, smoothNormals);
const auto vertexColors = GltfUtil::getVertexColors(model, primitive, 0);
const auto texcoords_0 = GltfUtil::getTexcoords(model, primitive, 0, glm::fvec2(0.0, 0.0), glm::fvec2(1.0, 1.0));
const auto imageryTexcoords = GltfUtil::getImageryTexcoords(
model,
primitive,
imageryTexcoordSetIndex,
glm::fvec2(imageryTexcoordTranslation),
glm::fvec2(imageryTexcoordScale));
const auto texcoords_0 = GltfUtil::getTexcoords(model, primitive, 0);
const auto imageryTexcoords = GltfUtil::getImageryTexcoords(model, primitive, 0);
const auto extent = GltfUtil::getExtent(model, primitive);
const auto faceVertexCounts = GltfUtil::getFaceVertexCounts(indices);

Expand Down
3 changes: 1 addition & 2 deletions src/core/src/FabricGeometryDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ FabricGeometryDefinition::FabricGeometryDefinition(
const CesiumGltf::MeshPrimitive& primitive,
bool smoothNormals,
bool hasImagery,
uint64_t imageryTexcoordSetIndex,
bool disableMaterials) {

const auto hasMaterial = GltfUtil::hasMaterial(primitive);
const auto hasPrimitiveSt = GltfUtil::hasTexcoords(model, primitive, 0);
const auto hasImagerySt = GltfUtil::hasImageryTexcoords(model, primitive, imageryTexcoordSetIndex);
const auto hasImagerySt = GltfUtil::hasImageryTexcoords(model, primitive, 0);

_hasMaterial = (hasMaterial || hasImagery) && !disableMaterials;
_hasTexcoords = hasPrimitiveSt || hasImagerySt;
Expand Down
Loading