-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add python type annotations #8
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,35 +17,35 @@ | |
ASSETS_DIRECTORY = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def attach_billboard(stage, root, name="card"): | ||
def attach_billboard(stage: Usd.Stage, root: UsdGeom.Xform, name="card") -> UsdGeom.Mesh: | ||
billboard = UsdGeom.Mesh.Define(stage, str(root.GetPath()) + "/" + name) | ||
billboard.CreatePointsAttr( | ||
[(-430, -145, 0), (430, -145, 0), (430, 145, 0), (-430, 145, 0)] | ||
) | ||
billboard.CreateFaceVertexCountsAttr([4]) | ||
billboard.CreateFaceVertexIndicesAttr([0, 1, 2, 3]) | ||
billboard.CreateExtentAttr([(-430, -145, 0), (430, 145, 0)]) | ||
texCoords = billboard.CreatePrimvar( | ||
texCoords = UsdGeom.PrimvarsAPI(billboard).CreatePrimvar( | ||
"st", Sdf.ValueTypeNames.TexCoord2fArray, UsdGeom.Tokens.varying | ||
) | ||
texCoords.Set([(0, 0), (1, 0), (1, 1), (0, 1)]) | ||
return billboard | ||
|
||
|
||
def attach_surface_shader(stage, material, path): | ||
def attach_surface_shader(stage: Usd.Stage, material: UsdShade.Material, path: str) -> UsdShade.Shader: | ||
shader = UsdShade.Shader.Define(stage, path) | ||
shader.CreateIdAttr("UsdPreviewSurface") | ||
shader.CreateInput("roughness", Sdf.ValueTypeNames.Float).Set(0.4) | ||
shader.CreateInput("metallic", Sdf.ValueTypeNames.Float).Set(0.0) | ||
|
||
material.CreateSurfaceOutput().ConnectToSource(shader, "surface") | ||
material.CreateSurfaceOutput().ConnectToSource(shader.CreateInput("surface", Sdf.ValueTypeNames.Color3f)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if this should be |
||
|
||
return shader | ||
|
||
|
||
def attach_texture( | ||
stage, shader, material_path, reader_name="stReader", shader_name="diffuseTexture" | ||
): | ||
stage: Usd.Stage, shader: UsdShade.Shader, material_path, reader_name="stReader", shader_name="diffuseTexture" | ||
) -> UsdShade.Shader: | ||
reader = UsdShade.Shader.Define(stage, material_path + "/" + reader_name) | ||
reader.CreateIdAttr("UsdPrimvarReader_float2") | ||
|
||
|
@@ -57,11 +57,11 @@ def attach_texture( | |
os.path.join(ASSETS_DIRECTORY, "USDLogoLrg.png") | ||
) | ||
diffuseTextureSampler.CreateInput("st", Sdf.ValueTypeNames.Float2).ConnectToSource( | ||
reader, "result" | ||
reader.CreateInput("result", Sdf.ValueTypeNames.Float2) | ||
) | ||
diffuseTextureSampler.CreateOutput("rgb", Sdf.ValueTypeNames.Float3) | ||
shader.CreateInput("diffuseColor", Sdf.ValueTypeNames.Color3f).ConnectToSource( | ||
diffuseTextureSampler, "rgb" | ||
diffuseTextureSampler.CreateInput("rgb", Sdf.ValueTypeNames.Color3f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are some more guesses on input vs output and type. The examples all run correctly, just not sure if they're doing the right thing. |
||
) | ||
|
||
return reader | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def change_test_dir(request, monkeypatch): | ||
monkeypatch.chdir(request.fspath.dirname) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
# -*- coding: utf-8 -*- | ||
|
||
# IMPORT FUTURE LIBRARIES | ||
from __future__ import print_function | ||
from __future__ import print_function, annotations | ||
|
||
# IMPORT THIRD-PARTY LIBRARIES | ||
from pxr import Tf, Usd | ||
|
||
|
||
def update(notice, sender): | ||
def update(notice: Usd.Notice.ObjectsChanged, sender: Usd.Stage): | ||
"""Print example data that you can get from the callback.""" | ||
print("The triggered sender", notice.GetStage()) | ||
print("Resynced paths", notice.GetResyncedPaths()) | ||
|
@@ -38,7 +38,7 @@ def main(): | |
# You must assign `Register` to a variable (even if you don't run | ||
# `del` on it later) or the callback goes out of scope and does nothing. | ||
# | ||
updated = Tf.Notice.Register(Usd.Notice.ObjectsChanged, update, stage) | ||
updated: Tf.Notice.Listener = Tf.Notice.Register(Usd.Notice.ObjectsChanged, update, stage) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically speaking, the use of annotations on variable assignments like this isn't necessary for mypy to work correctly, because the |
||
stage.DefinePrim("/SomeSphere") | ||
stage.GetPrimAtPath("/SomeSphere").SetMetadata("comment", "") | ||
|
||
|
@@ -54,13 +54,13 @@ def main(): | |
# `Usd.Notice.StageContentsChanged` | ||
# `Usd.Notice.StageEditTargetChanged` | ||
# | ||
contents = Tf.Notice.RegisterGlobally( | ||
contents: Tf.Notice.Listener = Tf.Notice.RegisterGlobally( | ||
Usd.Notice.StageContentsChanged, stage_changed | ||
) | ||
|
||
objects = Tf.Notice.RegisterGlobally(Usd.Notice.ObjectsChanged, objects_changed) | ||
objects: Tf.Notice.Listener = Tf.Notice.RegisterGlobally(Usd.Notice.ObjectsChanged, objects_changed) | ||
|
||
targets = Tf.Notice.RegisterGlobally( | ||
targets: Tf.Notice.Listener = Tf.Notice.RegisterGlobally( | ||
Usd.Notice.StageEditTargetChanged, target_changed | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
#include <pxr/usd/usd/clipsAPI.h> | ||
#include <pxr/usd/sdf/types.h> | ||
#include <pxr/usd/usd/stage.h> | ||
|
||
#include <pxr/base/vt/array.h> | ||
#include <pxr/base/gf/vec2d.h> | ||
|
||
int main() { | ||
auto stage = pxr::UsdStage::CreateInMemory(); | ||
|
@@ -30,6 +31,11 @@ int main() { | |
model.SetClipTemplateStride(1, template_set_name); | ||
model.SetClipPrimPath("/Template", template_set_name); | ||
|
||
pxr::VtArray<pxr::SdfAssetPath> assetPaths; | ||
model.GetClipAssetPaths(&assetPaths, non_template_set_name); | ||
pxr::VtVec2dArray active; | ||
model.GetClipActive(&active); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the new C++ code that I added to match the new python behavior, but I was not able to test it. chad $ USD_INSTALL_ROOT=~/dev/USD/.build-23.05-py39-stock cmake ..
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
USD_BOOST_PYTHON
linked by target "run_it" in directory /Users/chad/dev/USD-Cookbook/features/value_clips/cpp/template_and_explicit
USD_SDF
linked by target "run_it" in directory /Users/chad/dev/USD-Cookbook/features/value_clips/cpp/template_and_explicit
USD_TF
linked by target "run_it" in directory /Users/chad/dev/USD-Cookbook/features/value_clips/cpp/template_and_explicit
USD_USD
linked by target "run_it" in directory /Users/chad/dev/USD-Cookbook/features/value_clips/cpp/template_and_explicit
USD_USDGEOM
linked by target "run_it" in directory /Users/chad/dev/USD-Cookbook/features/value_clips/cpp/template_and_explicit
USD_VT
linked by target "run_it" in directory /Users/chad/dev/USD-Cookbook/features/value_clips/cpp/template_and_explicit My build uses the standard USD build script, and the contents of
I think there's just a minor adjustment that needs to be made to the |
||
|
||
prim.GetReferences().AddReference( | ||
"./ref.usda", | ||
pxr::SdfPath{"/Ref"} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[mypy] | ||
check_untyped_defs=true | ||
python_version=3.11 | ||
files=concepts/*/python,features/*/python | ||
|
||
[mypy-pxr.*] | ||
ignore_errors=true | ||
|
||
[mypy-PySide6.*] | ||
ignore_missing_imports = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new API change. tested and working.