@@ -24,7 +24,7 @@ const FSParams = graphics.FSDefaultUniforms;
2424const vertex_layout = getVertexLayout ();
2525
2626pub const MeshConfig = struct {
27- material : ? graphics.Material = null ,
27+ material : ? * graphics.Material = null ,
2828};
2929
3030pub fn init () ! void {
@@ -39,7 +39,7 @@ pub fn deinit() void {
3939/// These can be created on the fly, using a MeshBuilder, or loaded from GLTF files.
4040pub const Mesh = struct {
4141 bindings : graphics.Bindings = undefined ,
42- material : graphics.Material = undefined ,
42+ material : * graphics.Material = undefined ,
4343 bounds : boundingbox.BoundingBox = undefined ,
4444
4545 has_skin : bool = false ,
@@ -107,10 +107,12 @@ pub const Mesh = struct {
107107 }
108108 }
109109
110- var material : graphics.Material = undefined ;
110+ var material : * graphics.Material = undefined ;
111111 if (cfg .material == null ) {
112- const tex = graphics .createDebugTexture ();
113- material = graphics .Material .init (.{ .texture_0 = tex });
112+ // Todo: Use a backup material!
113+ debug .log ("No material in mesh config!" , .{});
114+ // const tex = graphics.createDebugTexture();
115+ // material = graphics.Material.init(.{ .texture_0 = tex });
114116 } else {
115117 material = cfg .material .? ;
116118 }
@@ -158,7 +160,7 @@ pub const Mesh = struct {
158160
159161 /// Draw this mesh
160162 pub fn draw (self : * Mesh , cam_matrices : CameraMatrices , model_matrix : math.Mat4 ) void {
161- graphics .drawWithMaterial (& self .bindings , & self .material , cam_matrices , model_matrix );
163+ graphics .drawWithMaterial (& self .bindings , self .material , cam_matrices , model_matrix );
162164 }
163165
164166 /// Draw this mesh, using the specified material instead of the set one
@@ -168,12 +170,12 @@ pub const Mesh = struct {
168170};
169171
170172/// Create a mesh out of some vertex data
171- pub fn createMesh (vertices : []PackedVertex , indices : []u32 , normals : [][3 ]f32 , tangents : [][4 ]f32 , material : graphics.Material ) Mesh {
173+ pub fn createMesh (vertices : []PackedVertex , indices : []u32 , normals : [][3 ]f32 , tangents : [][4 ]f32 , material : * graphics.Material ) Mesh {
172174 // create a mesh with the default vertex layout
173175 return createMeshWithLayout (vertices , indices , normals , tangents , material , vertex_layout );
174176}
175177
176- pub fn createSkinnedMesh (vertices : []PackedVertex , indices : []u32 , normals : [][3 ]f32 , tangents : [][4 ]f32 , joints : [][4 ]f32 , weights : [][4 ]f32 , material : graphics.Material , data : * zmesh.io.zcgltf.Data ) Mesh {
178+ pub fn createSkinnedMesh (vertices : []PackedVertex , indices : []u32 , normals : [][3 ]f32 , tangents : [][4 ]f32 , joints : [][4 ]f32 , weights : [][4 ]f32 , material : * graphics.Material , data : * zmesh.io.zcgltf.Data ) Mesh {
177179 // create a mesh with the default vertex layout
178180 // debug.log("Creating skinned mesh: {d} indices, {d} normals, {d}tangents, {d} joints, {d} weights", .{ indices.len, normals.len, tangents.len, joints.len, weights.len });
179181
@@ -199,7 +201,7 @@ pub fn createSkinnedMesh(vertices: []PackedVertex, indices: []u32, normals: [][3
199201}
200202
201203/// Create a mesh out of some vertex data with a given vertex layout
202- pub fn createMeshWithLayout (vertices : []PackedVertex , indices : []u32 , normals : [][3 ]f32 , tangents : [][4 ]f32 , material : graphics.Material , layout : graphics.VertexLayout ) Mesh {
204+ pub fn createMeshWithLayout (vertices : []PackedVertex , indices : []u32 , normals : [][3 ]f32 , tangents : [][4 ]f32 , material : * graphics.Material , layout : graphics.VertexLayout ) Mesh {
203205 // debug.log("Creating mesh: {d} indices", .{indices.len});
204206
205207 var bindings = graphics .Bindings .init (.{
@@ -219,7 +221,7 @@ pub fn createMeshWithLayout(vertices: []PackedVertex, indices: []u32, normals: [
219221}
220222
221223/// Creates a cube using a mesh builder
222- pub fn createCube (pos : Vec3 , size : Vec3 , color : Color , material : graphics.Material ) ! Mesh {
224+ pub fn createCube (pos : Vec3 , size : Vec3 , color : Color , material : * graphics.Material ) ! Mesh {
223225 var builder = MeshBuilder .init (mem .getAllocator ());
224226 defer builder .deinit ();
225227
@@ -466,7 +468,7 @@ pub const MeshBuilder = struct {
466468 }
467469
468470 /// Bakes a mesh out of the mesh builder from the current state
469- pub fn buildMesh (self : * const MeshBuilder , material : graphics.Material ) Mesh {
471+ pub fn buildMesh (self : * const MeshBuilder , material : * graphics.Material ) Mesh {
470472 const layout = getVertexLayout ();
471473 return createMeshWithLayout (self .vertices .items , self .indices .items , self .normals .items , self .tangents .items , material , layout );
472474 }
0 commit comments