pbrt/src/shapes/sphere.rs

37 lines
1.2 KiB
Rust

use crate::core::shape::CreateShape;
use crate::core::texture::FloatTexture;
use crate::utils::{Arena, FileLoc, ParameterDictionary};
use anyhow::Result;
use shared::core::shape::Shape;
use shared::shapes::SphereShape;
use shared::utils::Transform;
use std::collections::HashMap;
use std::sync::Arc;
impl CreateShape for SphereShape {
fn create(
render_from_object: Transform,
object_from_render: Transform,
reverse_orientation: bool,
parameters: ParameterDictionary,
_float_textures: &HashMap<String, Arc<FloatTexture>>,
_loc: FileLoc,
arena: &Arena,
) -> Result<Vec<Shape>> {
let radius = parameters.get_one_float("radius", 1.)?;
let zmin = parameters.get_one_float("zmin", -radius)?;
let zmax = parameters.get_one_float("zmax", radius)?;
let phimax = parameters.get_one_float("phimax", 360.)?;
let shape = SphereShape::new(
render_from_object,
object_from_render,
reverse_orientation,
radius,
zmin,
zmax,
phimax,
);
arena.alloc(vec![Shape::Sphere(shape)]);
Ok(vec![Shape::Sphere(shape)])
}
}