summaryrefslogtreecommitdiff
path: root/client/src/scene_prepare.rs
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/scene_prepare.rs')
-rw-r--r--client/src/scene_prepare.rs44
1 files changed, 29 insertions, 15 deletions
diff --git a/client/src/scene_prepare.rs b/client/src/scene_prepare.rs
index 05e9533..4e57e77 100644
--- a/client/src/scene_prepare.rs
+++ b/client/src/scene_prepare.rs
@@ -15,8 +15,10 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::{
+ armature::{self, RArmature},
download::Downloader,
meshops::{generate_normals, generate_tangents, generate_texcoords},
+ scene_render::SceneBgLayouts,
};
use anyhow::Result;
use bytemuck::{Pod, Zeroable};
@@ -36,7 +38,7 @@ use std::{
use weareshared::{
Affine3A,
packets::Resource,
- resources::{Image, MeshPart, Prefab},
+ resources::{Armature, Image, MeshPart, Prefab},
};
use wgpu::{
AddressMode, BindGroup, BindGroupDescriptor, BindGroupEntry, BindGroupLayout, BindingResource,
@@ -87,8 +89,7 @@ impl<K: Hash + Eq + Clone, V: Clone> DemandMap<K, V> {
pub struct ScenePreparer {
device: Arc<Device>,
queue: Arc<Queue>,
- texture_bgl: BindGroupLayout,
- material_bgl: BindGroupLayout,
+ layouts: SceneBgLayouts,
textures: DemandMap<(Resource<Image<'static>>, bool), (Arc<Texture>, Arc<BindGroup>)>,
placeholder_textures: DemandMap<TextureIdentityKind, (Arc<Texture>, Arc<BindGroup>)>,
@@ -110,12 +111,14 @@ pub struct RMeshPart {
pub va_normal: Arc<Buffer>,
pub va_tangent: Arc<Buffer>,
pub va_texcoord: Arc<Buffer>,
- pub va_joint_index: Option<Arc<Buffer>>,
- pub va_joint_weight: Option<Arc<Buffer>>,
pub tex_albedo: Arc<BindGroup>,
pub tex_normal: Arc<BindGroup>,
pub material: Arc<BindGroup>,
pub double_sided: bool,
+
+ pub va_joint_index: Option<Arc<Buffer>>,
+ pub va_joint_weight: Option<Arc<Buffer>>,
+ pub joint_uniform: Option<Arc<Buffer>>,
}
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -154,17 +157,11 @@ struct Material {
}
impl ScenePreparer {
- pub fn new(
- device: Arc<Device>,
- queue: Arc<Queue>,
- texture_bgl: BindGroupLayout,
- material_bgl: BindGroupLayout,
- ) -> Self {
+ pub fn new(device: Arc<Device>, queue: Arc<Queue>, layouts: SceneBgLayouts) -> Self {
Self {
device,
queue,
- texture_bgl,
- material_bgl,
+ layouts,
index_buffers: DemandMap::new(),
vertex_buffers: DemandMap::new(),
mesh_parts: DemandMap::new(),
@@ -247,7 +244,7 @@ impl ScenePreparer {
let tex_bg = create_texture(
&self.device,
&self.queue,
- &self.texture_bgl,
+ &self.layouts.texture,
&image,
dims.0,
dims.1,
@@ -272,7 +269,7 @@ impl ScenePreparer {
let tex_bg = create_texture(
&self.device,
&self.queue,
- &self.texture_bgl,
+ &self.layouts.texture,
&color,
1,
1,
@@ -458,6 +455,12 @@ impl ScenePreparer {
}
});
+ let armature = if let Some(res) = part.armature.clone() {
+ Some(dls.try_get(res)?)
+ } else {
+ Some(None)
+ };
+
if let (
Some((index, index_count)),
Some(va_normal),
@@ -466,6 +469,7 @@ impl ScenePreparer {
Some(va_position),
Some(va_joint_index),
Some(va_joint_weight),
+ Some(armature),
Some(tex_normal),
Some(tex_albedo),
Some(material),
@@ -477,11 +481,20 @@ impl ScenePreparer {
position,
joint_index,
joint_weight,
+ armature,
tex_normal,
tex_albedo,
material,
) {
let double_sided = part.g_double_sided.is_some();
+
+ let joint_uniform = if let Some(a) = armature {
+ let ra = RArmature::new(&self.device, a);
+ Some(ra.joint_mat_uniform_buffer.clone())
+ } else {
+ None
+ };
+
debug!("part created (took {:?}) {pres}", start.elapsed());
self.mesh_parts.insert(
pres,
@@ -498,6 +511,7 @@ impl ScenePreparer {
tex_normal,
material,
double_sided,
+ joint_uniform,
}),
0,
);