From d81eebe423fd3e00df5ff035ec24fe7fb37f2c62 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 7 Jan 2025 12:25:37 +0100 Subject: albedo texture works --- world/src/main.rs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'world/src/main.rs') diff --git a/world/src/main.rs b/world/src/main.rs index 033d176..7bcd021 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -1,6 +1,7 @@ #![feature(iter_array_chunks)] use anyhow::Result; use clap::Parser; +use log::info; use rand::random; use std::{ io::Write, @@ -12,7 +13,7 @@ use std::{ use weareshared::{ Affine3A, Vec3A, packets::{Data, Object, Packet, ReadWrite}, - resources::{Attribute, AttributeArray, IndexArray, Part, Prefab}, + resources::{AttributeArray, IndexArray, Part, Prefab}, store::ResourceStore, vec3a, }; @@ -73,38 +74,34 @@ fn main() -> Result<()> { .array_chunks::<3>() .collect::>(); - let mut albedo = None; + let mut tex_pbr_albedo = None; if let Some(tex) = p.material().pbr_metallic_roughness().base_color_texture() { let s = tex.texture().source().source(); if let gltf::image::Source::View { view, mime_type } = s { - let buf = &buffers[view.buffer().index()]; - albedo = Some(store.set(&buf.0)?); + info!("albedo texture is of type {mime_type:?}"); + let buf = &buffers[view.buffer().index()].0 + [view.offset()..view.offset() + view.length()]; + tex_pbr_albedo = Some(store.set(buf)?); } } let part = store.set( &Part { va_position: Some([ - Attribute::Vertex(store.set(&AttributeArray(pos_x).write_alloc())?), - Attribute::Vertex(store.set(&AttributeArray(pos_y).write_alloc())?), - Attribute::Vertex(store.set(&AttributeArray(pos_z).write_alloc())?), + store.set(&AttributeArray(pos_x).write_alloc())?, + store.set(&AttributeArray(pos_y).write_alloc())?, + store.set(&AttributeArray(pos_z).write_alloc())?, ]), va_normal: Some([ - Attribute::Vertex(store.set(&AttributeArray(norm_x).write_alloc())?), - Attribute::Vertex(store.set(&AttributeArray(norm_y).write_alloc())?), - Attribute::Vertex(store.set(&AttributeArray(norm_z).write_alloc())?), + store.set(&AttributeArray(norm_x).write_alloc())?, + store.set(&AttributeArray(norm_y).write_alloc())?, + store.set(&AttributeArray(norm_z).write_alloc())?, ]), va_texcoord: Some([ - Attribute::Vertex(store.set(&AttributeArray(uv_x).write_alloc())?), - Attribute::Vertex(store.set(&AttributeArray(uv_y).write_alloc())?), + store.set(&AttributeArray(uv_x).write_alloc())?, + store.set(&AttributeArray(uv_y).write_alloc())?, ]), - va_pbr_albedo: albedo.map(|a| { - [ - Attribute::Texture(a, 0), - Attribute::Texture(a, 1), - Attribute::Texture(a, 2), - ] - }), + tex_pbr_albedo, index: Some(store.set(&IndexArray(index).write_alloc())?), ..Part::default() } -- cgit v1.2.3-70-g09d2