Skip to content

Commit

Permalink
Tileset material nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jul 31, 2023
1 parent 10a5bc9 commit e5f3f2b
Show file tree
Hide file tree
Showing 22 changed files with 597 additions and 287 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
Checks: "-*,bugprone-*,performance-*,modernize-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-bugprone-exception-escape"
Checks: "-*,bugprone-*,performance-*,modernize-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-bugprone-exception-escape,-modernize-pass-by-value"
WarningsAsErrors: "*"
FormatStyle: none
18 changes: 16 additions & 2 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export float2 world_coordinate_2d(float2 min_world_xy=float2(-5000.0,-5000.0), f
anno::author("Cesium"),
anno::in_group("Cesium functions"),
anno::ui_order(300)
]]{
]]
{
// Get the world pos of the pixel
float3 world_pos = state::transform_vector(state::coordinate_internal, state::coordinate_world, state::position());

Expand Down Expand Up @@ -74,4 +75,17 @@ export color lookup_world_texture_color(uniform texture_2d texture = texture_2d(
wrap_v: ::tex::wrap_clamp);
}

export material cesium_gltf_material(*) = gltf_material();
// For internal use only. See note in FabricMaterial.cpp
export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup();

export color cesium_base_color_texture(gltf_texture_lookup_value base_color_texture)
[[
anno::display_name("Base color texture lookup color"),
anno::description("Returns color from the base color texture of the tile"),
anno::author("Cesium GS Inc."),
anno::in_group("Cesium functions"),
anno::ui_order(300)
]]
{
return color(base_color_texture.value.x, base_color_texture.value.y, base_color_texture.value.z);
}
6 changes: 4 additions & 2 deletions src/core/include/cesium/omniverse/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ class Context {
uint64_t tokenEventId,
uint64_t assetEventId);

std::filesystem::path getCesiumExtensionLocation() const;
std::filesystem::path getCertificatePath() const;
const std::filesystem::path& getCesiumExtensionLocation() const;
const std::filesystem::path& getCertificatePath() const;
const pxr::TfToken& getCesiumMdlPathToken() const;

bool creditsAvailable() const;
std::vector<std::pair<std::string, bool>> getCredits() const;
Expand Down Expand Up @@ -162,6 +163,7 @@ class Context {

std::filesystem::path _cesiumExtensionLocation;
std::filesystem::path _certificatePath;
pxr::TfToken _cesiumMdlPathToken;

glm::dmat4 _ecefToUsdTransform;
};
Expand Down
2 changes: 0 additions & 2 deletions src/core/include/cesium/omniverse/FabricGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ struct Model;

namespace cesium::omniverse {

class FabricMaterial;

class FabricGeometry {
public:
FabricGeometry(
Expand Down
46 changes: 26 additions & 20 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,29 @@
#include "cesium/omniverse/GltfUtil.h"

#include <omni/fabric/IPath.h>
#include <omni/fabric/Type.h>
#include <pxr/usd/sdf/assetPath.h>
#include <pxr/usd/sdf/path.h>

namespace omni::ui {
class DynamicTextureProvider;
}

namespace CesiumGltf {
struct ImageCesium;
struct MeshPrimitive;
struct Model;
} // namespace CesiumGltf

namespace cesium::omniverse {

class FabricTexture;

class FabricMaterial {
public:
FabricMaterial(
pxr::SdfPath path,
const pxr::SdfPath& path,
const FabricMaterialDefinition& materialDefinition,
pxr::SdfAssetPath defaultTextureAssetPath);
const pxr::TfToken& defaultTextureAssetPathToken);

~FabricMaterial();

void setMaterial(int64_t tilesetId, const MaterialInfo& materialInfo);
void setBaseColorTexture(const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo);

void setBaseColorTexture(const std::shared_ptr<FabricTexture>& texture, const TextureInfo& textureInfo);

void clearMaterial();
void clearBaseColorTexture();

void setActive(bool active);
Expand All @@ -41,18 +35,30 @@ class FabricMaterial {
[[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const;

private:
void initialize(pxr::SdfPath path, const FabricMaterialDefinition& materialDefinition);
void initialize();
void initializeFromExistingMaterial(const omni::fabric::Path& path);

void createMaterial(const omni::fabric::Path& materialPath);
void createShader(const omni::fabric::Path& shaderPath, const omni::fabric::Path& materialPath);
void createTexture(
const omni::fabric::Path& texturePath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput);

void reset();
void setTilesetId(int64_t tilesetId);
void setMaterialValues(const MaterialInfo& materialInfo);
void setBaseColorTextureValues(const pxr::SdfAssetPath& textureAssetPath, const TextureInfo& textureInfo);
void setShaderValues(const omni::fabric::Path& shaderPath, const MaterialInfo& materialInfo);
void setTextureValues(
const omni::fabric::Path& texturePath,
const pxr::TfToken& textureAssetPathToken,
const TextureInfo& textureInfo);

omni::fabric::Path _materialPath;
const FabricMaterialDefinition _materialDefinition;
const pxr::SdfAssetPath _defaultTextureAssetPath;
const pxr::TfToken _defaultTextureAssetPathToken;

omni::fabric::Path _materialPathFabric;
omni::fabric::Path _shaderPathFabric;
omni::fabric::Path _baseColorTexPathFabric;
std::vector<omni::fabric::Path> _shaderPaths;
std::vector<omni::fabric::Path> _baseColorTexturePaths;
std::vector<omni::fabric::Path> _allPaths;
};

} // namespace cesium::omniverse
15 changes: 9 additions & 6 deletions src/core/include/cesium/omniverse/FabricMaterialDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,31 @@
#include <glm/glm.hpp>
#include <pxr/base/gf/vec2f.h>
#include <pxr/base/gf/vec3f.h>

namespace CesiumGltf {
struct MeshPrimitive;
struct Model;
} // namespace CesiumGltf
#include <pxr/usd/sdf/path.h>

namespace cesium::omniverse {

struct MaterialInfo;

class FabricMaterialDefinition {
public:
FabricMaterialDefinition(const MaterialInfo& materialInfo, bool hasImagery, bool disableTextures);
FabricMaterialDefinition(
const MaterialInfo& materialInfo,
bool hasImagery,
bool disableTextures,
const pxr::SdfPath& tilesetMaterialPath);

[[nodiscard]] bool hasBaseColorTexture() const;
[[nodiscard]] bool hasVertexColors() const;
[[nodiscard]] bool hasTilesetMaterial() const;
[[nodiscard]] const pxr::SdfPath& getTilesetMaterialPath() const;

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

private:
bool _hasBaseColorTexture;
bool _hasVertexColors;
pxr::SdfPath _tilesetMaterialPath;
};

} // namespace cesium::omniverse
4 changes: 2 additions & 2 deletions src/core/include/cesium/omniverse/FabricMaterialPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FabricMaterialPool final : public ObjectPool<FabricMaterial> {
int64_t poolId,
const FabricMaterialDefinition& materialDefinition,
uint64_t initialCapacity,
pxr::SdfAssetPath defaultTextureAssetPath);
const pxr::TfToken& defaultTextureAssetPathToken);

[[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const;

Expand All @@ -25,7 +25,7 @@ class FabricMaterialPool final : public ObjectPool<FabricMaterial> {
private:
const int64_t _poolId;
const FabricMaterialDefinition _materialDefinition;
const pxr::SdfAssetPath _defaultTextureAssetPath;
const pxr::TfToken _defaultTextureAssetPathToken;
};

} // namespace cesium::omniverse
7 changes: 4 additions & 3 deletions src/core/include/cesium/omniverse/FabricResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ class FabricResourceManager {
bool shouldAcquireMaterial(
const CesiumGltf::MeshPrimitive& primitive,
bool hasImagery,
const pxr::SdfPath& materialPath) const;
const pxr::SdfPath& tilesetMaterialPath) const;

std::shared_ptr<FabricGeometry>
acquireGeometry(const CesiumGltf::Model& model, const CesiumGltf::MeshPrimitive& primitive, bool smoothNormals);

std::shared_ptr<FabricMaterial> acquireMaterial(const MaterialInfo& materialInfo, bool hasImagery);
std::shared_ptr<FabricMaterial>
acquireMaterial(const MaterialInfo& materialInfo, bool hasImagery, const pxr::SdfPath& tilesetMaterialPath);

std::shared_ptr<FabricTexture> acquireTexture();

Expand Down Expand Up @@ -107,7 +108,7 @@ class FabricResourceManager {
std::mutex _poolMutex;

std::unique_ptr<omni::ui::DynamicTextureProvider> _defaultTexture;
pxr::SdfAssetPath _defaultTextureAssetPath;
pxr::TfToken _defaultTextureAssetPathToken;
};

} // namespace cesium::omniverse
5 changes: 3 additions & 2 deletions src/core/include/cesium/omniverse/FabricTexture.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <pxr/base/tf/token.h>
#include <pxr/usd/sdf/assetPath.h>

#include <memory>
Expand All @@ -23,12 +24,12 @@ class FabricTexture {

void setActive(bool active);

[[nodiscard]] const pxr::SdfAssetPath& getAssetPath() const;
[[nodiscard]] const pxr::TfToken& getAssetPathToken() const;

private:
void reset();

std::unique_ptr<omni::ui::DynamicTextureProvider> _texture;
pxr::SdfAssetPath _assetPath;
pxr::TfToken _assetPathToken;
};
} // namespace cesium::omniverse
9 changes: 8 additions & 1 deletion src/core/include/cesium/omniverse/FabricUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ std::string printFabricStage();
FabricStatistics getStatistics();
void destroyPrim(const omni::fabric::Path& path);
void setTilesetTransform(int64_t tilesetId, const glm::dmat4& ecefToUsdTransform);
void setTilesetId(const omni::fabric::Path& pathFabric, int64_t tilesetId);
void setTilesetId(const omni::fabric::Path& path, int64_t tilesetId);
omni::fabric::Path toFabricPath(const pxr::SdfPath& path);
omni::fabric::Path joinPaths(const omni::fabric::Path& absolutePath, const omni::fabric::Token& relativePath);
std::vector<omni::fabric::Path>
copyMaterial(const omni::fabric::Path& srcMaterialPath, const omni::fabric::Path& dstMaterialPath);
bool materialHasCesiumNodes(const omni::fabric::Path& path);
bool isCesiumNode(const omni::fabric::Token& mdlIdentifier);
omni::fabric::Token getMdlIdentifier(const omni::fabric::Path& path);

} // namespace cesium::omniverse::FabricUtil
7 changes: 7 additions & 0 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace cesium::omniverse::FabricTokens {
extern const omni::fabric::TokenC baseColorTex;
extern const omni::fabric::TokenC cesium_base_color_texture;
extern const omni::fabric::TokenC cesium_texture_lookup;
extern const omni::fabric::TokenC constant;
extern const omni::fabric::TokenC doubleSided;
extern const omni::fabric::TokenC extent;
Expand All @@ -24,6 +26,7 @@ extern const omni::fabric::TokenC inputs_base_alpha;
extern const omni::fabric::TokenC inputs_base_color_factor;
extern const omni::fabric::TokenC inputs_base_color_texture;
extern const omni::fabric::TokenC inputs_emissive_factor;
extern const omni::fabric::TokenC inputs_excludeFromWhiteMode;
extern const omni::fabric::TokenC inputs_metallic_factor;
extern const omni::fabric::TokenC inputs_offset;
extern const omni::fabric::TokenC inputs_rotation;
Expand Down Expand Up @@ -71,6 +74,8 @@ extern const omni::fabric::TokenC _worldVisibility;

namespace cesium::omniverse::UsdTokens {
extern const pxr::TfToken& baseColorTex;
extern const pxr::TfToken& cesium_base_color_texture;
extern const pxr::TfToken& cesium_texture_lookup;
extern const pxr::TfToken& constant;
extern const pxr::TfToken& doubleSided;
extern const pxr::TfToken& extent;
Expand All @@ -88,6 +93,7 @@ extern const pxr::TfToken& inputs_base_alpha;
extern const pxr::TfToken& inputs_base_color_factor;
extern const pxr::TfToken& inputs_base_color_texture;
extern const pxr::TfToken& inputs_emissive_factor;
extern const pxr::TfToken& inputs_excludeFromWhiteMode;
extern const pxr::TfToken& inputs_metallic_factor;
extern const pxr::TfToken& inputs_offset;
extern const pxr::TfToken& inputs_rotation;
Expand Down Expand Up @@ -147,6 +153,7 @@ const omni::fabric::Type inputs_alpha_mode(omni::fabric::BaseDataType::eInt, 1,
const omni::fabric::Type inputs_base_alpha(omni::fabric::BaseDataType::eFloat, 1, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type inputs_base_color_factor(omni::fabric::BaseDataType::eFloat, 3, 0, omni::fabric::AttributeRole::eColor);
const omni::fabric::Type inputs_emissive_factor(omni::fabric::BaseDataType::eFloat, 3, 0, omni::fabric::AttributeRole::eColor);
const omni::fabric::Type inputs_excludeFromWhiteMode(omni::fabric::BaseDataType::eBool, 1, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type inputs_metallic_factor(omni::fabric::BaseDataType::eFloat, 1, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type inputs_offset(omni::fabric::BaseDataType::eFloat, 2, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type inputs_rotation(omni::fabric::BaseDataType::eFloat, 1, 0, omni::fabric::AttributeRole::eNone);
Expand Down
2 changes: 1 addition & 1 deletion src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ double getUsdMetersPerUnit();
pxr::SdfPath getRootPath();
pxr::SdfPath getPathUnique(const pxr::SdfPath& parentPath, const std::string& name);
std::string getSafeName(const std::string& name);
pxr::SdfAssetPath getDynamicTextureProviderAssetPath(const std::string& name);
pxr::TfToken getDynamicTextureProviderAssetPathToken(const std::string& name);
glm::dmat4 computeEcefToUsdTransformForPrim(const CesiumGeospatial::Cartographic& origin, const pxr::SdfPath& primPath);
glm::dmat4 computeUsdToEcefTransformForPrim(const CesiumGeospatial::Cartographic& origin, const pxr::SdfPath& primPath);
Cesium3DTilesSelection::ViewState
Expand Down
10 changes: 8 additions & 2 deletions src/core/src/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void Context::initialize(int64_t contextId, const std::filesystem::path& cesiumE

_cesiumExtensionLocation = cesiumExtensionLocation.lexically_normal();
_certificatePath = _cesiumExtensionLocation / "certs" / "cacert.pem";
const auto cesiumMdlPath = _cesiumExtensionLocation / "mdl" / "cesium.mdl";
_cesiumMdlPathToken = pxr::TfToken(cesiumMdlPath.generic_string());

_taskProcessor = std::make_shared<TaskProcessor>();
_httpAssetAccessor = std::make_shared<HttpAssetAccessor>(_certificatePath);
Expand Down Expand Up @@ -672,14 +674,18 @@ void Context::updateTroubleshootingDetails(
}
}

std::filesystem::path Context::getCesiumExtensionLocation() const {
const std::filesystem::path& Context::getCesiumExtensionLocation() const {
return _cesiumExtensionLocation;
}

std::filesystem::path Context::getCertificatePath() const {
const std::filesystem::path& Context::getCertificatePath() const {
return _certificatePath;
}

const pxr::TfToken& Context::getCesiumMdlPathToken() const {
return _cesiumMdlPathToken;
}

bool Context::getDebugDisableMaterials() const {
const auto cesiumDataUsd = UsdUtil::getOrCreateCesiumData();
bool disableMaterials;
Expand Down
Loading

0 comments on commit e5f3f2b

Please sign in to comment.