Skip to content

Commit

Permalink
Implementation of PDG APIs and other improvements. (#9)
Browse files Browse the repository at this point in the history
Update to H19.5 with PDG APIs.
  • Loading branch information
alexxbb authored Nov 1, 2022
1 parent 81196fd commit f027f51
Show file tree
Hide file tree
Showing 37 changed files with 1,721 additions and 595 deletions.
Empty file added .env
Empty file.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
on:
push:
tags:
- '*' # Push events to every tag not containing /
workflow_dispatch:

name: publish

env:
HFS: ""

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ windows-latest, ubuntu-latest ]

steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- run: cargo check

publish:
name: publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: katyo/publish-crates@v1
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
ignore-unpublished-changes: true
dry-run: true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ otls/backup
cmake-build-*
*/target
_build
*.hip*
*.hip*
.cargo
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## H19.5

# TODO:
* (New) HAPI_CookPDGAllOutputs
* HAPI_GetInstanceTransforms -> HAPI_GetInstanceTransformsOnPart
* HAPI_GetPDGGraphContexts + HAPI_GetPDGGraphContextsCount
* Bunch of new PDG APIs
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ exclude = [
[dependencies]
log = "0.4.14"
paste = "1.0.6"
parking_lot = "0.11.2"
duplicate = { version = "0.3.0", features = [], default-features = false }
parking_lot = "0.12.1"
duplicate = { version = "0.4.1", features = [], default-features = false }
tempfile = "3.3.0"

[dev-dependencies]
once_cell = "1.5.2"
env_logger = "0.8.2"
prettytable-rs = "0.8.0"
env_logger = "0.9.1"
prettytable-rs = "0.9.0"
fastrand = "1.6.0"
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;

fn main() {
if let Ok(_) = std::env::var("DOCS_RS") {
if std::env::var("DOCS_RS").is_ok() {
return;
}
let hfs = std::env::var("HFS").expect("HFS variable not set");
Expand Down
3 changes: 1 addition & 2 deletions examples/connecting_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use hapi_rs::Result;
use hapi_rs::{attribute::*, geometry::*, session::*};

fn main() -> Result<()> {
let mut session = quick_session()?;
session.initialize(&SessionOptions::default())?;
let session = quick_session(None)?;
let geom = session.create_input_node("Cube")?;
geom.node.cook_blocking(None)?;
let part_info = PartInfo::default()
Expand Down
96 changes: 96 additions & 0 deletions examples/cook_pdg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use env_logger;
use hapi_rs::enums::{PdgEventType, PdgWorkItemState};
use hapi_rs::node::{NodeType, Parameter};
use hapi_rs::parameter::ParmBaseTrait;
use hapi_rs::pdg::TopNode;
use hapi_rs::session::{new_in_process, SessionOptionsBuilder};
use hapi_rs::Result;
use std::ops::ControlFlow;

fn cook_async(node: &TopNode) -> Result<Vec<String>> {
node.dirty_node(true)?;
let mut all_results = vec![];
let mut num_tasks = 0;
let mut tasks_done = 0;
// TODO: Add progress bar
println!("Cooking PDG...Should take a couple of seconds");
node.cook_async(|step| {
match step.event.event_type() {
PdgEventType::EventWorkitemAdd => num_tasks += 1,
PdgEventType::EventWorkitemRemove => num_tasks -= 1,
PdgEventType::WorkitemStateChange => match step.event.current_state() {
PdgWorkItemState::Success | PdgWorkItemState::Cache => {
let workitem = node.get_workitem(step.event.workitem_id(), step.graph_id)?;
if let Some(results) = workitem.get_results()? {
all_results.extend(results.into_iter().filter_map(|wir|
// We only interested in rendered images
(wir.tag().unwrap() == "file/image").then(||wir.result().unwrap())));
}
tasks_done += 1;
}
PdgWorkItemState::Fail => {
let item = node.get_workitem(step.event.workitem_id(), step.graph_id)?;
eprintln!("Workitem {item:?} failed to cook");
}
_ => {}
},
PdgEventType::EventCookError => {
eprintln!("PDG Cook Error :(");
return Ok(ControlFlow::Break(false));
}
_ => {}
}
Ok(ControlFlow::Continue(()))
})?;
Ok(all_results)
}

fn main() -> Result<()> {
env_logger::init();
let out_dir = std::env::args().skip(1).next();
let out_dir = if let Some(out_dir) = out_dir {
let out_dir = std::path::PathBuf::from(out_dir);
if !out_dir.exists() {
eprintln!("Path doesn't exists");
std::process::exit(1);
}
out_dir
} else {
eprintln!("Pass a directory path to write PDG output to");
std::process::exit(1);
};

const NODE_TO_COOK: &str = "out";
const SUBNET: &str = "second";
const NUM_FRAMES: i32 = 10;
let otl = std::env::current_dir()
.unwrap()
.join("otls/pdg_examples.hda");

let options = SessionOptionsBuilder::default()
.threaded(true)
.env_variables([("JOB", out_dir.to_string_lossy())])
.build();
let session = new_in_process(Some(&options))?;
let lib = session.load_asset_file(&otl)?;
let asset = lib.try_create_first()?;
if let Parameter::Float(p) = asset.parameter("num_frames")? {
p.set_value(&[NUM_FRAMES as f32])?;
}
if let Parameter::String(p) = asset.parameter("pdg_workingdir").expect("parm") {
p.set_value([out_dir.to_string_lossy().to_string()])?;
}

asset.cook_blocking(None)?;

let subnet = asset.find_child_by_path(SUBNET)?;
let top_net = &subnet.find_top_networks()?[0];
let top_node = top_net
.find_child_by_name(NODE_TO_COOK, NodeType::Top, false)?
.expect("TOP node");
let top_node = top_node.to_top_node().expect("top node");
for output in cook_async(&top_node)? {
println!("{}", output);
}
Ok(())
}
3 changes: 1 addition & 2 deletions examples/curve_marshall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
use hapi_rs::{attribute::*, geometry::*, session::*, Result};

fn main() -> Result<()> {
let mut session = quick_session()?;
session.initialize(&SessionOptions::default())?;
let session = quick_session(None)?;
let geom = session.create_input_node("Curve")?;
geom.node.cook_blocking(None)?;
let part_info = PartInfo::default()
Expand Down
8 changes: 3 additions & 5 deletions examples/curve_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ use hapi_rs::session::{quick_session, SessionOptions};
use hapi_rs::Result;

fn main() -> Result<()> {
let mut session = quick_session()?;
let mut opt = SessionOptions::default();
opt.threaded = true;
session.initialize(&opt)?;
let opt = SessionOptions::builder().threaded(true).build();
let session = quick_session(Some(&opt))?;
let lib = session.load_asset_file("otls/sesi/nurbs_curve.hda")?;
let node = lib.try_create_first()?;
node.cook_blocking(None)?;

let obj_info = &node.get_objects_info()?[0];

let children = node.get_children(NodeType::Sop, NodeFlags::Curve, true)?;
let children = node.find_children_by_type(NodeType::Sop, NodeFlags::Curve, true)?;
for node_h in children {
let node = node_h.to_node(&session)?;
let geo = node.geometry()?.expect("geometry");
Expand Down
2 changes: 1 addition & 1 deletion examples/default_parm_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use hapi_rs::session::quick_session;
use hapi_rs::Result;

fn main() -> Result<()> {
let ses = quick_session()?;
let ses = quick_session(None)?;
let lib = ses.load_asset_file("otls/sesi/SideFX_spaceship.hda")?;
let parms = lib.get_asset_parms("SideFX::Object/spaceship")?;
for p in &parms {
Expand Down
5 changes: 2 additions & 3 deletions examples/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hapi_rs::geometry::{
};
use hapi_rs::node::HoudiniNode;
use hapi_rs::parameter::{Parameter, ParmBaseTrait};
use hapi_rs::session::{quick_session, Session, SessionOptions};
use hapi_rs::session::{quick_session, Session};
use hapi_rs::Result;

fn create_cube(session: &Session) -> Result<HoudiniNode> {
Expand Down Expand Up @@ -64,8 +64,7 @@ fn create_cube(session: &Session) -> Result<HoudiniNode> {
}

fn main() -> Result<()> {
let mut session = quick_session()?;
session.initialize(&SessionOptions::default())?;
let session = quick_session(None)?;
let cube = create_cube(&session)?;
let xform = session.create_node("Sop/xform", Some("PointGroupManipulator"), None)?;
xform.connect_input(0, &cube, 0)?;
Expand Down
4 changes: 2 additions & 2 deletions examples/materials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use hapi_rs::session::quick_session;
use hapi_rs::Result;

fn main() -> Result<()> {
let session = quick_session()?;
let lib = session.load_asset_file("otls/sesi/SideFX_spaceship.otl")?;
let session = quick_session(None)?;
let lib = session.load_asset_file("otls/sesi/SideFX_spaceship.hda")?;
let node = lib.try_create_first()?;
node.cook(None)?;
let geo = node.geometry()?.unwrap();
Expand Down
9 changes: 4 additions & 5 deletions examples/node_networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use hapi_rs::session::*;
use hapi_rs::Result;

fn main() -> Result<()> {
let mut session = quick_session()?;
session.initialize(&SessionOptions::default())?;
let session = quick_session(None)?;
let lib = session.load_asset_file("otls/sesi/FourShapes.hda")?;
let asset = lib.try_create_first()?;
let children = asset.get_children(NodeType::Any, NodeFlags::Any, false)?;
let children = asset.find_children_by_type(NodeType::Any, NodeFlags::Any, false)?;
println!("Editable Node Network Child Count: {}", children.len());

// Print original children
Expand All @@ -21,13 +20,13 @@ fn main() -> Result<()> {

println!("After CONNECT NODE");
// Print out children again
let children = asset.get_children(NodeType::Any, NodeFlags::Any, false)?;
let children = asset.find_children_by_type(NodeType::Any, NodeFlags::Any, false)?;
print_child_node(&session, &children)?;

// Delete the new node and print one last time
box_node.delete()?;
println!("After DELETING NODE");
let children = asset.get_children(NodeType::Any, NodeFlags::Any, false)?;
let children = asset.find_children_by_type(NodeType::Any, NodeFlags::Any, false)?;
print_child_node(&session, &children)?;

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions examples/object_geos_parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use hapi_rs::session::*;
use hapi_rs::Result;

fn main() -> Result<()> {
let mut session = quick_session()?;
session.initialize(&SessionOptions::default())?;
let session = quick_session(None)?;

let lib = session.load_asset_file("otls/sesi/SideFX_spaceship.hda")?;
let node = lib.try_create_first()?;
Expand Down
5 changes: 2 additions & 3 deletions examples/packed_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use hapi_rs::session::*;
use hapi_rs::Result;

fn main() -> Result<()> {
let mut session = quick_session()?;
session.initialize(&SessionOptions::default())?;
let session = quick_session(None)?;

let lib = session.load_asset_file("otls/sesi/PackedPrimitive.hda")?;
let asset = lib.try_create_first()?;
Expand All @@ -26,7 +25,7 @@ fn main() -> Result<()> {
co.set_packed_prim_instancing_mode(mode);
asset.cook_blocking(Some(&co))?;

let nodes = asset.get_children(NodeType::Sop, NodeFlags::Any, false)?;
let nodes = asset.find_children_by_type(NodeType::Sop, NodeFlags::Any, false)?;
for handle in nodes {
let node = handle.to_node(&session)?;
node.cook_blocking(Some(&co))?;
Expand Down
8 changes: 3 additions & 5 deletions examples/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR as FORMAT;
use prettytable::*;

fn main() -> Result<()> {
let mut session = quick_session()?;
let mut opt = SessionOptions::default();
opt.threaded = true;
session.initialize(&opt)?;
let lib = session.load_asset_file("otls/sesi/SideFX_spaceship.otl")?;
let opt = SessionOptions::builder().threaded(true).build();
let session = quick_session(Some(&opt))?;
let lib = session.load_asset_file("otls/sesi/SideFX_spaceship.hda")?;
let node = lib.try_create_first()?;
node.cook_blocking(None)?;

Expand Down
2 changes: 1 addition & 1 deletion examples/run_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ hou.hscript('set -g TEST=hapi')
"#;

fn main() -> Result<()> {
let ses = quick_session()?;
let ses = quick_session(None)?;
let lib = ses.load_asset_file("otls/hapi_script.hda")?;
let node = lib.try_create_first()?;
if let Parameter::String(parm) = node.parameter("code")? {
Expand Down
7 changes: 7 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_default:
@just --list


start_hars:
@echo "Starting HARS"
$HFS/bin/HARS -n $TMP/hars.pipe
Binary file modified otls/hapi_parms.hda
Binary file not shown.
Binary file added otls/hapi_pdg.hda
Binary file not shown.
Binary file added otls/pdg_examples.hda
Binary file not shown.
Loading

0 comments on commit f027f51

Please sign in to comment.