Skip to content

Commit

Permalink
Material cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Aug 15, 2023
1 parent 7f648af commit 1adfb5d
Show file tree
Hide file tree
Showing 32 changed files with 423 additions and 376 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
12 changes: 11 additions & 1 deletion apps/cesium.omniverse.dev.kit
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ app = true
[dependencies]
# Include basic configuration (that brings most of basic extensions)
"omni.app.dev" = {}
"omni.kit.window.material_graph" = {}
"cesium.omniverse" = {}
"cesium.powertools" = {}
#"omni.example.ui" = {}
Expand All @@ -17,6 +18,15 @@ app.useFabricSceneDelegate = true
app.usdrt.scene_delegate.enableProxyCubes = false
app.usdrt.scene_delegate.geometryStreaming.enabled = false
app.fastShutdown = true
# Both searchPaths settings must be set in order for material graph to find cesium mdl exports
renderer.mdl.searchPaths.custom = "${app}/../exts/cesium.omniverse/mdl"
materialConfig.searchPaths.custom = ["${app}/../exts/cesium.omniverse/mdl"]
materialConfig.materialGraph.userAllowList = ["cesium.mdl"]

[settings.app.exts]
folders.'++' = ["${app}/../exts"] # Make extensions from this repo available.
folders.'++' = [
"${app}", # Find other applications in this folder
"${app}/exts", # Find extensions in this folder
"${app}/../exts", # Find cesium.omniverse and cesium.usd.schemas
"${app}/../extern/nvidia/app/extscache" # Find omni.kit.window.material_graph
]
6 changes: 0 additions & 6 deletions apps/cesium.omniverse.dev.python.debug.kit
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,3 @@ app = true

[settings]
app.window.title = "Cesium For Omniverse Python Debugging App"

[settings.app.exts]
folders.'++' = [
"${app}",
"${app}/../exts"
]
6 changes: 0 additions & 6 deletions apps/cesium.omniverse.dev.trace.kit
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ app = true
[settings]
app.window.title = "Cesium For Omniverse Performance Tracing App"
app.fastShutdown = false

[settings.app.exts]
folders.'++' = [
"${app}",
"${app}/../exts"
]
7 changes: 0 additions & 7 deletions apps/cesium.performance.kit
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,3 @@ app = true

[settings]
app.window.title = "Cesium For Omniverse Performance Testing App"

[settings.app.exts]
folders.'++' = [
"${app}",
"${app}/exts",
"${app}/../exts"
]
8 changes: 8 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ if(exit_code AND NOT exit_code EQUAL 0)
endif()
# cmake-format: on

# Add a symlink to USD Composer (create) so that we can use its extensions (e.g. omni.kit.window.material_graph) in our internal applications
# Don't check for errors because we can still proceed with the build
if(UNIX)
execute_process(COMMAND bash "${PROJECT_SOURCE_DIR}/extern/nvidia/link_app.sh --app create")
elseif(WIN32)
execute_process(COMMAND cmd /C "${PROJECT_SOURCE_DIR}/extern/nvidia/link_app.bat --app create")
endif()

if(WIN32)
set(NVIDIA_PLATFORM_NAME "windows-x86_64")
elseif(UNIX AND NOT APPLE)
Expand Down
16 changes: 16 additions & 0 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mdl 1.8;

import ::anno::*;
import ::state::*;
import ::tex::*;

using ::gltf::pbr import *;

module [[
anno::version( 1, 0, 0),
anno::display_name("Cesium MDL functions")
]];

// For internal use only. See note in FabricMaterial.cpp
export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup();
export material cesium_material(*) [[ anno::hidden() ]] = gltf_material();
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
8 changes: 3 additions & 5 deletions src/core/include/cesium/omniverse/FabricGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ struct Model;

namespace cesium::omniverse {

class FabricMaterial;

class FabricGeometry {
public:
FabricGeometry(
const pxr::SdfPath& path,
const omni::fabric::Path& path,
const FabricGeometryDefinition& geometryDefinition,
bool debugRandomColors,
long stageId);
Expand All @@ -37,7 +35,7 @@ class FabricGeometry {
void setActive(bool active);
void setVisibility(bool visible);

[[nodiscard]] omni::fabric::Path getPathFabric() const;
[[nodiscard]] omni::fabric::Path getPath() const;
[[nodiscard]] const FabricGeometryDefinition& getGeometryDefinition() const;

void setMaterial(const omni::fabric::Path& materialPath);
Expand All @@ -47,7 +45,7 @@ class FabricGeometry {
void reset();
bool stageDestroyed();

const omni::fabric::Path _pathFabric;
const omni::fabric::Path _path;
const FabricGeometryDefinition _geometryDefinition;
const bool _debugRandomColors;
const long _stageId;
Expand Down
44 changes: 24 additions & 20 deletions src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,62 @@
#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 omni::fabric::Path& path,
const FabricMaterialDefinition& materialDefinition,
pxr::SdfAssetPath defaultTextureAssetPath,
const pxr::TfToken& defaultTextureAssetPathToken,
long stageId);
~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);

[[nodiscard]] omni::fabric::Path getPathFabric() const;
[[nodiscard]] omni::fabric::Path getPath() const;
[[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const;

private:
void initialize(pxr::SdfPath path, const FabricMaterialDefinition& materialDefinition);
void initialize();

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 setShaderValues(const omni::fabric::Path& shaderPath, const MaterialInfo& materialInfo);
void setTextureValues(
const omni::fabric::Path& texturePath,
const pxr::TfToken& textureAssetPathToken,
const TextureInfo& textureInfo);
void setTilesetId(int64_t tilesetId);
void setMaterialValues(const MaterialInfo& materialInfo);
void setBaseColorTextureValues(const pxr::SdfAssetPath& textureAssetPath, const TextureInfo& textureInfo);
bool stageDestroyed();

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

omni::fabric::Path _materialPathFabric;
omni::fabric::Path _shaderPathFabric;
omni::fabric::Path _baseColorTexPathFabric;
omni::fabric::Path _shaderPath;
omni::fabric::Path _baseColorTexturePath;
};

} // namespace cesium::omniverse
5 changes: 0 additions & 5 deletions src/core/include/cesium/omniverse/FabricMaterialDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
#include <pxr/base/gf/vec2f.h>
#include <pxr/base/gf/vec3f.h>

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

namespace cesium::omniverse {

struct MaterialInfo;
Expand Down
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,
long stageId);

[[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const;
Expand All @@ -26,7 +26,7 @@ class FabricMaterialPool final : public ObjectPool<FabricMaterial> {
private:
const int64_t _poolId;
const FabricMaterialDefinition _materialDefinition;
const pxr::SdfAssetPath _defaultTextureAssetPath;
const pxr::TfToken _defaultTextureAssetPathToken;
const long _stageId;
};

Expand Down
4 changes: 2 additions & 2 deletions src/core/include/cesium/omniverse/FabricResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ 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,
Expand Down Expand Up @@ -116,7 +116,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
4 changes: 3 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,8 @@ 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);

} // namespace cesium::omniverse::FabricUtil
2 changes: 1 addition & 1 deletion src/core/include/cesium/omniverse/OmniImagery.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace cesium::omniverse {
class OmniImagery {
public:
OmniImagery(pxr::SdfPath path);
OmniImagery(const pxr::SdfPath& path);

[[nodiscard]] pxr::SdfPath getPath() const;
[[nodiscard]] std::string getName() const;
Expand Down
17 changes: 9 additions & 8 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
// clang-format off

namespace cesium::omniverse::FabricTokens {
extern const omni::fabric::TokenC baseColorTex;
extern const omni::fabric::TokenC baseColorTexture;
extern const omni::fabric::TokenC cesium_material;
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;
extern const omni::fabric::TokenC faceVertexCounts;
extern const omni::fabric::TokenC faceVertexIndices;
extern const omni::fabric::TokenC gltf_material;
extern const omni::fabric::TokenC gltf_pbr_mdl;
extern const omni::fabric::TokenC gltf_texture_lookup;
extern const omni::fabric::TokenC info_implementationSource;
extern const omni::fabric::TokenC info_mdl_sourceAsset;
extern const omni::fabric::TokenC info_mdl_sourceAsset_subIdentifier;
Expand All @@ -24,6 +23,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 @@ -70,15 +70,14 @@ extern const omni::fabric::TokenC _worldVisibility;
}

namespace cesium::omniverse::UsdTokens {
extern const pxr::TfToken& baseColorTex;
extern const pxr::TfToken& baseColorTexture;
extern const pxr::TfToken& cesium_material;
extern const pxr::TfToken& cesium_texture_lookup;
extern const pxr::TfToken& constant;
extern const pxr::TfToken& doubleSided;
extern const pxr::TfToken& extent;
extern const pxr::TfToken& faceVertexCounts;
extern const pxr::TfToken& faceVertexIndices;
extern const pxr::TfToken& gltf_material;
extern const pxr::TfToken& gltf_pbr_mdl;
extern const pxr::TfToken& gltf_texture_lookup;
extern const pxr::TfToken& info_implementationSource;
extern const pxr::TfToken& info_mdl_sourceAsset;
extern const pxr::TfToken& info_mdl_sourceAsset_subIdentifier;
Expand All @@ -88,6 +87,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 +147,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
6 changes: 3 additions & 3 deletions src/core/include/cesium/omniverse/UsdUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ struct Decomposed {

class ScopedEdit {
public:
ScopedEdit(pxr::UsdStageRefPtr stage)
: _stage(std::move(stage))
ScopedEdit(const pxr::UsdStageRefPtr& stage)
: _stage(stage)
, _sessionLayer(_stage->GetSessionLayer())
, _sessionLayerWasEditable(_sessionLayer->PermissionToEdit())
, _originalEditTarget(_stage->GetEditTarget()) {
Expand Down Expand Up @@ -78,7 +78,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
Loading

0 comments on commit 1adfb5d

Please sign in to comment.