Skip to content

Commit

Permalink
Merge branch 'main' of github.com:alexxbb/hapi-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexxbb committed Nov 20, 2022
2 parents 5b87186 + 7c54c7d commit fb4f34f
Show file tree
Hide file tree
Showing 30 changed files with 1,108 additions and 639 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cmake-build-*
*/target
_build
*.hip*
.cargo
.cargo
_*
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# hapi-rs changelog
## [0.8.0]
## Changed
- AssetLibrary::try_create_first() can now crate nodes other than of Object type.
- Functions taking optional parent (`Option<NodeHandle>`) are now generic and can take `HoudiniNode` too.
- Improve the error type handling and printing.
- Remove `CookOptions` arg from `HoudiniNode::cook`, instead there's new `HoudiniNode::cook_with_options`.
- Add lots of `debug_assert!` for input validation.

## New
- `ManagerType` enum represents a network root node.
- Add several missing geometry APIs.

## [0.7.0]
## Changed
- Reworked parameter APIs
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository = "https://github.com/alexxbb/hapi-rs/"
keywords = ["vfx", "graphics", "gamedev", "houdini"]
categories = ["graphics", "game-development"]
readme = "README.md"
version = "0.7.0"
version = "0.8.0"
authors = ["Aleksei Rusev <hou.alexx@gmail.com>"]
edition = "2021"
license = "MIT"
Expand All @@ -25,4 +25,5 @@ tempfile = "3.3.0"
once_cell = "1.5.2"
env_logger = "0.9.1"
prettytable-rs = "0.9.0"
fastrand = "1.6.0"
fastrand = "1.6.0"
anyhow = "1.0.66"
2 changes: 1 addition & 1 deletion examples/connecting_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hapi_rs::{attribute::*, geometry::*, session::*};
fn main() -> Result<()> {
let session = quick_session(None)?;
let geom = session.create_input_node("Cube")?;
geom.node.cook_blocking(None)?;
geom.node.cook_blocking()?;
let part_info = PartInfo::default()
.with_part_type(PartType::Mesh)
.with_face_count(6)
Expand Down
8 changes: 4 additions & 4 deletions examples/cook_pdg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use hapi_rs::enums::{PdgEventType, PdgWorkItemState};
use hapi_rs::node::{NodeType, Parameter};
use hapi_rs::node::Parameter;

use hapi_rs::pdg::TopNode;
use hapi_rs::session::{new_in_process, SessionOptionsBuilder};
Expand Down Expand Up @@ -80,12 +80,12 @@ fn main() -> Result<()> {
p.set(0, out_dir.to_string_lossy())?;
}

asset.cook_blocking(None)?;
asset.cook_blocking()?;

let subnet = asset.find_child_by_path(SUBNET)?;
let subnet = asset.get_child_by_path(SUBNET)?.expect("child node");
let top_net = &subnet.find_top_networks()?[0];
let top_node = top_net
.find_child_by_name(NODE_TO_COOK, NodeType::Top, false)?
.find_child_node(NODE_TO_COOK, false)?
.expect("TOP node");
let top_node = top_node.to_top_node().expect("top node");
for output in cook_async(&top_node)? {
Expand Down
2 changes: 1 addition & 1 deletion examples/curve_marshall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use hapi_rs::{attribute::*, geometry::*, session::*, Result};
fn main() -> Result<()> {
let session = quick_session(None)?;
let geom = session.create_input_node("Curve")?;
geom.node.cook_blocking(None)?;
geom.node.cook_blocking()?;
let part_info = PartInfo::default()
.with_part_type(PartType::Curve)
.with_face_count(1)
Expand Down
2 changes: 1 addition & 1 deletion examples/curve_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() -> Result<()> {
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)?;
node.cook_blocking()?;

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

Expand Down
4 changes: 2 additions & 2 deletions examples/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use hapi_rs::Result;

fn create_cube(session: &Session) -> Result<HoudiniNode> {
let geometry = session.create_input_node("Cube")?;
geometry.node.cook(None)?;
geometry.node.cook()?;

let part_info = PartInfo::default()
.with_part_type(PartType::Mesh)
Expand Down Expand Up @@ -74,7 +74,7 @@ fn main() -> Result<()> {
if let Parameter::Float(p) = xform.parameter("t").expect("t parm") {
p.set_array([0.0, 1.0, 0.0])?
}
xform.cook(None)?;
xform.cook()?;

let geo = xform.geometry()?.unwrap();
let num_groups = geo.group_count_by_type(GroupType::Point, None)?;
Expand Down
2 changes: 1 addition & 1 deletion examples/materials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() -> Result<()> {
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)?;
node.cook()?;
let geo = node.geometry()?.unwrap();
let material = match geo.get_materials(None)?.unwrap() {
Materials::Single(mat) => mat,
Expand Down
4 changes: 2 additions & 2 deletions examples/node_networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() -> Result<()> {
print_child_node(&session, &children)?;

// Create a new node and connect one of the child to it
let box_node = session.create_node("geo", Some("ProgrammaticBox"), Some(asset.handle))?;
let box_node = session.create_node("geo", Some("ProgrammaticBox"), &asset)?;
box_node.connect_input(0, children[0], 0)?;
// Verify connection
box_node.input_node(0)?.expect("Connection");
Expand All @@ -37,7 +37,7 @@ fn print_child_node(session: &Session, ids: &[NodeHandle]) -> Result<()> {
for handle in ids {
let info = handle.info(session)?;
#[rustfmt::skip]
println!("\t{:?} - {}", handle, info.created_post_asset_load().then(|| "NEW").unwrap_or("EXISTING"));
println!("\t{:?} - {}", handle, if info.created_post_asset_load() {"NEW"} else {"EXISTING"});
}

Ok(())
Expand Down
94 changes: 47 additions & 47 deletions examples/object_geos_parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,63 @@ fn main() -> Result<()> {

let lib = session.load_asset_file("otls/sesi/SideFX_spaceship.hda")?;
let node = lib.try_create_first()?;
node.cook_blocking(None)?;
node.cook_blocking()?;
let _asset_info = node.asset_info()?;

for info in node.get_objects_info()? {
let obj_node = info.to_node()?;
if let Some(geometry) = obj_node.geometry()? {
for part_info in geometry.partitions()? {
println!(
"Object: {}, Display: {}, Partition: {}",
obj_node.path()?,
geometry.node.path_relative(Some(obj_node.handle))?,
part_info.part_id()
);
let attrib_names =
geometry.get_attribute_names(AttributeOwner::Point, Some(&part_info))?;
println!(
"{}",
&attrib_names.iter_str().collect::<Vec<&str>>().join("\n")
);
println!("Point Positions: ");
let attrib = geometry
.get_attribute(part_info.part_id(), AttributeOwner::Point, "P")?
.unwrap();
let Some(geometry) = obj_node.geometry()? else {
continue;
};
for part_info in geometry.partitions()? {
println!(
"Object: {}, Display: {}, Partition: {}",
obj_node.path()?,
geometry.node.path_relative(Some(obj_node.handle))?,
part_info.part_id()
);
let attrib_names =
geometry.get_attribute_names(AttributeOwner::Point, Some(&part_info))?;
println!(
"{}",
&attrib_names.iter_str().collect::<Vec<&str>>().join("\n")
);
println!("Point Positions: ");
let attrib = geometry
.get_attribute(part_info.part_id(), AttributeOwner::Point, "P")?
.unwrap();

let attrib = attrib.downcast::<NumericAttr<f32>>().unwrap();
let positions = attrib.get(part_info.part_id())?;
for p in 0..attrib.info().count() {
let idx = (p * attrib.info().tuple_size()) as usize;
println!("{:?}", &positions[idx..idx + 3])
}
let attrib = attrib.downcast::<NumericAttr<f32>>().unwrap();
let positions = attrib.get(part_info.part_id())?;
for p in 0..attrib.info().count() {
let idx = (p * attrib.info().tuple_size()) as usize;
println!("{:?}", &positions[idx..idx + 3])
}

println!("Number of Faces: {}", part_info.face_count());
let faces = geometry.get_face_counts(Some(&part_info))?;
if part_info.part_type() != PartType::Curve {
for face in faces.iter() {
print!("{}, ", face);
}
println!();
println!("Number of Faces: {}", part_info.face_count());
let faces = geometry.get_face_counts(Some(&part_info))?;
if part_info.part_type() != PartType::Curve {
for face in faces.iter() {
print!("{}, ", face);
}
let vertices = geometry.vertex_list(Some(&part_info))?;
println!("Vertex Indices Into Points Array");
let mut curr_idx = 0;
assert!(curr_idx < vertices.len());
for (face, count) in faces.iter().enumerate() {
for _ in 0..(*count as usize) {
println!(
"Vertex: {0}, \
belonging to face: {1}, \
index: {2} of point array ",
curr_idx, face, vertices[curr_idx]
);
curr_idx += 1;
}
println!();
}
let vertices = geometry.vertex_list(Some(&part_info))?;
println!("Vertex Indices Into Points Array");
let mut curr_idx = 0;
assert!(curr_idx < vertices.len());
for (face, count) in faces.iter().enumerate() {
for _ in 0..(*count as usize) {
println!(
"Vertex: {0}, \
belonging to face: {1}, \
index: {2} of point array ",
curr_idx, face, vertices[curr_idx]
);
curr_idx += 1;
}
}
}
}

Ok(())
}
13 changes: 4 additions & 9 deletions examples/packed_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ fn main() -> Result<()> {
}
);
co.set_packed_prim_instancing_mode(mode);
asset.cook_blocking(Some(&co))?;
asset.cook_with_options(&co, true)?;

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))?;
node.cook_with_options(&co, true)?;
let geo = node.geometry()?.expect("geometry");
println!(
"Part count for node {:?}: {}",
Expand All @@ -37,15 +37,10 @@ fn main() -> Result<()> {
);
for part in geo.partitions()? {
println!(
"Part {}\n Point Count = {}\n Type = {}",
"Part {}\n Point Count = {}\n Type = {:?}",
part.part_id(),
part.point_count(),
match part.part_type() {
PartType::Mesh => "Mesh",
PartType::Curve => "Curve",
PartType::Instancer => "Instancer",
p => "oops",
}
part.part_type(),
);
}
}
Expand Down
11 changes: 8 additions & 3 deletions examples/parameters.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
use hapi_rs::parameter::Parameter;
use hapi_rs::parameter::{Parameter, ParmType};
use hapi_rs::session::{quick_session, SessionOptions};
use hapi_rs::Result;
use prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR as FORMAT;
use prettytable::*;

fn main() -> Result<()> {
env_logger::init();
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)?;
node.cook_blocking()?;

let mut table = prettytable::Table::new();
table.set_format(*FORMAT);
table.set_titles(row!["Parameter", "Value"]);
for parm in node.parameters()? {
let name = parm.name()?;
let val_str = match parm {
let typ = parm.info().parm_type();
let val_str = match &parm {
Parameter::Int(p) if typ == ParmType::Toggle => {
format!("{:?}", if p.get(0)? == 1 { "On" } else { "Off" })
}
Parameter::Int(p) => format!("{:?}", p.get(0)?),
Parameter::Float(p) => format!("{:?}", p.get(0)?),
Parameter::String(p) => format!("{:?}", p.get(0)?),
Expand Down
Loading

0 comments on commit fb4f34f

Please sign in to comment.