internal static void RenderLandentries(this LandEntryRenderBatch geometry, Material material, RenderingBridge renderingBridge) { foreach (var g in geometry) { foreach (var t in g.Value) { BufferMesh m = t.Key; material.BufferMaterial = m.Material; material.BufferMaterial = m.Material; renderingBridge.RenderMesh(m, t.Value); } } }
public abstract void RenderMesh(BufferMesh mesh, List <RenderMatrices> matrices);
private static (AttachHelper.VertexWeights[] vertices, BufferMesh[] polydata) FromWeight(Mesh mesh) { List <AttachHelper.VertexWeights> vertices = new(); List <int> offsets = new(); int offset = 0; foreach (var primitive in mesh.Primitives) { // read vertices primitive.VertexAccessors.TryGetValue("POSITION", out Accessor positions); primitive.VertexAccessors.TryGetValue("NORMAL", out Accessor normals); primitive.VertexAccessors.TryGetValue("WEIGHTS_0", out Accessor weights); primitive.VertexAccessors.TryGetValue("JOINTS_0", out Accessor joints); var positionArray = positions.AsVector3Array(); var normalArray = normals?.AsVector3Array(); var weightsArray = weights.AsVector4Array(); var jointsArray = joints.AsVector4Array(); int vertCount = positionArray.Count; for (int i = 0; i < vertCount; i++) { // position var pos = positionArray[i]; // normal (may be null) var nrm = normalArray?[i] ?? Vector3.UnitY; var joint = jointsArray[i]; var weight = weightsArray[i]; List <(int, float)> skinning = new(); if (weight.X > 0) { skinning.Add(((int)joint.X, weight.X)); } if (weight.Y > 0) { skinning.Add(((int)joint.Y, weight.Y)); } if (weight.Z > 0) { skinning.Add(((int)joint.Z, weight.Z)); } if (weight.W > 0) { skinning.Add(((int)joint.W, weight.W)); } vertices.Add(new(pos, nrm, skinning.ToArray())); } offsets.Add(offset); offset += positionArray.Count; } // first, lets put the poly meshes together BufferMesh[] polyMeshes = new BufferMesh[mesh.Primitives.Count]; int offsetIndex = 0; foreach (var primitive in mesh.Primitives) { // getting positions again to get corner count var positions = primitive.VertexAccessors["POSITION"]; // read corners primitive.VertexAccessors.TryGetValue("TEXCOORD_0", out Accessor uvs); primitive.VertexAccessors.TryGetValue("COLOR_0", out Accessor colors); var uvArray = uvs?.AsVector2Array(); var colorArray = colors?.AsColorArray(); BufferCorner[] corners = new BufferCorner[positions.Count]; for (int i = 0; i < corners.Length; i++) { Vector2 uv = uvArray?[i] ?? default; Vector4 col = colorArray?[i] ?? Vector4.UnitW; corners[i] = new((ushort)i, new(col.X, col.Y, col.Z, col.W), uv); } // Read indices uint[] indices = GetIndices(primitive.IndexAccessor, positions.Count, primitive.DrawPrimitiveType); ushort vertexReadOffset = (ushort)offsets[offsetIndex]; polyMeshes[offsetIndex] = new(corners, indices, GetMaterial(primitive.Material), vertexReadOffset); offsetIndex++; } return(vertices.ToArray(), polyMeshes); }