summaryrefslogtreecommitdiff
path: root/client/src/armature.rs
blob: 1156071f7b1d2b8d6cdd21c55f7305bf59fa0387 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
    wearechat - generic multiplayer game with voip
    Copyright (C) 2025 metamuffin

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, version 3 of the License only.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/
use glam::Mat4;
use std::sync::Arc;
use weareshared::resources::ArmaturePart;
use wgpu::{Buffer, BufferDescriptor, BufferUsages, Device, Queue};

const MAX_JOINTS: usize = 128;
pub struct RArmature {
    pub joint_mat_uniform_buffer: Arc<Buffer>,
    joint_mat: Vec<Mat4>,
    _data: ArmaturePart,
}

impl RArmature {
    pub fn new(device: &Device, armature: ArmaturePart) -> Self {
        Self {
            joint_mat_uniform_buffer: Arc::new(device.create_buffer(&BufferDescriptor {
                label: Some("joint uniform"),
                size: (MAX_JOINTS * size_of::<f32>() * 16) as u64,
                usage: BufferUsages::COPY_DST | BufferUsages::UNIFORM,
                mapped_at_creation: false,
            })),
            _data: armature,
            joint_mat: vec![],
        }
    }
    pub fn update(&mut self) {
        self.joint_mat.fill(Mat4::IDENTITY);
    }
    pub fn write_uniform(&self, queue: &Queue) {
        queue.write_buffer(
            &self.joint_mat_uniform_buffer,
            0,
            bytemuck::cast_slice(self.joint_mat.as_slice()),
        );
    }
}