You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use prometheus_engine::*;use glam::Vec3;// 1. Create a soldierletmut soldier = Entity::orpp_soldier(2.0);// scale 2.0 for 256³ grid
soldier.set_position(Vec3::new(128.0,92.0,128.0));// 2. Aim at something
soldier.aim_at(Vec3::new(200.0,80.0,150.0));// 3. Update (solves FK, IK, attachments)
soldier.update();// 4. Fire — bullet comes from muzzle automaticallyifletSome(fire) = soldier.fire(){println!("Bullet from {:?} going {:?}", fire.origin, fire.direction);}// 5. Rasterize into voxel gridletmut grid = vec![0u8;256*256*256*8];
soldier.rasterize(256, |x, y, z, mat, r, g, b| {// set voxel at (x,y,z) with material mat and color (r,g,b)});
Skeleton
Create
// Prefab skeletonslet human = Skeleton::human(1.0);// 21 bones, standard proportionslet cat = Skeleton::cat(1.0);// 26 bones, with tail and ears// Custom skeletonletmut sk = Skeleton::new("root");
sk.add_bone("spine","root",10.0,Vec3::Y,JointConstraint::BallSocket{cone_angle:0.3,twist_min: -0.2,twist_max:0.2});
sk.add_bone("arm","spine",15.0,Vec3::NEG_X,JointConstraint::Hinge{axis:Vec3::X,min_angle:0.0,max_angle:2.6});
Pose
// Set bone rotation
sk.set_rotation("spine",Quat::from_rotation_y(0.5));// Set hinge angle (for knees, elbows)
sk.set_hinge_angle("shin_l",0.5);// 0.5 radians ≈ 29°// Solve forward kinematics (MUST call after changing rotations)
sk.solve_forward();// Read world positionslet head_pos = sk.bone("head").world_position;let hand_pos = sk.bone("hand_r").world_end_position;
body.rasterize(&skeleton, grid_size, |x, y, z, mat, r, g, b| {set_voxel(x, y, z, mat, r, g, b);});
IK (Inverse Kinematics)
Two-Bone IK (legs, arms)
// Place left foot at target position, knee points forward
ik::apply_leg_ik(&mut skeleton,"thigh_l","shin_l",
foot_target,// Vec3: where foot should be
pole_target,// Vec3: direction knee should point);
skeleton.solve_forward();// update after IK
Aim IK
// Make head look at target
ik::aim_bone_at(&mut skeleton,"head", target_pos);// Turn entire body to face direction (smooth)
ik::turn_skeleton_to(&mut skeleton, target_pos,0.05);// 0.05 = turn speed
// Attach to entity
entity.attach(ak);// After entity.update(), get world positions:let(muzzle_pos, muzzle_dir) = entity.attachments[0].muzzle().unwrap();