## Copyright (c) 2022, NVIDIA CORPORATION.  All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto.  Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##

import omni.kit.test
from .test_hydra_common import RtxHydraTest
from .test_common import set_transform_helper, wait_for_update
from pxr import Gf, UsdVol


class TestRtxHydraVolume(RtxHydraTest):
    TEST_PATH = "hydra/volume"
    PRIM_PATH = "/World/volume"

    def create_geometry(self, name=PRIM_PATH):
        open_vdb_asset = UsdVol.OpenVDBAsset.Define(self.ctx.get_stage(), name + "/OpenVDBAsset")
        open_vdb_asset.GetFilePathAttr().Set(self.get_volumes_path("sphere.vdb"))
        open_vdb_asset.GetFieldNameAttr().Set("density")
        volume = UsdVol.Volume.Define(self.ctx.get_stage(), name)
        volume.CreateFieldRelationship("density", open_vdb_asset.GetPath())
        set_transform_helper(volume.GetPath(), translate=Gf.Vec3d(0, 150, 0), scale=Gf.Vec3d(20.0, 20.0, 20.0))
        return volume

    # simple test, create a volume with a OpenVDB asset
    # Unstable via OM-54845
    async def test_UNSTABLE_create_UNSTABLE(self):
        self.add_floor()
        self.create_geometry()
        await wait_for_update()
        await self.capture_and_compare(self.TEST_PATH, "create_sphere.png", threshold=1e-3)

    # test changing the OpenVDBAsset file path
    # Unstable via OM-54845
    async def test_UNSTABLE_change_to_torus_UNSTABLE(self):
        self.add_floor()
        self.create_geometry()
        open_vdb_asset = UsdVol.OpenVDBAsset(self.ctx.get_stage().GetPrimAtPath(self.PRIM_PATH + "/OpenVDBAsset"))
        open_vdb_asset.GetFilePathAttr().Set(self.get_volumes_path("torus.vdb"))
        await wait_for_update()
        await self.capture_and_compare(self.TEST_PATH, "change_to_torus.png", threshold=1e-3)
