Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Oct 4, 2023
1 parent e5aa976 commit dd8fa66
Show file tree
Hide file tree
Showing 16 changed files with 457 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/core/include/cesium/omniverse/FabricGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class FabricGeometry {
[[nodiscard]] const FabricGeometryDefinition& getGeometryDefinition() const;

void setMaterial(const omni::fabric::Path& materialPath);
void setTextureIndex(uint64_t textureIndex);

private:
void initialize();
Expand Down
4 changes: 2 additions & 2 deletions src/core/include/cesium/omniverse/FabricGeometryPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace cesium::omniverse {
class FabricGeometryPool final : public ObjectPool<FabricGeometry> {
public:
FabricGeometryPool(
int64_t poolId,
uint64_t poolId,
const FabricGeometryDefinition& geometryDefinition,
uint64_t initialCapacity,
bool debugRandomColors,
Expand All @@ -22,7 +22,7 @@ class FabricGeometryPool final : public ObjectPool<FabricGeometry> {
void setActive(std::shared_ptr<FabricGeometry> geometry, bool active) override;

private:
const int64_t _poolId;
const uint64_t _poolId;
const FabricGeometryDefinition _geometryDefinition;
const bool _debugRandomColors;
const long _stageId;
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 @@ -11,7 +11,7 @@ namespace cesium::omniverse {
class FabricMaterialPool final : public ObjectPool<FabricMaterial> {
public:
FabricMaterialPool(
int64_t poolId,
uint64_t poolId,
const FabricMaterialDefinition& materialDefinition,
uint64_t initialCapacity,
const pxr::TfToken& defaultTextureAssetPathToken,
Expand All @@ -24,7 +24,7 @@ class FabricMaterialPool final : public ObjectPool<FabricMaterial> {
void setActive(std::shared_ptr<FabricMaterial> material, bool active) override;

private:
const int64_t _poolId;
const uint64_t _poolId;
const FabricMaterialDefinition _materialDefinition;
const pxr::TfToken _defaultTextureAssetPathToken;
const long _stageId;
Expand Down
65 changes: 65 additions & 0 deletions src/core/include/cesium/omniverse/FabricMultiTextureMaterial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once

#include "cesium/omniverse/FabricMaterialDefinition.h"
#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 cesium::omniverse {

class FabricMultiTextureMaterial {
public:
FabricMultiTextureMaterial(
const omni::fabric::Path& path,
const FabricMaterialDefinition& materialDefinition,
const pxr::TfToken& defaultTextureAssetPathToken,
long stageId);
~FabricMultiTextureMaterial();

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

void clearMaterial();
void clearBaseColorTexture();

void setActive(bool active);

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

private:
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);
bool stageDestroyed();

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

omni::fabric::Path _shaderPath;
omni::fabric::Path _baseColorTexturePath;
};

} // namespace cesium::omniverse
16 changes: 8 additions & 8 deletions src/core/include/cesium/omniverse/FabricResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class FabricResourceManager {
createMaterialPool(const FabricMaterialDefinition& materialDefinition, long stageId);
std::shared_ptr<FabricTexturePool> createTexturePool();

int64_t getNextGeometryId();
int64_t getNextMaterialId();
int64_t getNextTextureId();
int64_t getNextPoolId();
uint64_t getNextGeometryId();
uint64_t getNextMaterialId();
uint64_t getNextTextureId();
uint64_t getNextPoolId();

std::vector<std::shared_ptr<FabricGeometryPool>> _geometryPools;
std::vector<std::shared_ptr<FabricMaterialPool>> _materialPools;
Expand All @@ -132,10 +132,10 @@ class FabricResourceManager {

bool _debugRandomColors{false};

std::atomic<int64_t> _geometryId{0};
std::atomic<int64_t> _materialId{0};
std::atomic<int64_t> _textureId{0};
std::atomic<int64_t> _poolId{0};
std::atomic<uint64_t> _geometryId{0};
std::atomic<uint64_t> _materialId{0};
std::atomic<uint64_t> _textureId{0};
std::atomic<uint64_t> _poolId{0};

std::mutex _poolMutex;

Expand Down
4 changes: 3 additions & 1 deletion src/core/include/cesium/omniverse/FabricTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ struct ImageCesium;
namespace cesium::omniverse {
class FabricTexture {
public:
FabricTexture(const std::string& name);
FabricTexture(const std::string& name, uint64_t index);
~FabricTexture();

void setImage(const CesiumGltf::ImageCesium& image);

void setActive(bool active);

[[nodiscard]] const pxr::TfToken& getAssetPathToken() const;
[[nodiscard]] uint64_t getIndex() const;

private:
void reset();

std::unique_ptr<omni::ui::DynamicTextureProvider> _texture;
pxr::TfToken _assetPathToken;
uint64_t _index;
};
} // namespace cesium::omniverse
4 changes: 2 additions & 2 deletions src/core/include/cesium/omniverse/FabricTexturePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace cesium::omniverse {

class FabricTexturePool final : public ObjectPool<FabricTexture> {
public:
FabricTexturePool(int64_t poolId, uint64_t initialCapacity);
FabricTexturePool(uint64_t poolId, uint64_t initialCapacity);

protected:
std::shared_ptr<FabricTexture> createObject(uint64_t objectId) override;
void setActive(std::shared_ptr<FabricTexture> texture, bool active) override;

private:
const int64_t _poolId;
const uint64_t _poolId;
};

} // namespace cesium::omniverse
2 changes: 2 additions & 0 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
((primvars_displayOpacity, "primvars:displayOpacity")) \
((primvars_normals, "primvars:normals")) \
((primvars_st, "primvars:st")) \
((primvars_textureIndex, "primvars:textureIndex")) \
((primvars_vertexColor, "primvars:vertexColor"))

TF_DECLARE_PUBLIC_TOKENS(UsdTokens, USD_TOKENS);
Expand Down Expand Up @@ -140,6 +141,7 @@ const omni::fabric::Type primvars_displayColor(omni::fabric::BaseDataType::eFloa
const omni::fabric::Type primvars_displayOpacity(omni::fabric::BaseDataType::eFloat, 1, 1, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type primvars_normals(omni::fabric::BaseDataType::eFloat, 3, 1, omni::fabric::AttributeRole::eNormal);
const omni::fabric::Type primvars_st(omni::fabric::BaseDataType::eFloat, 2, 1, omni::fabric::AttributeRole::eTexCoord);
const omni::fabric::Type primvars_textureIndex(omni::fabric::BaseDataType::eInt, 1, 0, omni::fabric::AttributeRole::eNone);
const omni::fabric::Type primvars_vertexColor(omni::fabric::BaseDataType::eFloat, 3, 1, omni::fabric::AttributeRole::eColor);
const omni::fabric::Type Shader(omni::fabric::BaseDataType::eTag, 1, 0, omni::fabric::AttributeRole::ePrimTypeName);
const omni::fabric::Type subdivisionScheme(omni::fabric::BaseDataType::eToken, 1, 0, omni::fabric::AttributeRole::eNone);
Expand Down
17 changes: 17 additions & 0 deletions src/core/src/FabricGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ void FabricGeometry::setMaterial(const omni::fabric::Path& materialPath) {
materialBindingFabric[0] = materialPath;
}

void FabricGeometry::setTextureIndex(uint64_t textureIndex) {
if (stageDestroyed()) {
return;
}

auto srw = UsdUtil::getFabricStageReaderWriter();
auto textureIndexFabric = srw.getArrayAttributeWr<int>(_path, FabricTokens::primvars_textureIndex);
textureIndexFabric[0] = static_cast<int>(textureIndex);
}

void FabricGeometry::initialize() {
const auto hasTexcoords = _geometryDefinition.hasTexcoords();
const auto hasNormals = _geometryDefinition.hasNormals();
Expand Down Expand Up @@ -134,6 +144,7 @@ void FabricGeometry::initialize() {

if (hasTexcoords) {
attributes.addAttribute(FabricTypes::primvars_st, FabricTokens::primvars_st);
attributes.addAttribute(FabricTypes::primvars_textureIndex, FabricTokens::primvars_textureIndex);
}

if (hasNormals) {
Expand All @@ -157,6 +168,7 @@ void FabricGeometry::initialize() {
// Initialize primvars
size_t primvarsCount = 0;
size_t primvarIndexSt = 0;
size_t primvarTextureIndex = 0;
size_t primvarIndexNormal = 0;
size_t primvarIndexVertexColor = 0;

Expand All @@ -165,6 +177,7 @@ void FabricGeometry::initialize() {

if (hasTexcoords) {
primvarIndexSt = primvarsCount++;
primvarTextureIndex = primvarsCount++;
}

if (hasNormals) {
Expand All @@ -179,6 +192,7 @@ void FabricGeometry::initialize() {
srw.setArrayAttributeSize(_path, FabricTokens::primvarInterpolations, primvarsCount);
srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayColor, 1);
srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayOpacity, 1);
srw.setArrayAttributeSize(_path, FabricTokens::primvars_textureIndex, 1);

// clang-format off
auto primvarsFabric = srw.getArrayAttributeWr<omni::fabric::TokenC>(_path, FabricTokens::primvars);
Expand All @@ -194,6 +208,8 @@ void FabricGeometry::initialize() {
if (hasTexcoords) {
primvarsFabric[primvarIndexSt] = FabricTokens::primvars_st;
primvarInterpolationsFabric[primvarIndexSt] = FabricTokens::vertex;
primvarsFabric[primvarTextureIndex] = FabricTokens::primvars_textureIndex;
primvarInterpolationsFabric[primvarTextureIndex] = FabricTokens::constant;
}

if (hasNormals) {
Expand Down Expand Up @@ -245,6 +261,7 @@ void FabricGeometry::reset() {

if (hasTexcoords) {
srw.setArrayAttributeSize(_path, FabricTokens::primvars_st, 0);
srw.setArrayAttributeSize(_path, FabricTokens::primvars_textureIndex, 0);
}

if (hasNormals) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/FabricGeometryPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace cesium::omniverse {

FabricGeometryPool::FabricGeometryPool(
int64_t poolId,
uint64_t poolId,
const FabricGeometryDefinition& geometryDefinition,
uint64_t initialCapacity,
bool debugRandomColors,
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/FabricMaterialPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace cesium::omniverse {

FabricMaterialPool::FabricMaterialPool(
int64_t poolId,
uint64_t poolId,
const FabricMaterialDefinition& materialDefinition,
uint64_t initialCapacity,
const pxr::TfToken& defaultTextureAssetPathToken,
Expand Down
Loading

0 comments on commit dd8fa66

Please sign in to comment.