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 a572c76 commit f67019f
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .vscode/launch.linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"exceptionList": "libcesium.omniverse.plugin.so;libcesium.omniverse.cpp.tests.plugin.so"
},
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "python import sys;sys.path.insert(0, '/usr/share/gcc/python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)",
"ignoreFailures": false
},
{
"text": "-enable-pretty-printing",
"ignoreFailures": true
Expand Down
30 changes: 30 additions & 0 deletions exts/cesium.omniverse/mdl/cesium.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,33 @@ module [[
// 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();

export gltf_texture_lookup_value cesium_texture_array_lookup(
uniform texture_2d texture_0,
uniform texture_2d texture_1,
uniform texture_2d texture_2
)
{
gltf_texture_lookup_value tex_ret;
tex_ret.valid = true;

// uniform texture_2d[3] textures;
// textures[0] = texture_0;
// textures[1] = texture_1;
// textures[2] = texture_2;

// int texture_index = ::scene::data_lookup_int("textureIndex");
// texture_index = texture_index % 3;

// for (int i = 0; i < 3; i++) {
// if (i == texture_index) {
// tex_ret.value = tex::lookup_float4(
// tex: textures[i],
// coord: float2(0.0, 0.0),
// wrap_u: ::tex::wrap_clamp,
// wrap_v: ::tex::wrap_clamp);
// }
// }

return tex_ret;
}
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
16 changes: 15 additions & 1 deletion src/core/include/cesium/omniverse/FabricMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class FabricMaterial {
const omni::fabric::Path& path,
const FabricMaterialDefinition& materialDefinition,
const pxr::TfToken& defaultTextureAssetPathToken,
long stageId);
long stageId,
bool usesTextureArray,
uint64_t textureArrayLength);
~FabricMaterial();

void setMaterial(int64_t tilesetId, const MaterialInfo& materialInfo);
Expand All @@ -34,6 +36,8 @@ class FabricMaterial {
[[nodiscard]] const omni::fabric::Path& getPath() const;
[[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const;

bool usesTextureArray() const;

private:
void initialize();

Expand All @@ -43,13 +47,20 @@ class FabricMaterial {
const omni::fabric::Path& texturePath,
const omni::fabric::Path& shaderPath,
const omni::fabric::Token& shaderInput);
void createTextureArray(
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 setTextureArrayValues(
const omni::fabric::Path& texturePath,
const std::vector<pxr::TfToken>& textureAssetPathTokens);
void setTilesetId(int64_t tilesetId);
bool stageDestroyed();

Expand All @@ -60,6 +71,9 @@ class FabricMaterial {

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

bool _usesTextureArray;
uint64_t _textureArrayLength;
};

} // namespace cesium::omniverse
2 changes: 2 additions & 0 deletions src/core/include/cesium/omniverse/FabricResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class FabricResourceManager {

bool _debugRandomColors{false};

bool _usesTextureArray{true};

std::atomic<uint64_t> _geometryId{0};
std::atomic<uint64_t> _materialId{0};
std::atomic<uint64_t> _textureId{0};
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
6 changes: 6 additions & 0 deletions src/core/include/cesium/omniverse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
#define USD_TOKENS \
(baseColorTexture) \
(cesium_material) \
(cesium_texture_array_lookup) \
(cesium_texture_lookup) \
(constant) \
(doubleSided) \
Expand Down Expand Up @@ -60,6 +61,9 @@ __pragma(warning(push)) __pragma(warning(disable : 4003))
((inputs_scale, "inputs:scale")) \
((inputs_tex_coord_index, "inputs:tex_coord_index")) \
((inputs_texture, "inputs:texture")) \
((inputs_texture_0, "inputs:texture_0")) \
((inputs_texture_1, "inputs:texture_1")) \
((inputs_texture_2, "inputs:texture_2")) \
((inputs_vertex_color_name, "inputs:vertex_color_name")) \
((inputs_wrap_s, "inputs:wrap_s")) \
((inputs_wrap_t, "inputs:wrap_t")) \
Expand All @@ -72,6 +76,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 +145,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, 1, 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
20 changes: 20 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 @@ -180,6 +193,10 @@ void FabricGeometry::initialize() {
srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayColor, 1);
srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayOpacity, 1);

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

// clang-format off
auto primvarsFabric = srw.getArrayAttributeWr<omni::fabric::TokenC>(_path, FabricTokens::primvars);
auto primvarInterpolationsFabric = srw.getArrayAttributeWr<omni::fabric::TokenC>(_path, FabricTokens::primvarInterpolations);
Expand All @@ -194,6 +211,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 +264,7 @@ void FabricGeometry::reset() {

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

if (hasNormals) {
Expand Down
Loading

0 comments on commit f67019f

Please sign in to comment.