Use From
This commit is contained in:
parent
676fb20ad4
commit
12159dd0b5
|
|
@ -41,6 +41,19 @@ struct SphereData {
|
||||||
glossiness: f32,
|
glossiness: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&Sphere> for SphereData {
|
||||||
|
fn from(s: &Sphere) -> Self {
|
||||||
|
SphereData {
|
||||||
|
center: s.center,
|
||||||
|
radius: s.radius,
|
||||||
|
emit_color: s.emit_color,
|
||||||
|
pad1: 0.0,
|
||||||
|
reflect_color: s.reflect_color,
|
||||||
|
glossiness: s.glossiness,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Tracer {
|
pub struct Tracer {
|
||||||
view_buf: wgpu::Buffer,
|
view_buf: wgpu::Buffer,
|
||||||
pipeline: wgpu::RenderPipeline,
|
pipeline: wgpu::RenderPipeline,
|
||||||
|
|
@ -192,17 +205,7 @@ impl Tracer {
|
||||||
|
|
||||||
impl TracerData {
|
impl TracerData {
|
||||||
pub fn new(device: &wgpu::Device, tracer: &Tracer, spheres: &[Sphere]) -> Self {
|
pub fn new(device: &wgpu::Device, tracer: &Tracer, spheres: &[Sphere]) -> Self {
|
||||||
let spheres: Vec<_> = spheres
|
let spheres: Vec<_> = spheres.iter().map(SphereData::from).collect();
|
||||||
.iter()
|
|
||||||
.map(|s| SphereData {
|
|
||||||
center: s.center,
|
|
||||||
radius: s.radius,
|
|
||||||
emit_color: s.emit_color,
|
|
||||||
pad1: 0.0,
|
|
||||||
reflect_color: s.reflect_color,
|
|
||||||
glossiness: s.glossiness,
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let spheres_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
let spheres_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
contents: cast_slice(&spheres),
|
contents: cast_slice(&spheres),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user